summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-06-11 09:55:38 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-06-11 10:00:48 -0300
commit9e479065f5ecc3017868d01380e024f11070baf2 (patch)
tree08d098e9f18bff08db9eb4c20b3032bf285ed3a5 /demos
parentbc6d91c8973619a6c4ce54a140197ba93d184cec (diff)
new space shooter demo
ortho camera sort fix, closes #2063
Diffstat (limited to 'demos')
-rw-r--r--demos/2d/space_shooter/asteroid.gd49
-rw-r--r--demos/2d/space_shooter/asteroid.scnbin0 -> 4516 bytes
-rw-r--r--demos/2d/space_shooter/bg_gradient.pngbin0 -> 1572 bytes
-rw-r--r--demos/2d/space_shooter/big_star.pngbin0 -> 275 bytes
-rw-r--r--demos/2d/space_shooter/enemy1.gd37
-rw-r--r--demos/2d/space_shooter/enemy1.pngbin0 -> 7048 bytes
-rw-r--r--demos/2d/space_shooter/enemy1.scnbin0 -> 3759 bytes
-rw-r--r--demos/2d/space_shooter/enemy2.gd56
-rw-r--r--demos/2d/space_shooter/enemy2.pngbin0 -> 5676 bytes
-rw-r--r--demos/2d/space_shooter/enemy2.scnbin0 -> 3801 bytes
-rw-r--r--demos/2d/space_shooter/enemy_shot.gd32
-rw-r--r--demos/2d/space_shooter/enemy_shot.pngbin0 -> 330 bytes
-rw-r--r--demos/2d/space_shooter/enemy_shot.scnbin0 -> 3944 bytes
-rw-r--r--demos/2d/space_shooter/engine.cfg21
-rw-r--r--demos/2d/space_shooter/explosion.scnbin0 -> 1497 bytes
-rw-r--r--demos/2d/space_shooter/fire.pngbin0 -> 357 bytes
-rw-r--r--demos/2d/space_shooter/game_state.gd24
-rw-r--r--demos/2d/space_shooter/level.scnbin0 -> 9185 bytes
-rw-r--r--demos/2d/space_shooter/level_tiles.resbin0 -> 720 bytes
-rw-r--r--demos/2d/space_shooter/level_tiles.scnbin0 -> 2148 bytes
-rw-r--r--demos/2d/space_shooter/main_menu.gd20
-rw-r--r--demos/2d/space_shooter/main_menu.scnbin0 -> 2402 bytes
-rw-r--r--demos/2d/space_shooter/meteorite.pngbin0 -> 6072 bytes
-rw-r--r--demos/2d/space_shooter/parallax.scnbin0 -> 3307 bytes
-rw-r--r--demos/2d/space_shooter/rail.gd26
-rw-r--r--demos/2d/space_shooter/ship.gd88
-rw-r--r--demos/2d/space_shooter/ship.pngbin0 -> 2815 bytes
-rw-r--r--demos/2d/space_shooter/ship.scnbin0 -> 6752 bytes
-rw-r--r--demos/2d/space_shooter/shoot.pngbin0 -> 222 bytes
-rw-r--r--demos/2d/space_shooter/shot.gd47
-rw-r--r--demos/2d/space_shooter/shot.scnbin0 -> 3990 bytes
-rw-r--r--demos/2d/space_shooter/small_star.pngbin0 -> 90 bytes
-rw-r--r--demos/2d/space_shooter/sound_explode.wavbin0 -> 75832 bytes
-rw-r--r--demos/2d/space_shooter/sound_shoot.wavbin0 -> 78888 bytes
-rw-r--r--demos/2d/space_shooter/tile.pngbin0 -> 810 bytes
35 files changed, 400 insertions, 0 deletions
diff --git a/demos/2d/space_shooter/asteroid.gd b/demos/2d/space_shooter/asteroid.gd
new file mode 100644
index 0000000000..f21b9777bb
--- /dev/null
+++ b/demos/2d/space_shooter/asteroid.gd
@@ -0,0 +1,49 @@
+
+extends Area2D
+
+# member variables here, example:
+# var a=2
+# var b="textvar"
+
+const SPEED=-200
+const Y_RANDOM=10
+
+var points=1
+
+
+var speed_y=0.0
+
+func _process(delta):
+
+ translate( Vector2(SPEED,speed_y) * delta )
+
+func _ready():
+ # Initialization here
+ speed_y=rand_range(-Y_RANDOM,Y_RANDOM)
+ pass
+
+var destroyed=false
+
+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+=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()
+ pass # replace with function body
diff --git a/demos/2d/space_shooter/asteroid.scn b/demos/2d/space_shooter/asteroid.scn
new file mode 100644
index 0000000000..b881725ea4
--- /dev/null
+++ b/demos/2d/space_shooter/asteroid.scn
Binary files differ
diff --git a/demos/2d/space_shooter/bg_gradient.png b/demos/2d/space_shooter/bg_gradient.png
new file mode 100644
index 0000000000..3e71976dc6
--- /dev/null
+++ b/demos/2d/space_shooter/bg_gradient.png
Binary files differ
diff --git a/demos/2d/space_shooter/big_star.png b/demos/2d/space_shooter/big_star.png
new file mode 100644
index 0000000000..7726a7aa12
--- /dev/null
+++ b/demos/2d/space_shooter/big_star.png
Binary files differ
diff --git a/demos/2d/space_shooter/enemy1.gd b/demos/2d/space_shooter/enemy1.gd
new file mode 100644
index 0000000000..051798742a
--- /dev/null
+++ b/demos/2d/space_shooter/enemy1.gd
@@ -0,0 +1,37 @@
+
+extends Area2D
+
+# member variables here, example:
+# var a=2
+# var b="textvar"
+
+const SPEED=-200
+
+func _process(delta):
+ get_parent().translate(Vector2(SPEED*delta,0))
+
+
+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+=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
+
+func _on_visibility_exit_screen():
+ queue_free()
+
diff --git a/demos/2d/space_shooter/enemy1.png b/demos/2d/space_shooter/enemy1.png
new file mode 100644
index 0000000000..242d8f0055
--- /dev/null
+++ b/demos/2d/space_shooter/enemy1.png
Binary files differ
diff --git a/demos/2d/space_shooter/enemy1.scn b/demos/2d/space_shooter/enemy1.scn
new file mode 100644
index 0000000000..14298f0a59
--- /dev/null
+++ 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
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
diff --git a/demos/2d/space_shooter/enemy2.png b/demos/2d/space_shooter/enemy2.png
new file mode 100644
index 0000000000..5b63033696
--- /dev/null
+++ b/demos/2d/space_shooter/enemy2.png
Binary files differ
diff --git a/demos/2d/space_shooter/enemy2.scn b/demos/2d/space_shooter/enemy2.scn
new file mode 100644
index 0000000000..1d31f9c30e
--- /dev/null
+++ 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
new file mode 100644
index 0000000000..238d24e4a2
--- /dev/null
+++ b/demos/2d/space_shooter/enemy_shot.gd
@@ -0,0 +1,32 @@
+
+extends Area2D
+
+# member variables here, example:
+# var a=2
+# var b="textvar"
+
+const SPEED = -800
+
+func _process(delta):
+ 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
+ set_process(false)
+ get_node("anim").play("splash")
+
+func _on_visibility_exit_screen():
+ queue_free()
+
diff --git a/demos/2d/space_shooter/enemy_shot.png b/demos/2d/space_shooter/enemy_shot.png
new file mode 100644
index 0000000000..04287211a9
--- /dev/null
+++ b/demos/2d/space_shooter/enemy_shot.png
Binary files differ
diff --git a/demos/2d/space_shooter/enemy_shot.scn b/demos/2d/space_shooter/enemy_shot.scn
new file mode 100644
index 0000000000..13f5ae89e5
--- /dev/null
+++ b/demos/2d/space_shooter/enemy_shot.scn
Binary files differ
diff --git a/demos/2d/space_shooter/engine.cfg b/demos/2d/space_shooter/engine.cfg
new file mode 100644
index 0000000000..12fd49b6e9
--- /dev/null
+++ b/demos/2d/space_shooter/engine.cfg
@@ -0,0 +1,21 @@
+[application]
+
+name="Simple Shooter"
+main_scene="res://main_menu.scn"
+
+[autoload]
+
+game_state="res://game_state.gd"
+
+[display]
+
+width=1024
+height=600
+
+[input]
+
+move_up=[key(Up)]
+move_down=[key(Down)]
+move_left=[key(Left)]
+move_right=[key(Right)]
+shoot=[key(Space)]
diff --git a/demos/2d/space_shooter/explosion.scn b/demos/2d/space_shooter/explosion.scn
new file mode 100644
index 0000000000..4edcf709cb
--- /dev/null
+++ b/demos/2d/space_shooter/explosion.scn
Binary files differ
diff --git a/demos/2d/space_shooter/fire.png b/demos/2d/space_shooter/fire.png
new file mode 100644
index 0000000000..1c68c36213
--- /dev/null
+++ b/demos/2d/space_shooter/fire.png
Binary files differ
diff --git a/demos/2d/space_shooter/game_state.gd b/demos/2d/space_shooter/game_state.gd
new file mode 100644
index 0000000000..26ef086f14
--- /dev/null
+++ b/demos/2d/space_shooter/game_state.gd
@@ -0,0 +1,24 @@
+extends Node
+
+
+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()
+
+
+
+func game_over():
+ if (points>max_points):
+ max_points=points
+ #save high score
+ var f = File.new()
+ 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
new file mode 100644
index 0000000000..12a679f8b6
--- /dev/null
+++ b/demos/2d/space_shooter/level.scn
Binary files differ
diff --git a/demos/2d/space_shooter/level_tiles.res b/demos/2d/space_shooter/level_tiles.res
new file mode 100644
index 0000000000..8712b8c799
--- /dev/null
+++ b/demos/2d/space_shooter/level_tiles.res
Binary files differ
diff --git a/demos/2d/space_shooter/level_tiles.scn b/demos/2d/space_shooter/level_tiles.scn
new file mode 100644
index 0000000000..3fb91d8cb3
--- /dev/null
+++ 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
new file mode 100644
index 0000000000..52221aba1b
--- /dev/null
+++ b/demos/2d/space_shooter/main_menu.gd
@@ -0,0 +1,20 @@
+
+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
+
+
+
+
+func _on_play_pressed():
+ 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
new file mode 100644
index 0000000000..b87cc5d3a8
--- /dev/null
+++ b/demos/2d/space_shooter/main_menu.scn
Binary files differ
diff --git a/demos/2d/space_shooter/meteorite.png b/demos/2d/space_shooter/meteorite.png
new file mode 100644
index 0000000000..92fb4387df
--- /dev/null
+++ b/demos/2d/space_shooter/meteorite.png
Binary files differ
diff --git a/demos/2d/space_shooter/parallax.scn b/demos/2d/space_shooter/parallax.scn
new file mode 100644
index 0000000000..f67277dc01
--- /dev/null
+++ 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
new file mode 100644
index 0000000000..803a09fe84
--- /dev/null
+++ b/demos/2d/space_shooter/rail.gd
@@ -0,0 +1,26 @@
+
+extends Node2D
+
+
+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))
+
+func _ready():
+ set_process(true)
+ # Initialization here
+
+
+
diff --git a/demos/2d/space_shooter/ship.gd b/demos/2d/space_shooter/ship.gd
new file mode 100644
index 0000000000..fa444868a4
--- /dev/null
+++ b/demos/2d/space_shooter/ship.gd
@@ -0,0 +1,88 @@
+
+extends Area2D
+
+# member variables here, example:
+# var a=2
+# var b="textvar"
+
+const SPEED = 200
+
+var screen_size
+
+var prev_shooting=false
+
+func _process(delta):
+
+ var motion = Vector2()
+ if Input.is_action_pressed("move_up"):
+ motion+=Vector2(0,-1)
+ if Input.is_action_pressed("move_down"):
+ motion+=Vector2(0,1)
+ if Input.is_action_pressed("move_left"):
+ motion+=Vector2(-1,0)
+ if Input.is_action_pressed("move_right"):
+ 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
+
+ set_pos(pos)
+
+ if (shooting and not prev_shooting):
+ # 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
+ get_node("../..").add_child(shot)
+ #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) )
+
+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
+ get_node("anim").play("explode")
+ get_node("sfx").play("sound_explode")
+ get_node("../hud/game_over").show()
+ get_node("/root/game_state").game_over()
+ get_parent().stop()
+ set_process(false)
+
+
+func _on_ship_body_enter( body ):
+ _hit_something()
+
+
+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.png b/demos/2d/space_shooter/ship.png
new file mode 100644
index 0000000000..a36b833903
--- /dev/null
+++ b/demos/2d/space_shooter/ship.png
Binary files differ
diff --git a/demos/2d/space_shooter/ship.scn b/demos/2d/space_shooter/ship.scn
new file mode 100644
index 0000000000..82c710eda7
--- /dev/null
+++ b/demos/2d/space_shooter/ship.scn
Binary files differ
diff --git a/demos/2d/space_shooter/shoot.png b/demos/2d/space_shooter/shoot.png
new file mode 100644
index 0000000000..6e80ddab93
--- /dev/null
+++ b/demos/2d/space_shooter/shoot.png
Binary files differ
diff --git a/demos/2d/space_shooter/shot.gd b/demos/2d/space_shooter/shot.gd
new file mode 100644
index 0000000000..813587d670
--- /dev/null
+++ b/demos/2d/space_shooter/shot.gd
@@ -0,0 +1,47 @@
+
+extends Area2D
+
+# member variables here, example:
+# var a=2
+# var b="textvar"
+
+const SPEED = 800
+
+func _process(delta):
+ translate(Vector2(delta*SPEED,0))
+
+func _ready():
+ # Initialization here
+ set_process(true)
+ pass
+
+var hit=false
+
+func _hit_something():
+ if (hit):
+ return
+ 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
+ if (area.has_method("destroy")):
+ #duck typing at it's best
+ area.destroy()
+ _hit_something()
+
+
+ pass
+
+
+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
new file mode 100644
index 0000000000..64c8c25ebe
--- /dev/null
+++ b/demos/2d/space_shooter/shot.scn
Binary files differ
diff --git a/demos/2d/space_shooter/small_star.png b/demos/2d/space_shooter/small_star.png
new file mode 100644
index 0000000000..71c3c531cd
--- /dev/null
+++ b/demos/2d/space_shooter/small_star.png
Binary files differ
diff --git a/demos/2d/space_shooter/sound_explode.wav b/demos/2d/space_shooter/sound_explode.wav
new file mode 100644
index 0000000000..229c85399c
--- /dev/null
+++ b/demos/2d/space_shooter/sound_explode.wav
Binary files differ
diff --git a/demos/2d/space_shooter/sound_shoot.wav b/demos/2d/space_shooter/sound_shoot.wav
new file mode 100644
index 0000000000..ad74f328cb
--- /dev/null
+++ b/demos/2d/space_shooter/sound_shoot.wav
Binary files differ
diff --git a/demos/2d/space_shooter/tile.png b/demos/2d/space_shooter/tile.png
new file mode 100644
index 0000000000..d8f41d16f6
--- /dev/null
+++ b/demos/2d/space_shooter/tile.png
Binary files differ