Skip to content

Instantly share code, notes, and snippets.

@codetravis
codetravis / eleven_eight.monkey
Created January 6, 2017 22:52
11.8 Add transition to next level scene when boss is destroyed
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))
@codetravis
codetravis / eleven_seven.monkey
Created January 6, 2017 22:43
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
@codetravis
codetravis / eleven_six.monkey
Created January 6, 2017 13:50
11.6 Update constructors in the Game class and the projectile firing check
Method CreatePlayer()
Local box:ftObject = Self.engine.CreateBox(120, 20, engine.GetCanvasWidth()/2, engine.GetCanvasHeight()/2)
box.SetColor(0, 70, 70)
box.SetMaxSpeed(20.0)
box.SetMinSpeed(-20.0)
box.SetColGroup(PLAYER_GROUP)
box.SetColType(Self.engine.ctBox)
box.SetText("PLAYER")
Local projectile_type:ProjectileType = New ProjectileType()
' Update the constructor to use the new string identifier
@codetravis
codetravis / eleven_five.monkey
Created January 6, 2017 13:46
11.5 Modify character class to handle more character types
Import fantomX
Import projectile_type
Class Character
Field box:ftObject
Field current_health:Int
Field max_health:Int
' changing is_player to character_type
Field character_type:String
@codetravis
codetravis / eleven_four.monkey
Created January 6, 2017 13:42
11.4 Set collisions between player and projectiles with the final boss
Import fantomX
Class CustomEngine Extends ftEngine
' Add player and projectile collision to the final boss
Method OnObjectCollision:Int(obj_one:ftObject, obj_two:ftObject)
If (obj_one.GetText() = "PLAYER" And (obj_two.GetText() = "ENEMY" Or obj_two.GetText() = "FINALBOSS"))
CharacterCollision(obj_one, obj_two)
Else If (obj_two.GetText() = "PLAYER" And (obj_one.GetText() = "ENEMY" Or obj_one.GetText() = "FINALBOSS"))
CharacterCollision(obj_two, obj_one)
@codetravis
codetravis / eleven_three.monkey
Created January 5, 2017 13:55
11.3 Add a simple pattern for the Boss' movements
' Character Class
Method Update(game_width:Float, game_height:Float)
Local x_speed:Float = Self.box.GetSpeedX()
Local y_speed:Float = Self.box.GetSpeedY()
If (Self.is_player)
If (KeyDown(KEY_LEFT))
Self.box.SetSpeedX(x_speed - 1.0)
Else If (KeyDown(KEY_RIGHT))
Self.box.SetSpeedX(x_speed + 1.0)
@codetravis
codetravis / eleven_two.monkey
Last active January 5, 2017 13:32
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
@codetravis
codetravis / eleven_one.monkey
Created January 4, 2017 12:22
11.1 Creating the Boss
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
@codetravis
codetravis / ten_four.monkey
Last active January 3, 2017 00:00
10.4 Call the GameReset method when the ENTER key is pressed
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)
' Manage the visibility of the game over scene
game_over_scene.SetVisible(True)
game_over_scene.SetAlpha(1.0)
' Reset the game if the player hits ENTER during game over
@codetravis
codetravis / ten_three.monkey
Created January 2, 2017 23:52
10.3 Refactor the player creation code into a method
' Game class
Method OnCreate()
Self.engine = New CustomEngine
play_scene = engine.GetDefaultScene()
play_layer = engine.GetDefaultLayer()
play_scene.AddLayer(play_layer)
' Create our player
CreatePlayer()