At the time of writing this book, Monk didn't create the needed folder structure for you. So, you need to manually set up the folder for our project:
chainreaction
. chainreaction.data
. chainreaction.data
folder into your .data
folder. fantomEngine.monkey
. chainreaction.monkey
.Strict #rem Script: chainreaction.monkey Description: Sample script from chapter #5 of the book "Monkey Game Development Beginners guide" by PacktPub Author: Michael Hartlef #end Import fantomEngine Global g:game
It looks familiar, right? If not, then please study Chapter 4, Game# 3 Comet Crusher, where we did the same. What's next? Adding the game
class to our file.
game
with the 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
Remember, we want to utilize the OnSuspend
and OnResume
events.
OnSuspend
and OnResume
, and close the class.Method OnResume:Int() Return 0 End Method OnSuspend:Int() Return 0 End End
And like with every Monkey app, we need to add the Main
function.
Main
function header.Function Main:Int()
game
class, store it inside the variable g
, and then close the function.g = New game Return 0 End
To interface with fantomEngine, we will now create an instance of its ftEngine
class.
engine
, which is an instance of the ftEngine
class. Next, insert methods for its OnObjectTouch, OnObjectTransition, OnObjectCollision
, and OnObjectTimer
methods.Class engine Extends ftEngine Method OnObjectTouch:Int(obj:ftObject, touchId:Int) Return 0 End Method OnObjectTransition:Int(transId:Int, obj:ftObject) Return 0 End Method OnObjectCollision:Int(obj:ftObject, obj2:ftObject) Return 0 End Method OnLayerTimer:Int(timerId:Int, obj:ftObject) Return 0 end End
This is the basic structure of our game. Save the file and build it to see if any errors appear.
They say, just like history, Monkey game development repeats itself. We are once again interfacing with the fantomEngine; this is a huge timesaver.
3.137.220.92