1
1
extends CharacterBody3D
2
2
3
- const SPEED = 5.0
4
- const JUMP_VELOCITY = 4.5
3
+
4
+ const SPEED = 10.0
5
+ const JUMP_VELOCITY = 5
5
6
const mouse_sensitivity = 0.002
6
7
8
+ @onready var firesound = $ firesound
9
+ @onready var dryFireSound = $ dryFireSound
10
+ @onready var animplayer = $ Camera3D/pistol/AnimationPlayer
7
11
12
+ # Animation names
13
+ var fire_animation :String = "attachment_vm_pi_papa320_mag_skeleton|fire1"
14
+ var reload_animation :String = "attachment_vm_pi_papa320_mag_skeleton|reload_empty"
15
+ var draw_animation :String = "attachment_vm_pi_papa320_mag_skeleton|draw_first"
16
+ var draw_empty_animation :String = "attachment_vm_pi_papa320_mag_skeleton|draw_empty"
17
+ var idle_animation :String = "attachment_vm_pi_papa320_mag_skeleton|idle"
18
+ var ads_animation :String = "ads"
8
19
9
- # Get the gravity from the project settings to be synced with RigidBody nodes.
10
- var gravity = ProjectSettings .get_setting ("physics/3d/default_gravity" )
11
- var ammo = 5
20
+ var ammo = 7
12
21
var shots = 0
13
- var is_moving = false
14
- var stop_walking = true
15
- var reload_finished = true
16
22
var ads = false
23
+ var reload_finished = true
24
+ var inspecting = false
25
+
26
+ # Get the gravity from the project settings to be synced with RigidBody nodes.
27
+ var gravity = ProjectSettings .get_setting ("physics/3d/default_gravity" )
28
+
17
29
# Initialize the animation player and the audio stream players
18
- @onready var animplayer = $ Camera3D/pistol/AnimationPlayer
19
- @onready var firesound = $ firesound
20
- @onready var dryFireSound = $ dryFireSound
21
30
@onready var camera = $ Camera3D
22
31
23
32
@@ -27,8 +36,6 @@ func _input(event):
27
36
camera .rotate_x (- event .relative .y * mouse_sensitivity )
28
37
camera .rotation .x = clampf (camera .rotation .x , - deg_to_rad (70 ), deg_to_rad (70 ))
29
38
30
-
31
-
32
39
func _physics_process (delta ):
33
40
# Add the gravity.
34
41
if not is_on_floor ():
@@ -37,28 +44,15 @@ func _physics_process(delta):
37
44
if Input .is_action_just_pressed ("ui_accept" ) and is_on_floor ():
38
45
velocity .y = JUMP_VELOCITY
39
46
# Handle the left mouse button (fire) event
40
- if Input .is_action_just_pressed ("fire" ) and reload_finished :
41
- if ammo != 0 :
42
- animplayer .stop ()
43
- animplayer .play ("attachment_vm_pi_papa320_mag_skeleton|fire1" )
44
- firesound .playing = true
45
- shots += 1
46
- ammo -= 1
47
- if ammo == 0 :
48
- dryFireSound .playing = true
49
- if Input .is_action_just_pressed ("reload" ):
47
+ if Input .is_action_just_pressed ("fire" ):
48
+ shoot ()
49
+ if Input .is_action_just_pressed ("reload" ) and not inspecting :
50
50
reload ()
51
51
if Input .is_action_just_pressed ("ads" ):
52
- if ads and reload_finished :
53
- ads = false
54
- animplayer .play_backwards ("ads" )
55
- elif ads and not reload_finished :
56
- pass
57
- elif not ads and not reload_finished :
58
- pass
59
- else :
60
- ads = true
61
- animplayer .play ("ads" )
52
+ ads_func ()
53
+ if Input .is_action_just_pressed ("inspect" ):
54
+ draw ()
55
+
62
56
# Get the input direction and handle the movement/deceleration.
63
57
# As good practice, you should replace UI actions with custom gameplay actions.
64
58
var input_dir = Input .get_vector ("left" , "right" , "forward" , "backward" )
@@ -72,37 +66,72 @@ func _physics_process(delta):
72
66
73
67
move_and_slide ()
74
68
idle ()
75
-
76
-
77
- func _on_animation_player_animation_started (anim_name ):
78
- if anim_name == "" and not is_moving :
79
- stop_walking = true
80
- elif anim_name == "attachment_vm_pi_papa320_mag_skeleton|reload_empty" :
81
- reload_finished = false
82
- stop_walking = true
83
- else :
84
- stop_walking = false
85
69
86
70
87
-
88
-
89
- func _on_animation_player_animation_finished (anim_name ):
90
- if anim_name == "attachment_vm_pi_papa320_mag_skeleton|reload_empty" :
91
- reload_finished = true
92
-
93
71
func reload ():
94
72
if ammo == 0 :
95
- animplayer .play ("attachment_vm_pi_papa320_mag_skeleton|reload_empty" )
96
- ammo += 5
73
+ animplayer .play (reload_animation )
74
+ ammo += 7
97
75
shots = 0
98
- elif ammo == 5 :
76
+ elif ammo == 7 :
99
77
pass
100
78
else :
101
- animplayer .play ("attachment_vm_pi_papa320_mag_skeleton|reload_empty" )
79
+ animplayer .play (reload_animation )
102
80
ammo += shots
103
81
shots = 0
104
82
83
+
84
+ func draw ():
85
+ if ads :
86
+ pass
87
+ elif ! reload_finished :
88
+ pass
89
+ elif ammo == 0 :
90
+ animplayer .stop ()
91
+ animplayer .play (draw_empty_animation )
92
+ else :
93
+ animplayer .stop ()
94
+ animplayer .play (draw_animation )
95
+
96
+ func shoot ():
97
+ if reload_finished and not inspecting :
98
+ if ammo != 0 :
99
+ animplayer .stop ()
100
+ animplayer .play (fire_animation )
101
+ firesound .playing = true
102
+ shots += 1
103
+ ammo -= 1
104
+ if ammo == 0 :
105
+ dryFireSound .playing = true
106
+ else :
107
+ pass
108
+ func ads_func ():
109
+ if ads and reload_finished :
110
+ ads = false
111
+ animplayer .play_backwards (ads_animation )
112
+ elif ads and not reload_finished or inspecting :
113
+ pass
114
+ elif not ads and not reload_finished or inspecting :
115
+ pass
116
+ else :
117
+ ads = true
118
+ animplayer .play (ads_animation )
119
+
105
120
func idle ():
106
121
if animplayer .is_playing () == false :
107
- animplayer .play ("attachment_vm_pi_papa320_mag_skeleton|idle" )
122
+ animplayer .play (idle_animation )
123
+
124
+
125
+
126
+ func _on_animation_player_animation_started (anim_name ):
127
+ if anim_name == reload_animation :
128
+ reload_finished = false
129
+ elif anim_name == draw_animation or anim_name == draw_empty_animation :
130
+ inspecting = true
131
+
132
+ func _on_animation_player_animation_finished (anim_name ):
133
+ if anim_name == reload_animation :
134
+ reload_finished = true
135
+ elif anim_name == draw_animation or anim_name == draw_empty_animation :
136
+ inspecting = false
108
137
0 commit comments