Jump to content
IGNORED

Random location set?


Retro Lord

Recommended Posts

I'm in a bit of a jam. I have a playfield made up of 9 screens. At the start of the game I want the game too decide upon 1 of the screens where the "artifact" is. Aka missile0. The player walks around searching for it. Any ideas on a way too set this up and also making the game remember where the "artifact" is located if the player leaves the screen without picking it up (aka touching it)?

 

My setup for the screens is

if v=1 then playfield:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
X.....X.................X......X
X.....X.................X......X
X.....X.................X......X
X.....X.....XXXXX.......XX......
X.....X.....XXXXX.......XX......
X.....X.....XXXXXXX.....XX......
X...........X..................X
X...........X..................X
X...........X..................X
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end

 

etc.

 

And going to another screen is as simple as checking for the players x,y position.

Link to comment
Share on other sites

Neat. So at the titlescreen I could have:

 if joy0fire then goto start : a = (rand&1) + (rand&7)

And then a system to check what value a is like:

 if a=0 && v=2 then missile0x=50:missile0y=50 else missile0x=200:missile0y=200

 if a=1 && v=4 then missile0x=50:missile0y=50 else missile0x=200:missile0y=200

 if a=2 && v=6 then missile0x=50:missile0y=50 else missile0x=200:missile0y=200

v would be the counter for the rooms. Am way of how this would work?

Link to comment
Share on other sites

I think I almost solved it. If I do the code I mentioned above without the else variable at the end it kind of works, but missile0 only appears in screen v=2 and no other screen. And if I leave after finding it it's always present in all the other screens aswell.

 

If I include the else variable missile0 is not in any of the screens.

 

 

 

UPDATE:
Found something that almost worked. if I changed

 if joy0fire then goto start : a = (rand&1) + (rand&7)

too


 if joy0fire then g = (rand&7) : goto start

missile0 is indeed at a randomly chosen screen. I still have the issue with keeping it from appearing if you leave the screen without picking it up.

Edited by Retro Lord
Link to comment
Share on other sites

Neat. So at the titlescreen I could have:

 if joy0fire then goto start : a = (rand&1) + (rand&7)

And then a system to check what value a is like:

 if a=0 && v=2 then missile0x=50:missile0y=50 else missile0x=200:missile0y=200

 if a=1 && v=4 then missile0x=50:missile0y=50 else missile0x=200:missile0y=200

 if a=2 && v=6 then missile0x=50:missile0y=50 else missile0x=200:missile0y=200

v would be the counter for the rooms. Am way of how this would work?

This code looks very redundant. There should be a much easier way to do it than having so many similar if/else statements.

 

I'm not sure how v is being used in the rest of your program. If you post the .bas source file I could assist you further.

Link to comment
Share on other sites

It looks like variable v holds which room you are currently in and can be 0-8. It also looks like you always begin in room 0. So I would recommend generating a number between 1-8. This will prevent the random number from ever being the starting room.

if joy0fire then g = (rand&7) + 1 : goto start

Now g will contain a room 1-8 to hide the item in. Instead of having an if for each room you can simply compare g with v. If they are equal, you must be in the room with the item. Then we can use data arrays to lookup the x and y positions for each room. Notice that v is used to index into the _item_x_location data array. For example if v is 3,

_item_x_location[v] will evaluate to 120 since 120 is the 3rd item in the _item_x_location[v] array.

 if g = v then missile0x=_item_x_location[v] : missile0y=_item_y_location[v] else missile0x=0 : missile0y = 0

 data _item_x_location
 30, 30, 120, 80, 50, 50, 50, 50, 50
end
 data _item_y_location
 50, 50, 20, 50, 50, 50, 50, 50, 50
end

Hope that helps.

Edited by ZackAttack
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...