How do I make a map?

I’ve been working on a game that needs and requires a map but I can’t make one because I dont know how

1 Like

What type of map? Elaborate.

Basic I guess I have 1 type of tree and I want to make a map out of them. But randomly generated 1 space apart to 2 space apart for x and y is 3 spaces to 4

Ok, so your question is how you generate a map, as opposed to what the representation would be (which is what I thought at first)?

The question is still a bit vague, because it’s not clear what “randomly generated 1 space apart to 2 space apart” means. Do you want each tree to be either 1 or 2 spaces from the next tree over, or do you want the average spaces between the trees to be somewhere between 1 and 2 spaces? There’s also an issue with specifying distributions in both directions - how do the two probabilities interact?

Once you get that sorted out, you then use the random() function (lots of discussion about it on the forums) to figure out where you put a tree. For example, to get trees with 1 or 2 spaces in between each one, you’d do something like this:

for (col = random(2, 4); col < NUM_COLS; col += random(2, 4)) {
    add_tree(row, col);
}

Which treets the border like a tree as well, which may not be what you want.

Alternatively, to get an average space somewhere between 1 and 2, you could do something like this:

for (col = 0; col < NUM_COLS; col += 1) {
    if (random(0, 2) == 0) {
        add_tree(row, col);
    }
}

If my math is right, that will give an average space between trees of 1, though it will place them side by side 50% of the time, and will leave a row blank about 1 time out of every 2 to the NUM_COLS rows.

2 Likes

The spaces were the same as a tree’s dimension but I will tryyout code thanks😁

although I get the error that col was not declared in this scope.
in fact a lot come up could you tell me how to fix them? I R SMRT.

I’m sorry, but those fragments weren’t meant to be working code, just examples of two different ways you might go about populating a map with randomly placed objects. The fix for col not being declared is simple, but fixing that is unlikely to make your code work because we haven’t seen enough of your code. Even if it does work, neither example even tries to deal with distribution in a column, because you haven’t said how you want the column and row distributions to interact.

Interact? Since I R Smrt can you explain what that means.Would it help if I uploaded the code

it always helps if you were to upload code, it helps the community to figure out what you are going to do, and how to better guide you :slight_smile:

1 Like

I actually started a thread on that uploading stuff.

1 Like

You said you wanted “an empty space or two between trees”. Ok, in 1 dimension that might look like this:

▢🌲▢🌲▢🌲▢▢🌲▢🌲▢🌲▢▢🌲▢🌲▢▢🌲▢🌲▢🌲▢🌲

But if you add a more lines just copying the first, I’d say it’s not right:

▢🌲▢🌲▢🌲▢▢🌲▢🌲▢🌲▢▢🌲▢🌲▢▢🌲▢🌲▢🌲▢🌲
▢🌲▢🌲▢🌲▢▢🌲▢🌲▢🌲▢▢🌲▢🌲▢▢🌲▢🌲▢🌲▢🌲
▢🌲▢🌲▢🌲▢▢🌲▢🌲▢🌲▢▢🌲▢🌲▢▢🌲▢🌲▢🌲▢🌲
▢🌲▢🌲▢🌲▢▢🌲▢🌲▢🌲▢▢🌲▢🌲▢▢🌲▢🌲▢🌲▢🌲
▢🌲▢🌲▢🌲▢▢🌲▢🌲▢🌲▢▢🌲▢🌲▢▢🌲▢🌲▢🌲▢🌲

Because there’s 0 spaces vertically between trees; what you’ve got is columns of trees that are 1 or 2 spaces apart. Or maybe this is what you want? Or maybe you want different random lines but don’t care about vertical spacing? Or maybe you want that 1 or 2 spaces apart in a euclidean or taxicab metric? Or maybe something completely different?

1 Like

I’m not quite sure what you mean but what you displayed is basically what was trying to get at.
Would it be possible to implement this in this

.#include <Arduboy.h>
Arduboy arduboy;

Void setup()
{
arduboy.begin();
}
Void loop()
{
Arduboy.clear();
}

Maps are more of an intermediate/advanced topic when it comes to Arduboy. I think you might be better off starting with a simpler type of game and work your way up to more complicated concepts.

Something like pong, or try to recreate the flappyball game?

B…b…but I wanted a mapped game😭
Lol :joy:
Doesn’t flappy bird require maps?

But still I would like to make a start😐

No. It generates everything based on keeping track of object positions and parameters.

1 Like

B…b…but I wanted a mapped game​:sob:

Mapping becomes complicated pretty quickly with Arduboy. If your world is very small you might not need to worry about utilizing individual bits, but that is usually what needs to happen to allow your game to fit on the device.

If you map is larger than 128x64 pixels (screen resolution) you’ll also need to create some kind of view system.

First, you need to figure out what information you are storing. For examples, you said you want trees, what is the image size? Would it be better to use a tile approach breaking a tall 16x32px tree into two 16x16px images? Or will your trees be objects? If you are storing them as object locations you need to figure out the size of your room or game area. One byte allows values from 0-255 so if you wanted the simplest solution to store directly the x and y coordinates, the furthest they could be from the top left corner would be x: 255 y: 255. This could be extended by multiplying the values by a constant. If they will always be at least 16px away horizontally, multiply the stored coordinate values by 16. Meaning your maximum value would be 16x255=4080. But a game world that large would be difficult to fill with content.

Read up on C++ arrays, even by looking at how images are stored in Arduboy games to see how maps could be stored.

Once you’ve wrapped your head around storing the information, rendering it will depend on the approach you took for step one.

I spent months researching and planning my implementation for Mystic Balloons map system. Again, I would recommend starting with something simpler. Learn to crawl before signing up for the 100m dash! Haha.

3 Likes

How would I do that?

Ok but still it’s nagging at my mind anyway We’re would I start when I’m ready?

For each object that appears on the screen you create variables to keep track of the position of that object and anything required to draw that object. You then write functions to use the values of those variables to draw the object. You modify those variables to move the object, change it’s appearance, detect if it has come in contact with another object, etc.

In the case of the Flappy Ball game:


For “Floaty” the ball there’s:

char ballY = BALL_Y_START;      // Floaty's height
char ballYprev = BALL_Y_START;  // Previous height
char ballYi = BALL_Y_START;     // Floaty's initial height for the current arc
int ballV = 0;                  // For height calculations (Vi + ((a * t) / 2))
byte ballFrame = 0;             // Frame count for the current arc
char ballFlapper = BALL_RADIUS; // Floaty's wing length

ballY is the current Y position of Floaty
ballFlapper is used to keep track of Floaty’s wing position to make it flap.
These are the only variables required to draw Floaty. Everything else is either a constant, such as BALL_RADIUS and BALL_X, or is calculated as necessary.
The drawFloaty() function uses this information to draw Floaty for each frame.

The other variables above are used and modified to move Floaty and determine if a collision with a pipe or screen edge has occurred. moveFloaty() is one such function used for this.


For the pipes there’s:

char pipes[2][PIPE_ARRAY_SIZE]; // Row 0 for x values, row 1 for gap location
byte pipeGap = PIPE_GAP_MAX;    // Height of gap between pipes to fly through

These give us the information needed to draw the pipes and determine if Floaty has collided with one.


Similarly, other variables and constants are used to draw and keep track of the score and other aspects of the game.

1 Like