Jump to content

Photo

Joystick question


7 replies to this topic

#1 waderain OFFLINE  

waderain

    Space Invader

  • 27 posts
  • Location:sometimes Arizona, sometimes Montana

Posted Mon May 6, 2019 1:20 PM

anybody have some good simple smooth code for controls that only go left, right, up and down. No diagonal control

 

I've been experimenting but nothing I've done works very well.



#2 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 29,020 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Mon May 6, 2019 9:07 PM

If I was doing it, I'd have a bit for left/right and a bit for up/down. If the up/down bit is on, don't look at left/right movement. If the left/right bit is on, don't look at up/down movement.



#3 Nukey Shay OFFLINE  

Nukey Shay

    Sheik Yerbouti

  • 21,966 posts
  • Location:The land of Gorch

Posted Sat May 18, 2019 2:33 AM

Something like this?

 

 if joy0up || joy0down then playery=playery+joy0up-joy0down:goto skiphoriz

 playerx=playerx+joy0right-joy0left

skiphoriz

 

If you want left/right to have priority, use those first.


Edited by Nukey Shay, Sat May 18, 2019 2:34 AM.


#4 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 29,020 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat May 18, 2019 5:36 AM

Something like this?

 

 if joy0up || joy0down then player0y=player0y+joy0up-joy0down:goto skiphoriz

 player0x=player0x+joy0right-joy0left

skiphoriz

 

If you want left/right to have priority, use those first.

 

Those joystick thingies can only be used in if-thens. You get an Unresolved Symbol error if you try to use them in other ways.



#5 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 29,020 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Sat May 18, 2019 7:06 AM

This works, but there's probably a better way to do it:
  

   ;***************************************************************
   ;
   ;  Variable aliases go here (DIMs).
   ;
   dim _Bit4_JoyU = y
   dim _Bit5_JoyD = y
   dim _Bit6_JoyL = y
   dim _Bit7_JoyR = y


   ;***************************************************************
   ;
   ;  Defines the edges of the playfield for an 8 x 8 sprite.
   ;  If your sprite is a different size, you'll need to adjust
   ;  the numbers.
   ;
   const _P_Edge_Top = 9
   const _P_Edge_Bottom = 88
   const _P_Edge_Left = 1
   const _P_Edge_Right = 153


   ;***************************************************************
   ;
   ;  Defines shape of player0 sprite.
   ;
   player0:
   %00111100
   %01111110
   %11000011
   %10111101
   %11111111
   %11011011
   %01111110
   %00111100
end


   ;***************************************************************
   ;
   ;  Sets starting position of player0.
   ;
   player0x = 77 : player0y = 53



__Main_Loop


   ;***************************************************************
   ;
   ;  Sets color of player0 sprite.
   ;
   COLUP0 = $9C


   ;***************************************************************
   ;
   ;  Skips up/down movement if player is moving left or right.
   ;
   if _Bit6_JoyL{6} || _Bit7_JoyR{7}  then goto __Skip_Joy0Down


   ;***************************************************************
   ;
   ;  Up movement check.
   ;
   if !joy0up then _Bit4_JoyU{4} = 0 : goto __Skip_Joy0Up

   if player0y > _P_Edge_Top then player0y = player0y - 1 : _Bit4_JoyU{4} = 1

__Skip_Joy0Up


   ;***************************************************************
   ;
   ;  Down movement check.
   ;
   if !joy0down then _Bit5_JoyD{5} = 0 : goto __Skip_Joy0Down

   if player0y < _P_Edge_Bottom then player0y = player0y + 1 : _Bit5_JoyD{5} = 1

__Skip_Joy0Down


   ;***************************************************************
   ;
   ;  Skips left/right movement if player is moving up or down.
   ;
   if _Bit4_JoyU{4} || _Bit5_JoyD{5} then goto __Skip_Joy0Right


   ;***************************************************************
   ;
   ;  Left movement check.
   ;
   if !joy0left then _Bit6_JoyL{6} = 0 : goto __Skip_Joy0Left

   if player0x > _P_Edge_Left then player0x = player0x - 1 : _Bit6_JoyL{6} = 1

__Skip_Joy0Left


   ;***************************************************************
   ;
   ;  Right movement check.
   ;
   if !joy0right then _Bit7_JoyR{7} = 0 : goto __Skip_Joy0Right

   if player0x < _P_Edge_Right then player0x = player0x + 1 : _Bit7_JoyR{7} = 1

__Skip_Joy0Right


   ;***************************************************************
   ;
   ;  Displays the screen.
   ;
   drawscreen


   goto __Main_Loop
  
Attached File  no_diagonal_movement.bas   2.76KB   3 downloads
 
Attached File  no_diagonal_movement.bin   4KB   5 downloads

#6 tabar OFFLINE  

tabar

    Combat Commando

  • 7 posts

Posted Sat May 18, 2019 3:39 PM

how would this routine look in standard 2600 machine/assembly language.



#7 Nukey Shay OFFLINE  

Nukey Shay

    Sheik Yerbouti

  • 21,966 posts
  • Location:The land of Gorch

Posted Sat May 18, 2019 5:13 PM

A number of ways.  Dunno what bB's equates for player0x/player0y are, but a routine that favors left and right when diagonals are used goes like this:

 

 
   ldx player0x
   ldy player0y
   lda SWCHA
   asl
   bcs NotRight
   inx
   cpx #154
   beq DontSave
   bne Update
 
NotRight:
   asl
   bcs NotLeft
   dex
   txa
   beq DontSave
   bne Update
 
NotLeft:
   asl
   bcs NotDown
   iny
   cpy #89
   beq DontSave
   bne Update
 
NotDown:
   bmi DontSave
   dey
   cpy #8
   beq DontSave
Update
   stx player0x
   sty player0y
DontSave:

 

If you don't want -any- diagonals or button combos to be recognized at all, just use a table that throws away invalid directions:

 

 
   lda SWCHA
   lsr
   lsr
   lsr
   lsr
   tax
   lda Directions,x
   beq DontMove
   cpx #12
   bcc UpdateX
   clc
   adc player0y
   cmp #89
   beq DontMove
   cmp #8
   beq DontMove
   sta player0y
   bne End
 
UpdateX
   adc player0x
   beq DontMove
   cmp #154
   beq DontMove
   sta player0x
DontMove:
End:
...
;somewhere in rom tables:
Directions:
   .byte 0,0,0,0,0,0,0,1
   .byte 0,0,0,-1,0,1,-1,0

 



#8 tabar OFFLINE  

tabar

    Combat Commando

  • 7 posts

Posted Yesterday, 8:01 PM

thank you.






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users