monkey coder

Monkey Coder – Point Counter

Monkey Coder – Point Counter

1. NOTICE:
———-
I have added the line:

Points += 1 ‘Add 1 point

in every bounce control method. It adds one point to each bounce.

2. NOTICE:
———-
I have written the following code to print the points

‘ Print Points START
Method PrintPoints:Int()
Print (“Points” + “:” + Points)
Return True
End
‘ Print Points END

3. NOTICE
———-
I have put PrintPoints() inside Method OnUpdate:Int()

‘ OnUpdate START
Method OnUpdate:Int()

BallUpdate()
PrintPoints()

Return True
End
‘ OnUpdate END

By |Monkey Coder|Commenti disabilitati su Monkey Coder – Point Counter

Monkey Coder – XY Bouncing Ball

Monkey Coder – XY Bouncing Ball

*********************
X POSITION MANAGEMENT
*********************

1. Notice:
———-
I have created on Class yourgame Extends App a new variable:

The code:
Field bXSpeed:Float = 3.0 ‘ X Speed (add 3.0 pixel every 1/60 sec)

2. Notice:
———-
I have created the Method BallUpdate:Int() to change the ball position. The ball has to stay inside the canvas. I verify the x position of the ball (bx variable) and I need to invert speed to create the bounce effect :)

The code:

‘ Update Ball START
Method BallUpdate:Int()
bX += bXSpeed ‘Add the X speed of the ball to its X position every 1/60 sec (frame rate: 60 fps)

If bX < 5.0 Then ' To control left bounce bX = 5.0 'Set the X position back to 5.0 bXSpeed *= -1 'Inverse the balls X speed Endif If bX > 635.0 Then ‘ To control right bounce
bX = 635.0 ‘Set the X position back to 635.0
bXSpeed *= -1 ‘Inverse the balls X speed
Endif

Return True
End
‘ Update Ball END

3. Notice:
———-
Very very Important: I put the BallUpdate() inside Method OnUpdate:Int() to execute BallUpdate().
Without this code the ball does not change its position!!!

The code:

‘ OnUpdate START
Method OnUpdate:Int()

BallUpdate()

Return True
End
‘ OnUpdate END

*********************
Y POSITION MANAGEMENT
*********************

I do the same job for variables “bY” ball Y position and “bYSpeed” ball Y position Speed.

' 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)
Field bXSpeed:Float = 3.0 ' X Speed (add 3.0 every 1/60 sec)
Field bYSpeed:Float = 3.0 ' Y Speed (add 3.0 every 1/60 sec)

' 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()

BallUpdate()

Return True
End
' OnUpdate END

' Update Ball START
Method BallUpdate:Int()
bX += bXSpeed 'Add the X speed of the ball to its X position every 1/60 sec (frame rate: 60 fps)
bY += bYSpeed 'Add the Y speed of the ball to its Y position every 1/60 sec (frame rate: 60 fps)

If bX < 5.0 Then ' To control left bounce
	bX = 5.0 'Set the X position back to 5.0 
	bXSpeed *= -1 'Inverse the balls X speed
Endif

If bX > 635.0 Then ' To control right bounce
	bX = 635.0 'Set the X position back to 635.0
	bXSpeed *= -1 'Inverse the balls X speed
Endif

If bY > 475.0 Then ' To control bottom bounce
	bY = 475.0 'Set the Y position back to 635.0
	bYSpeed *= -1 'Inverse the balls Y speed
Endif

If bY < 5.0 Then ' To control top bounce
	bY = 5.0 'Set the Y position back to 635.0
	bYSpeed *= -1 'Inverse the balls Y speed
Endif

Return True
End
' Update Ball 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 – XY Bouncing Ball

Monkey Coder – X Bouncing Ball

Monkey Coder – X Bouncing Ball

1. Notice:
———-
I have created on Class yourgame Extends App a new variable:

The code:
Field bXSpeed:Float = 3.0 ‘ X Speed (add 3.0 pixel every 1/60 sec)

2. Notice:
———-
I have created the Method BallUpdate:Int() to change the ball position. The ball has to stay inside the canvas. I verify the x position of the ball (bx variable) and I need to invert speed to create the bounce effect :)

The code:

‘ Update Ball START
Method BallUpdate:Int()
bX += bXSpeed ‘Add the X speed of the ball to its X position every 1/60 sec (frame rate: 60 fps)

If bX < 5.0 Then ' To control left bounce bX = 5.0 'Set the X position back to 5.0 bXSpeed *= -1 'Inverse the balls X speed Endif If bX > 635.0 Then ‘ To control right bounce
bX = 635.0 ‘Set the X position back to 635.0
bXSpeed *= -1 ‘Inverse the balls X speed
Endif

Return True
End
‘ Update Ball END

3. Notice:
———-
Very very Important: I put the BallUpdate() inside Method OnUpdate:Int() to execute BallUpdate().
Without this code the ball does not change its position!!!

The code:

‘ OnUpdate START
Method OnUpdate:Int()

