Let's design a level!

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

I "coordinated" the operation of electric walls. Rather than random zapping - which gives you little chance, and no real gameplay - they now operate in a pattern.  I designed a y-constrained level to test them out - and actually it's pretty cool.

The electric fences now extend downwards over multiple frames, rather than appearing instantly. That works nicely too.


As always, power cycle to restart, or SELECT or RESET to go to the next level.

Andrew Davie

#1
So, here's the actual level data. I'm gonna walk you through it!
Firstly, the structure...

struct PLANET_DEFINITION {

    unsigned char millingTime;
    unsigned char dogeValue;
    unsigned char extraDogeValue;
    unsigned char weather;

    unsigned char randomInit[5];
    unsigned char dogeRequired[5];
    unsigned char timeToComplete[5];
    enum WEAPON weapon[5];

    unsigned char flags;    // CAVEDEF_...
    unsigned char borderCharacter;
    unsigned char interiorCharacter;

    unsigned char objectCount;
    unsigned char objectData;
};


Here's the level in the video...

const unsigned char planetUseWall[] = {
    // clang-format off

    20,                             // milling
    10, 15,                         // doge $
    0,                              // shake

     16,  11,  50,  56,  8,         // randomiser[level]
     30,  12,  12,  12,  12,        // doge req
    200, 200, 200, 200, 200,

    WEAPON_MACE,                    // 0
    WEAPON_PIPE,                    // 1
    WEAPON_PIPE,                    // 2
    WEAPON_PIPE,                    // 3
    WEAPON_PIPE,                    // 4

    CAVEDEF_LOCK_Y,CH_STEELWALL, CH_BLANK,           // flags, border, fill

    // Random objects

    2,
    CH_GEODOGE, 80,40,40,40,40,
    CH_ROCK, 50,40,40,40,40,

    // Start of cave draw

    DRAW_RECT,CH_BRICKWALL, 0,1,40,8,

    CH_INSULATOR_TOP, 6,2,
    CH_INSULATOR_BOTTOM, 6,7,


    CH_INSULATOR_TOP, 11,2,
    CH_INSULATOR_BOTTOM, 11,7,

    CH_BRICKWALL, 14,2,
    CH_INSULATOR_TOP, 14,3,
    CH_INSULATOR_BOTTOM, 14,6,
    CH_BRICKWALL, 14,7,


    CH_INSULATOR_TOP, 17,2,
    CH_INSULATOR_BOTTOM, 17,7,

    CH_BRICKWALL, 20,2,
    CH_INSULATOR_TOP, 20,3,
    CH_INSULATOR_BOTTOM, 20,6,
    CH_BRICKWALL, 20,7,

    CH_INSULATOR_TOP, 23,2,
    CH_INSULATOR_BOTTOM, 23,7,

    CH_BRICKWALL, 26,2,
    CH_INSULATOR_TOP, 26,3,
    CH_INSULATOR_BOTTOM, 26,6,
    CH_BRICKWALL, 26,7,

    CH_INSULATOR_TOP, 29,2,
    CH_INSULATOR_BOTTOM, 29,7,
   
    CH_BRICKWALL, 32,2,
    CH_BRICKWALL, 32,3,
    CH_BRICKWALL, 32,4,
    CH_INSULATOR_TOP, 32,5,
    CH_INSULATOR_BOTTOM, 32,7,

    DRAW_FILLED_RECT, CH_GEODOGE, 30, 2, 10, 5, CH_GEODOGE,

    CH_DOORCLOSED, 38, 5,
    CH_MELLON_HUSK_BIRTH, 2, 3,

    CH_WYRM_HEAD_U, 38, 2,

    DRAW_EOF,

    // EXTRAS
    // LEVEL 0 HERE

    DRAW_EOF,

     // LEVEL 1
    DRAW_EOF,

    // LEVEL 2
    DRAW_EOF,

    // LEVEL 3
    DRAW_EOF, // LEVEL 4

    DRAW_EOF,

    'T', 'E', 'S', 'T', END_STRING

    // clang-format on
};


We start with:

    20,                             // milling
    10, 15,                         // doge $
    0,                              // shake

