Block- Man Script
Posted: Sat Dec 10, 2022 4:18 pm
Simple script to make a block move around a 800x600 window using the arrow keys.
(Extracted and modified from the "Simple Break-Out Clone" script by: ArtBlink & Figgy/CtZ & amyren, found elsewhere on this forum)
Two issue: How can I use the initial position without it being instantly updated before any key is pressed?
How can I avoid the speed increase when moving diagonally?
(Extracted and modified from the "Simple Break-Out Clone" script by: ArtBlink & Figgy/CtZ & amyren, found elsewhere on this forum)
Code: Select all
@DISPLAY{WIDTH = 800, HEIGHT = 600, MODE = "WINDOWED"} ;Create the window
CreateBrush(1,32,32,#GREEN) ; CREATE BLOCK-MAN
BM_Xpos = #CENTER ; Set initial X-position
BM_Ypos = #CENTER ; Set initial Y-position
SPEED = 5 ; Set the movement speed
Function p_UpdateScreen()
;Check Key-presses and move Block-Man:
If IsKeyDown("LEFT") = True Then BM_XPos = BM_XPos - SPEED
If IsKeyDown("RIGHT") = True Then BM_XPos = BM_XPos + SPEED
If IsKeyDown("UP") = True Then BM_YPos = BM_YPos - SPEED
If IsKeyDown("DOWN") = True Then BM_Ypos = BM_Ypos + SPEED
;Check if Block-Man leaves the screen and reposition if he does:
If BM_XPos < 0 Then BM_XPos = 0
If BM_XPos > 768 Then BM_XPos = 768
If BM_Ypos < 0 Then BM_Ypos = 0
If BM_Ypos > 568 Then BM_Ypos = 568
DisplayBrush(1, BM_Xpos, BM_Ypos)
EndFunction
BeginDoubleBuffer()
EscapeQuit(True)
Repeat
Cls()
p_UpdateScreen()
Flip()
Forever
EndDoubleBuffer()How can I avoid the speed increase when moving diagonally?