Instantly share code, notes, and snippets.

Embed
What would you like to do?
9.3 Change scenes on update if the player is destroyed
' Game Class
Method OnUpdate()
Local time_delta:Float = Float(engine.CalcDeltaTime())/60.0
' Change scenese when the player is destroyed
If (player.box.GetText() = "DESTROYED" And play_scene.isActive = True)
play_scene.SetActive(False)
game_over_scene.SetActive(True)
game_over_scene.SetAlpha(1.0)
Else
If ((Millisecs() - Self.last_enemy_time) > Self.next_enemy_interval)
CreateEnemy()
Self.last_enemy_time = Millisecs()
End
player.Update(engine.GetCanvasWidth(), engine.GetCanvasHeight())
If (KeyDown(KEY_SPACE) And player.FireProjectile())
CreateProjectile(player)
End
For Local projectile:Projectile = Eachin Self.projectiles
projectile.Update()
If (projectile.box.GetText() = "DESTROYED")
projectile.box.Remove()
Self.projectiles.RemoveFirst(projectile)
End
End
For Local enemy:Character = Eachin Self.enemies
enemy.Update(engine.GetCanvasWidth(), engine.GetCanvasHeight())
If (enemy.box.GetText() = "DESTROYED")
If (enemy.current_health <= 0)
Self.player.IncreaseScore(enemy.point_value)
End
enemy.box.Remove()
Self.enemies.RemoveFirst(enemy)
End
End
End
If engine.GetPaused() = False
engine.Update(time_delta)
engine.CollisionCheck()
End
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment