2022-04-03 00:56:09 +00:00
|
|
|
extends Node
|
2022-04-03 00:53:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
export var bullet: PackedScene = preload("res://src/entities/Bullet.tscn")
|
|
|
|
export var bullet_container_node_path: String = "../.."
|
|
|
|
onready var bullet_container_node: Node = get_node(bullet_container_node_path)
|
|
|
|
onready var source: Node2D = get_parent()
|
2022-04-03 14:44:18 +00:00
|
|
|
var _timer : Timer = null
|
2022-04-03 00:09:19 +00:00
|
|
|
|
2022-04-03 14:44:18 +00:00
|
|
|
func _ready():
|
|
|
|
_timer = Timer.new()
|
|
|
|
add_child(_timer)
|
|
|
|
_timer.set_wait_time(0.3)
|
|
|
|
_timer.set_one_shot(true)
|
|
|
|
_timer.start()
|
2022-04-03 00:09:19 +00:00
|
|
|
|
|
|
|
func _process(_delta):
|
2022-04-03 14:44:18 +00:00
|
|
|
print(_timer.get_time_left())
|
|
|
|
if Input.is_action_just_pressed("player_shoot") and _timer.get_time_left()==0:
|
2022-04-03 00:53:56 +00:00
|
|
|
shoot()
|
2022-04-03 14:44:18 +00:00
|
|
|
|
|
|
|
#restart timer
|
|
|
|
_timer.set_wait_time(0.3)
|
|
|
|
_timer.set_one_shot(true)
|
|
|
|
_timer.start()
|
2022-04-03 00:53:56 +00:00
|
|
|
|
2022-04-03 00:09:19 +00:00
|
|
|
|
2022-04-03 00:53:56 +00:00
|
|
|
func shoot():
|
2022-04-03 00:37:44 +00:00
|
|
|
var new_bullet = bullet.instance()
|
2022-04-03 00:53:56 +00:00
|
|
|
new_bullet.set_position(source.global_position)
|
|
|
|
bullet_container_node.add_child(new_bullet)
|
2022-04-03 00:56:09 +00:00
|
|
|
var rotation = new_bullet.get_angle_to(source.get_global_mouse_position())
|
2022-04-03 00:53:56 +00:00
|
|
|
new_bullet.set_rotation(rotation)
|
2022-04-03 06:26:54 +00:00
|
|
|
new_bullet.get_node("Ownership").entity_owner = source
|
2022-04-03 07:04:30 +00:00
|
|
|
new_bullet.add_collision_exception_with(source)
|