summaryrefslogtreecommitdiff
path: root/demos/2d/space_shooter
diff options
context:
space:
mode:
Diffstat (limited to 'demos/2d/space_shooter')
-rw-r--r--demos/2d/space_shooter/asteroid.gd42
-rw-r--r--demos/2d/space_shooter/asteroid.scnbin4516 -> 3548 bytes
-rw-r--r--demos/2d/space_shooter/enemy1.gd29
-rw-r--r--demos/2d/space_shooter/enemy1.scnbin3759 -> 3369 bytes
-rw-r--r--demos/2d/space_shooter/enemy2.gd51
-rw-r--r--demos/2d/space_shooter/enemy2.scnbin3801 -> 3253 bytes
-rw-r--r--demos/2d/space_shooter/enemy_shot.gd19
-rw-r--r--demos/2d/space_shooter/enemy_shot.scnbin3944 -> 3218 bytes
-rw-r--r--demos/2d/space_shooter/explosion.scnbin1497 -> 1756 bytes
-rw-r--r--demos/2d/space_shooter/game_state.gd20
-rw-r--r--demos/2d/space_shooter/level.scnbin9185 -> 6496 bytes
-rw-r--r--demos/2d/space_shooter/level_tiles.scnbin2168 -> 1825 bytes
-rw-r--r--demos/2d/space_shooter/main_menu.gd13
-rw-r--r--demos/2d/space_shooter/main_menu.scnbin2402 -> 1903 bytes
-rw-r--r--demos/2d/space_shooter/parallax.scnbin3307 -> 2814 bytes
-rw-r--r--demos/2d/space_shooter/rail.gd18
-rw-r--r--demos/2d/space_shooter/ship.gd65
-rw-r--r--demos/2d/space_shooter/ship.scnbin6752 -> 4965 bytes
-rw-r--r--demos/2d/space_shooter/shot.gd34
-rw-r--r--demos/2d/space_shooter/shot.scnbin4079 -> 3315 bytes
20 files changed, 123 insertions, 168 deletions
diff --git a/demos/2d/space_shooter/asteroid.gd b/demos/2d/space_shooter/asteroid.gd
index f21b9777bb..9f6734e122 100644
--- a/demos/2d/space_shooter/asteroid.gd
+++ b/demos/2d/space_shooter/asteroid.gd
@@ -1,49 +1,43 @@
extends Area2D
-# member variables here, example:
-# var a=2
-# var b="textvar"
+# Member variables
+const SPEED = -200
+const Y_RANDOM = 10
-const SPEED=-200
-const Y_RANDOM=10
+var points = 1
+var speed_y = 0.0
+var destroyed = false
-var points=1
-
-
-var speed_y=0.0
func _process(delta):
+ translate(Vector2(SPEED, speed_y)*delta)
- translate( Vector2(SPEED,speed_y) * delta )
func _ready():
- # Initialization here
- speed_y=rand_range(-Y_RANDOM,Y_RANDOM)
- pass
+ speed_y = rand_range(-Y_RANDOM, Y_RANDOM)
-var destroyed=false
func destroy():
if (destroyed):
- return
- destroyed=true
+ 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+=1
-
+ # Accumulate points
+ get_node("/root/game_state").points += 1
+
+
func is_enemy():
- return not destroyed
-
+ return not destroyed
+
func _on_visibility_enter_screen():
set_process(true)
- #make it spin!
+ # Make it spin!
get_node("anim").play("spin")
-
+
func _on_visibility_exit_screen():
queue_free()
- pass # replace with function body
diff --git a/demos/2d/space_shooter/asteroid.scn b/demos/2d/space_shooter/asteroid.scn
index b881725ea4..6bca98cd30 100644
--- a/demos/2d/space_shooter/asteroid.scn
+++ b/demos/2d/space_shooter/asteroid.scn
Binary files differ
diff --git a/demos/2d/space_shooter/enemy1.gd b/demos/2d/space_shooter/enemy1.gd
index 051798742a..204995c05d 100644
--- a/demos/2d/space_shooter/enemy1.gd
+++ b/demos/2d/space_shooter/enemy1.gd
@@ -1,17 +1,15 @@
extends Area2D
-# member variables here, example:
-# var a=2
-# var b="textvar"
+# Member variables
+const SPEED = -200
+
+var destroyed=false
-const SPEED=-200
func _process(delta):
- get_parent().translate(Vector2(SPEED*delta,0))
+ get_parent().translate(Vector2(SPEED*delta, 0))
-
-var destroyed=false
func is_enemy():
return not destroyed
@@ -19,19 +17,20 @@ func is_enemy():
func destroy():
if (destroyed):
- return
- destroyed=true
+ return
+ destroyed = true
get_node("anim").play("explode")
- set_process(false)
+ set_process(false)
get_node("sfx").play("sound_explode")
- #accum points
- get_node("/root/game_state").points+=5
+ # Accumulate points
+ get_node("/root/game_state").points += 5
+
func _on_visibility_enter_screen():
set_process(true)
- get_node("anim").play("zigzag")
- get_node("anim").seek(randf()*2.0) #make it start from any pos
+ get_node("anim").play("zigzag")
+ get_node("anim").seek(randf()*2.0) # Make it start from any pos
+
func _on_visibility_exit_screen():
queue_free()
-
diff --git a/demos/2d/space_shooter/enemy1.scn b/demos/2d/space_shooter/enemy1.scn
index 14298f0a59..805071b772 100644
--- a/demos/2d/space_shooter/enemy1.scn
+++ b/demos/2d/space_shooter/enemy1.scn
Binary files differ
diff --git a/demos/2d/space_shooter/enemy2.gd b/demos/2d/space_shooter/enemy2.gd
index 4f632a053d..bfdb743103 100644
--- a/demos/2d/space_shooter/enemy2.gd
+++ b/demos/2d/space_shooter/enemy2.gd
@@ -1,56 +1,51 @@
extends Area2D
-# member variables here, example:
-# var a=2
-# var b="textvar"
-const SPEED=-220
-const SHOOT_INTERVAL=1
-var shoot_timeout=0
+# Member variables
+const SPEED = -220
+const SHOOT_INTERVAL = 1
+
+var shoot_timeout = 0
+var destroyed=false
+
func _process(delta):
- translate( Vector2(SPEED*delta,0) )
- shoot_timeout-=delta
+ translate(Vector2(SPEED*delta, 0))
+ shoot_timeout -= delta
- if (shoot_timeout<0):
-
- shoot_timeout=SHOOT_INTERVAL
+ if (shoot_timeout < 0):
+ shoot_timeout = SHOOT_INTERVAL
- #instance a shot
+ # 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
+ # 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
+ return
+ destroyed = true
get_node("anim").play("explode")
- set_process(false)
+ set_process(false)
get_node("sfx").play("sound_explode")
- #accum points
- get_node("/root/game_state").points+=10
+ # Accumulate 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
diff --git a/demos/2d/space_shooter/enemy2.scn b/demos/2d/space_shooter/enemy2.scn
index 1d31f9c30e..644add77aa 100644
--- a/demos/2d/space_shooter/enemy2.scn
+++ b/demos/2d/space_shooter/enemy2.scn
Binary files differ
diff --git a/demos/2d/space_shooter/enemy_shot.gd b/demos/2d/space_shooter/enemy_shot.gd
index 238d24e4a2..6c782b69f1 100644
--- a/demos/2d/space_shooter/enemy_shot.gd
+++ b/demos/2d/space_shooter/enemy_shot.gd
@@ -1,32 +1,31 @@
extends Area2D
-# member variables here, example:
-# var a=2
-# var b="textvar"
-
+# Member variables
const SPEED = -800
+var hit = false
+
+
func _process(delta):
- translate(Vector2(delta*SPEED,0))
+ translate(Vector2(delta*SPEED, 0))
+
func _ready():
- # Initialization here
set_process(true)
-var hit=false
-
func is_enemy():
return true
+
func _hit_something():
if (hit):
return
- hit=true
+ hit = true
set_process(false)
get_node("anim").play("splash")
+
func _on_visibility_exit_screen():
queue_free()
-
diff --git a/demos/2d/space_shooter/enemy_shot.scn b/demos/2d/space_shooter/enemy_shot.scn
index 13f5ae89e5..353c9058f7 100644
--- a/demos/2d/space_shooter/enemy_shot.scn
+++ b/demos/2d/space_shooter/enemy_shot.scn
Binary files differ
diff --git a/demos/2d/space_shooter/explosion.scn b/demos/2d/space_shooter/explosion.scn
index 4edcf709cb..6fc105fac3 100644
--- a/demos/2d/space_shooter/explosion.scn
+++ b/demos/2d/space_shooter/explosion.scn
Binary files differ
diff --git a/demos/2d/space_shooter/game_state.gd b/demos/2d/space_shooter/game_state.gd
index f66d0fa8fa..0aa5e1f42b 100644
--- a/demos/2d/space_shooter/game_state.gd
+++ b/demos/2d/space_shooter/game_state.gd
@@ -1,24 +1,22 @@
-extends Node
+extends Node
+# Member variables
var points = 0
var max_points = 0
func _ready():
var f = File.new()
- #load high score
-
- if (f.open("user://highscore",File.READ)==OK):
-
- max_points=f.get_var()
+ # Load high score
+ if (f.open("user://highscore", File.READ) == OK):
+ max_points = f.get_var()
func game_over():
- if (points>max_points):
- max_points=points
- #save high score
+ if (points > max_points):
+ max_points = points
+ # Save high score
var f = File.new()
- f.open("user://highscore",File.WRITE)
+ f.open("user://highscore", File.WRITE)
f.store_var(max_points)
- \ No newline at end of file
diff --git a/demos/2d/space_shooter/level.scn b/demos/2d/space_shooter/level.scn
index 12a679f8b6..6d5f8005f5 100644
--- a/demos/2d/space_shooter/level.scn
+++ b/demos/2d/space_shooter/level.scn
Binary files differ
diff --git a/demos/2d/space_shooter/level_tiles.scn b/demos/2d/space_shooter/level_tiles.scn
index 4d1feea70f..932be39a29 100644
--- a/demos/2d/space_shooter/level_tiles.scn
+++ b/demos/2d/space_shooter/level_tiles.scn
Binary files differ
diff --git a/demos/2d/space_shooter/main_menu.gd b/demos/2d/space_shooter/main_menu.gd
index 52221aba1b..a7f242da7b 100644
--- a/demos/2d/space_shooter/main_menu.gd
+++ b/demos/2d/space_shooter/main_menu.gd
@@ -1,20 +1,11 @@
extends Control
-# member variables here, example:
-# var a=2
-# var b="textvar"
func _ready():
-
- get_node("score").set_text( "HIGH SCORE: "+str( get_node("/root/game_state").max_points ) )
- # Initialization here
- pass
-
-
+ get_node("score").set_text("HIGH SCORE: " + str(get_node("/root/game_state").max_points))
func _on_play_pressed():
- get_node("/root/game_state").points=0
+ get_node("/root/game_state").points = 0
get_tree().change_scene("res://level.scn")
- pass # replace with function body
diff --git a/demos/2d/space_shooter/main_menu.scn b/demos/2d/space_shooter/main_menu.scn
index b87cc5d3a8..91b0b37b14 100644
--- a/demos/2d/space_shooter/main_menu.scn
+++ b/demos/2d/space_shooter/main_menu.scn
Binary files differ
diff --git a/demos/2d/space_shooter/parallax.scn b/demos/2d/space_shooter/parallax.scn
index f67277dc01..2753d16e84 100644
--- a/demos/2d/space_shooter/parallax.scn
+++ b/demos/2d/space_shooter/parallax.scn
Binary files differ
diff --git a/demos/2d/space_shooter/rail.gd b/demos/2d/space_shooter/rail.gd
index 22ebd02670..7362dff97d 100644
--- a/demos/2d/space_shooter/rail.gd
+++ b/demos/2d/space_shooter/rail.gd
@@ -1,25 +1,19 @@
extends Node2D
+# Member variables
+const SPEED = 200
+var offset = 0
-const SPEED=200
-# member variables here, example:
-# var a=2
-# var b="textvar"
func stop():
set_process(false)
-var offset=0
-
func _process(delta):
- offset+=delta*SPEED
- set_pos(Vector2(offset,0))
+ offset += delta*SPEED
+ set_pos(Vector2(offset, 0))
+
func _ready():
set_process(true)
- # Initialization here
-
-
-
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
diff --git a/demos/2d/space_shooter/ship.scn b/demos/2d/space_shooter/ship.scn
index 82c710eda7..c60e2e3e3b 100644
--- a/demos/2d/space_shooter/ship.scn
+++ b/demos/2d/space_shooter/ship.scn
Binary files differ
diff --git a/demos/2d/space_shooter/shot.gd b/demos/2d/space_shooter/shot.gd
index 28b67bd26d..936dde73d1 100644
--- a/demos/2d/space_shooter/shot.gd
+++ b/demos/2d/space_shooter/shot.gd
@@ -1,48 +1,40 @@
extends Area2D
-# member variables here, example:
-# var a=2
-# var b="textvar"
-
+# Member variables
const SPEED = 800
+var hit = false
+
+
func _process(delta):
- translate(Vector2(delta*SPEED,0))
+ translate(Vector2(delta*SPEED, 0))
+
func _ready():
- # Initialization here
set_process(true)
- pass
-var hit=false
func _hit_something():
if (hit):
return
- hit=true
+ hit = true
set_process(false)
get_node("anim").play("splash")
+
func _on_visibility_exit_screen():
queue_free()
- pass # replace with function body
-
-func _on_shot_area_enter( area ):
- #hit an enemy or asteroid
+func _on_shot_area_enter(area):
+ # Hit an enemy or asteroid
if (area.has_method("destroy")):
- #duck typing at it's best
+ # Duck typing at it's best
area.destroy()
_hit_something()
-
-
- pass
-func _on_shot_body_enter( body ):
- #hit the tilemap
+func _on_shot_body_enter(body):
+ # Hit the tilemap
_hit_something()
- pass # replace with function body
-
diff --git a/demos/2d/space_shooter/shot.scn b/demos/2d/space_shooter/shot.scn
index 86a20ffa47..9daf4ebe82 100644
--- a/demos/2d/space_shooter/shot.scn
+++ b/demos/2d/space_shooter/shot.scn
Binary files differ