Instantly share code, notes, and snippets.

Embed
What would you like to do?
11.12 Let the game get to the game over state once the player beats the last level
' Game class
Method OnUpdate()
Local time_delta:Float = Float(engine.CalcDeltaTime())/60.0
If (player.box.GetText() = "DESTROYED" And play_scene.isActive)
play_scene.SetActive(False)
game_over_scene.SetActive(True)
game_over_scene.SetVisible(True)
game_over_scene.SetAlpha(1.0)
' reset the game if the player won or lost
Else If (game_over_scene.isActive Or game_won_scene.isActive)
If (KeyDown(KEY_ENTER))
ResetGame()
End
Else If (next_level_scene.isActive)
If (KeyDown(KEY_ENTER))
NextLevel()
End
Else
If (Self.game_state = STATE_LEVEL)
If (Millisecs() - Self.start_time > Self.boss_time)
Self.game_state = STATE_BOSS
CreateFinalBoss()
Else If ((Millisecs() - Self.last_enemy_time) > Self.next_enemy_interval)
CreateEnemy()
Self.last_enemy_time = Millisecs()
End
Else If (Self.game_state = STATE_BOSS)
If (final_boss.box.GetText() = "DESTROYED" And play_scene.isActive)
Self.player.IncreaseScore(final_boss.point_value)
final_boss.box.Remove()
' Update the current level when the boss is defeated
Self.current_level += 1
play_scene.SetActive(False)
' set the scene to the game won scene if the the player just beat the final level
If (current_level > FINAL_LEVEL)
game_won_scene.SetActive(True)
game_won_scene.SetVisible(True)
game_won_scene.SetAlpha(1.0)
Else
next_level_scene.SetActive(True)
next_level_scene.SetVisible(True)
next_level_scene.SetAlpha(1.0)
End
Else
' ..................
End
' ...............
' Update the Reset game method to handle game won reset as well
Method ResetGame()
current_level = 1
game_state = STATE_LEVEL
start_time = Millisecs()
game_won_scene.SetActive(False)
game_won_scene.SetVisible(False)
game_over_scene.SetActive(False)
game_over_scene.SetVisible(False)
next_level_scene.SetActive(False)
next_level_scene.SetVisible(False)
play_scene.SetActive(True)
play_scene.SetAlpha(1.0)
Self.player.box.Remove()
CreatePlayer()
For Local enemy:Character = Eachin Self.enemies
enemy.box.Remove()
Self.enemies.RemoveFirst(enemy)
End
For Local projectile:Projectile = Eachin Self.projectiles
projectile.box.Remove()
Self.projectiles.RemoveFirst(projectile)
End
End
Method NextLevel()
game_state = STATE_LEVEL
start_time = Millisecs()
next_level_scene.SetActive(False)
next_level_scene.SetVisible(False)
game_over_scene.SetVisible(False)
' Hide the game won scene when we go to the next level
game_won_scene.SetVisible(False)
play_scene.SetActive(True)
play_scene.SetAlpha(1.0)
For Local enemy:Character = Eachin Self.enemies
enemy.box.Remove()
Self.enemies.RemoveFirst(enemy)
End
For Local projectile:Projectile = Eachin Self.projectiles
projectile.box.Remove()
Self.projectiles.RemoveFirst(projectile)
End
final_boss.box.Remove()
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment