2015-06-11 14:55:38 +02:00
|
|
|
|
|
|
|
extends Area2D
|
|
|
|
|
2015-11-21 16:13:43 +01:00
|
|
|
# Member variables
|
|
|
|
const SPEED = -200
|
|
|
|
const Y_RANDOM = 10
|
2015-06-11 14:55:38 +02:00
|
|
|
|
2015-11-21 16:13:43 +01:00
|
|
|
var points = 1
|
|
|
|
var speed_y = 0.0
|
|
|
|
var destroyed = false
|
2015-06-11 14:55:38 +02:00
|
|
|
|
|
|
|
|
2016-05-30 22:34:59 +02:00
|
|
|
func _fixed_process(delta):
|
2015-11-21 16:13:43 +01:00
|
|
|
translate(Vector2(SPEED, speed_y)*delta)
|
2015-06-11 14:55:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
2015-11-21 16:13:43 +01:00
|
|
|
speed_y = rand_range(-Y_RANDOM, Y_RANDOM)
|
2015-06-11 14:55:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
func destroy():
|
|
|
|
if (destroyed):
|
2015-11-21 16:13:43 +01:00
|
|
|
return
|
|
|
|
destroyed = true
|
2015-06-11 14:55:38 +02:00
|
|
|
get_node("anim").play("explode")
|
2016-05-30 22:34:59 +02:00
|
|
|
set_fixed_process(false)
|
2015-06-11 14:55:38 +02:00
|
|
|
get_node("sfx").play("sound_explode")
|
2015-11-21 16:13:43 +01:00
|
|
|
# Accumulate points
|
|
|
|
get_node("/root/game_state").points += 1
|
|
|
|
|
|
|
|
|
2015-06-11 14:55:38 +02:00
|
|
|
func is_enemy():
|
2015-11-21 16:13:43 +01:00
|
|
|
return not destroyed
|
|
|
|
|
2015-06-11 14:55:38 +02:00
|
|
|
|
|
|
|
func _on_visibility_enter_screen():
|
2016-05-30 22:34:59 +02:00
|
|
|
set_fixed_process(true)
|
2015-11-21 16:13:43 +01:00
|
|
|
# Make it spin!
|
2015-06-11 14:55:38 +02:00
|
|
|
get_node("anim").play("spin")
|
2015-11-21 16:13:43 +01:00
|
|
|
|
2015-06-11 14:55:38 +02:00
|
|
|
|
|
|
|
func _on_visibility_exit_screen():
|
|
|
|
queue_free()
|