RHillFake Posted August 6, 2014 Share Posted August 6, 2014 I cannot find out how to do a rotating vehicle like in Combat, Asteroids, or Indy 500 etc. The only way I could think of is if joy0left && f < 39 && f > 29 then player0: and so on until it reaches the end and resets f to 0. Does anyone else know a better way to do this where the sprites will look nice? Thanks! PS I am trying to make a plane like Combat Quote Link to comment Share on other sites More sharing options...
bogax Posted August 6, 2014 Share Posted August 6, 2014 Not sure this will be what you want but it might give you some ideas. Here all the sprites data is in a table called ships and the sprite pointer is pointed to the correct spot in the table set optimization noinlinedata dim swfl = s dim swsv = t rem I prefer shorter names dim p0plo = player0pointerlo dim p0phi = player0pointerhi dim p0ptr = p0phi.p0plo dim dtmp = temp2.temp1 rem name the bytes of the sprite table location const shipslo = <ships const shipshi = >ships const upper_limit = shipslo + 105 rem start with the first entry in the table p0plo = shipslo p0phi = shipshi player0height = 6 COLUBK = $64 COLUPF = $1F COLUBK = 0 COLUPF = $64 COLUP0 = $28 COLUP1 = $D2 player0x = 110 : player0y = 44 player1x = 80 : player1y = 54 player1: %00111100 %01111110 %11111111 %11111111 %11111111 %11111111 %01111110 %00111100 end main rem sets a bit in swfl if a switch was not pressed last time rem and is pressed this time. bit 7 is right. bit 6 is left swfl = ((SWCHA ^ $F0) & swsv) & $F0 : swsv = SWCHA rem increments or decrements the sprite pointer by 7 rem ie the number of rows per sprite, and wraps at the limits rem there are 16 sprites (and so 16 possible orientations) rem in the table, 0..15 15 * 7 = 105 rem since the table is page aligned shipslo should always be 0 if swfl{6} then p0plo = p0plo + 7 : if p0plo > upper_limit then p0plo = shipslo if swfl{7} then p0plo = p0plo - 7 : if p0plo = 249 then p0plo = 105 rem displays the low byte of the pointer on the screen rem $55 is just for reference to show which bits are which var36 = p0plo var40 = $55 draw COLUP0 = $28 COLUP1 = $D2 drawscreen goto main asm align 256 end data ships $10, $10, $38, $38, $7C, $7C, $00, $08, $18, $38, $78, $F8, $38, $08 $00, $0C, $3C, $F8, $78, $30, $10, $00, $00, $FE, $7C, $78, $30, $20 $00, $60, $78, $7E, $78, $60, $00, $20, $30, $78, $7C, $FE, $00, $00 $10, $30, $78, $F8, $3C, $0C, $00, $08, $38, $F8, $78, $38, $18, $08 $00, $7C, $7C, $38, $38, $10, $10, $20, $38, $3E, $3C, $38, $30, $20 $10, $18, $3C, $3E, $78, $60, $00, $08, $18, $3C, $7C, $FE, $00, $00 $00, $0C, $3C, $FC, $3C, $0C, $00, $00, $00, $FE, $7C, $3C, $18, $08 $00, $60, $78, $3E, $3C, $18, $10, $20, $30, $38, $3C, $3E, $38, $20 end 1 Quote Link to comment Share on other sites More sharing options...
RHillFake Posted August 6, 2014 Author Share Posted August 6, 2014 Not sure this will be what you want but it might give you some ideas. Here all the sprites data is in a table called ships and the sprite pointer is pointed to the correct spot in the table set optimization noinlinedata dim swfl = s dim swsv = t rem I prefer shorter names dim p0plo = player0pointerlo dim p0phi = player0pointerhi dim p0ptr = p0phi.p0plo dim dtmp = temp2.temp1 rem name the bytes of the sprite table location const shipslo = <ships const shipshi = >ships const upper_limit = shipslo + 105 rem start with the first entry in the table p0plo = shipslo p0phi = shipshi player0height = 6 COLUBK = $64 COLUPF = $1F COLUBK = 0 COLUPF = $64 COLUP0 = $28 COLUP1 = $D2 player0x = 110 : player0y = 44 player1x = 80 : player1y = 54 player1: %00111100 %01111110 %11111111 %11111111 %11111111 %11111111 %01111110 %00111100 end main rem sets a bit in swfl if a switch was not pressed last time rem and is pressed this time. bit 7 is right. bit 6 is left swfl = ((SWCHA ^ $F0) & swsv) & $F0 : swsv = SWCHA rem increments or decrements the sprite pointer by 7 rem ie the number of rows per sprite, and wraps at the limits rem there are 16 sprites (and so 16 possible orientations) rem in the table, 0..15 15 * 7 = 105 rem since the table is page aligned shipslo should always be 0 if swfl{6} then p0plo = p0plo + 7 : if p0plo > upper_limit then p0plo = shipslo if swfl{7} then p0plo = p0plo - 7 : if p0plo = 249 then p0plo = 105 rem displays the low byte of the pointer on the screen rem $55 is just for reference to show which bits are which var36 = p0plo var40 = $55 draw COLUP0 = $28 COLUP1 = $D2 drawscreen goto main asm align 256 end data ships $10, $10, $38, $38, $7C, $7C, $00, $08, $18, $38, $78, $F8, $38, $08 $00, $0C, $3C, $F8, $78, $30, $10, $00, $00, $FE, $7C, $78, $30, $20 $00, $60, $78, $7E, $78, $60, $00, $20, $30, $78, $7C, $FE, $00, $00 $10, $30, $78, $F8, $3C, $0C, $00, $08, $38, $F8, $78, $38, $18, $08 $00, $7C, $7C, $38, $38, $10, $10, $20, $38, $3E, $3C, $38, $30, $20 $10, $18, $3C, $3E, $78, $60, $00, $08, $18, $3C, $7C, $FE, $00, $00 $00, $0C, $3C, $FC, $3C, $0C, $00, $00, $00, $FE, $7C, $3C, $18, $08 $00, $60, $78, $3E, $3C, $18, $10, $20, $30, $38, $3C, $3E, $38, $20 end That works great, but how would I go about making my own sprite table? Quote Link to comment Share on other sites More sharing options...
bogax Posted August 6, 2014 Share Posted August 6, 2014 Here's a slightly different version that uses a variable, shipo for the ship orientation It's limited to 0..15 and the sprite pointer is set from that using a times 7 multiplication table I broke the ships table in to individual sprites one sprite per line except for sprite 0 which I've converted to binary set optimization noinlinedata dim swfl = s dim swsv = t dim shipo = o rem I prefer shorter names dim p0plo = player0pointerlo dim p0phi = player0pointerhi dim p0ptr = p0phi.p0plo dim dtmp = temp2.temp1 rem name the bytes of the sprite table location const shipslo = <ships const shipshi = >ships const upper_limit = shipslo + 105 rem start with the first entry in the table p0plo = shipslo p0phi = shipshi player0height = 6 shipo = 0 COLUBK = $64 COLUPF = $1F COLUBK = 0 COLUPF = $64 COLUP0 = $28 COLUP1 = $D2 player0x = 110 : player0y = 44 player1x = 80 : player1y = 54 player1: %00111100 %01111110 %11111111 %11111111 %11111111 %11111111 %01111110 %00111100 end main rem sets a bit in swfl if a switch was not pressed last time rem and is pressed this time. bit 7 is right. bit 6 is left swfl = ((SWCHA ^ $F0) & swsv) & $F0 : swsv = SWCHA rem increments or decrements the shipo (ship orientation) by 1 rem and since the number of possible sprites is 16 and 16 is rem a power of 2 wrapping is implimented by ANDing shipo with $0F rem p0plo is then set using a multipication table (times7) if swfl{6} then shipo = shipo + 1 if swfl{7} then shipo = shipo - 1 shipo = shipo & $0F p0plo = times7[shipo] rem displays the low byte of the pointer on the screen rem $55 is just for reference to show which bits are which var36 = p0plo var40 = $55 draw COLUP0 = $28 COLUP1 = $D2 drawscreen goto main asm align 256 end rem here I've broken the table in to individual sprites rem and converted the first entry to binary. notice that rem the data is flipped relative to how it appears on screen rem (here the ship 0 is pointing up, on screen ship 0 points down) data ships %00010000 %00010000 %00111000 %00111000 %01111100 %01111100 %00000000 $08, $18, $38, $78, $F8, $38, $08 $00, $0C, $3C, $F8, $78, $30, $10 $00, $00, $FE, $7C, $78, $30, $20 $00, $60, $78, $7E, $78, $60, $00 $20, $30, $78, $7C, $FE, $00, $00 $10, $30, $78, $F8, $3C, $0C, $00 $08, $38, $F8, $78, $38, $18, $08 $00, $7C, $7C, $38, $38, $10, $10 $20, $38, $3E, $3C, $38, $30, $20 $10, $18, $3C, $3E, $78, $60, $00 $08, $18, $3C, $7C, $FE, $00, $00 $00, $0C, $3C, $FC, $3C, $0C, $00 $00, $00, $FE, $7C, $3C, $18, $08 $00, $60, $78, $3E, $3C, $18, $10 $20, $30, $38, $3C, $3E, $38, $20 end data times7 $00, $07, $0E, $15, $1C, $23, $2A, $31, $38, $3F, $46, $4D, $54, $5B, $62, $69 end Quote Link to comment Share on other sites More sharing options...
LS_Dracon Posted August 6, 2014 Share Posted August 6, 2014 (edited) What I did recently was divide by 15 like this : lda RotationVar ;(0-255) and #$F0 lsr lsr lsr lsr tay ;Y = 0-15 So doesn't matter what value are in rotationvar, it's always be 0 to 15 (16 directions) Naturally, inc rotationvar if you press left, or dec rotationvar if you press right. Sorry I don't know how to translate this for BatariBasic. Edited August 6, 2014 by LS_Dracon Quote Link to comment Share on other sites More sharing options...
LS_Dracon Posted August 6, 2014 Share Posted August 6, 2014 (edited) Double post.... Edited August 6, 2014 by LS_Dracon Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.