Moved handgun code to handgun
parent
428934850b
commit
1d0680eebf
|
@ -1,26 +1,64 @@
|
|||
extends "res://Classes/Weapon/Weapon.gd"
|
||||
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
#var trigger_held_primary = false
|
||||
#var trigger_held_secondary = false
|
||||
#var is_reloading = false
|
||||
|
||||
func set_trigger_held_primary(active:bool):
|
||||
trigger_held_primary = active
|
||||
|
||||
if active:
|
||||
shoot(camera, true)
|
||||
print("trigger_active", active)
|
||||
|
||||
#func get_trigger_held_primary():
|
||||
# return trigger_held_primary
|
||||
# print("trigger_get")
|
||||
|
||||
# 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
|
||||
func shoot(camera, primary):
|
||||
if not Automatic:
|
||||
if cached_fire == true:
|
||||
return
|
||||
|
||||
if is_reloading:
|
||||
return
|
||||
|
||||
if currently_fireing == true:
|
||||
cached_fire = true
|
||||
yield($Model/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
|
||||
|
||||
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, player.name)
|
||||
|
||||
if hit is Player:
|
||||
var kill = true if hit.health <= 0 else false
|
||||
|
||||
#print ("Player: kill = ", kill, " Target health: ", hit.health)
|
||||
emit_signal("damage_dealt", kill)
|
||||
|
||||
#print(get_signal_connection_list("damage_dealt")[0]["target"].name)
|
||||
|
||||
if kill:
|
||||
player.score(hit.name)
|
||||
|
||||
#print(get_signal_connection_list("ammo_changed")[0]["target"].name)
|
||||
emit_signal("ammo_changed", self)
|
||||
|
||||
if current_rounds == 0:
|
||||
reload()
|
||||
|
||||
return current_rounds
|
||||
|
|
|
@ -42,64 +42,6 @@ func _ready():
|
|||
func switched_to_weapon():
|
||||
emit_signal("ammo_changed", self)
|
||||
|
||||
func shoot(camera, primary, trigger_held):
|
||||
if not Automatic:
|
||||
if cached_fire == true:
|
||||
return
|
||||
|
||||
if currently_fireing == true:
|
||||
cached_fire = true
|
||||
yield($Model/AnimationPlayer, "animation_finished")
|
||||
|
||||
# TODO: mutexes
|
||||
currently_fireing = true
|
||||
cached_fire = false
|
||||
|
||||
while current_rounds > 0 and trigger_held:
|
||||
rpc("fire_weapon", current_rounds)
|
||||
rpc("compute_bullet_flyby")
|
||||
|
||||
current_rounds -= 1
|
||||
|
||||
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, player.name)
|
||||
|
||||
if hit is Player:
|
||||
var kill = true if hit.health <= 0 else false
|
||||
|
||||
#print ("Player: kill = ", kill, " Target health: ", hit.health)
|
||||
emit_signal("damage_dealt", kill)
|
||||
|
||||
#print(get_signal_connection_list("damage_dealt")[0]["target"].name)
|
||||
|
||||
if kill:
|
||||
player.score(hit.name)
|
||||
|
||||
#print(get_signal_connection_list("ammo_changed")[0]["target"].name)
|
||||
emit_signal("ammo_changed", self)
|
||||
|
||||
if not Automatic:
|
||||
break
|
||||
else:
|
||||
yield(get_tree().create_timer(Delay),"timeout")
|
||||
|
||||
if current_rounds == 0:
|
||||
reload()
|
||||
|
||||
return current_rounds
|
||||
|
||||
sync func fire_weapon(var rounds_left):
|
||||
show_muzzle_flash(rounds_left)
|
||||
show_tracer()
|
||||
|
@ -167,14 +109,14 @@ remote func compute_bullet_flyby():
|
|||
func reload():
|
||||
rpc("play_reload_animation")
|
||||
|
||||
currently_fireing = true
|
||||
is_reloading = true
|
||||
cached_fire = false
|
||||
|
||||
yield($Model/AnimationPlayer, "animation_finished")
|
||||
|
||||
if not cached_fire:
|
||||
currently_fireing = false
|
||||
|
||||
#if not cached_fire:
|
||||
currently_fireing = false
|
||||
is_reloading = false
|
||||
current_rounds = Rounds
|
||||
|
||||
emit_signal("ammo_changed", self)
|
||||
|
|
|
@ -326,6 +326,7 @@ __meta__ = {
|
|||
visible = false
|
||||
margin_top = -264.542
|
||||
margin_bottom = -80.5416
|
||||
|
||||
[connection signal="pressed" from="MenuContainer/MainMenu/QuickConnect" to="." method="join_test_server"]
|
||||
[connection signal="pressed" from="MenuContainer/MainMenu/Connect" to="." method="open_menu" binds= [ "ConnectMenu" ]]
|
||||
[connection signal="pressed" from="MenuContainer/MainMenu/Disconnect" to="." method="free_client"]
|
||||
|
|
Reference in New Issue