diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2015-12-09 08:49:06 +0100 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2015-12-09 08:49:06 +0100 |
commit | db9da152765357c5e484792fc5e31a25acbc7616 (patch) | |
tree | f58497abcecc0a74d3d12132f134a5e0b279cc24 /demos/2d/space_shooter/ship.gd | |
parent | efbb834936fdc9da9789ad37c9cc61e0b90cda95 (diff) | |
parent | 52d515b611ed1f593e23b0adabedbd9fd59dc7db (diff) |
Merge pull request #2853 from akien-mga/pr-demos-code-formatting
Improve demos code formatting and update to 2.0
Diffstat (limited to 'demos/2d/space_shooter/ship.gd')
-rw-r--r-- | demos/2d/space_shooter/ship.gd | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/demos/2d/space_shooter/ship.gd b/demos/2d/space_shooter/ship.gd index fa444868a4..b6c1200632 100644 --- a/demos/2d/space_shooter/ship.gd +++ b/demos/2d/space_shooter/ship.gd @@ -1,71 +1,65 @@ extends Area2D -# member variables here, example: -# var a=2 -# var b="textvar" - +# Member variables const SPEED = 200 var screen_size +var prev_shooting = false +var killed = false -var prev_shooting=false func _process(delta): - var motion = Vector2() if Input.is_action_pressed("move_up"): - motion+=Vector2(0,-1) + motion += Vector2(0, -1) if Input.is_action_pressed("move_down"): - motion+=Vector2(0,1) + motion += Vector2(0, 1) if Input.is_action_pressed("move_left"): - motion+=Vector2(-1,0) + motion += Vector2(-1, 0) if Input.is_action_pressed("move_right"): - motion+=Vector2(1,0) + motion += Vector2(1, 0) var shooting = Input.is_action_pressed("shoot") - + var pos = get_pos() - pos+=motion*delta*SPEED - if (pos.x<0): - pos.x=0 - if (pos.x>screen_size.x): - pos.x=screen_size.x - if (pos.y<0): - pos.y=0 - if (pos.y>screen_size.y): - pos.y=screen_size.y - + pos += motion*delta*SPEED + if (pos.x < 0): + pos.x = 0 + if (pos.x > screen_size.x): + pos.x = screen_size.x + if (pos.y < 0): + pos.y = 0 + if (pos.y > screen_size.y): + pos.y = screen_size.y + set_pos(pos) if (shooting and not prev_shooting): - # just pressed + # Just pressed var shot = preload("res://shot.scn").instance() - #use the position3d as reference - shot.set_pos( get_node("shootfrom").get_global_pos() ) - #put it two parents above, so it is not moved by us + # Use the Position2D as reference + shot.set_pos(get_node("shootfrom").get_global_pos()) + # Put it two parents above, so it is not moved by us get_node("../..").add_child(shot) - #play sound + # Play sound get_node("sfx").play("shoot") - prev_shooting = shooting + + # Update points counter + get_node("../hud/score_points").set_text(str(get_node("/root/game_state").points)) - #update points counter - get_node("../hud/score_points").set_text( str(get_node("/root/game_state").points) ) func _ready(): - # Initialization here screen_size = get_viewport().get_rect().size set_process(true) - pass -var killed=false func _hit_something(): if (killed): return - killed=true + killed = true get_node("anim").play("explode") get_node("sfx").play("sound_explode") get_node("../hud/game_over").show() @@ -74,15 +68,14 @@ func _hit_something(): set_process(false) -func _on_ship_body_enter( body ): +func _on_ship_body_enter(body): _hit_something() -func _on_ship_area_enter( area ): +func _on_ship_area_enter(area): if (area.has_method("is_enemy") and area.is_enemy()): _hit_something() func _on_back_to_menu_pressed(): get_tree().change_scene("res://main_menu.scn") - pass # replace with function body |