2017-07-30 21:25:42 +01:00
|
|
|
extends Sprite
|
|
|
|
|
|
|
|
var Bullet = load("res://Bullet.tscn")
|
|
|
|
|
|
|
|
var gun_cooldown = 0
|
2017-07-30 21:49:58 +01:00
|
|
|
var gun_delay = 0.1125
|
2017-07-30 21:25:42 +01:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
set_fixed_process(true)
|
|
|
|
|
|
|
|
func _fixed_process(delta):
|
2017-07-30 21:49:58 +01:00
|
|
|
gun_cooldown = clamp(gun_cooldown - delta, 0, 1)
|
2017-07-30 21:25:42 +01:00
|
|
|
|
2017-07-30 21:49:58 +01:00
|
|
|
func fire(delta, vel, dir):
|
2017-07-30 21:25:42 +01:00
|
|
|
if gun_cooldown <= 0:
|
|
|
|
var new_bullet = Bullet.instance()
|
|
|
|
var gun_pos = get_global_pos()
|
2017-07-31 15:49:04 +01:00
|
|
|
new_bullet.set_pos(gun_pos + vel)
|
2017-07-30 21:25:42 +01:00
|
|
|
get_tree().get_root().add_child(new_bullet)
|
2017-07-30 21:49:58 +01:00
|
|
|
new_bullet.fire(delta, vel, dir, 512)
|
2017-07-30 21:25:42 +01:00
|
|
|
gun_cooldown += gun_delay
|