Jump to content
IGNORED

Player1 movement and playfield error


Rabbit 2600

Recommended Posts

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




Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 by bogax
Link to comment
Share on other sites

I think the simplest way would be to
keep a flag for each room

If you choose a room and the flag
is not set, set the flag

If you choose a room and the flag is
set choose a different room

You'd also need some way to know if there
are any unvisited rooms left.

You could keep a count of the number of
different rooms you've visited so you know
when you've run out of rooms

But if you're choosing a room at random
it might take you a while to find the last
unvisited room

You could count set flags before you
choose a room

If you choose a room that's been visited
you could step through the rooms looking
for an unvisited room counting set flags as
you go.


Another way would be to create a pseudo random
number generator that counts through the rooms
visiting each room once.

For 9 rooms that would be easy just choose a
number 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 9
Seed it with rand and stop when you get back
to where you started (so you'd have to remember
where you started and what your step is)


About rand
I'd use rand16 when ever you can spare a variable
for it
The Rand16 numbers are much nicer than the 8 bit
generator

The "normal" way to get a range of random numbers
is to start with a random number between 0 and .9999
and multiply by the number of numbers in the range
ie you want 9 numbers 0..8 so you multiply rand
by 9 and take the integer part to get a range 0..8
bB rand16 returns numbers 0..255 you can think of that
as the equivalent of 0 to .99 multiplyed by 256
So 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 about
fitting it into 8 bits.
255 would fill eight bits not leaving room to add
anything.
To multiply by 9 you'd multiply by 8 and add 1
You can easily multiply by powers of 2
ie 1, 2, 4, 8 etc by shifting which is what bB
does for (constant) powers of 2 and it's much
faster than invoking a mutiplication routine.
But if you multiply by a power of 2 and the result
is >255 the top bits are lost. If you divide by a
power of 2 the bottom bits are lost.
So you want to keep as much as possible in the 8
bits you have.
You want to mutiply by 8 and 1 then divide by 256.
In order to fit in 8 bits you can combine the
multiplication and division and just divide by
other than 256.
So start with rand/2 to leave room to add but not
lose any more bits to shifting than we have to.
Then divide that by 8 and add it to it's self
to get 9 ie
rand/2 + (rand/2)/8 = (rand * 8 + rand)/16
now we've got our answer divided by 16 we need
to divide by 16 more to total division by 256

So altogether in bB it would be

a = rand/2 : a = (a/8 + a)/16
Edited by bogax
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...