Skip to content

Instantly share code, notes, and snippets.

@codetravis
Created December 21, 2016 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codetravis/006dbeb81cdd427b87fa46023bae29bc to your computer and use it in GitHub Desktop.
Save codetravis/006dbeb81cdd427b87fa46023bae29bc to your computer and use it in GitHub Desktop.
8.13 add check for player FireProjectile when updating, also change slightly how projectiles are made
' Game Class
Method OnUpdate()
Local time_delta:Float = Float(engine.CalcDeltaTime())/60.0
If ((Millisecs() - Self.last_enemy_time) > Self.next_enemy_interval)
CreateEnemy()
Self.last_enemy_time = Millisecs()
End
player.Update(engine.GetCanvasWidth(), engine.GetCanvasHeight())
' Add our character can fire check here
If (KeyDown(KEY_SPACE) And player.FireProjectile())
CreateProjectile(player)
End
For Local enemy:Character = Eachin Self.enemies
enemy.Update(engine.GetCanvasWidth(), engine.GetCanvasHeight())
If (enemy.box.GetText() = "DESTROYED")
enemy.box.Remove()
Self.enemies.RemoveFirst(enemy)
End
End
If engine.GetPaused() = False
engine.Update(time_delta)
engine.CollisionCheck()
End
End
' ............................
Method CreateProjectile(character:Character)
Local projectile_box:ftObject = Self.engine.CreateBox(20, 10, character.box.GetPosX() + character.box.GetWidth()/2, character.box.GetPosY())
projectile_box.SetColGroup(PROJECTILES)
If (character.is_player)
projectile_box.SetSpeedX(50)
projectile_box.SetColor(0, 255, 255)
projectile_box.SetColWith(ENEMY_GROUP, True)
Else
projectile_box.SetPosX(character.box.GetPosX() - character.box.GetWidth()/2)
projectile_box.SetSpeedX(-50)
projectile_box.SetColor(255, 255, 0)
projectile_box.SetColWith(PLAYER_GROUP, True)
End
projectile_box.SetText("PROJECTILE")
Self.projectiles.AddLast(New Projectile(projectile_box, character.projectile_type))
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment