From a86214275a3010927c1fd7e9c3b5df7d5f6f9d19 Mon Sep 17 00:00:00 2001 From: unfa Date: Mon, 5 Apr 2021 04:14:09 +0200 Subject: [PATCH] Fixed dead resource references in Character scenes, also added layered sound effect playback to Weapon.tscn --- .../SFX/Weapons_Handun_Shot_01_A.wav.import | 21 +++ .../SFX/Weapons_Handun_Shot_01_B.wav.import | 21 +++ .../SFX/Weapons_Handun_Shot_01_C.wav.import | 21 +++ .../SFX/Weapons_Handun_Shot_02_A.wav.import | 21 +++ .../SFX/Weapons_Handun_Shot_02_B.wav.import | 21 +++ .../SFX/Weapons_Handun_Shot_02_C.wav.import | 21 +++ .../SFX/Weapons_Handun_Shot_03_A.wav.import | 21 +++ .../SFX/Weapons_Handun_Shot_03_B.wav.import | 21 +++ .../SFX/Weapons_Handun_Shot_03_C.wav.import | 21 +++ Game/Assets/Characters/Default/Default.tscn | 4 +- .../HerMajestyTheQueen.tscn | 14 +- .../Characters/SmartFridge/SmartFridge.tscn | 11 +- Game/Assets/Weapons/Handgun/Handgun.tscn | 37 +++-- Game/Classes/Audio/LayeredSoundPlayer.gd | 21 +++ Game/Classes/Audio/SoundPlayer.gd | 2 +- Game/Classes/Player/Player.tscn | 4 +- Game/Classes/Weapon/Weapon.gd | 153 ++++++++++++++++++ Game/Classes/Weapon/Weapon.tscn | 82 ++++++++++ 18 files changed, 486 insertions(+), 31 deletions(-) create mode 100644 Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_A.wav.import create mode 100644 Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_B.wav.import create mode 100644 Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_C.wav.import create mode 100644 Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_A.wav.import create mode 100644 Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_B.wav.import create mode 100644 Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_C.wav.import create mode 100644 Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_A.wav.import create mode 100644 Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_B.wav.import create mode 100644 Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_C.wav.import create mode 100644 Game/Classes/Audio/LayeredSoundPlayer.gd create mode 100644 Game/Classes/Weapon/Weapon.gd create mode 100644 Game/Classes/Weapon/Weapon.tscn diff --git a/Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_A.wav.import b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_A.wav.import new file mode 100644 index 0000000..d91dc3f --- /dev/null +++ b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_A.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/Weapons_Handun_Shot_01_A.wav-b5049ef4e85c0808d916a354169d81be.sample" + +[deps] + +source_file="res://Assets/Audio/SFX/Weapons_Handun_Shot_01_A.wav" +dest_files=[ "res://.import/Weapons_Handun_Shot_01_A.wav-b5049ef4e85c0808d916a354169d81be.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop=false +compress/mode=0 diff --git a/Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_B.wav.import b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_B.wav.import new file mode 100644 index 0000000..820edc2 --- /dev/null +++ b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_B.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/Weapons_Handun_Shot_01_B.wav-91e94d7b9c40af17e0b85445c3cd4794.sample" + +[deps] + +source_file="res://Assets/Audio/SFX/Weapons_Handun_Shot_01_B.wav" +dest_files=[ "res://.import/Weapons_Handun_Shot_01_B.wav-91e94d7b9c40af17e0b85445c3cd4794.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop=false +compress/mode=0 diff --git a/Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_C.wav.import b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_C.wav.import new file mode 100644 index 0000000..4d64c6a --- /dev/null +++ b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_01_C.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/Weapons_Handun_Shot_01_C.wav-5bd4324dcd7f9d7616ebe5cd03928aa4.sample" + +[deps] + +source_file="res://Assets/Audio/SFX/Weapons_Handun_Shot_01_C.wav" +dest_files=[ "res://.import/Weapons_Handun_Shot_01_C.wav-5bd4324dcd7f9d7616ebe5cd03928aa4.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop=false +compress/mode=0 diff --git a/Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_A.wav.import b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_A.wav.import new file mode 100644 index 0000000..a4394db --- /dev/null +++ b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_A.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/Weapons_Handun_Shot_02_A.wav-59af1bc71ddcc00f6f73dc8b1cc905dc.sample" + +[deps] + +source_file="res://Assets/Audio/SFX/Weapons_Handun_Shot_02_A.wav" +dest_files=[ "res://.import/Weapons_Handun_Shot_02_A.wav-59af1bc71ddcc00f6f73dc8b1cc905dc.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop=false +compress/mode=0 diff --git a/Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_B.wav.import b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_B.wav.import new file mode 100644 index 0000000..915b31c --- /dev/null +++ b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_B.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/Weapons_Handun_Shot_02_B.wav-6db638e923eff625fc24be7746e3cbf9.sample" + +[deps] + +source_file="res://Assets/Audio/SFX/Weapons_Handun_Shot_02_B.wav" +dest_files=[ "res://.import/Weapons_Handun_Shot_02_B.wav-6db638e923eff625fc24be7746e3cbf9.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop=false +compress/mode=0 diff --git a/Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_C.wav.import b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_C.wav.import new file mode 100644 index 0000000..5d4a3c5 --- /dev/null +++ b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_02_C.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/Weapons_Handun_Shot_02_C.wav-7976192c394ee6f94fbbf58e48ecf770.sample" + +[deps] + +source_file="res://Assets/Audio/SFX/Weapons_Handun_Shot_02_C.wav" +dest_files=[ "res://.import/Weapons_Handun_Shot_02_C.wav-7976192c394ee6f94fbbf58e48ecf770.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop=false +compress/mode=0 diff --git a/Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_A.wav.import b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_A.wav.import new file mode 100644 index 0000000..24337f1 --- /dev/null +++ b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_A.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/Weapons_Handun_Shot_03_A.wav-8995aec4a701c64d2659a79326402ecb.sample" + +[deps] + +source_file="res://Assets/Audio/SFX/Weapons_Handun_Shot_03_A.wav" +dest_files=[ "res://.import/Weapons_Handun_Shot_03_A.wav-8995aec4a701c64d2659a79326402ecb.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop=false +compress/mode=0 diff --git a/Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_B.wav.import b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_B.wav.import new file mode 100644 index 0000000..9096377 --- /dev/null +++ b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_B.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/Weapons_Handun_Shot_03_B.wav-0ec5401d1dee25f9fe11ace2be944c05.sample" + +[deps] + +source_file="res://Assets/Audio/SFX/Weapons_Handun_Shot_03_B.wav" +dest_files=[ "res://.import/Weapons_Handun_Shot_03_B.wav-0ec5401d1dee25f9fe11ace2be944c05.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop=false +compress/mode=0 diff --git a/Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_C.wav.import b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_C.wav.import new file mode 100644 index 0000000..0f93524 --- /dev/null +++ b/Game/Assets/Audio/SFX/Weapons_Handun_Shot_03_C.wav.import @@ -0,0 +1,21 @@ +[remap] + +importer="wav" +type="AudioStreamSample" +path="res://.import/Weapons_Handun_Shot_03_C.wav-3e9fd58bf53f5166e71559cd82c6c971.sample" + +[deps] + +source_file="res://Assets/Audio/SFX/Weapons_Handun_Shot_03_C.wav" +dest_files=[ "res://.import/Weapons_Handun_Shot_03_C.wav-3e9fd58bf53f5166e71559cd82c6c971.sample" ] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop=false +compress/mode=0 diff --git a/Game/Assets/Characters/Default/Default.tscn b/Game/Assets/Characters/Default/Default.tscn index 3fa382e..34dda02 100644 --- a/Game/Assets/Characters/Default/Default.tscn +++ b/Game/Assets/Characters/Default/Default.tscn @@ -14,12 +14,12 @@ script = ExtResource( 2 ) max_health = 90 [node name="Hand" parent="Camera" index="0"] -transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.395602, -0.559 ) +transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.396491, -0.559 ) [node name="WeaponBobAnimationTree" parent="Camera/Hand" index="0"] parameters/playback = SubResource( 1 ) [node name="MeshInstance" type="MeshInstance" parent="." index="6"] -transform = Transform( 1, 0, 0, 0, -0.00441578, -0.99999, 0, 0.99999, -0.00441578, 0, 0.883, 0 ) +transform = Transform( 1, 0, 0, 0, -0.00441578, -0.99999, 0, 0.99999, -0.00441578, 0, 0.888784, 0 ) mesh = SubResource( 2 ) material/0 = null diff --git a/Game/Assets/Characters/HerMajestyTheQueen/HerMajestyTheQueen.tscn b/Game/Assets/Characters/HerMajestyTheQueen/HerMajestyTheQueen.tscn index f0ef713..0f5caef 100644 --- a/Game/Assets/Characters/HerMajestyTheQueen/HerMajestyTheQueen.tscn +++ b/Game/Assets/Characters/HerMajestyTheQueen/HerMajestyTheQueen.tscn @@ -1,11 +1,13 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://Classes/Player/Player.tscn" type="PackedScene" id=1] [ext_resource path="res://Assets/Characters/HerMajestyTheQueen/HerMajestyTheQueen.gd" type="Script" id=2] [ext_resource path="res://Assets/Characters/HerMajestyTheQueen/Throne/Throne.gltf" type="PackedScene" id=3] [ext_resource path="res://Assets/Characters/HerMajestyTheQueen/RoyalGuard/RoyalGuard.tscn" type="PackedScene" id=4] -[sub_resource type="CapsuleShape" id=1] +[sub_resource type="AnimationNodeStateMachinePlayback" id=1] + +[sub_resource type="CapsuleShape" id=2] radius = 1.2 height = 0.6 @@ -15,12 +17,18 @@ script = ExtResource( 2 ) [node name="Camera" parent="." index="0"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.52414, -0.0651628 ) +[node name="Hand" parent="Camera" index="0"] +transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.399838, -0.559 ) + +[node name="WeaponBobAnimationTree" parent="Camera/Hand" index="0"] +parameters/playback = SubResource( 1 ) + [node name="Billboard" parent="." index="1"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.27203, 0 ) [node name="CollisionShapeBody" parent="." index="2"] transform = Transform( 1, 0, 0, 0, -1.62921e-07, 1, 0, -1, -1.62921e-07, 0, 1.5, 0 ) -shape = SubResource( 1 ) +shape = SubResource( 2 ) [node name="Throne" parent="." index="6" instance=ExtResource( 3 )] transform = Transform( -1, 0, -3.25841e-07, 0, 1, 0, 3.25841e-07, 0, -1, 0, 0.989432, 0 ) diff --git a/Game/Assets/Characters/SmartFridge/SmartFridge.tscn b/Game/Assets/Characters/SmartFridge/SmartFridge.tscn index b8367c0..658bdce 100644 --- a/Game/Assets/Characters/SmartFridge/SmartFridge.tscn +++ b/Game/Assets/Characters/SmartFridge/SmartFridge.tscn @@ -1,10 +1,8 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://Classes/Player/Player.tscn" type="PackedScene" id=1] [ext_resource path="res://Assets/Characters/SmartFridge/SmartFridge.gltf" type="PackedScene" id=2] [ext_resource path="res://Assets/Characters/SmartFridge/SmartFridge.gd" type="Script" id=3] -[ext_resource path="res://Assets/Audio/SFX/Ambient_Pipes.wav" type="AudioStream" id=4] - [sub_resource type="AnimationNodeStateMachinePlayback" id=1] @@ -15,7 +13,7 @@ extents = Vector3( 0.497026, 0.468212, 1 ) script = ExtResource( 3 ) [node name="Hand" parent="Camera" index="0"] -transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.390004, -0.559 ) +transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.398653, -0.559 ) [node name="WeaponBobAnimationTree" parent="Camera/Hand" index="0"] parameters/playback = SubResource( 1 ) @@ -24,12 +22,7 @@ parameters/playback = SubResource( 1 ) transform = Transform( 1, 0, 0, 0, -1.62921e-07, 1, 0, -1, -1.62921e-07, 0, 0.997194, 0.228745 ) shape = SubResource( 2 ) -[node name="Ambient" parent="Sounds" index="5"] -stream = ExtResource( 4 ) - [node name="SmartFridge" parent="." index="6" instance=ExtResource( 2 )] transform = Transform( -1, 0, -3.25841e-07, 0, 1, 0, 3.25841e-07, 0, -1, 0, 0, 0.313989 ) -[editable path="Camera/Hand/Weapon"] -[editable path="Camera/Hand/Weapon/Handgun"] [editable path="SmartFridge"] diff --git a/Game/Assets/Weapons/Handgun/Handgun.tscn b/Game/Assets/Weapons/Handgun/Handgun.tscn index a29b259..ee0dabb 100644 --- a/Game/Assets/Weapons/Handgun/Handgun.tscn +++ b/Game/Assets/Weapons/Handgun/Handgun.tscn @@ -1,11 +1,12 @@ -[gd_scene load_steps=14 format=2] +[gd_scene load_steps=15 format=2] [ext_resource path="res://Assets/Weapons/Handgun/Handgun.gltf" type="PackedScene" id=1] [ext_resource path="res://Classes/Weapon/Weapon.gd" type="Script" id=2] -[ext_resource path="res://Assets/Audio/SFX/Weapons_Handun_Shot.wav" type="AudioStream" id=3] +[ext_resource path="res://Classes/Audio/LayeredSoundPlayer.gd" type="Script" id=3] [ext_resource path="res://Assets/Effects/CircleSoft.svg" type="Texture" id=4] [ext_resource path="res://Assets/Audio/SFX/Weapons-Empty.wav" type="AudioStream" id=5] [ext_resource path="res://Assets/Audio/SFX/Weapons-Handgun-Reload.wav" type="AudioStream" id=6] +[ext_resource path="res://Classes/Audio/SoundPlayer.tscn" type="PackedScene" id=7] [sub_resource type="Gradient" id=1] offsets = PoolRealArray( 0, 0.0511628, 0.0883721, 0.302326, 1 ) @@ -73,20 +74,28 @@ transform = Transform( -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0, 1, -0.0373 [node name="Sounds" type="Spatial" parent="."] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.295478, 0.724833, 0.584699 ) -[node name="SoundShoot" type="AudioStreamPlayer3D" parent="Sounds"] -transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0 ) -stream = ExtResource( 3 ) -attenuation_model = 3 -unit_db = 3.0 -unit_size = 25.0 -emission_angle_enabled = true -emission_angle_degrees = 60.0 -attenuation_filter_cutoff_hz = 15000.0 - -[node name="SoundEmpty" type="AudioStreamPlayer3D" parent="Sounds"] +[node name="Empty" type="AudioStreamPlayer3D" parent="Sounds"] stream = ExtResource( 5 ) -[node name="SoundReload" type="AudioStreamPlayer3D" parent="Sounds"] +[node name="Reload" type="AudioStreamPlayer3D" parent="Sounds"] stream = ExtResource( 6 ) +[node name="Shoot" type="Spatial" parent="Sounds"] +script = ExtResource( 3 ) + +[node name="A" type="Spatial" parent="Sounds/Shoot"] + +[node name="SoundPlayer" parent="Sounds/Shoot/A" instance=ExtResource( 7 )] +SoundClip = "res://Assets/Audio/SFX/Weapons_Handun_Shot_01_A.wav" + +[node name="B" type="Spatial" parent="Sounds/Shoot"] + +[node name="SoundPlayer" parent="Sounds/Shoot/B" instance=ExtResource( 7 )] +SoundClip = "res://Assets/Audio/SFX/Weapons_Handun_Shot_01_B.wav" + +[node name="C" type="Spatial" parent="Sounds/Shoot"] + +[node name="SoundPlayer" parent="Sounds/Shoot/C" instance=ExtResource( 7 )] +SoundClip = "res://Assets/Audio/SFX/Weapons_Handun_Shot_01_C.wav" + [editable path="Handgun"] diff --git a/Game/Classes/Audio/LayeredSoundPlayer.gd b/Game/Classes/Audio/LayeredSoundPlayer.gd new file mode 100644 index 0000000..257adcf --- /dev/null +++ b/Game/Classes/Audio/LayeredSoundPlayer.gd @@ -0,0 +1,21 @@ +extends Spatial + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + + +func play(): + $A/SoundPlayer.play() + $B/SoundPlayer.play() + $C/SoundPlayer.play() + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/Game/Classes/Audio/SoundPlayer.gd b/Game/Classes/Audio/SoundPlayer.gd index 86195bb..37419bc 100644 --- a/Game/Classes/Audio/SoundPlayer.gd +++ b/Game/Classes/Audio/SoundPlayer.gd @@ -6,7 +6,7 @@ const SFX_dir = "res://Assets/Audio/SFX/" # all sound clips must reside somewher onready var player = $AudioStreamPlayer3D # playback backend -export(String, FILE, "*-01.wav") var SoundClip = SFX_dir + "Test-01.wav" +export(String, FILE, "*_01*.wav") var SoundClip = SFX_dir + "Test-01.wav" export(bool) var AutoPlay = false export(float) var MinimumRandomDistance = 0.35 # gives optimal playback repetition for sound clip groups of different sizes. export(bool) var PlayUntilEnd = false # determines if the play() function is allowed to sop a previously started sound diff --git a/Game/Classes/Player/Player.tscn b/Game/Classes/Player/Player.tscn index c0d1121..fd98f67 100644 --- a/Game/Classes/Player/Player.tscn +++ b/Game/Classes/Player/Player.tscn @@ -9,7 +9,7 @@ [ext_resource path="res://Assets/UI/HUD.tscn" type="PackedScene" id=7] [ext_resource path="res://Classes/Player/Player.gd" type="Script" id=8] [ext_resource path="res://Classes/Player/WeaponsManager.gd" type="Script" id=9] -[ext_resource path="res://Assets/Weapons/GrenadeLauncher/GranadeLauncher.tscn" type="PackedScene" id=10] +[ext_resource path="res://Assets/Weapons/GrenadeLauncher/GrenadeLauncher.tscn" type="PackedScene" id=10] [ext_resource path="res://Assets/Effects/CircleSoft.svg" type="Texture" id=11] [ext_resource path="res://Assets/Maps/DM1/OmniFlicker.gd" type="Script" id=12] @@ -220,7 +220,7 @@ script = ExtResource( 8 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.53592, -0.0651628 ) [node name="Hand" type="Spatial" parent="Camera"] -transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.394059, -0.559 ) +transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.335, -0.39248, -0.559 ) [node name="WeaponBobAnimationTree" type="AnimationTree" parent="Camera/Hand"] tree_root = SubResource( 12 ) diff --git a/Game/Classes/Weapon/Weapon.gd b/Game/Classes/Weapon/Weapon.gd new file mode 100644 index 0000000..fc72621 --- /dev/null +++ b/Game/Classes/Weapon/Weapon.gd @@ -0,0 +1,153 @@ +extends Spatial + +signal damage_dealt +signal ammo_changed(type, amount) + +export(bool) var Hitscan = false +export(int) var Damage = 100 +export(float) var Delay = 0.1 +export(bool) var Automatic = false +export(int) var Rounds = 10 +export(int) var MaxRoundsInClip = 10 +export(int) var Clips = 1 +export(int) var MaxClips = 4 + +onready var camera = get_parent().get_parent().get_parent() +onready var player = camera.get_parent() + +onready var ejector = find_node("Ejector") +onready var muzzle = find_node("Muzzle") + +onready var current_rounds = Rounds + +var currently_fireing = false +var cached_fire = false + +#onready var sound_shoot = $SoundShoot + +var casing = preload("res://Assets/Weapons/Handgun/Casing.tscn") +var tracer = preload("res://Assets/Effects/BulletTracer.tscn") + +func _ready(): + $Sounds.global_transform.origin = camera.global_transform.origin + +func shoot(camera): + if cached_fire == true: + return + + if currently_fireing == true: + cached_fire = true + yield($Handgun/AnimationPlayer, "animation_finished") + + # TODO: mutexes + currently_fireing = true + cached_fire = false + + if current_rounds > 0: + rpc("fire_weapon", current_rounds) + rpc("compute_bullet_flyby") + + current_rounds -= 1 + emit_signal("ammo_changed", "handgun", current_rounds) + + var space_state = get_world().direct_space_state + + var crosshair_pos = get_viewport().size / 2 + + var from = camera.project_ray_origin(crosshair_pos) + var to = from + camera.project_ray_normal(crosshair_pos) * 1000 + + var result = space_state.intersect_ray(from, to) + + if "collider" in result: + var hit = result.collider + + if hit.has_method("on_hit"): + hit.rpc("on_hit", 30, result.position) + + if hit is Player: + emit_signal("damage_dealt") + print(player.get_network_master()) + else: + reload() + + return current_rounds + +sync func fire_weapon(var rounds_left): + show_muzzle_flash(rounds_left) + show_tracer() + spawn_casing() + yield($Handgun/AnimationPlayer, "animation_finished") + + if !cached_fire: + currently_fireing = false + +sync func dry_fire(): + pass + +func show_muzzle_flash(var rounds_left): + $Handgun/AnimationPlayer.stop() + + if rounds_left == 1: + $Handgun/AnimationPlayer.play("Empty", -1, 2) + else: + $Handgun/AnimationPlayer.play("Shoot", -1, 2) + + $MuzzleFlash.emitting = true + yield(get_tree().create_timer(0.07),"timeout") + $MuzzleFlash.emitting = false + + $Sounds/Shoot.play() + +func show_tracer(): + var tracer_instance = tracer.instance() + tracer_instance.hide() + tracer_instance.global_transform = muzzle.global_transform + + get_tree().root.call_deferred("add_child", tracer_instance) + tracer_instance.call_deferred("show") + +func spawn_casing(): + #while [ true ]: + #var casing_instance = load("res://Assets/Weapons/Handgun/Casing.tscn").instance() + var casing_instance = casing.instance() + casing_instance.global_transform = ejector.global_transform + + casing_instance.rotate_object_local(Vector3.FORWARD, deg2rad(90)) + + casing_instance.angular_velocity = - ejector.global_transform.basis[2] * rand_range(23, 37) + casing_instance.linear_velocity = ejector.global_transform.basis[0] * rand_range(3.2, 4.5) - ejector.global_transform.basis[2] * rand_range(2.6, 3.7) + + get_tree().root.call_deferred("add_child", casing_instance) + + #yield(get_tree().create_timer(1),"timeout") + + +remote func compute_bullet_flyby(): + var local_player = get_tree().root.get_node("Game").local_player + var transform = find_node("Muzzle").global_transform + + var from = global_transform.xform(Vector3()) + var to = global_transform.xform(Vector3(-1000, 0, 0)) + + if local_player: + local_player.on_bullet_flyby(from, to) + +func reload(): + rpc("play_reload_animation") + + currently_fireing = true + cached_fire = false + + yield($Handgun/AnimationPlayer, "animation_finished") + + if not cached_fire: + currently_fireing = false + + current_rounds = Rounds + + emit_signal("ammo_changed", "handgun", current_rounds) + +sync func play_reload_animation(): + $Handgun/AnimationPlayer.play("Reload", 0.5, 1) + $Sounds/Reload.play() diff --git a/Game/Classes/Weapon/Weapon.tscn b/Game/Classes/Weapon/Weapon.tscn new file mode 100644 index 0000000..9da04a9 --- /dev/null +++ b/Game/Classes/Weapon/Weapon.tscn @@ -0,0 +1,82 @@ +[gd_scene load_steps=12 format=2] + +[ext_resource path="res://Assets/Weapons/Handgun/Handgun.gltf" type="PackedScene" id=1] +[ext_resource path="res://Classes/Weapon/Weapon.gd" type="Script" id=2] +[ext_resource path="res://Assets/Audio/SFX/Weapons_Handun_Shot_01_A.wav" type="AudioStream" id=3] +[ext_resource path="res://Assets/Effects/CircleSoft.svg" type="Texture" id=4] + +[sub_resource type="Gradient" id=1] +offsets = PoolRealArray( 0, 0.0511628, 0.0883721, 0.302326, 1 ) +colors = PoolColorArray( 0, 0, 0, 1, 2, 2, 2, 1, 0.901961, 0.866667, 0.576471, 1, 0.909804, 0.592157, 0.168627, 1, 0, 0, 0, 1 ) + +[sub_resource type="GradientTexture" id=2] +gradient = SubResource( 1 ) + +[sub_resource type="Curve" id=3] +_data = [ Vector2( 0, 0.986364 ), 0.0, -0.872434, 0, 0, Vector2( 0.092437, 0.752585 ), 0.0, 0.0, 0, 0, Vector2( 1, 0.198039 ), -0.85103, 0.0, 0, 0 ] + +[sub_resource type="CurveTexture" id=4] +curve = SubResource( 3 ) + +[sub_resource type="ParticlesMaterial" id=5] +direction = Vector3( 0, 0, -5 ) +spread = 15.0 +gravity = Vector3( 0, 0, 0 ) +initial_velocity = 8.0 +initial_velocity_random = 0.75 +damping = 100.0 +damping_random = 0.5 +scale_random = 1.0 +scale_curve = SubResource( 4 ) +color_ramp = SubResource( 2 ) + +[sub_resource type="SpatialMaterial" id=6] +flags_transparent = true +flags_unshaded = true +vertex_color_use_as_albedo = true +params_blend_mode = 1 +params_billboard_mode = 3 +particles_anim_h_frames = 1 +particles_anim_v_frames = 1 +particles_anim_loop = false +albedo_texture = ExtResource( 4 ) + +[sub_resource type="QuadMesh" id=7] +material = SubResource( 6 ) +size = Vector2( 0.3, 0.3 ) + +[node name="Weapon" type="Spatial"] +script = ExtResource( 2 ) + +[node name="MuzzleFlash" type="Particles" parent="."] +transform = Transform( -4.37113e-08, 0, 0.999999, 0, 0.999999, 0, -1, 0, -4.37114e-08, -0.3053, 0.124057, 0 ) +cast_shadow = 0 +emitting = false +amount = 16 +lifetime = 0.1 +one_shot = true +explosiveness = 1.0 +visibility_aabb = AABB( -0.176241, -0.185755, -0.556571, 0.352482, 0.37151, 0.655134 ) +process_material = SubResource( 5 ) +draw_pass_1 = SubResource( 7 ) + +[node name="Handgun" parent="." instance=ExtResource( 1 )] + +[node name="Muzzle" parent="Handgun" index="0"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.331868, 0.125291, 0 ) + +[node name="Ejector" parent="Handgun" index="1"] +transform = Transform( -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0, 1, -0.0373496, 0.126382, -0.00737098 ) + +[node name="Sounds" type="Spatial" parent="."] +transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0.63089, 0.616708, 0.43745 ) + +[node name="SoundShoot" type="AudioStreamPlayer3D" parent="Sounds"] +stream = ExtResource( 3 ) +unit_db = 4.0 +unit_size = 25.0 +emission_angle_enabled = true +emission_angle_degrees = 60.0 +attenuation_filter_cutoff_hz = 15000.0 + +[editable path="Handgun"]