virtualx-engine/demos/2d/space_shooter/asteroid.gd
Rémi Verschelde 7589b2bf60 Improve code formatting
The scripts were streamlined using more or less the following conventions:
 - space after a comma in lists of arguments
 - spaces around weak operators (+, -), no spaces around strong operators (*, /)
 - spaces around comparison operators and compound assignment operators
 - space after a comment start (#)
 - removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now)
 - function blocks separate by two newlines
 - comment sentences start with an upper-case letter
2015-12-09 08:39:12 +01:00

44 lines
696 B
GDScript

extends Area2D
# Member variables
const SPEED = -200
const Y_RANDOM = 10
var points = 1
var speed_y = 0.0
var destroyed = false
func _process(delta):
translate(Vector2(SPEED, speed_y)*delta)
func _ready():
# Initialization here
speed_y = rand_range(-Y_RANDOM, Y_RANDOM)
func destroy():
if (destroyed):
return
destroyed = true
get_node("anim").play("explode")
set_process(false)
get_node("sfx").play("sound_explode")
# Accumulate points
get_node("/root/game_state").points += 1
func is_enemy():
return not destroyed
func _on_visibility_enter_screen():
set_process(true)
# Make it spin!
get_node("anim").play("spin")
func _on_visibility_exit_screen():
queue_free()