-
Notifications
You must be signed in to change notification settings - Fork 13
/
GameScene.gd
74 lines (58 loc) · 1.8 KB
/
GameScene.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
extends Node2D
enum GameState { Loading, Running, GameOver }
onready var State = GameState.Loading;
onready var enemyObj = preload("res://Enemy.tscn")
var Player = null
var cam = null
func _ready():
var labelText = "Stage " + str(globals.currentStage)
$Label.set_text(labelText)
$AnimationPlayer.play("Stage Display")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
$HUD/Kills.set_text("Kills:" + str(globals.kills))
pass
func _input(event):
if(State == GameState.GameOver):
get_tree().change_scene("TitleScene.tscn")
func startAnimationDone():
$Label.visible = false
Player = load("res://Player.tscn").instance()
Player.position = Vector2(300,720/2)
cam = Camera2D.new()
cam.position.x = 360
cam.make_current()
Player.add_child(cam)
add_child(Player)
SpawnEnemies()
State = GameState.Running
func _on_Area2D_area_entered(area):
#Did we hit the trigger to queue boss fight?
if(area.get_collision_layer_bit(4)):
if(State == GameState.Running):
Player.speed = 0
globals.currentStage = globals.currentStage + 1
get_tree().reload_current_scene()
func _on_GroundArea_area_entered(area):
if(State == GameState.Running):
Player.explode()
func PlayerDied():
for i in Player.get_children():
i.queue_free()
remove_child(Player)
State = GameState.GameOver
$Label.set_text("Game Over")
$Label.visible = true
$Label.set_position(Vector2(1280/2 - 200, 720/2))
func SpawnEnemy(x,y):
var enemy = enemyObj.instance()
enemy.set_position(Vector2(x,y))
add_child(enemy)
func SpawnEnemies():
randomize()
# One extra plane per stage
for i in range(0,10+globals.currentStage):
SpawnEnemy(700 + randi()%5000,randi()%int(get_viewport_rect().size.y))
func SpawnBossWave():
for i in range(0,10):
SpawnEnemy(3800 + randi()%220, randi()%720)