We will now build the basic structure for every game. Follow the given steps:
Strict
command, so that Monkey will keep us on track regarding giving identifiers the right type.Strict
#rem Script: Pongo.Monkey Description: Sample script from chapter #2 of the book "Monkey Game Development Beginners guide" by PacktPub Author: Michael Hartlef #end
mojo
, we have to import it.Import mojo
pongo
class that extends from mojo's
app class. We will include empty OnCreate, OnUpdate
, and OnRender
methods that we will fill later on.Class pongo Extends App Method OnCreate:Int() SetUpdateRate(60) Return True End Method OnUpdate:Int() Return True End Method OnRender:Int() Return True End End Function Main:Int() New pongo Return True End
Function Main:Int() New pongo 'This creates a new running instance from our class Return True End
S2038_02_02.Monkey
and let it run by pressing Ctrl + R on Windows or cmd + R on OSX. After you have selected the HTML5 platform target and Trans has created a HTML5 project, it should start your HTML5-compatible browser and display a blank canvas, most likely in white.This basic structure can be reused with every game you start. Only the class name should be changed from pongo
to something that fits your game.
Downloading the example code for this book
You can download the example code files for all Packt books you have purchased, using your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.