Create a gist now

Instantly share code, notes, and snippets.

Embed
11.2 Make a way to get to the final boss fight
#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
Field player:Character
Field enemies:List<Character>
Field last_enemy_time:Float
Field next_enemy_interval:Float
Field projectiles:List<Projectile>
Field final_boss:Character
' Need to save the start time
' and the time the boss should show up
Field start_time:Float
Field boss_time:Float
' track the game state
Field game_state:Int
Const PLAYER_GROUP:Int = 1
Const ENEMY_GROUP:Int = 2
Const PROJECTILES:Int = 3
' create const to store our game states
Const STATE_LEVEL:Int = 1
Const STATE_BOSS:Int = 2
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>()
game_over_scene = engine.CreateScene()
game_over_layer = engine.CreateLayer()
game_over_scene.AddLayer(game_over_layer)
engine.SetDefaultLayer(game_over_layer)
Local font:ftFont = engine.LoadFont("vt323_sample_2.txt")
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)
engine.SetDefaultLayer(play_layer)
' Get the start time and set the Boss Time
' to 15 secs for now for testing
' and set the game state to the level
Self.start_time = Millisecs()
Self.boss_time = 15000
Self.game_state = STATE_LEVEL
Seed = Millisecs()
End
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)
Else If (game_over_scene.isActive)
If (KeyDown(KEY_ENTER))
ResetGame()
End
Else
' check whether or not we need to move to the boss state
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)
' Call update for the final boss
Self.final_boss.Update(engine.GetCanvasWidth(), engine.GetCanvasHeight())
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
' ................
Method ResetGame()
' reset the games state and start time
game_state = STATE_LEVEL
start_time = Millisecs()
game_over_scene.SetActive(False)
game_over_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
' ..................
End
Function Main()
New Game()
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment