LoginLogin

4-directional circle pad movement?

Root / Programming Questions / [.]

ElectriicDevCreated:
Can't seem to figure out how to get 4-directional circle pad movement working. Does anybody have an example on this kinda thing?

Like, the player moves a sprite using the circle pad but they can't move diagonally. If you've played the first Legend of Zelda game on 3DS Virtual Console, that kind of movement is what I'm trying to achieve.

Orthogonal movement. One solution is shown here: https://smilebasicsource.com/forum?fpid=6680#post_6680 The idea there being that if either X or Y is greater (in either direction) than the threshold value .2, take that as the direction. It's easier than mapping the angle to a right one. You could of course replace the ...B=B OR with just changing your sprite's position.

HERE IS ORTHAGONAL MOVEMENT EXAMPLE OK LETS GO
PX = 10 'player X position
PY = 10 'player Y position
T = 0.2 'threshold value

WHILE 1
    STICK OUT CX, CY 'Get circle pad values
    
'check for dominant direction
    IF CX<CY AND CX>T THEN DIR = 1 ELSEIF CX>CY AND CY>T THEN DIR = 2 'DIR1 is up, DIR2 is right
    IF CX>CY AND CX<T THEN DIR = 3 ELSEIF CX<CY AND CY<T THEN DIR = 4 'DIR3 is down, DIR4 is left
   
 IF CX == 0 AND CY == 0 THEN DIR = 0 'not moving

    IF DIR == 1 then 'move up
    IF DIR == 2 then 'move right
    IF DIR == 3 then 'move down
    IF DIR == 4 then 'move left
WEND
This should work.

I'll try these out, thank you!