As this is the first time, we will work with the resources files and will need to set up the folder of our project in a slightly different manner:
.data
. cometcrusher.data
folder into your .data
folder. fantomEngine.monkey
.Inside the new script add the following lines; by now you will know them pretty well.
Strict #rem Script: cometcrusher.monkey Description: Sample script from chapter #4 of the book "Monkey Game Development Beginners guide" by PacktPub Author: Michael Hartlef #end Import fantomEngine
g
, which holds an instance of our main class called game
.Global g:game
Then add the game
class to our source file.
game
with OnCreate, OnUpdate
, and OnRender
methods.Class game Extends App Method OnCreate:Int() Return 0 End Method OnUpdate:Int() Return 0 End Method OnRender:Int() Return 0 End End
The last thing that is needed for a valid Monkey app is the Main
function.
Main
function header.Function Main:Int()
game
class and store it inside the variable g
. Then, close the function.g = New game Return 0 End
fantomEngine supports different object, layer, and timer-related event methods. To fill them with life, and of course use fantomEngine, we need to create an instance of the ftEngine
class.
engine
, as an instance of the ftEngine
class. Inside it, create methods for its OnObjectCollision, OnObjectTimer, OnObjectUpdate
, and OnLayerUpdate
methods.Class engine Extends ftEngine '------------------------------------------ Method OnObjectCollision:Int(obj:ftObject, obj2:ftObject) Return 0 End Method OnObjectTimer:Int(timerId:Int, obj:ftObject) Return 0 End Method OnObjectUpdate:Int(obj:ftObject) Return 0 End Method OnLayerUpdate:Int(layer:ftLayer) Return 0 end End
That's it. Save your file and if you like, let it build to see if any error shows up. Remember, save save save!