I ported the code from pico8-lua, but it doesn't work as expected. If I press "up" to jump, it reacts delayed.
Any hints for a beginner?
Code: Select all
@DISPLAY{WIDTH = 800, HEIGHT = 600, MODE = "WINDOWED"} ;Create the window
CreateBrush(1, 16, 16, #GREEN) ; CREATE BLOCK-MAN
CreateBrush(2, 32, 32, #GRAY) ; CREATE OBSTICLE
CreateBrush(3,800, 5, #WHITE) ; create floor
; ----------------- init
x = 380 ; x position player
y = 555 ; y position player
dx = 0 ; x movement player
dy = 0 ; y movement player
onground = True ; true if player is "on ground" else false
jump = 0 ; jump height
jumpmax = 5 ; maximum jump height
speed = 3 ; movement speed player
jumping = False ; seems to be needed for Hollywood
Function p_UpdateScreen()
dx = 0
dy = dy + 1
If IsKeyDown("LEFT") = True Then dx = dx - speed
If IsKeyDown("RIGHT") = True Then dx = dx + speed
If IsKeyDown("UP") = True And (jumping = False And onground = True) Then jumping = True
If jumping = True
onground=False
jump=jump + 1
dy = dy - 2
EndIf
If jump >jumpmax
jump = 0
jumping = False
onground = True
EndIf
; If jump > jumpmax
; dy = dy + 5
; ElseIf jump <= 0
; onground = True
;; dy = 0
; EndIf
If dy > 0 Then onground = True
If onground
jump = 0
; dy = 0
EndIf
x = x + dx
y = y + dy
;Check if player leaves the screen
If x < 0 Then x = 0
If x > 784 Then x = 784
If y < 0 Then y = 0
If y > 555 Then y = 555
DisplayBrush(1, x, y)
DisplayBrush(3, 0,555+16)
EndFunction
BeginDoubleBuffer()
EscapeQuit(True)
Repeat
Cls()
p_UpdateScreen()
Flip()
Forever
EndDoubleBuffer()