In many cases, a byte is a "how much" value. The first, milling, determines how frequently new pebbles (which become geodoge) are placed on the board during gameplay.  Effectively, the following runs continuously....

    // // randomly place a new pebble
    if (rangeRandom(256) < theCave->millingTime) {


So, the larger the milliingTime value, the more frequently we see new pebbles.

Next is "doge,$" which are at the moment unused. Reserved for adding points when you collect doge.

Next, "weather".  This is a "how much" value and is used to randomly shake the screen. Think: earthquakes. It will probably have a non-zero value in levels with lava.

Now we come to this block:

    unsigned char randomInit[5];
    unsigned char dogeRequired[5];
    unsigned char timeToComplete[5];
    enum WEAPON weapon[5];

We can have multiple planets, each with multiple levels.  So this is one "planet" and within the planet definition we have the level data. Here we have 5 bytes = 5 levels, describing differences in levels.

Firstly, the basic board layout consists of some random objects placed with variable probability. To ensure that we get the SAME random distribution every time we play each level, we initialise the pseudo-random seeds with a value derived from the 'randomInit' value.  A nice bonus here is that if I don't really like the look/distribution of random objects, I can just try incrementing/changing this value in my data and see what it looks like then.

Next 'dogeRequired'.  Essentially, how many doge you need to collect before the door opens.

Next 'timeToComplete'.  Self-explanatory, really. As the levels increase, this value can be lowered to increase the difficulty.

Next, 'weapon' - which describes the planet-specfic weapon (what happens when you press the fire button). Current weapons are defined as:

enum WEAPON {
    WEAPON_NONE = 0,
    WEAPON_PIPE,
    WEAPON_ROPE,
    WEAPON_MACE,
    WEAPON_GUN,
};


I'll add more as I can think of them. You can have a different weapon, if I wish, on each level.


Following all that, we have...

    unsigned char flags;    // CAVEDEF_...
    unsigned char borderCharacter;
    unsigned char interiorCharacter;

Flags describe to the scrolling system (for now) how to constrain the scroll. We have 0 - full scrolling, and we have lockX and lockY (and both together).  It's useful for horizontal-only levels such as in the above video, or vertical-only, or single-screen, no scrolling.

'borderCharacter' is drawn around the extreme edges of the 40x22 board

'interiorCharacter' is used to pre-fill the board inside the border.  These interior characters may be overwritten by later stuff in the planet definition, as follows...

    unsigned char objectCount;
    unsigned char objectData;

This is a block of randomly added objects. The example from this planet:

    2,
    CH_GEODOGE, 80,40,40,40,40,
    CH_ROCK, 50,40,40,40,40,

That says that there are two random object types (there can be up to 255).  Each line defines the object type (basically which character from the character set), and the "how much" values (as above) for the 5 levels.  So essentially since the interiorCharacter is blank in this planet, it just replaces blanks with CH_GEODOGE 80/256 of the time, and with CH_ROCK 50/256 of the time (on level 0).  Other levels can have different 'densities' of such objects.

Next, we hit the 'raw data' area which can't be defined by a C struct. So we treat it as an unsigned char * from now on.

    DRAW_RECT,CH_BRICKWALL, 0,1,40,8,

There are a number of 'commands' such as DRAW_RECT, DRAW_FILLED_RECT, DRAW_LINE. Depending on the command, a variable number of parameters follow. In this case, it's saying draw a rectangle (unfilled) starting at (0,1) and (40,8) in size.

When there's no command, then it's simply place an object...

    CH_INSULATOR_TOP, 6,2,
    CH_INSULATOR_BOTTOM, 6,7,

This example places the top and bottom insulators (part of an electric fence) at (6,2) and (6,7) respectively. Note that the in-game logic will generate an electric 'arc' extending downward from every 'CH_INSULATOR_TOP' character that is on the board.

A whole whack of individual objects are dropped on the board, and at some point we have the following

    CH_DOORCLOSED, 38, 5,
    CH_MELLON_HUSK_BIRTH, 2, 3,

Essentially, the closed exit-door, and the place where the player starts playing from.  Here, (38,5) towards the right edge, is the exit. The player starts at the left edge, near the top.

And almost finally we have this block.

    DRAW_EOF,

    // EXTRAS
    // LEVEL 0 HERE

    DRAW_EOF,

     // LEVEL 1
    DRAW_EOF,

    // LEVEL 2
    DRAW_EOF,

    // LEVEL 3
    DRAW_EOF, // LEVEL 4

    DRAW_EOF,

The DRAW_EOF marks the end of the 'standard' (level 0) definition of a planet. But there's the option of adding to (or overriding) that base level, with an additional definition block for levels 1 to 4.  Each ended by the DRAW_EOF.  So for example, if I wanted to add a wyrm on level 1, I'd put something like the following inside that level 1 block.  I don't have anything there right now, but for example this would add lava to level 1, which does not appear in level 0.

    CH_LAVA_0, 1,20,

At the very bottom there's an option to put a string to give a name to the planet, which can be printed onscreen as you start playing...

    'T', 'E', 'S', 'T', END_STRING

And that's it!  From this structure comes all of the planets/levels that I've shown so far.

It would be awesome to have a level editor, but I doubt I'll ever get a round tuit. I'll just be creating levels by defining these structures by hand. Could be worse!

Andrew Davie

Here's another level, of sorts... actually reasonably fun to play...


Bomberman94

#3
Tested last available binary (WenHopPlanetPluto_20260610@12_26_08) and screen still flips but different. Depending on ,,tv type" switch it directly goes into game and screen is divided into two halves and rolls (= setting COLOR) or remains in the menu but automatically changes planet selection, but screen is solid (= setting BW). I attached links to YT videos of each:

https://youtu.be/ylOUzTxTxmo?is=fM8d22jGhOBYbP_l

https://youtu.be/GxMELXfS9XA?is=LvSH4MNx8n2KNJrV

Edit: I pressed ,,game reset" in COLOR setting once  to force the menu but it directly returns into the game again.