monkey coder

Monkey Coder – Input – Arrow Keys

Monkey Coder – Input – Arrow Keys

1. Notice:
——
I have created variables for the X position and Y position of the Ball

‘ Ball
Field bX:Float = 320.0 ‘X pos of the ball in the middle of canvas (canvas size: 640×480)
Field bY:Float = 240.0 ‘Y pos in the middle of the canvas (canvas size: 640×480)

2. Notice:
——
I have created the Method ControlPlayer to control the arrow keys, they are coded as KEY_UP, KEY_DOWN, KEY_RIGHT, KEY_LEFT

‘ Control Player Input START
Method ControlPlayer:Int()

‘ Control START
If KeyDown(KEY_UP) Then ‘Check if UP key is pressed
bY -= 5.0 ‘subtract 5 pixel from Y position

If bY < 5.0 Then bY = 5.0 'Check against top wall (canvas size: 640x480) Endif ' Control END ' Control Player Input START If KeyDown(KEY_DOWN) Then 'Check if DOWN key is pressed bY += 5.0 'Add 5 pixels to Y position If bY > 475.0 Then bY = 475.0 ‘Check against bottomwall (canvas size: 640×480)
Endif
‘ Control END

‘ Control Player Input START
If KeyDown(KEY_RIGHT) Then ‘Check if RIGHT key is pressed
bX += 5.0 ‘Add 5 pixels to X position

If bX > 635.0 Then bX = 635.0 ‘Check against rightwall (canvas size: 640×480)
Endif
‘ Control END

‘ Control Player Input START
If KeyDown(KEY_LEFT) Then ‘Check if LEFT key is pressed
bX -= 5.0 ‘substract 5 pixels to X position

If bX < 5.0 Then bX = 5.0 'Check against leftwall (canvas size: 640x480) Endif ' Control END Return True End ' Control Player Input END 3. Notice: ------ I have created a Method UpdateGame to put inside it ControlPlayer() wrote above in the point 2. ' Update Game START Method UpdateGame:Int() ControlPlayer() 'Control the player up an down Return True End ' Update Game END 4. Notice: ------ I have put inside Method OnUpdate:Int() the UpdateGame() ' OnUpdate START Method OnUpdate:Int() UpdateGame() Return True End ' OnUpdate END Flow Chart: Method OnUpdate ->call-> UpdateGame() ->call-> ControlPlayer() ->control-> arrow keys and variables

' STEP 1 All games open with this first command
Strict

#rem
Script: pong.monkey
Description: it is a remake of an old game!
Author: Andrea Tonin
#End

' STEP 2 Import framework mojo - it is a 2D framamework to support graphics, sound, input, device events
Import mojo

' STEP 3 Creation of Class - yourgame - (we can use the name of the game)

' Class yourgame START *****************************************
Class yourgame Extends App

' Ball
Field bX:Float = 320.0 'X pos of the ball in the middle of canvas (canvas size: 640x480)
Field bY:Float = 240.0 'Y pos in the middle of the canvas (canvas size: 640x480)

' STEP 4 Creation of Method OnCreate - OnUpdate - OnRender

' OnCreate START
Method OnCreate:Int()
SetUpdateRate(60)
Return True
End
' OnCreate END

' OnUpdate START
Method OnUpdate:Int()

UpdateGame()

Return True
End
' OnUpdate END

' Control Player Input START
Method ControlPlayer:Int()

' Control START
If KeyDown(KEY_UP) Then 'Check if UP key is pressed
bY -= 5.0 'subtract 5 pixel from Y position

If bY < 5.0 Then bY = 5.0 'Check against top wall (canvas size: 640x480)
Endif
' Control END

' Control Player Input START
If KeyDown(KEY_DOWN) Then 'Check if DOWN key is pressed
bY += 5.0 'Add 5 pixels to Y position

If bY > 475.0 Then bY = 475.0 'Check against bottomwall (canvas size: 640x480)
Endif
' Control END

' Control Player Input START
If KeyDown(KEY_RIGHT) Then 'Check if RIGHT key is pressed
bX += 5.0 'Add 5 pixels to X position

If bX > 635.0 Then bX = 635.0 'Check against rightwall (canvas size: 640x480)
Endif
' Control END

' Control Player Input START
If KeyDown(KEY_LEFT) Then 'Check if LEFT key is pressed
bX -= 5.0 'substract 5 pixels to X position

If bX < 5.0 Then bX = 5.0 'Check against leftwall (canvas size: 640x480)
Endif
' Control END

Return True
End
' Control Player Input END

' Update Game START
Method UpdateGame:Int()
ControlPlayer() 'Control the player up an down
Return True
End
' Update Game END

' OnRender START
Method OnRender:Int()
Cls 'Clear the canvas each frame

DrawCircle(bX, bY, 5) 'Draw the ball with a radius of 5

Return True
End
' OnRender END

End
' Class yourgame END ********************************************

' Step 5 Creation of Main function

Function Main:Int()
' Create a running istance from our class - the class - yourgame - has been created at STEP 3 
New yourgame
Return True
End
By |Monkey Coder|Commenti disabilitati su Monkey Coder – Input – Arrow Keys

Monkey Coder – Draw Geometry

Monkey Coder – Draw Geometry

Notice:

You can draw geometric figures.

The code is:

‘ DrawPlayField START *********
Method DrawPlayField:Int()

DrawCircle (100,200,20) ‘ x,y,r
DrawEllipse (100,300,20,40) ‘ x,y,r1,r2
DrawOval (400,200,100,200) ‘ x,y,r1,r2
DrawPoint(5,5) ‘ x,y
DrawLine (300,300,400,400) ‘ x,y,x,y
DrawRect (10,10,200,100) ‘ x,y,x,y

