-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rifle_Point.gd
87 lines (61 loc) · 1.94 KB
/
Rifle_Point.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
extends Spatial
const DAMAGE = 4
const IDLE_ANIM_NAME = "Rifle_idle"
const FIRE_ANIM_NAME = "Rifle_fire"
var is_weapon_enabled = false
var player_node = null
var ammo_in_weapon = 50
var spare_ammo = 100
const AMMO_IN_MAG = 50
const CAN_RELOAD = true
const CAN_REFILL = true
const RELOADING_ANIM_NAME = "Rifle_reload"
func _ready():
pass
func fire_weapon():
var ray = $Ray_Cast
ray.force_raycast_update()
if ray.is_colliding():
var body = ray.get_collider()
if body == player_node:
pass
elif body.has_method("bullet_hit"):
body.bullet_hit(DAMAGE, ray.global_transform)
ammo_in_weapon -= 1
player_node.create_sound("Rifle_shot", ray.global_transform.origin)
func equip_weapon():
if player_node.animation_manager.current_state == IDLE_ANIM_NAME:
is_weapon_enabled = true
return true
if player_node.animation_manager.current_state == "Idle_unarmed":
player_node.animation_manager.set_animation("Rifle_equip")
return false
func unequip_weapon():
if player_node.animation_manager.current_state == IDLE_ANIM_NAME:
if player_node.animation_manager.current_state != "Rifle_unequip":
player_node.animation_manager.set_animation("Rifle_unequip")
if player_node.animation_manager.current_state == "Idle_unarmed":
is_weapon_enabled = false
return true
return false
func reload_weapon():
var can_reload = false
if player_node.animation_manager.current_state == IDLE_ANIM_NAME:
can_reload = true
if spare_ammo <= 0 or ammo_in_weapon == AMMO_IN_MAG:
can_reload = false
if can_reload == true:
var ammo_needed = AMMO_IN_MAG - ammo_in_weapon
if spare_ammo >= ammo_needed:
spare_ammo -= ammo_needed
ammo_in_weapon = AMMO_IN_MAG
else:
ammo_in_weapon += spare_ammo
spare_ammo = 0
player_node.animation_manager.set_animation(RELOADING_ANIM_NAME)
player_node.create_sound("Gun_cock", player_node.camera.global_transform.origin)
return true
return false
func reset_weapon():
ammo_in_weapon = 50
spare_ammo = 100