This commit is contained in:
Robin Hübner 2017-07-30 22:49:58 +02:00
parent 0a8e9f5cc0
commit 28a51c47de
3 changed files with 12 additions and 11 deletions

View File

@ -8,11 +8,12 @@ onready var sprite = get_node("Sprite")
func _ready(): func _ready():
set_fixed_process(true) set_fixed_process(true)
func fire(vel, dir, speed): func fire(delta, vel, dir, speed):
velocity = vel + (dir * speed) velocity = (dir * (speed * delta)) + (dir * vel.length())
sprite.rotate(dir.angle())
func _fixed_process(delta): func _fixed_process(delta):
move(velocity * delta) move(velocity)
lifetime -= delta lifetime -= delta
if lifetime <= 0: if lifetime <= 0:
queue_free() queue_free()

8
Gun.gd
View File

@ -3,19 +3,19 @@ extends Sprite
var Bullet = load("res://Bullet.tscn") var Bullet = load("res://Bullet.tscn")
var gun_cooldown = 0 var gun_cooldown = 0
var gun_delay = 0.25 var gun_delay = 0.1125
func _ready(): func _ready():
set_fixed_process(true) set_fixed_process(true)
func _fixed_process(delta): func _fixed_process(delta):
gun_cooldown = gun_cooldown - delta gun_cooldown = clamp(gun_cooldown - delta, 0, 1)
func fire(vel, dir): func fire(delta, vel, dir):
if gun_cooldown <= 0: if gun_cooldown <= 0:
var new_bullet = Bullet.instance() var new_bullet = Bullet.instance()
var gun_pos = get_global_pos() var gun_pos = get_global_pos()
new_bullet.set_pos(gun_pos) new_bullet.set_pos(gun_pos)
get_tree().get_root().add_child(new_bullet) get_tree().get_root().add_child(new_bullet)
new_bullet.fire(vel, dir, 256) new_bullet.fire(delta, vel, dir, 512)
gun_cooldown += gun_delay gun_cooldown += gun_delay

View File

@ -43,8 +43,8 @@ func _fixed_process(delta):
is_moving = false is_moving = false
if Input.is_action_pressed("player_attack_primary"): if Input.is_action_pressed("player_attack_primary"):
left_gun.fire(ship_vel, -ship_dir) left_gun.fire(delta, ship_vel, -ship_dir)
right_gun.fire(ship_vel, -ship_dir) right_gun.fire(delta, ship_vel, -ship_dir)
elif Input.is_action_pressed("player_attack_secondary"): elif Input.is_action_pressed("player_attack_secondary"):
pass pass