Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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