Dag / Day 4: Videogame's Devlog - graphics, minimap and level up

Created Fri, 07 Jun 2024 22:35:13 +0200 Modified Fri, 07 Jun 2024 22:35:13 +0200

Day 4 - Graphics, minimap and level up

Tonight is the night! I need to implement graphics!

Well, how to do it? Old videogames were made with spritesheets, so I decide to do the same. I downloaded a spritesheet from a free itch.io download link, and I am ready to go…?

But what’s the basic idea? I have to draw the map exactly as I did before, but instead of drawing colored squares, I have to draw textures.

The steps are:

  1. load the spritesheet
  2. while drawing the map, if the tile is a wall then go to the spritesheet and take the 4th square by row and column
    1. for example, if the wall is at row 1 and column 1, then the square is at row 0, column 0, wide 16 and high 16
    2. if the character is at row 2 and column 1, then the square is at row 161 and column 116, wide 16 and high 16, and so on
    3. this is because the spritesheet is 16x16 and every square is 16x16

This is feasible, so I decide to go ahead: I modify the main structure by adding row column and spritesheet where the graphics are saved.

After that, instead of drawing colored squares I decide to draw textures, each 16x16 and… it’s a great idea, everything works, I just have to be careful to change the sprites of the enemies.

Wouldn’t it be nice a minimap in the HUD too? Of course, it may come in handy for me for debugging purposes but also for the player in the future.

I notice that minimap is the same map I normally draw, but with pixels 1x1 instead of tiles. Basically there is no need to rewrite the code, just to make a function that draws a general map.

Since the code is starting to be a mess, I decide to refactor it a bit: dictionary will store each element’s characteristics, like this:

    {
        "enemy": {
            "x": 10,
            "y": 10,
            "hp": 10,
            "attack": 2,
            "walkable": False,
            ...
        },
        ...
    }

Look how it’s beautiful!

dungeon6.png

Now it’s time to improve the HUD and set health points and attack points to the protagonist and enemies.

I decide to also change the function that inserts stuff into the map: in case of enemies/living people, it also inserts additional parameters such as residual hp or collected tool, so that I can manage enemies’ items and death as well.

dungeon7.png

I finally decide to implement a simple level up (experience) and level up mechanism, by using some math functions and randomness.