commit 4d92e2c8f38e4e620251de6e3a91e8db8a93d743
parent 12bdd63c09858a148d368d8239d7f5a925707757
Author: Sophie <info@soophie.de>
Date: Wed, 18 Dec 2024 00:55:59 +0100
feat: Added/updated levels
Diffstat:
7 files changed, 75 insertions(+), 45 deletions(-)
diff --git a/assets/background.png b/assets/background.png
Binary files differ.
diff --git a/include/level.h b/include/level.h
@@ -1,6 +1,6 @@
#pragma once
-#define LEVELS 3
+#define LEVELS 5
typedef struct Level level_t;
@@ -9,6 +9,8 @@ typedef enum {
LEVEL_1,
LEVEL_2,
LEVEL_3,
+ LEVEL_4,
+ LEVEL_5,
} level_e;
#include "game.h"
diff --git a/include/tile.h b/include/tile.h
@@ -22,6 +22,7 @@ typedef enum {
TILE_BG_BRICK_1,
TILE_BG_BRICK_2,
TILE_BG_BRICK_3,
+ TILE_BG_INFO,
} tile_e;
struct Tile {
diff --git a/src/game.c b/src/game.c
@@ -119,9 +119,11 @@ void game_update(game_t *game) {
break;
}
case STATE_GAME: {
- if (IsKeyPressed(KEY_ESCAPE)) {
- game->state = STATE_MENU;
- game->menu->idx = 0;
+ if (!game->victory && !game->defeat) {
+ if (IsKeyPressed(KEY_ESCAPE)) {
+ game->state = STATE_MENU;
+ game->menu->idx = 0;
+ }
}
if (game->level != NULL) {
// defeat
diff --git a/src/level.c b/src/level.c
@@ -9,6 +9,25 @@
const char *LEVEL_MAP_1 = {
"........................"
"........................"
+ "........................"
+ "..I....................."
+ "........................"
+ "........................"
+ ".............o.........."
+ "..................2....."
+ "........................"
+ "........................"
+ ".....3........e....u...."
+ "............--xxxxxxxx.."
+ "....p..................."
+ "..xxxxxxxxxxx..........."
+ "........................"
+ "........................"
+};
+
+const char *LEVEL_MAP_2 = {
+ "........................"
+ "........................"
"........k.......O......."
"..1....................."
"........................"
@@ -25,7 +44,7 @@ const char *LEVEL_MAP_1 = {
"........................"
};
-const char *LEVEL_MAP_2 = {
+const char *LEVEL_MAP_3 = {
"........................"
"........................"
"......3....b............"
@@ -44,14 +63,33 @@ const char *LEVEL_MAP_2 = {
"........................"
};
-const char *LEVEL_MAP_3 = {
+const char *LEVEL_MAP_4 = {
"........................"
+ "............o..........."
+ "..1....................."
+ ".........e.........u...."
+ "........---.......---..."
+ "......s................."
+ "...xxtxxxxxx..-.....3..."
+ ".....w...b.............."
+ "...e.w............j....."
+ "..---x...........ejj...."
+ "..............xtxxxxxx.."
+ "...2.....---...w........"
+ "....p..........w........"
+ "..xxxxx................."
"........................"
- "...b.....1....e...k....."
- "............-txx-......."
+ "........................"
+};
+
+const char *LEVEL_MAP_5 = {
+ "........................"
+ "........................"
+ "...b.....1........k....."
+ ".........z..-txx-......."
".............w.........."
"............-w..-......."
- "........s....w......u..."
+ ".............w......u..."
"..x---xxxxxxxtxxx--xxx.."
"....e........w....e....."
"...---....2..w--txxx...."
@@ -63,39 +101,6 @@ const char *LEVEL_MAP_3 = {
"........................"
};
-// const char *LEVEL_MAP_3 = {
-// "........................................"
-// "........................................"
-// "........................................"
-// "........................................"
-// "........................................"
-// "........................................"
-// "........................................"
-// "........................................"
-// "........................................"
-// "........................................"
-// "......e..................e...s.........."
-// "....xxxxx...--...xxxxxxxxxxxxxxxxx......"
-// "........................................"
-// "............--.........................."
-// "....................e..................."
-// "............--...xxxxxxxxt-............."
-// ".........................w.............."
-// "............--...........w-............."
-// "..............e.......s..w..e..........."
-// "..........xxxxxxxxxxxxxxxxxxxxxxxt--x..."
-// ".................................w......"
-// ".................................w--...."
-// ".................................w......"
-// ".................................w--...."
-// "........................e........w......"
-// "....................xxtxxxtxx----x--...."
-// "....p.......e.........w...w............."
-// "..xxxxx..-----...xxxxxxxxxxxxxxxxxxxxx.."
-// "........................................"
-// "........................................"
-// };
-
void level_generate(game_t *game, const char *map, int width, int height) {
game->player = NULL;
game->tiles = malloc(sizeof(tile_t) * width * height);
@@ -161,6 +166,9 @@ void level_generate(game_t *game, const char *map, int width, int height) {
case '3':
tile->type = TILE_BG_BRICK_3;
break;
+ case 'I':
+ tile->type = TILE_BG_INFO;
+ break;
default:
break;
}
@@ -258,9 +266,18 @@ void level_load(game_t *game, level_e type) {
level_generate(game, LEVEL_MAP_3, 24, 16);
level->width = 24;
level->height = 16;
- // level_generate(game, LEVEL_MAP_3, 40, 30);
- // level->width = 40;
- // level->height = 30;
+ break;
+ }
+ case LEVEL_4: {
+ level_generate(game, LEVEL_MAP_4, 24, 16);
+ level->width = 24;
+ level->height = 16;
+ break;
+ }
+ case LEVEL_5: {
+ level_generate(game, LEVEL_MAP_5, 24, 16);
+ level->width = 24;
+ level->height = 16;
break;
}
}
diff --git a/src/player.c b/src/player.c
@@ -384,6 +384,10 @@ void player_update(player_t *player, game_t *game) {
for (int i = 0; i < game->entities_len; i++) {
entity_t *entity = &game->entities[i];
if (entity->is_bad) {
+ // ignore gates
+ if (entity->type == ENTITY_GATE) {
+ continue;
+ }
// ignore frozen enemies
if (entity->type == ENTITY_ENEMY && entity->enemy->frozen) {
continue;
diff --git a/src/tile.c b/src/tile.c
@@ -86,6 +86,10 @@ void tile_draw(tile_t *tile, game_t *game) {
DrawTextureRec(game->assets.background, texture_rect_v(0, 6, 2, 2, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);
break;
}
+ case TILE_BG_INFO: {
+ DrawTextureRec(game->assets.background, texture_rect_v(12, 0, 10, 6, TILE_WIDTH, TILE_HEIGHT), tile->pos, WHITE);
+ break;
+ }
}
}