BallUpdate()

Return True
End
‘ OnUpdate END

1. Notice:
----------
I have created on Class yourgame Extends App a new variable:

The code:
Field bXSpeed:Float = 3.0 ' X Speed (add 3.0 pixel every 1/60 sec)


2. Notice:
----------
I have created the Method BallUpdate:Int() to change the ball position. The ball has to stay inside the canvas. I verify the x position of the ball (bx variable) and I need to invert speed to create the bounce effect :)

The code:

' Update Ball START
Method BallUpdate:Int()
bX += bXSpeed 'Add the X speed of the ball to its X position every 1/60 sec (frame rate: 60 fps)

If bX < 5.0 Then ' To control left bounce
	bX = 5.0 'Set the X position back to 5.0 
	bXSpeed *= -1 'Inverse the balls X speed
Endif

If bX > 635.0 Then ' To control right bounce
	bX = 635.0 'Set the X position back to 635.0
	bXSpeed *= -1 'Inverse the balls X speed
Endif

Return True
End
' Update Ball END

3. Notice:
----------
Very very Important: I put the BallUpdate() inside Method OnUpdate:Int() to execute BallUpdate().
Without this code the ball does not change its position!!! 

The code:

' OnUpdate START
Method OnUpdate:Int()

BallUpdate()

Return True
End
' OnUpdate END
By |Monkey Coder|Commenti disabilitati su Monkey Coder – X Bouncing Ball

Monkey Coder – Input Mouse Codes

Monkey Coder – Input Mouse Codes

‘ Example START
If KeyDown(MOUSE_LEFT) Then ‘Check if MOUSE LEFT key is pressed

‘ You want to do…

Endif
‘ Example END

‘ Input Mouse Codes:

MOUSE_LEFT : Int
MOUSE_MIDDLE : Int
MOUSE_RIGHT : Int

By |Monkey Coder|Commenti disabilitati su Monkey Coder – Input Mouse Codes

Monkey Coder – Input Keyboard Codes

Monkey Coder – Input Keyboard Codes

‘ Example START
If KeyDown(KEY_DOWN) Then ‘Check if DOWN key is pressed

‘ You want to do…

Endif
‘ Example END

‘ Input Keyboard Codes:

CHAR_BACKSPACE : Int
CHAR_DELETE : Int
CHAR_DOWN : Int
CHAR_END : Int
CHAR_ENTER : Int
CHAR_ESCAPE : Int
CHAR_HOME : Int
CHAR_INSERT : Int
CHAR_LEFT : Int
CHAR_PAGEDOWN : Int
CHAR_PAGEUP : Int
CHAR_RIGHT : Int
CHAR_TAB : Int
CHAR_UP : Int
KEY_0 : Int
KEY_1 : Int
KEY_2 : Int
KEY_3 : Int
KEY_4 : Int
KEY_5 : Int
KEY_6 : Int
KEY_7 : Int
KEY_8 : Int
KEY_9 : Int
KEY_A : Int
KEY_B : Int
KEY_BACKSLASH : Int
KEY_BACKSPACE : Int
KEY_C : Int
KEY_CLOSEBRACKET : Int
KEY_COMMA : Int
KEY_CONTROL : Int
KEY_D : Int
KEY_DELETE : Int
KEY_DOWN : Int
KEY_E : Int
KEY_END : Int
KEY_ENTER : Int
KEY_EQUALS : Int
KEY_ESCAPE : Int
KEY_F : Int
KEY_F1 : Int
KEY_F10 : Int
KEY_F11 : Int
KEY_F12 : Int
KEY_F2 : Int
KEY_F3 : Int
KEY_F4 : Int
KEY_F5 : Int
KEY_F6 : Int
KEY_F7 : Int
KEY_F8 : Int
KEY_F9 : Int
KEY_G : Int
KEY_H : Int
KEY_HOME : Int
KEY_I : Int
KEY_INSERT : Int
KEY_J : Int
KEY_K : Int
KEY_L : Int
KEY_LEFT : Int
KEY_LMB : Int
KEY_M : Int
KEY_MINUS : Int
KEY_MMB : Int
KEY_N : Int
KEY_O : Int
KEY_OPENBRACKET : Int
KEY_P : Int
KEY_PAGEDOWN : Int
KEY_PAGEUP : Int
KEY_PERIOD : Int
KEY_Q : Int
KEY_QUOTES : Int
KEY_R : Int
KEY_RIGHT : Int
KEY_RMB : Int
KEY_S : Int
KEY_SEMICOLON : Int
KEY_SHIFT : Int
KEY_SLASH : Int
KEY_SPACE : Int
KEY_T : Int
KEY_TAB : Int
KEY_TILDE : Int
KEY_TOUCH0 : Int
KEY_U : Int
KEY_UP : Int
KEY_V : Int
KEY_W : Int
KEY_X : Int
KEY_Y : Int
KEY_Z : Int

By |Monkey Coder|Commenti disabilitati su Monkey Coder – Input Keyboard Codes