Instantly share code, notes, and snippets.

Embed
What would you like to do?
11.7 Add a Next Level scene
#FantomX_UsePhysics = True
Import fantomX
Import character
Import projectile
Import custom_engine
Class Game Extends App
Field engine:ftEngine
Field play_layer:ftLayer
Field play_scene:ftScene
Field game_over_scene:ftScene
Field game_over_layer:ftLayer
' add a next level scene and layer
Field next_level_scene:ftScene
Field next_level_layer:ftLayer
' ..............................
Method OnCreate()
Self.engine = New CustomEngine
play_scene = engine.GetDefaultScene()
play_layer = engine.GetDefaultLayer()
play_scene.AddLayer(play_layer)
CreatePlayer()
Self.enemies = New List<Character>()
Self.last_enemy_time = Millisecs()
Self.next_enemy_interval = 3000
Self.projectiles = New List<Projectile>()
Local font:ftFont = engine.LoadFont("vt323_sample_2.txt")
' Refactor scene creation code to its own methods
BuildGameOverScene(font)
BuildNextLevelScene(font)
engine.SetDefaultLayer(play_layer)
Self.start_time = Millisecs()
Self.boss_time = 15000
Self.game_state = STATE_LEVEL
Seed = Millisecs()
End
' move game over scene creation code here
Method BuildGameOverScene(font:ftFont)
game_over_scene = engine.CreateScene()
game_over_layer = engine.CreateLayer()
game_over_scene.AddLayer(game_over_layer)
engine.SetDefaultLayer(game_over_layer)
Local game_over_text:ftObject = engine.CreateText(font, "GAME OVER",
engine.GetCanvasWidth()/2 - 75, engine.GetCanvasHeight()/2 - 50, engine.taTopLeft)
Local game_over_instruction:ftObject = engine.CreateText(font, "Press ENTER to Restart",
engine.GetCanvasWidth()/4, engine.GetCanvasHeight()/2 + 50, engine.taTopLeft)
game_over_scene.SetActive(False)
End
' create next level scene here
Method BuildNextLevelScene(font:ftFont)
next_level_scene = engine.CreateScene()
next_level_layer = engine.CreateLayer()
next_level_scene.AddLayer(next_level_layer)
engine.SetDefaultLayer(next_level_layer)
Local next_level_text:ftObject = engine.CreateText(font, "YOU BEAT THE BOSS",
engine.GetCanvasWidth()/2 - 75, engine.GetCanvasHeight()/2 - 50, engine.taTopLeft)
Local next_level_congrats:ftObject = engine.CreateText(font, "CONGRATULATIONS!",
engine.GetCanvasWidth()/2 - 75, engine.GetCanvasHeight()/2, engine.taTopLeft)
Local next_level_instruction:ftObject = engine.CreateText(font, "Press ENTER to Go to the Next Level",
engine.GetCanvasWidth()/4, engine.GetCanvasHeight()/2 + 50, engine.taTopLeft)
next_level_scene.SetActive(False)
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment