Rabbit 2600 Posted October 16, 2013 Share Posted October 16, 2013 Having a strange bug I can't seem to fix. When h = 0 then a stationary robot is placed on the playfield. When h = 1 then a moving robot is placed on the playfield. The error occurs when h = 1, when the bot also known as player1 moves about the playfield changes instead of being static, how come? rem CODE INSPIRED BY Atarius Maximus at http://www.atariage.com/forums/index.php?showtopic=109288 TITLESCREEN COLUPF = $0E COLUP1 = $0E playfield: ................................ ................................ ..................XX............ ............X................... .........X...................... ................................ ...................X............ ................................ ..................X............. ................................ ................................ end drawscreen if joy0fire then a = (rand&5) : COLUPF = rand : COLUBK = rand : goto WORLD_SETUP goto TITLESCREEN WORLD_SETUP player0x = 50 player0y = 50 dim _P1_L_R = player1x.a dim _P1_U_D = player1y.b dim _P0_L_R = player0x.c dim _P0_U_D = player0y.d WORLD_UPPER_LEFT rem POSSIBLY INEFFICIENT CODE, SEPARATE COLOR INFO FOR EACH FRAME... player0: %00100100 %00100100 %00011000 %00011000 %00111100 %00000000 %00011000 %00011000 end if joy0right then REFP0 = 0 if joy0left then REFP0 = 8 if a = 0 then gosub __LAKE if a = 1 then gosub __VERTICAL_RIVER if a = 2 then gosub __CROSS if a = 3 then gosub __BLOCKS if a = 4 then gosub __LAKE_BLOCKS if a = 5 then gosub __WRENCH drawscreen if joy0right then _P0_L_R = _P0_L_R + 0.50 if joy0left then _P0_L_R = _P0_L_R - 0.50 if joy0up then _P0_U_D = _P0_U_D - 0.50 if joy0down then _P0_U_D = _P0_U_D + 0.50 if joy0right && collision(player0,playfield) then _P0_L_R = _P0_L_R - 0.20 if joy0left && collision(player0,playfield) then _P0_L_R = _P0_L_R + 0.20 if joy0up && collision(player0,playfield) then _P0_U_D = _P0_U_D + 0.20 if joy0down && collision(player0,playfield) then _P0_U_D = _P0_U_D - 0.20 if player0x > 138 then player0x = 10 : h = (rand&1) : player1x = rand : player1y = rand if player1x < 10 then player1x = rand if player1x > 139 then player1x = rand if player1y < 10 then player1y = rand if player1y > 90 then player1y = rand if h = 0 then gosub __WHEEL_BOT if h = 1 then gosub __HOVERBOT goto WORLD_UPPER_LEFT __LAKE playfield: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X..............................X X..............................X X.............XXXX.............X X............XXXXXX............X X............XXXXXX............X X............XXXXXX............X X.............XXXX.............X X..............................X X..............................X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end return __VERTICAL_RIVER playfield: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X..............................X X..............................X X..............XX..............X X..............XX..............X X..............XX..............X X..............XX..............X X..............XX..............X X..............................X X..............................X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end return __CROSS playfield: ...............X ...............X ...............X ...............X .............XXX XXXXXXXXXXXXXXXX .............XXX ...............X ...............X ...............X ...............X end return __BLOCKS playfield: ................................ ................................ ....XXXX................XXXX.... ....XXXX................XXXX.... ................................ ................................ ................................ ....XXXX................XXXX.... ....XXXX................XXXX.... ................................ ................................ end return __LAKE_BLOCKS playfield: ................................ ................................ ...............XX............... ..............XXXX.............. ....XXX......XXXXXX......XXX.... ....XXX.....XXXXXXXX.....XXX.... ....XXX......XXXXXX......XXX.... ..............XXXX.............. ...............XX............... ................................ ................................ end return __WRENCH playfield: ................................ ................................ ................................ ....XXXX................XXXX.... .......X................X....... .......XXXXXXXXXXXXXXXXXX....... .......X................X....... ....XXXX................XXXX.... ................................ ................................ ................................ end return __HOVERBOT f=f+1 rem POSSIBLY INEFFICIENT CODE, SEPARATE COLOR INFO FOR EACH FRAME... if f = 10 then player1: %00000000 %00000000 %00000000 %00011100 %00100010 %00010000 %00100010 %00011100 %00001000 %00111110 end if f = 20 then player1: %00000000 %00000000 %00000000 %00011100 %00100010 %00001000 %00100010 %00011100 %00001000 %00011100 end if f = 30 then player1: %00000000 %00000000 %00000000 %00011100 %00100010 %00000100 %00100010 %00011100 %00001000 %00001000 end if f = 40 then player1: %00000000 %00000000 %00000000 %00011100 %00100010 %00000000 %00100010 %00011100 %00001000 %00011100 end if f=40 then f=0 if _P1_L_R < _P0_L_R then _P1_L_R = _P1_L_R + 0.10 if _P1_L_R > _P0_L_R then _P1_L_R = _P1_L_R - 0.10 return __WHEEL_BOT f=f+1 if f = 10 then player1: %01001001 %00101010 %00010100 %00111110 %01000001 %00011100 %00100010 %00010000 %00100010 %00011100 end if f = 20 then player1: %01001001 %00101010 %00010100 %00111110 %01000001 %00011100 %00100010 %00001000 %00100010 %00011100 end if f = 30 then player1: %01001001 %00101010 %00010100 %00111110 %01000001 %00011100 %00100010 %00000100 %00100010 %00011100 end if f = 40 then player1: %01001001 %00101010 %00010100 %00111110 %01000001 %00011100 %00100010 %00000000 %00100010 %00011100 end if f=40 then f=0 return Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted October 16, 2013 Share Posted October 16, 2013 Take a look at this: dim _P1_L_R = player1x.a Then take a look at this: if joy0fire then a = (rand&5) : COLUPF = rand : COLUBK = rand : goto WORLD_SETUP if a = 0 then gosub __LAKE if a = 1 then gosub __VERTICAL_RIVER if a = 2 then gosub __CROSS if a = 3 then gosub __BLOCKS if a = 4 then gosub __LAKE_BLOCKS if a = 5 then gosub __WRENCH Do you notice a problem? It looks like you are trying to use a variable that is already being used, so when the sprite moves, it changes a and when a changes, the playfield changes. In other words, use a different variable (something other than a, b, c, or d). Quote Link to comment Share on other sites More sharing options...
bogax Posted October 16, 2013 Share Posted October 16, 2013 (edited) And you don't need to keep redrawing the playfield. Also rand&5 will be one of 0, 1, 4, 5 2, 3 will never come up Untested rem CODE INSPIRED BY Atarius Maximus at http://www.atariage.com/forums/index.php?showtopic=109288 TITLESCREEN COLUPF = $0E COLUP1 = $0E playfield: ................................ ................................ ..................XX............ ............X................... .........X...................... ................................ ...................X............ ................................ ..................X............. ................................ ................................ end drawscreen if !joy0fire then TITLESCREEN a = rand/2 : a = (a/2 + a)/32 : gosub drw_pf : COLUPF = rand : COLUBK = rand WORLD_SETUP player0x = 50 : player0y = 50 : a = 0 dim _P1_L_R = player1x.a dim _P1_U_D = player1y.b dim _P0_L_R = player0x.c dim _P0_U_D = player0y.d WORLD_UPPER_LEFT rem POSSIBLY INEFFICIENT CODE, SEPARATE COLOR INFO FOR EACH FRAME... player0: %00100100 %00100100 %00011000 %00011000 %00111100 %00000000 %00011000 %00011000 end if joy0right then REFP0 = 0 if joy0left then REFP0 = 8 drawscreen if joy0right then _P0_L_R = _P0_L_R + 0.50 if joy0left then _P0_L_R = _P0_L_R - 0.50 if joy0up then _P0_U_D = _P0_U_D - 0.50 if joy0down then _P0_U_D = _P0_U_D + 0.50 if joy0right && collision(player0,playfield) then _P0_L_R = _P0_L_R - 0.20 if joy0left && collision(player0,playfield) then _P0_L_R = _P0_L_R + 0.20 if joy0up && collision(player0,playfield) then _P0_U_D = _P0_U_D + 0.20 if joy0down && collision(player0,playfield) then _P0_U_D = _P0_U_D - 0.20 if player0x > 138 then player0x = 10 : h = (rand&1) : player1x = rand : player1y = rand if player1x < 10 then player1x = rand if player1x > 139 then player1x = rand if player1y < 10 then player1y = rand if player1y > 90 then player1y = rand if h = 0 then gosub __WHEEL_BOT if h = 1 then gosub __HOVERBOT goto WORLD_UPPER_LEFT drw_pf on a goto __LAKE __VERTICAL_RIVER __CROSS __BLOCKS __LAKE_BLOCKS __WRENCH __LAKE playfield: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X..............................X X..............................X X.............XXXX.............X X............XXXXXX............X X............XXXXXX............X X............XXXXXX............X X.............XXXX.............X X..............................X X..............................X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end return __VERTICAL_RIVER playfield: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X..............................X X..............................X X..............XX..............X X..............XX..............X X..............XX..............X X..............XX..............X X..............XX..............X X..............................X X..............................X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX end return __CROSS playfield: ...............X ...............X ...............X ...............X .............XXX XXXXXXXXXXXXXXXX .............XXX ...............X ...............X ...............X ...............X end return __BLOCKS playfield: ................................ ................................ ....XXXX................XXXX.... ....XXXX................XXXX.... ................................ ................................ ................................ ....XXXX................XXXX.... ....XXXX................XXXX.... ................................ ................................ end return __LAKE_BLOCKS playfield: ................................ ................................ ...............XX............... ..............XXXX.............. ....XXX......XXXXXX......XXX.... ....XXX.....XXXXXXXX.....XXX.... ....XXX......XXXXXX......XXX.... ..............XXXX.............. ...............XX............... ................................ ................................ end return __WRENCH playfield: ................................ ................................ ................................ ....XXXX................XXXX.... .......X................X....... .......XXXXXXXXXXXXXXXXXX....... .......X................X....... ....XXXX................XXXX.... ................................ ................................ ................................ end return __HOVERBOT f=f+1 rem POSSIBLY INEFFICIENT CODE, SEPARATE COLOR INFO FOR EACH FRAME... if f = 10 then player1: %00000000 %00000000 %00000000 %00011100 %00100010 %00010000 %00100010 %00011100 %00001000 %00111110 end if f = 20 then player1: %00000000 %00000000 %00000000 %00011100 %00100010 %00001000 %00100010 %00011100 %00001000 %00011100 end if f = 30 then player1: %00000000 %00000000 %00000000 %00011100 %00100010 %00000100 %00100010 %00011100 %00001000 %00001000 end if f = 40 then player1: %00000000 %00000000 %00000000 %00011100 %00100010 %00000000 %00100010 %00011100 %00001000 %00011100 end if f=40 then f=0 if _P1_L_R < _P0_L_R then _P1_L_R = _P1_L_R + 0.10 if _P1_L_R > _P0_L_R then _P1_L_R = _P1_L_R - 0.10 return __WHEEL_BOT f=f+1 if f = 10 then player1: %01001001 %00101010 %00010100 %00111110 %01000001 %00011100 %00100010 %00010000 %00100010 %00011100 end if f = 20 then player1: %01001001 %00101010 %00010100 %00111110 %01000001 %00011100 %00100010 %00001000 %00100010 %00011100 end if f = 30 then player1: %01001001 %00101010 %00010100 %00111110 %01000001 %00011100 %00100010 %00000100 %00100010 %00011100 end if f = 40 then player1: %01001001 %00101010 %00010100 %00111110 %01000001 %00011100 %00100010 %00000000 %00100010 %00011100 end if f=40 then f=0 return Edited October 16, 2013 by bogax Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted October 17, 2013 Author Share Posted October 17, 2013 Ahhh, how silly of me! Thanks a lot for the help guys =) Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted October 17, 2013 Author Share Posted October 17, 2013 Hm, another question. I have the map made up of 9 screens divided into 3 rows with 3 screens each. And when you leave the current screen a new one is picked at random. How do I make the game remember that the player has been to already visited screens and don't randomise them again? Quote Link to comment Share on other sites More sharing options...
bogax Posted October 17, 2013 Share Posted October 17, 2013 (edited) I think the simplest way would be tokeep a flag for each roomIf you choose a room and the flag is not set, set the flagIf you choose a room and the flag isset choose a different roomYou'd also need some way to know if there are any unvisited rooms left.You could keep a count of the number ofdifferent rooms you've visited so you knowwhen you've run out of roomsBut if you're choosing a room at randomit might take you a while to find the lastunvisited roomYou could count set flags before youchoose a roomIf you choose a room that's been visitedyou could step through the rooms lookingfor an unvisited room counting set flags asyou go.Another way would be to create a pseudo randomnumber generator that counts through the roomsvisiting each room once.For 9 rooms that would be easy just choose anumber between 1 and 8 with no factors that are evenly divisible in to 9 (ie it can't be 3 or 6) and step through the rooms modulo 9Seed it with rand and stop when you get backto where you started (so you'd have to rememberwhere you started and what your step is)About randI'd use rand16 when ever you can spare a variablefor itThe Rand16 numbers are much nicer than the 8 bitgeneratorThe "normal" way to get a range of random numbersis to start with a random number between 0 and .9999and multiply by the number of numbers in the rangeie you want 9 numbers 0..8 so you multiply randby 9 and take the integer part to get a range 0..8bB rand16 returns numbers 0..255 you can think of thatas the equivalent of 0 to .99 multiplyed by 256So you just need to multiply rand by 9 (in this case)and divide by 256.You could use an 8.8 variable.Or you can do it in bB if you're careful aboutfitting it into 8 bits.255 would fill eight bits not leaving room to addanything.To multiply by 9 you'd multiply by 8 and add 1You can easily multiply by powers of 2ie 1, 2, 4, 8 etc by shifting which is what bBdoes for (constant) powers of 2 and it's muchfaster than invoking a mutiplication routine.But if you multiply by a power of 2 and the resultis >255 the top bits are lost. If you divide by apower of 2 the bottom bits are lost.So you want to keep as much as possible in the 8bits you have.You want to mutiply by 8 and 1 then divide by 256.In order to fit in 8 bits you can combine themultiplication and division and just divide byother than 256.So start with rand/2 to leave room to add but notlose any more bits to shifting than we have to.Then divide that by 8 and add it to it's selfto get 9 ierand/2 + (rand/2)/8 = (rand * 8 + rand)/16now we've got our answer divided by 16 we needto divide by 16 more to total division by 256So altogether in bB it would be a = rand/2 : a = (a/8 + a)/16 Edited October 17, 2013 by bogax Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted October 18, 2013 Author Share Posted October 18, 2013 Hm, good idea and well put, I think I can pull something like that of, thanks =) 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.