Retro Lord Posted January 7, 2015 Share Posted January 7, 2015 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 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXend etc. And going to another screen is as simple as checking for the players x,y position. Quote Link to comment Share on other sites More sharing options...
ZackAttack Posted January 7, 2015 Share Posted January 7, 2015 You could use this to generate a random number between 0 and 8. (Add 1 if you need 1-9 instead) a = (rand&1) + (rand&7) There are other ways you could do it too. Though I'm guessing the speed for this isn't critical since it's at the start of the game. Quote Link to comment Share on other sites More sharing options...
Retro Lord Posted January 7, 2015 Author Share Posted January 7, 2015 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? Quote Link to comment Share on other sites More sharing options...
Retro Lord Posted January 7, 2015 Author Share Posted January 7, 2015 (edited) 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 January 7, 2015 by Retro Lord Quote Link to comment Share on other sites More sharing options...
ZackAttack Posted January 8, 2015 Share Posted January 8, 2015 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. Quote Link to comment Share on other sites More sharing options...
Retro Lord Posted January 8, 2015 Author Share Posted January 8, 2015 Yeah, I'm not that good at optimizing my codes so I believe they are really bloated and a majority of it could be done alot better. Cheers for having a look at it. Download = default.bas Quote Link to comment Share on other sites More sharing options...
ZackAttack Posted January 8, 2015 Share Posted January 8, 2015 (edited) 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 January 8, 2015 by ZackAttack Quote Link to comment Share on other sites More sharing options...
Retro Lord Posted January 8, 2015 Author Share Posted January 8, 2015 Neat solution! Thanks a bunch, that was very helpful! 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.