Some nice game as mini mario so you can expand more in your purpose game

Here the code :
Code: Select all
InitSprite()
InitKeyboard()
InitMouse()
#SCREEN_WIDTH = 800
#SCREEN_HEIGHT = 600
#PLAYER_WIDTH = 32
#PLAYER_HEIGHT = 32
#GROUND_Y = 550
OpenWindow(0, 0, 0, #SCREEN_WIDTH/DesktopResolutionX(), #SCREEN_HEIGHT/DesktopResolutionY(), "Mini Mario", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
Structure Player
x.f
y.f
vx.f
vy.f
onGround.b
EndStructure
Global mario.Player
mario\x = 100
mario\y = #GROUND_Y - #PLAYER_HEIGHT
mario\vx = 0
mario\vy = 0
mario\onGround = #True
Global gravity.f = 0.5
Global jumpForce.f = -10
Global moveSpeed.f = 4
Repeat
ClearScreen(RGB(135, 206, 235)) ; blue sky
ExamineKeyboard()
; move to left/right
If KeyboardPushed(#PB_Key_Left)
mario\vx = -moveSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
mario\vx = moveSpeed
Else
mario\vx = 0
EndIf
; jump
If KeyboardPushed(#PB_Key_Space) And mario\onGround
mario\vy = jumpForce
mario\onGround = #False
EndIf
; gravity
mario\vy + gravity
; position update
mario\x + mario\vx
mario\y + mario\vy
; Collision with the ground
If mario\y >= #GROUND_Y - #PLAYER_HEIGHT
mario\y = #GROUND_Y - #PLAYER_HEIGHT
mario\vy = 0
mario\onGround = #True
EndIf
StartDrawing(ScreenOutput())
; draw of ground
Box(0, #GROUND_Y, #SCREEN_WIDTH, #SCREEN_HEIGHT - #GROUND_Y, RGB(34, 139, 34)) ; green ground
; draw of player
Box(mario\x, mario\y, #PLAYER_WIDTH, #PLAYER_HEIGHT, RGB(255, 0, 0)) ; red player
StopDrawing()
FlipBuffers()
Delay(16) ; ~60 FPS
Until KeyboardPushed(#PB_Key_Escape)
Enjoy and happy coding !