NcJump devlog #3


Welcome to this new devlog on the development of ncJump. Previously I wrote about improvements on movement on the camera and serialization of the state of the game, and I concluded mentioning about being able to start crafting actual levels. Some bug fixing and generic improvements were needed on various aspects of my code, but I managed to shape something interesting that, although it may seem incomplete, it is a convincing baseline.

Jump higher

From a gameplay perspective, the player gains confidence with the elements of interactivity of the game. It first moves, then jumps, then jumps higher. The implementation is straightforward thanks to Box2D. If the jump button is still down, keep applying a small force upwards. Keep in mind that force should be weaker than gravity, otherwise the character would take off into space.

void can_jump_higher(Input& input, Entity& entity) {
  if (input.jump.down) {
    auto force = b2Vec2(0.0f, small_amount);
    entity.physics->body->ApplyForceToCenter(force, true);
  }
}

Resizing the tilemap

This was less straightforward. I am starting to believe the more something is boring the more is difficult to implement. Resizing is not trivial, many things should be considered. For simplicity here I will focus on the concrete tiles grid only. At the beginning I used a simple vector to store all concrete tiles of the map and with a simple formula (y + x * height) I was able to index a cell of the grid. Then I realized that resizing this vector was not convenient as the order of the tiles in the cells would not be preserved.

As a solution, I changed the structure from a simple vector to a vector of vectors, so we could say a list of columns. That simplified indexing as you could just use the subscript operator to access the right tile (tiles[x][y]).

It also simplified resizing. If you want to change the width of the tilemap, you just modify the number of columns by calling tiles.resize(new_width). As you can imagine, if the width shrinks, you lose those columns, while if the width grows, you get new columns with a default concrete tile. I can not overstate the importance of default values. Changing the height is slightly different, as you need to resize all the columns.

for (uint32_t i = 0; i < width; ++i) {
  tiles[i].resize(new_height);
}

I hope you enjoyed this devlog. Stay tuned for the next one as I will discuss about dynamic entities!

Leave a comment

Log in with itch.io to leave a comment.