diff options
author | Anton Yabchinskiy <arn@bestmx.ru> | 2015-07-29 23:01:36 +0300 |
---|---|---|
committer | Anton Yabchinskiy <arn@bestmx.ru> | 2015-07-29 23:01:36 +0300 |
commit | dc8df8a91a995796f0f330bf6bb6b209f6dfce08 (patch) | |
tree | 46cfe09124703b07860754d6b44e0289422e0573 /demos/2d/space_shooter/enemy2.gd | |
parent | 16746f157f83d666079ba3266acec13d35b84c3f (diff) | |
parent | 922356b903061cda7591090bf19e8346c3a78cf5 (diff) |
Merge branch 'master' of github.com:okamstudio/godot
Diffstat (limited to 'demos/2d/space_shooter/enemy2.gd')
-rw-r--r-- | demos/2d/space_shooter/enemy2.gd | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/demos/2d/space_shooter/enemy2.gd b/demos/2d/space_shooter/enemy2.gd new file mode 100644 index 0000000000..4f632a053d --- /dev/null +++ b/demos/2d/space_shooter/enemy2.gd @@ -0,0 +1,56 @@ + +extends Area2D + +# member variables here, example: +# var a=2 +# var b="textvar" +const SPEED=-220 +const SHOOT_INTERVAL=1 +var shoot_timeout=0 + +func _process(delta): + translate( Vector2(SPEED*delta,0) ) + shoot_timeout-=delta + + if (shoot_timeout<0): + + shoot_timeout=SHOOT_INTERVAL + + #instance a shot + var shot = preload("res://enemy_shot.scn").instance() + #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 + get_parent().add_child(shot) + +var destroyed=false + +func is_enemy(): + return not destroyed + +func destroy(): + if (destroyed): + return + destroyed=true + get_node("anim").play("explode") + set_process(false) + get_node("sfx").play("sound_explode") + #accum points + get_node("/root/game_state").points+=10 + +func _ready(): + set_fixed_process(true) + # Initialization here + pass + + + + +func _on_visibility_enter_screen(): + set_process(true) + pass # replace with function body + + +func _on_visibility_exit_screen(): + queue_free() + pass # replace with function body |