i'm having issues figuring this out. I have code that makes at sprite move but I want to incorporate a viewless boarder so that when the sprite go the edge of the play area provided, it's based on a chess board, the sprite will stop moving but it will still move away from the border, in other words, I want movement code that includes only the dimensions of the checkered area only and makes the sprite only allowed to move in that area. How could I do that? Also, should I include what I have coded?
How to make a motion border for sprites with if statments?
Root / Programming Questions / [.]
Techster14Created:
uh is this what you're looking for?
IF PX%<BSX% THEN PX%=BSX% IF PX%>BEX% THEN PX%=BEX% IF PY%<BSX% THEN PY%=BSY% IF PY%>BEX% THEN PY%=BEY%PX% is the sprite position x coordinates. PY% is the Y coordinates. BSX% and BSY% are the lower x and y limitations. So you could set BSX% to 72 and it the sprite couldn't go anywhere to the left of that, and the same goes for BSY% except the sprite can't go above it. With BEX% and BEY%, it's the higher limitation. So the sprite can't go to the right of BEX% and it can't go below BEY%. I hope this helps.
My code is
’up If button(0)==1 then Spofs 1, x,y-k Endif ‘Down If button(0)==2 then Spofs 1,x,y+k Endif ‘Left If button(0)==4 then Spofs 1,x-k,y Endif ‘Right If button(0)==8 then Spofs 1,x+k,y EndifHow would i set the movement area border parameters into this code? K represents the “slope” or change in position of the x or y values.
Also if possible, can someone teach me how to use collision testing? I’m wanting to code in an enemy sprite that will cause damage to your sprite if they collide and i can’t figure out how it works.
I’ve been using smileBASIC for 2 years now so yeah i’m still a newb but i’ve made a cmd prompt and other things.
He's probably new. BTW if you want to detect multiple button presses, useWhat does theBUTTON(0) AND #A
#Ado? Also, will that allow me to condense my movement system to one if statement?
Oh, ok, just making sure. So i could do
BUTTON(0) AND #UPand it will allow my sprite to move if the up button is pressed?
I know it needs to be in an if statement, since all computer programs simplify to basic logic.
I’m trying to prevent the sprite from going out of bounds.
uh is this what you're looking for?The solution was given to you by random.IF PX%<BSX% THEN PX%=BSX% IF PX%>BEX% THEN PX%=BEX% IF PY%<BSX% THEN PY%=BSY% IF PY%>BEX% THEN PY%=BEY%PX% is the sprite position x coordinates. PY% is the Y coordinates. BSX% and BSY% are the lower x and y limitations. So you could set BSX% to 72 and it the sprite couldn't go anywhere to the left of that, and the same goes for BSY% except the sprite can't go above it. With BEX% and BEY%, it's the higher limitation. So the sprite can't go to the right of BEX% and it can't go below BEY%. I hope this helps.
So then my code should look like this:
if button(0) and (#up or #down or #right or #left) then {insert move code here} Endif While true: If px%<bs%...
So then my code should look like this:The problem with this is that all of the button inputs are in one IF statement, and it would be hard to figure out which way it should go. It's better to use 4 IF statements.if button(0) and (#up or #down or #right or #left) then {insert move code here} Endif While true: If px%<bs%...