Skip to content

Instantly share code, notes, and snippets.

@codetravis
codetravis / fourteen_six.monkey
Created March 14, 2017 22:54
14.6 Shoot and Scoot pattern
' Fire and run pattern
Function ShootAndScootPattern(box:ftObject, game_width:Float, game_height:Float, max_y_speed:Float=5.0)
If (box.GetSpeedY() < 0.1 And box.GetSpeedY() > -0.1)
If (box.GetPosX() < game_width/1.5)
' Using the boxes Tag property to tell enemies to fire
box.SetTag(1)
If (box.GetPosY() > game_height/2)
box.SetSpeedY(max_y_speed * -1)
Else
box.SetSpeedY(max_y_speed)
@codetravis
codetravis / fourteen_five.monkey
Created March 14, 2017 22:17
14.5 Step up and down pattern
' New stepped height change pattern
Function StepChangeHeightPattern(box:ftObject, game_width:Float, game_height:Float,
start_x:Float, start_y:Float, step_width:Float=100.0,
step_height:Float=25.0, number_of_steps:Int=10, max_y_speed:Float=5.0)
Local current_x:Float = box.GetPosX()
Local current_y:Float = box.GetPosY()
Local modifier:Int = 1
If (start_y > game_height/2)
modifier = -1
End
@codetravis
codetravis / fourteen_six.monkey
Created February 12, 2017 12:30
14.6 Update OnObjectCollision to use Contains instead of an equals comparison for ENEMY in the object text
Import fantomX
Class CustomEngine Extends ftEngine
Method OnObjectCollision:Int(obj_one:ftObject, obj_two:ftObject)
' Change all of our engine checks to use Contains() instead of = so we can use various enemy types
If (obj_one.GetText().Contains("PLAYER") And (obj_two.GetText().Contains("ENEMY") Or obj_two.GetText().Contains("FINALBOSS")))
CharacterCollision(obj_one, obj_two)
Else If (obj_two.GetText().Contains("PLAYER") And (obj_one.GetText().Contains("ENEMY") Or obj_one.GetText().Contains("FINALBOSS")))
CharacterCollision(obj_two, obj_one)
@codetravis
codetravis / fourteen_five.monkey
Last active February 12, 2017 12:40
14.5 Update the Enemy generator code to set the enemy type
' Game Class
' Modify the CreateEnemy method to set the enemies box Text different
' for each enemy so the type is set properly
Method CreateEnemy()
Local rand_enemy:Float = Rnd(0, 3)
Local projectile_type:ProjectileType = New ProjectileType()
Local width = 48
Local height = 32
Local health = 1
@codetravis
codetravis / fourteen_four.monkey
Last active February 12, 2017 14:39
14.4 Make changes to the Character class to utilize the new AI movement patterns
Import fantomX
Import projectile_type
' include our ai movement patterns
Import ai_movement
Class Character
Field box:ftObject
Field current_health:Int
Field max_health:Int
@codetravis
codetravis / fourteen_three.monkey
Created February 11, 2017 19:32
14.3 New file to hold AI movement patterns
Import fantomX
' Added this file to hold our various AI movement patterns
Function SimpleBossPattern(box:ftObject, game_width:Float, game_height:Float)
Local y_speed:Float = box.GetSpeedY()
Local x_speed:Float = box.GetSpeedX()
If (box.GetPosY() < 0)
box.SetSpeedY(y_speed + 0.5)
@codetravis
codetravis / fourteen_two.monkey
Created February 7, 2017 14:04
14.2 Create a smaller player graphic and load it from the spritesheet
Method CreatePlayer()
' load the new, smaller player image from the modified sprite sheet, and add the animation frame count
Local box:ftObject = engine.CreateAnimImage(game_sprite_atlas.GetImage("player_submarine_two_animation"), 0, 0,
96, game_sprite_atlas.GetImageHeight("player_submarine_two_animation"), 4, engine.GetCanvasWidth()/2, engine.GetCanvasHeight()/2)
box.SetMaxSpeed(10.0)
box.SetMinSpeed(-10.0)
box.SetFriction(0.5)
box.SetColGroup(PLAYER_GROUP)
box.SetColType(Self.engine.ctBox)
box.SetText("PLAYER")
@codetravis
codetravis / fourteen_one.monkey
Created February 7, 2017 13:32
14.1 Add friction to the player movement and modify player speed
Method CreatePlayer()
Local box:ftObject = engine.CreateAnimImage(game_sprite_atlas.GetImage("player_submarine_anim"), 0, 0,
128, game_sprite_atlas.GetImageHeight("player_submarine_anim"), 3, engine.GetCanvasWidth()/2, engine.GetCanvasHeight()/2)
' Change the player max speed and add friction
box.SetMaxSpeed(10.0)
box.SetMinSpeed(-10.0)
box.SetFriction(0.5)
box.SetColGroup(PLAYER_GROUP)
box.SetColType(Self.engine.ctBox)
box.SetText("PLAYER")
@codetravis
codetravis / thirteen_five.monkey
Created February 3, 2017 15:06
13.5 Add Boss image from sprite sheet
' Give the boss an image from the sprite sheet
Method CreateFinalBoss()
Local box:ftObject = Self.engine.CreateImage(game_sprite_atlas.GetImage("tutorial_boss"), engine.GetCanvasWidth() - 10, engine.GetCanvasHeight()/2)
box.SetColor(255, 0, 255)
box.SetMaxSpeed(20.0)
box.SetMinSpeed(-20.0)
box.SetColGroup(ENEMY_GROUP)
box.SetColWith(PLAYER_GROUP, True)
box.SetText("FINALBOSS")
Local projectile_type:ProjectileType = New ProjectileType(1, 1000, 0.2, 25, 1.5)
@codetravis
codetravis / thirteen_four.monkey
Created February 3, 2017 14:55
13.4 Add projectile images from sprite sheet
' use our sprite atlas for projectiles
Method CreateProjectile(character:Character, width_modifier:Float=0, height_modifier:Float=0)
Local projectile_box:ftObject
If (character.character_type = "PLAYER")
projectile_box = Self.engine.CreateImage(game_sprite_atlas.GetImage("player_projectile"),
character.box.GetPosX() + character.box.GetWidth()/2 + width_modifier,
character.box.GetPosY() + height_modifier)
projectile_box.SetSpeedX(10)
projectile_box.SetColor(0, 255, 255)
projectile_box.SetColWith(ENEMY_GROUP, True)