2015-06-11 12:55:38 +00:00
|
|
|
|
|
|
|
extends Area2D
|
|
|
|
|
2015-11-21 15:13:43 +00:00
|
|
|
# Member variables
|
|
|
|
const SPEED = -220
|
|
|
|
const SHOOT_INTERVAL = 1
|
|
|
|
|
|
|
|
var shoot_timeout = 0
|
|
|
|
var destroyed=false
|
|
|
|
|
2015-06-11 12:55:38 +00:00
|
|
|
|
|
|
|
func _process(delta):
|
2015-11-21 15:13:43 +00:00
|
|
|
translate(Vector2(SPEED*delta, 0))
|
|
|
|
shoot_timeout -= delta
|
2015-06-11 12:55:38 +00:00
|
|
|
|
2015-11-21 15:13:43 +00:00
|
|
|
if (shoot_timeout < 0):
|
|
|
|
shoot_timeout = SHOOT_INTERVAL
|
2015-06-11 12:55:38 +00:00
|
|
|
|
2015-11-21 15:13:43 +00:00
|
|
|
# Instance a shot
|
2015-06-11 12:55:38 +00:00
|
|
|
var shot = preload("res://enemy_shot.scn").instance()
|
2015-11-21 15:13:43 +00:00
|
|
|
# Set pos as "shoot_from" Position2D node
|
|
|
|
shot.set_pos(get_node("shoot_from").get_global_pos())
|
|
|
|
# Add it to parent, so it has world coordinates
|
2015-06-11 12:55:38 +00:00
|
|
|
get_parent().add_child(shot)
|
2015-11-21 15:13:43 +00:00
|
|
|
|
2015-06-11 12:55:38 +00:00
|
|
|
|
|
|
|
func is_enemy():
|
|
|
|
return not destroyed
|
|
|
|
|
2015-11-21 15:13:43 +00:00
|
|
|
|
2015-06-11 12:55:38 +00:00
|
|
|
func destroy():
|
|
|
|
if (destroyed):
|
2015-11-21 15:13:43 +00:00
|
|
|
return
|
|
|
|
destroyed = true
|
2015-06-11 12:55:38 +00:00
|
|
|
get_node("anim").play("explode")
|
2015-11-21 15:13:43 +00:00
|
|
|
set_process(false)
|
2015-06-11 12:55:38 +00:00
|
|
|
get_node("sfx").play("sound_explode")
|
2015-11-21 15:13:43 +00:00
|
|
|
# Accumulate points
|
|
|
|
get_node("/root/game_state").points += 10
|
|
|
|
|
2015-06-11 12:55:38 +00:00
|
|
|
|
|
|
|
func _ready():
|
2015-11-21 15:13:43 +00:00
|
|
|
set_fixed_process(true)
|
2015-06-11 12:55:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_visibility_enter_screen():
|
|
|
|
set_process(true)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_visibility_exit_screen():
|
|
|
|
queue_free()
|