Skip to content

Instantly share code, notes, and snippets.

@codetravis
codetravis / thirteen_three.monkey
Created February 3, 2017 13:49
13.3 Create enemies with animations and images
' change how we randomize and create the enemies
Method CreateEnemy()
Local rand_enemy:Float = Rnd(0, 3)
Local projectile_type:ProjectileType = New ProjectileType()
Local width = 48
Local height = 32
Local health = 1
Local points = 10
Local rand_y:Float = Rnd(height, Self.engine.GetCanvasHeight())
@codetravis
codetravis / thirteen_two.monkey
Last active February 3, 2017 15:14
13.2 Load a sprite atlas and pull the player animation from it.
Class Game Extends App
'......................
Field current_level:Int
' add field to hold new sprite sheet
Field game_sprite_atlas:ftSpriteAtlas
'.......................
Method OnCreate()
Self.engine = New CustomEngine
play_scene = engine.GetDefaultScene()
@codetravis
codetravis / thirteen_one.monkey
Last active February 3, 2017 15:13
13.1 Loading player sprite sheet and attaching it to the player
Class Game Extends App
'......................
Field current_level:Int
' add fields to hold new player image
Field player_image:Image
Const FINAL_LEVEL:Int = 2
'.................
@codetravis
codetravis / twelve_three.monkey
Last active January 14, 2017 16:18
12.3 Have the Boss shoot more
' Game Class
Method OnUpdate()
'...............
Else
Self.final_boss.Update(engine.GetCanvasWidth(), engine.GetCanvasHeight())
' change the boss' shooting pattern to 3 projectiles
If Self.final_boss.FireProjectile()
Local boss_width:Float = final_boss.box.GetWidth()
Local boss_height:Float = final_boss.box.GetHeight()
CreateProjectile(final_boss, 100, boss_height/2 * -1)
@codetravis
codetravis / twelve_two.monkey
Created January 14, 2017 15:41
12.2 Tell projectiles to collide with the player character and damage it
' CustomEngine class
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)
End
'Update projectile collision to check for collision with the player
If (obj_one.GetText() = "PROJECTILE" And
@codetravis
codetravis / twelve_one.monkey
Created January 14, 2017 15:26
12.1 The Boss shoots back
' Game Class
Method OnUpdate()
' ..............
Else
Self.final_boss.Update(engine.GetCanvasWidth(), engine.GetCanvasHeight())
' Have the Boss shoot
If Self.final_boss.FireProjectile()
CreateProjectile(final_boss)
End
End
@codetravis
codetravis / eleven_twelve.monkey
Last active January 14, 2017 15:39
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
@codetravis
codetravis / eleven_eleven.monkey
Created January 6, 2017 23:41
11.11 Track the current level and set a maximum level
#FantomX_UsePhysics = True
Import fantomX
Import character
Import projectile
Import custom_engine
Class Game Extends App
Field engine:ftEngine
@codetravis
codetravis / eleven_ten.monkey
Created January 6, 2017 23:34
11.10 Add the Game Won scene to the game
#FantomX_UsePhysics = True
Import fantomX
Import character
Import projectile
Import custom_engine
Class Game Extends App
Field engine:ftEngine
@codetravis
codetravis / eleven_nine.monkey
Created January 6, 2017 22:54
11.9 Add method to allow players on next level scene to continue
Method NextLevel()
game_state = STATE_LEVEL
start_time = Millisecs()
next_level_scene.SetActive(False)
next_level_scene.SetVisible(False)
game_over_scene.SetVisible(False)
play_scene.SetActive(True)
play_scene.SetAlpha(1.0)
For Local enemy:Character = Eachin Self.enemies
enemy.box.Remove()