Jump to content
IGNORED

How do you limit joystick to 4-way movement?


Random Terrain

Recommended Posts

I used to know how to do this stuff on the VIC-20 and Commodore 64, but I cannot remember how to limit the joystick to 4-way movement. I'm almost done with my test program with the random mazes and a little sprite you can move around, but the little thing can sneak diagonally sometimes and go over little bits of the wall.

 

How do you stop the player from moving diagonally?

 

Thanks.

Link to comment
Share on other sites

I used to know how to do this stuff on the VIC-20 and Commodore 64, but I cannot remember how to limit the joystick to 4-way movement. I'm almost done with my test program with the random mazes and a little sprite you can move around, but the little thing can sneak diagonally sometimes and go over little bits of the wall.

 

How do you stop the player from moving diagonally?

 

Thanks.

938370[/snapback]

If you stop reading the joystick once you have you've detected movement in a single direction then you won't get diagonals.

Edited by vdub_bobby
Link to comment
Share on other sites

If you stop reading the joystick once you have you've detected movement in a single direction then you won't get diagonals.

Thanks.

 

Does it matter that the little sprite moves like Pac-Man? It doesn't stop until it comes to a wall.

 

Oh yeah, and about what you said, is this the best way to do that?

 

  if joy0up then do some stuff : goto skipstick
 if joy0down then do some stuff : goto skipstick
 if joy0left then do some stuff : goto skipstick
 if joy0right then do some stuff
skipstick

Edited by Random Terrain
Link to comment
Share on other sites

Oh yeah, and about what you said, is this the best way to do that?

 

  if joy0up then do some stuff : goto skipstick
 if joy0down then do some stuff : goto skipstick
 if joy0left then do some stuff : goto skipstick
 if joy0right then do some stuff
skipstick

938396[/snapback]

I dunno about "best," but that looks like it will certainly work. That's how I'd do it, anyway.

 

Or put it in a subroutine and:

   if joy0up then do some stuff : return
  if joy0down then do some stuff : return
  if joy0left then do some stuff : return
  if joy0right then do some stuff : return
  return

Link to comment
Share on other sites

I dunno about "best," but that looks like it will certainly work.  That's how I'd do it, anyway.

 

Or put it in a subroutine and:

   if joy0up then do some stuff : return
  if joy0down then do some stuff : return
  if joy0left then do some stuff : return
  if joy0right then do some stuff : return
  return

938407[/snapback]

Thanks. That's a good alternative to remember. I'd have to have a label for either one, so I guess the goto version will work OK for now unless something changes. Maybe I should check to see which one takes up more bytes.

Link to comment
Share on other sites

After trying and failing many times, I found a different way to stop the diagonal movement and stop the player from passing through bits of the wall. I had to jump to the same movement related gosubs twice and make the x and y negative/positive variables equal zero at the right time.

Edited by Random Terrain
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...