First Monkey steps - leonard-thieu/monkey GitHub Wiki
Skid spills some source...
We begin with the smallest monkey program.
Function Main()
Print "Hello"
End
In which, with the HTML5 target selected, we verify we are able to create and view our monkey developments.
To learn more about the Main entry point of a program make sure you read the Programs and Declarations section of the Language reference.
We now build a mojo App which we call Game (in monkey class names are typically capitalized).
Import mojo
Class Game Extends App
Method OnCreate()
Print "hello"
End
End
Function Main()
New Game()
End
A mojo App is used to provide us methods of input, graphics and sound. The framework above creates a single App using the Game class definition.
With our game object defined we extend the basic Update and Render parts of the app.
The minimum requirements for an animating monkey application are an App implementing the methods:
- OnCreate must call SetUpdateRate
- OnUpdate can use mojo input commands
- OnRender can use mojo drawing commands
The following draws an animated spiral shape using the DrawPoint command.
Import mojo
Class Game Extends App
' radial sprial with axis aligned phase
Function DrawSpiral(clock)
Local w=DeviceWidth/2
For Local i#=0 Until w*1.5 Step .2
Local x#,y#
x=w+i**Sin(i**3+clock)
y=w+i**Cos(i**2+clock)
DrawPoint x,y
Next
End
Field updateCount
Method OnCreate()
Print "spiral"
SetUpdateRate 60
End
Method OnUpdate()
updateCount+=1
End
Method OnRender()
Cls
DrawSpiral updateCount
DrawSpiral updateCount*1.1
End
End
Function Main()
New Game()
End
Each spiral drawn by the program begins at the middle of the screen and spirals out using the Maths functions Sin and Cos.
Here is the final application:
<iframe src="data/First monkey steps/spiral/spiral.build/html5/MonkeyGame.html" width=640 height=480 scrolling=no></iframe>