QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: codevsb12 on February 16, 2020, 08:33:19 pm
-
what do i need to do so that my character stops moving when it hits the corner of the screen?
i already set up some variables such as x speed, y speed, x max, y max, etc.
-
Show the code you already have first, so people can help debug it.
-
DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,00,00,00 DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00 DATA 00,00,00,00,00,00,14,14,14,14,00,14,14,14,14,00,00,00,00,00,00 DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00,00 DATA 00,00,00,00,00,00,14,14,14,14,14,14,00,00,00,00,00,00,14,14,00 DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,14,14 DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,14,14,14,14 DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00 DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,00 DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00 DATA 00,00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00 DATA 00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00,00 DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,00,00,00,00,14,14,14,14,14,00,14,14,14,14,14,00,00,00,00,00 DATA 00,00,00,00,00,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00 DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00 DATA 00,00,00,00,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00 DATA 00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00 DATA 00,00,00,14,14,14,14,00,00,00,00,00,00,14,14,14,14,00,14,14,00 DATA 00,00,14,14,14,14,14,00,00,00,00,00,00,14,14,14,14,14,14,14,00 DATA 00,00,00,14,14,14,14,14,14,00,00,00,00,14,14,14,14,14,14,14,00 DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,14,14,00,00,00 DATA 00,00,00,00,00,14,14,14,00,00,00,00,00,14,14,00,00,00,00,00,00
GET (0, 1)-(20, 30), player%
()
xp = 64
yp = 70
xb = 400
yb = 300
xmax = 639
ymax = 349
xspd = 0
yspd = 0
tecla:
-
Use IF to limit xp and yp to the screen boundaries:
DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,00,00,00 DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00 DATA 00,00,00,00,00,00,14,14,14,14,00,14,14,14,14,00,00,00,00,00,00 DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,00,00,00,00 DATA 00,00,00,00,00,00,14,14,14,14,14,14,00,00,00,00,00,00,14,14,00 DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,14,14 DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,14,14,14,14 DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00 DATA 00,00,00,00,00,00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,00 DATA 00,00,00,00,00,00,00,14,14,14,14,14,14,14,00,00,00,00,14,14,00 DATA 00,00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00 DATA 00,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,00,00 DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 14,14,14,14,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,14,14,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,00,00,00,00,00,14,14,14,14,14,14,14,14,14,00,00,00,00,00,00 DATA 00,00,00,00,00,14,14,14,14,14,00,14,14,14,14,14,00,00,00,00,00 DATA 00,00,00,00,00,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00 DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,00,00,00,00,00 DATA 00,00,00,00,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00 DATA 00,00,00,14,14,14,14,14,00,00,00,00,00,14,14,14,14,00,00,00,00 DATA 00,00,00,14,14,14,14,00,00,00,00,00,00,14,14,14,14,00,14,14,00 DATA 00,00,14,14,14,14,14,00,00,00,00,00,00,14,14,14,14,14,14,14,00 DATA 00,00,00,14,14,14,14,14,14,00,00,00,00,14,14,14,14,14,14,14,00 DATA 00,00,00,00,14,14,14,14,14,00,00,00,14,14,14,14,14,14,00,00,00 DATA 00,00,00,00,00,14,14,14,00,00,00,00,00,14,14,00,00,00,00,00,00
GET (0, 1)-(20, 30), player%
()
xp = 64
yp = 70
xb = 400
yb = 300
xmax = 639
ymax = 349
xspd = 0
yspd = 0
_DISPLAY is used here to stop the flickering, and instead of a GOTO, I added a DO/LOOP block.
PS: When you post code in the forum, make sure to add [code=qb64] before and [/code] after your code block.
-
just wanna check if it runs on dos box or something before i put it in my code
edit: it doesnt
c'mon, i know someone has the solution...
edit2: i tried it by myself, and now my character dies when going straight to the right
i dont even need to put the entire code, so...
xp = 64
yp = 70
xb = 400
yb = 300
xmax = 639
ymax = 349
tecla:
-
c'mon, i know someone has the solution...
Love your attitude.
When is your homework due?
-
The bounds checking should be immediately after you change the variables.
The way you've got it, if that code is in a loop, you'll get PUTs with invalid
parameters. It probably won't crash QB64, but why take a chance?
-
just wanna check if it runs on dos box or something before i put it in my code
Are you using QB64 or some other QB? Dosbox shouldn't matter if you're using QB64, amirite?