Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
7.4 Add enemy generator
#FantomX_UsePhysics = True
Import fantomX
Import character
Class Game Extends App
Field engine:ftEngine
Field default_layer:ftLayer
Field default_scene:ftScene
Field player:Character
Field enemies:List<Character>
' variable to hold the last time we created an enemy
Field last_enemy_time:Float
Method OnCreate()
Self.engine = New ftEngine
default_scene = engine.GetDefaultScene()
default_layer = engine.GetDefaultLayer()
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)
Self.player = New Character(box, True)
' Initialize the enemies list
Self.enemies = New List<Character>()
' Initialize last enemy time
Self.last_enemy_time = Millisecs()
End
Method OnUpdate()
Local time_delta:Float = Float(engine.CalcDeltaTime())/60.0
' Create an enemy if enough time has passed
If ((Millisecs() - last_enemy_time) > 3000)
CreateEnemy()
Self.last_enemy_time = Millisecs()
End
player.Update(engine.GetCanvasWidth(), engine.GetCanvasHeight())
If engine.GetPaused() = False
engine.Update(time_delta)
End
End
' Create and enemy at the edge of the screen and start them heading left
Method CreateEnemy()
Local box:ftObject = Self.engine.CreateBox(50, 30, Self.engine.GetCanvasWidth(), engine.GetCanvasHeight()/2)
box.SetColor(200, 200, 0)
box.SetSpeedX(-10)
enemies.AddLast(New Character(box))
End
Method OnRender()
engine.Clear(255, 0, 0)
engine.Render()
engine.SetColor(0, 70, 70)
engine.RenderFlush()
End
End
Function Main()
New Game()
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment