so://phie

freezo

A retro platform game
git clone git://soophie.de/freezo

feat: Added level background (unstable)


commit: 4845e8ea4007b452b2b3660902b677cad089d916
parent: 57bc5859707882c32f3459e8bd9542cf69c6ea08
author: Sophie <info@soophie.de>
time: 2024-12-16 00:49

diff --git a/assets/background.png b/assets/background.png

new file mode 100644

index 0000000..c8337b8

Binary files /dev/null and b/assets/background.png differ

diff --git a/include/game.h b/include/game.h

index cb8e14b..60db194 100644

--- a/include/game.h

+++ b/include/game.h

1@@ -20,6 +20,7 @@ struct Assets {

2 Texture2D entities;

3 Texture2D font;

4 Texture2D images;

5+ Texture2D background;

6 };

7

8 struct Game {

9

10

diff --git a/src/game.c b/src/game.c

index 38d6b9d..8d57ae4 100644

--- a/src/game.c

+++ b/src/game.c

1@@ -31,6 +31,7 @@ game_t *game_create(void) {

2 .assets.entities = texture_load("assets/entities.png", SCALE),

3 .assets.font = texture_load("assets/font.png", SCALE - 1),

4 .assets.images = texture_load("assets/images.png", SCALE),

5+ .assets.background = texture_load("assets/background.png", SCALE),

6 .camera = (Camera2D) {

7 .offset = (pos_t) { 0.0, 0.0 },

8 .zoom = 1,

9@@ -146,6 +147,7 @@ void game_update(game_t *game) {

10 void game_draw(game_t *game) {

11 BeginDrawing();

12 ClearBackground(BLACK);

13+ DrawTextureRec(game->assets.background, (Rectangle) { 0, 0, WINDOW_WIDTH * TILE_WIDTH, WINDOW_HEIGHT * TILE_HEIGHT }, (pos_t) { 0, 0 }, WHITE);

14 if (game->level != LEVEL_NULL) {

15 BeginMode2D(game->camera);

16 for (int i = 0; i < game->tiles_len; i++) {

17@@ -204,5 +206,6 @@ void game_free(game_t *game) {

18 UnloadTexture(game->assets.entities);

19 UnloadTexture(game->assets.font);

20 UnloadTexture(game->assets.images);

21+ UnloadTexture(game->assets.background);

22 free(game);

23 }

24

25

diff --git a/src/level.c b/src/level.c

index 09de3cd..e1821ab 100644

--- a/src/level.c

+++ b/src/level.c

1@@ -20,7 +20,7 @@ const char *LEVEL_MAP_1 = {

2 "................e......."

3 "...............--xxxxx.."

4 "....p..................."

5- "..ggggggggg---xxxxxxxx.."

6+ "..xxxxxxxxx---xxxxxxxx.."

7 "........................"

8 "........................"

9 };

10@@ -85,6 +85,7 @@ void level_generate(game_t *game, const char *map, int width, int height) {

11 game->entities_len = 0;

12 game->effects = NULL;

13 game->effects_len = 0;

14+ game->xp = 0;

15 for (int y = 0; y < height; y++) {

16 for (int x = 0; x < width; x++) {

17 int idx = y * width + x;

18

19