Jump to content
IGNORED

Rotation?


Happy_Dude

Recommended Posts

I'm having problems working out which sprite to display and when. I have a

direction variable set-up like this: U,D,L,R,Ul,Ur,Dl,Dr

with the first 4 bits being the direction of movement and the last 4

representing the diagonal sprites.

The sprite should not be able to move diagonaly.

 

Can anyone point me to some example 6502 code?

Or give me some hints on what to do?

Link to comment
Share on other sites

The sprite should not be able to move diagonaly

 

So does that mean that you want only 4-way movement (as seen in Pacman)? Or 8-way? Or higher?

 

What system are you programming for?

Yep 4-way movment.

Programming for the NES. Follow the link in my sig ;)

Link to comment
Share on other sites

I dunno how the NES does things, but the Atari 2600 stores the direction as an OFF bit in SWCHA (the upper nybble is used for the left controller). So if you wanted a routine that simply looks at the bits and gets the proper offset value to use in the bitmap tables, you could do this...

 

;1st player uses high nybble of SWCHA
;bit locations RLDUxxxx

lda  SWCHA

and  #$F0

cmp  #$F0

bne  Get_Direction;jump if any of the upper bits are off
;stick is not being moved if all bits still on
;add in instructions to fetch old offset from ram
;and jmp to end of routine



Get_Direction:

bmi  Check_Left
;stick is being moved right...
;add in offset value for (right) here
;and jmp to end of routine



Check_Left:

asl

bmi  Check_Down
;stick is being moved left...
;add in offset value for (left) here
;and jmp to end of routine



Check_Down:

asl

bmi  Up
;stick is being moved down...
;add in offset value for (down) here
;and jmp to end of routine



Up:
;stick is being moved up...
;add in offset value for (up) here


;end of routine

 

Each time you ASL, you are moving the bit to check into the high bit. Then you just branch if it's positive or negative. You'd need to reorder those to use with your variable...and change the BMI's to BPL's if it uses ON to signify a direction being moved. That will work fine if all 4 bitmaps exist on the same page in memory.

Link to comment
Share on other sites

I already have the sprite moving in the direction it's heading and turning

in the 4 directions but I can't work out how to "make" it rotate from one direction into the next

 

btw: I'm ROL'ing the top bit into the carry flag to check it


   lda direction

   rol

   bcc .notup

Link to comment
Share on other sites

Hm...you could set up a seperate variable like this...

(bits)

 

UU|UR|RR|DR|DD|DL|LL|UL

 

...and just ROL or ROR that each time through the loop (when the controller is being moved) until the ON bit matches the direction desired. If it doesn't match, skip the movement routine (just rotate in place). If it matches, check the direction and update your player co-cordinates. If you have the bitmaps of equal size, you can just ADC the number of bytes to get the offset of the corresponding bitmap.

Link to comment
Share on other sites

The shortest path. Like if you are currently pointing down (00001000 in the second variable), check if the direction wanted is higher by using a BCS instruction...and then have seperate lines to either ROL or ROR it. You might need to cross-reference that to deal with things like moving up to left tho.

 

Or include a routine at the top that changes that bit value to be a value from 0 to 7...and then use a lookup table for those 8 possible directions to load the next value it should be INSTEAD of using ROL/ROR. That would only take 8 bytes.

Link to comment
Share on other sites

I think I'v figured it out. I'll have the input code call animation routines

instead of Sprite drawing ones. The animation code will load a pointer

to the actual sprite code which will be executed after the animation.

 

Am I miles off ? if not how would I use a memory pointer ?

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...