Game Dev: Digging tunnels and flooding them (Group 13)

Hi!

This week, I have been helping out on the programming side of Mole Munch. I started programming for the team last week during the days leading up to the alpha, and have continued helping out with that this week.

My task this week was to work on the tunnel system, which I consider one of our core mechanics. Mole Munch is about constantly switching between surface and dig mode, avoiding gardeners on the surface and water spreading in your tunnel below ground. Belowis a diagram stating the pros and cons about surface versus dig mode. It is taken directly from our design document.

Above ground Below ground
Positive > Safe from and can walk over flooded tunnels

> Can eat vegetables

> Faster

> See everything

> Gardeners will not notice you

Negative > See less

> Much slower

> Gardeners can detect the player

> Touching gardeners kills the player

> Leaves dirt trail

> is killed if water in flooded tunnel reaches player

> Old flooded tunnels act as walls and can not be penetrated

The idea is that the player will leave a trail of dirt behind when below ground, which gardeners will flood with water if they find it. My goal this week was to implement all of the pros and cons of both surface and dig mode, except for the loss of vision planned for surface mode. This meant implementing tunnels and water spreading!

So, how do you code tunnels and water spreading?

The idea is to spawn dirt squares at the player’s position if the player is in dig mode and is not colliding with any already spawned dirts. By making the dirt size slightly bigger than the player’s, I can ensure a chain of dirts will always be connected wherever the player has gone in dig mode.

Like this!

Like this!

It is important that the dirts are connected, because of the way I planned water spreading. When a gardener collides with a dirt tile, they will tell that particular dirt tile to get flooded. The dirt goes from a dirt state, to a filling state for a short period of time, to finally enter the water state. When a dirt enters the water state, it checks if it is colliding with any other dirts that have not turned into water. If it is, those dirts are also told to get flooded. That way, a chain reaction is created and water travels from dirt to dirt, getting closer and closer to the player.

Screenshot of the game. Graphics are currently being implemented, but not by me :)

Screenshot of the game. Everything is currently boxes, but other coders are hard at work implementing graphics.

So, how did I do all this in code? 

First off, I created a new entity class called Dirt. Each copy of Dirt is a dirt tile. In order to make it easier on the computer, I decided to create all dirts at the beginning of the game and then have them be visualized when needed, rather then have them dynamically created and put into a vector each time the game spawns a dirt. In the beginning of the game, 300 dirts are created and put into the entity vector. When a new dirt needs to be created, there is a for loop that loops through the entity vector, looking for a dirt that is not existing yet. When one is found, the dirt’s CreateDirt(posx,posy) function is called, giving it a place to position to go to.

A problem with this method, is that the entity vector needs to be looped whenever dirt is interacted with. The code did work, but some lag was had. To solve this, I put all of the dirt in its own vector, and performance improved significantly.

All collision checking loops in Mole Munch is currently handled by PlayState. In its update function, playstate will loop through all entities, checking what collidies with what and sending signals to the entities in question on how to react. Since I had already coded collision last week, implementing the collision checks required was not a huge task.

However, another performance issue appeared when water spreading was to be implemented. What I had was that each update, all dirt tiles would check if they were colliding with any water tiles and set themselves to flooded if that was the case. However, there is a lot of dirt tiles in Mole Munch, the maximum being at 300, so a lot of useless collision checking was done.  To solve this, I had dirt recently converted into water check for collision with dirt tiles instead. Since only 1-5 tiles can be converted into water at the same time, this was a much more efficient way of doing it and no lag was had.

Here is the different solutions illustrated. The brown ones are dirts and the blue ones are water.  If you want to see how many people have been phoned by sales people, do you ask everyone in the world if they have been phoned by a sales person, or do you ask the sales person how many they have phoned?

Here are the different solutions illustrated. The brown ones are dirts and the blue ones are water.
If you want to see how many people have been phoned by sales people, do you ask everyone in the world if they have been phoned by a sales person, or do you ask the sales person how many they have phoned?

The rest of the challenges regarding this particular feature (Water acts as wall for player when in dig mode, player cannot enter dig mode if there is water below, player dies if spreading water reaches player, enemies stop when colliding with dirt tiles) were relatively easy to implement.

Overall I am pleased with my work this week. My solution to the dirt spawning and water spreading problem do result in very blocky tunnels, but considering our time limit I think this solution is good enough for what we are aiming for. We must move from implementing features to polishing as soon as possible.

Thanks for reading, until next time!

3 reaktioner på ”Game Dev: Digging tunnels and flooding them (Group 13)

  1. Nice work, Sebastian!

    It’s all very clear what you’ve done this week, and more importantly, how and why you’ve done it. I especially like how you go through the process step by step all the while you are motivating your choices and explaining the problems you encountered.
    The pictures are also a great addition.

    Keep it up!

    Gilla

  2. Pingback: Mole Munch – Final build download | mnniska
  3. Fiquei muito feliz com a notícia da reÃvÃan§o£o, e espero muito a entrada de Sergio Perez e Pastor Maldonado na F1.São pilotos decididos, que trarão mais alegria à categoria.

    Gilla

Lämna en kommentar