Jump to content

Recommended Posts

I'm making a game that plays like Dark Cavern only there's a thing to get (missile1) while avoiding (and possibly shooting) enemies and when you get this thing, it reappears somewhere else on the board. My question is how do I make sure missile1 isn't stuck in the walls where player0 can't get to it?

untitledproject.bas

Edited by atari2600land
Link to comment
https://forums.atariage.com/topic/95204-maze-game-question/
Share on other sites

I'm making a game that plays like Dark Cavern only there's a thing to get (missile1) while avoiding (and possibly shooting) enemies and when you get this thing, it reappears somewhere else on the board. My question is how do I make sure missile1 isn't stuck in the walls where player0 can't get to it?

You could start by limiting the places that the square can appear-- i.e., think of it like dividing the game screen into cells or blocks, as in a piece of graphing paper, and the square must appear in a cell, it can never be partly in one cell and partly in another cell. Since you want the square's position to line up with the walls of the maze-- which are drawn with the playfield-- you'll want the invisible cells of the game screen to coincide with the playfield pixels. So the first thing to do is make sure that when you randomly position missile1, its x and y coordinates put it squarely inside a cell.

 

After experimenting with different x values for missile1, I find that the values 36, 40, 44, ..., through 152 will fit within the maze and coincide with the pfpixel columns. Since those are all multiples of 4, dividing them by 4 gives us 9, 10, 11, ..., through 38. You could use two "if" statements to keep looping back to get another random number until you get a value between 9 and 38, but another method would be to add 8 or keep subtracting 30 until the random value is in the desired range. And then you can multiply the result by 4 to get the x value, as follows:

 

135 c=rand
  if c<9 then c=c+8
135a if c>38 then c=c-30 : goto 135a
  c=4*c

After experimenting with different y values, the ones that will work best are 14, 22, 30, ..., through 78. They skip 8 from one to the next, because one pfpixel is 8 (double) scan lines tall. But they aren't multiples of 8, so if we subtract 6 we get 8, 16, 24, ..., through 72, and then dividing by 8 gives us 1, 2, 3, ..., through 9. So we can use the following for the y value:

 

136 g=rand
136a if g>9 then g=g-9 : goto 136a
  g=8*g+6
140 missile1x=c : missile1y=g : missile1height=4

This code will ensure that the square (missile1) is always positioned in a way that coincides with a pfpixel block-- i.e., it will never end up being partly in one cell and partly in another cell.

 

By the way, the above code also requires that you add the following line to your program:

 

  include div_mul.asm

The only remaining problem is to make sure that the square doesn't end up inside a maze wall. We can use the pfread function to do this, but we should do this before converting c and g back into valid x and y values, and we have to adjust c and g to match the pfpixel coordinates, as follows (this code would replace the previous code):

 

135 c=rand
  if c<9 then c=c+8
135a if c>38 then c=c-30 : goto 135a
136 g=rand
136a if g>9 then g=g-9 : goto 136a
  temp1=c-8
  if pfread(temp1,g) then goto 135
  c=4*c
  g=8*g+6
140 missile1x=c : missile1y=g : missile1height=4

This will prevent missile1 from ever ending up inside of a wall! :)

 

MR

Link to comment
https://forums.atariage.com/topic/95204-maze-game-question/#findComment-1154892
Share on other sites

I'd say the easiest way would be just to always shift the missile to the right if it's inside a wall at init.

example:

missile1x = c

if collision(missile1, playfield) then c = c + 1

Or loop back to "135 c=rand, like so: "if collision(missile1,playfield) then goto 135". I don't know why I didn't think of either of those! But I still prefer my original solution-- at least, the part about positioning the missile so it lines up with the pfpixel positions-- and then instead of using "pfread", do "if collision(missile1,playfield) then goto 135".

 

No, hang on a moment-- the collision will only work *after* you draw the screen and get the missile inside a wall, so that isn't the best solution after all (unless you don't mind having the missile pop up momentarily in a wall and then being repositioned). Using pfread will make sure you fix the missile's position *before* you even draw the screen.

 

MR

Link to comment
https://forums.atariage.com/topic/95204-maze-game-question/#findComment-1155163
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...