How to generate a game map on the fly?

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
TheDysk
Posts: 1
Joined: Fri Jan 06, 2023 12:10 pm

How to generate a game map on the fly?

Post by TheDysk »

I am writing a ZX81 game, in BASIC, that will have an 80 x 80 map area grid. I want to calculate a number, between 1 and 16, for each grid reference on the fly. The generated number will relate to a map tile for trees, buildings, waters, etc.

The generation of the tiles needs to look random but should always generate the same tile for any given grid reference within the same run of the game. e.g. a new run will generate a new random seed number that will be used in the calculation of the tiles for the grid references.

I've played around with calculating remainders from the sum of the grid reference and the seed and dividing by a random number between 1 and 16. Unfortunately, it's not giving me the random tiles I want as large areas that are close to each other in the grid are generating the same result so there is little or no random difference between adjacent cells in the grid.

Can anyone suggest a calculation method given the grid reference and a seed number (generated at the start of the game) that will give some level or randomness to the selection of one of the 16 tiles? The results should look random when compared to adjacent grid cells but any given grid reference should always generate the same tile when visited multiple times within the same game. e.g. cell 10,15 should generate a tree tile; if the player goes elsewhere on the map and then comes back to 10,15 it should again generate a tree tile.
Last edited by TheDysk on Sat Jan 07, 2023 1:59 pm, edited 1 time in total.
dr beep
Posts: 2339
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: How to generate a game map on the fly?

Post by dr beep »

Your question is too generic to help you.

Any pseudo RND will calculate in a fixed order, so that will not solve your question.
Your code will have to solve the irregularities from the RND in the same way a mazegenerator would create a maze.

Give an exemple of how your map would be, what is on it?
TheDysk
Posts: 1
Joined: Fri Jan 06, 2023 12:10 pm

Re: How to generate a game map on the fly?

Post by TheDysk »

Here is one of my blog posts that show how the map looks in the current version of the game for PC. I originally wrote it back in the 80s.

https://thedysk.blogspot.com/2022/06/th ... e-v10.html

For the ZX81 version, I want to generate a map instead of storing the map in memory. That way I can build in some additional gameplay elements.

So, I want to generate something like the map in the blog but I don't need it to look exactly like it does now. It will just be an 80x80 game space with random (sudo-random) selected values of each grid reference and I will use these to display the correct map tiles for each grid reference when visited by the player. The displayed grid will be 5x5 and will be generated on the fly so that I do not have to store a full map or generate the full map at the start of the game.
Last edited by TheDysk on Sat Jan 07, 2023 11:02 pm, edited 1 time in total.
dr beep
Posts: 2339
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: How to generate a game map on the fly?

Post by dr beep »

TheDysk wrote: Sat Jan 07, 2023 11:01 pm Here is one of my blog posts that show how the map looks in the current version of the game for PC. I originally wrote it back in the 80s.

https://thedysk.blogspot.com/2022/06/th ... e-v10.html

For the ZX81 version, I want to generate a map instead of storing the map in memory. That way I can build in some additional gameplay elements.

So, I want to generate something like the map in the blog but I don't need it to look exactly like it does now. It will just be an 80x80 game space with random (sudo-random) selected values of each grid reference and I will use these to display the correct map tiles for each grid reference when visited by the player. The displayed grid will be 5x5 and will be generated on the fly so that I do not have to store a full map or generate the full map at the start of the game.
This still doesn't say much.
What requirements should be met to draw a map,
minumum width, length, islands, lakes etc....

you need requirements to define your output.
The output can be generated based on an entrypoint value in the routine.
Other value is other map.
but you need requirements
dr beep
Posts: 2339
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: How to generate a game map on the fly?

Post by dr beep »

TheDysk wrote: Sat Jan 07, 2023 11:01 pm The displayed grid will be 5x5 and will be generated on the fly so that I do not have to store a full map or generate the full map at the start of the game.
If you only need 25 fields set on or off without further rules you can simply start at a random place in the ROM, read 5 addresses in a row and store lowest 5 bits of each address
Post Reply