Return True
End
‘ DrawPlayField END ***********

' STEP 1 All games open with this first command
Strict

#rem
Script: 
Description: 
Author: Andrea Tonin
#End

' STEP 2 Import framework mojo - it is a 2D framamework to support graphics, sound, input, device events
Import mojo

' STEP 3 Creation of Class - yourgame - (we can use the name of the game)

' Class yourgame START *****************************************
Class yourgame Extends App

' STEP 4 Creation of Method OnCreate - OnUpdate - OnRender

	' OnCreate START *******
	Method OnCreate:Int()
	SetUpdateRate(60)
	Return True
	End
	' OnCreate END *********

	' OnUpdate START *******
	Method OnUpdate:Int()
	Return True
	End
	' OnUpdate END *********
	
	' DrawPlayField START *********
	Method DrawPlayField:Int()
	
	DrawCircle (100,200,20)     ' x,y,r
	DrawEllipse (100,300,20,40) ' x,y,r1,r2
	DrawOval (400,200,100,200)  ' x,y,r1,r2
	DrawPoint(5,5)              ' x,y
	DrawLine (300,300,400,400)  ' x,y,x,y
	DrawRect (10,10,200,100)    ' x,y,x,y
	
	Return True
	End
    ' DrawPlayField END ***********

	' OnRender START *******
	Method OnRender:Int()
	
	Cls 'Clear the canvas each frame, the canvas will be black!
    DrawPlayField() 'this call draws the background
	
	Return True
	End
	' OnRender END *********

End
' Class yourgame END ********************************************

' Step 5 Creation of Main function

Function Main:Int()
	' Create a running istance from our class - the class - yourgame - has been created at STEP 3 
	New yourgame
	Return True
End
By |Monkey Coder|Commenti disabilitati su Monkey Coder – Draw Geometry

Monkey Coder – Draw

Monkey Coder – Draw

Notice:

Between the – Method OnUpdate – and the – Method OnRender – we have to create the – Method DrawPlayField –

The code is:

‘ DrawPlayField START *********
Method DrawPlayField:Int()

‘Draw the top wall with a rectangle
DrawRect(10,10,200,100)

Return True
End
‘ DrawPlayField END ***********

You can draw Rectangles, Circles and others things…

After inside – Method OnRender – you can write:

Cls ‘Clear the canvas each frame, the canvas will be black!
DrawPlayField() ‘this call draws the background

DrawPlayField() is the same you have created above.

' STEP 1 All games open with this first command
Strict

#rem
Script: 
Description: 
Author: Andrea Tonin
#End

' STEP 2 Import framework mojo - it is a 2D framamework to support graphics, sound, input, device events
Import mojo

' STEP 3 Creation of Class - yourgame - (we can use the name of the game)

' Class yourgame START *****************************************
Class yourgame Extends App

' STEP 4 Creation of Method OnCreate - OnUpdate - OnRender

	' OnCreate START *******
	Method OnCreate:Int()
	SetUpdateRate(60)
	Return True
	End
	' OnCreate END *********

	' OnUpdate START *******
	Method OnUpdate:Int()
	Return True
	End
	' OnUpdate END *********
	
	' DrawPlayField START *********
	Method DrawPlayField:Int()
	'Draw the top wall with a rectangle
	DrawRect(10,10,200,100)
	Return True
	End
    ' DrawPlayField END ***********

	' OnRender START *******
	Method OnRender:Int()
	
	Cls 'Clear the canvas each frame, the canvas will be black!
    DrawPlayField() 'this call draws the background
	
	Return True
	End
	' OnRender END *********

End
' Class yourgame END ********************************************

' Step 5 Creation of Main function

Function Main:Int()
	' Create a running istance from our class - the class - yourgame - has been created at STEP 3 
	New yourgame
	Return True
End
By |Monkey Coder|Commenti disabilitati su Monkey Coder – Draw

Monkey Coder – Base White Canvas

Monkey Coder – Base White Canvas

' STEP 1 All games open with this first command
Strict

#rem
Script: 
Description: 
Author: Andrea Tonin
#End

' STEP 2 Import framework mojo - it is a 2D framamework to support graphics, sound, input, device events
Import mojo

' STEP 3 Creation of Class - yourgame - (we can use the name of the game)

' Class yourgame START *****************************************
Class yourgame Extends App

' STEP 4 Creation of Method OnCreate - OnUpdate - OnRender

	' OnCreate START *******
	Method OnCreate:Int()
	SetUpdateRate(60)
	Return True
	End
	' OnCreate END *********

	' OnUpdate START *******
	Method OnUpdate:Int()
	Return True
	End
	' OnUpdate END *********

	' OnRender START *******
	Method OnRender:Int()
	Return True
	End
	' OnRender END *********

End
' Class yourgame END ********************************************

' Step 5 Creation of Main function

Function Main:Int()
	' Create a running istance from our class - the class - yourgame - has been created at STEP 3 
	New yourgame
	Return True
End
By |Monkey Coder|Commenti disabilitati su Monkey Coder – Base White Canvas

Monkey Coder – Hello World

Monkey Coder – Hello World

Monkey is a next-generation games programming language that allows you to create apps on multiple platforms with the greatest of ease.

Let’go on!

' This is only a single line comment

#rem
Multiple line comment
Multiple line comment
#end

'The main function is required in every project!!!!
' ********** Function Main() START **********
Function Main()
	' Render the text
	Print ("Hello World")
' Every function needs to be closed!!!
End
' ********* Function Main() END    **********

By |Monkey Coder|Commenti disabilitati su Monkey Coder – Hello World