aboutsummaryrefslogtreecommitdiff
path: root/source/gamemode.c
diff options
context:
space:
mode:
authorEmil Williams2026-02-17 06:47:32 +0000
committerEmil Williams2026-02-17 07:56:38 +0000
commit428b68f791edcb89c811c9aca5dedbf7ec5d1335 (patch)
tree1608be97acc9c94e4cfca18264de86e8b7557e5b /source/gamemode.c
parent0bb3381eefcb645f1abd516e3a6827bad1767406 (diff)
downloadMonobomberman-428b68f791edcb89c811c9aca5dedbf7ec5d1335.tar.xz
Monobomberman-428b68f791edcb89c811c9aca5dedbf7ec5d1335.tar.zst
revised tiles, powerups, timer + basic gameplay8e8m
Diffstat (limited to 'source/gamemode.c')
-rw-r--r--source/gamemode.c101
1 files changed, 64 insertions, 37 deletions
diff --git a/source/gamemode.c b/source/gamemode.c
index d548773..6a09b08 100644
--- a/source/gamemode.c
+++ b/source/gamemode.c
@@ -1,33 +1,84 @@
#include "all.h"
-void MultiPlayer(game_t * game) {
+static void MapPrint(game_t * game) {
u8 width = game->config.map_x;
u8 height = game->config.map_y;
- int i, j;
+ printf("texture, explosive, breakable, lethal, pickup\n");
+ for (int i = 0; i < width; ++i) {
+ for (int j = 0; j < height; ++j) {
+ tile_data_t * tile = &game->tiles.state[i][j];
+ printf("%2d:%1d:%1d:%1d:%1d ", tile->texture, tile->explosive, tile->breakable, tile->lethal, tile->pickup);
+ }
+ printf("\n");
+ }
+}
- for (i = 0; i < PLAYER_LIMIT; ++i) {
- for (j = 0; j < BOMB_LIMIT; ++j) {
+static void GamemodeReset(game_t * game) {
+ for (int i = 0; i < PLAYER_LIMIT; ++i) {
+ for (int j = 0; j < BOMB_LIMIT; ++j) {
game->bombs.timer[i][j] = 0;
}
}
+ bzero(game->players.state, sizeof(*game->players.state) * PLAYER_LIMIT);
+}
+
+static void PlayerPlaceCorners(game_t * game, u8 * color, size_t color_count) {
+ u8 width = game->config.map_x;
+ u8 height = game->config.map_y;
+ float player_x[4] =
+ {0, (width-1), (width-1), 0 };
+ float player_y[4] =
+ {0, (height-1), 0, (height-1)};
+
+ for (int i = 0; i < MIN(game->config.player_count, PLAYER_LIMIT); ++i) {
+ game->players.x[i] = player_x[i % color_count];
+ game->players.y[i] = player_y[i % color_count];
+ game->players.color[i] = color[i % color_count];
+ }
+}
+
+static void MapClearCorners(game_t * game) {
+ /* areas that must be passible nothings */
+ u8 width = game->config.map_x;
+ u8 height = game->config.map_y;
+
+ u8 offset_x[12] =
+ {0, 1, 0, width-1, width-2, width-1, width-1, width-2, width-1, 0, 1, 0};
+ u8 offset_y[12] =
+ {0, 0, 1, height-1, height-1, height-2, 0, 0, 1, height-1, height-1, height-2};
+
+ for (int i = 0; i < MIN((game->config.player_count * 3), 12); ++i) {
+ game->tiles.state[offset_x[i]][offset_y[i]] = passable_tile;
+ }
+}
+
+void MultiPlayer(game_t * game) {
+ u8 width = game->config.map_x;
+ u8 height = game->config.map_y;
+ int i, j;
+
+ GamemodeReset(game);
+
for (i = 0; i < width; ++i) {
for (j = 0; j < height; ++j) {
- game->tiles.state[i][j]._ = rand() % 10 ? IMPASSIBLE_BREAKABLE_WALL : PASSIBLE_NOTHING;
- /* game->tiles.state[i][j]._ |= rand() % 3 ? 0 : POWERUP; */
+ game->tiles.state[i][j] = rand() % 10 ? breakable_wall : passable_tile;
+ if (rand() % 3 == 0)
+ {
+ game->tiles.state[i][j].pickup = rand() % 5 ? POWERUP_POWER : POWERUP_BOMB;
+ } else if (rand() % 10 == 0) {
+ game->tiles.state[i][j].pickup = POWERUP_PIERCE;
+ }
}
}
for (i = 1; i < width; i += 2) {
for (j = 1; j < height; j += 2) {
- game->tiles.state[i][j]._ = IMPASSIBLE_WALL;
+ game->tiles.state[i][j] = impassable_wall;
}
}
- bzero(game->players.state, sizeof(*game->players.state) * PLAYER_LIMIT);
-
for (i = 0; i < MIN(PLAYER_LIMIT, game->config.player_count); ++i) {
- bzero(&game->players.state[i]._, sizeof(game->players.state[i]._));
game->players.state[i].bomb_limit = 1;
game->players.state[i].power = 2;
game->players.state[i].speed = 2;
@@ -37,11 +88,6 @@ void MultiPlayer(game_t * game) {
game->time_limit = game->config.ups * 60 * 3;
- float player_x[4] =
- {0, (width-1), (width-1), 0 };
- float player_y[4] =
- {0, (height-1), 0, (height-1)};
-
u8 color[4] = {
GAME_RED | GAME_GREEN | GAME_OPAQUE,
GAME_RED | GAME_GREEN | GAME_BLUE | GAME_OPAQUE,
@@ -49,26 +95,7 @@ void MultiPlayer(game_t * game) {
GAME_BLUE | GAME_OPAQUE,
};
- for (i = 0; i < MIN(game->config.player_count, PLAYER_LIMIT); ++i) {
- game->players.x[i] = player_x[i % 4];
- game->players.y[i] = player_y[i % 4];
- game->players.color[i] = color[i % 4];
- }
-
- /* areas that must be passible nothings */
- u8 offset_x[12] =
- {0, 1, 0, width-1, width-2, width-1, width-1, width-2, width-1, 0, 1, 0};
- u8 offset_y[12] =
- {0, 0, 1, height-1, height-1, height-2, 0, 0, 1, height-1, height-1, height-2};
-
- for (i = 0; i < MIN((game->config.player_count * 3), 12); ++i) {
- game->tiles.state[offset_x[i]][offset_y[i]]._ = PASSIBLE_NOTHING;
- }
-
- for (i = 0; i < width; ++i) {
- for (j = 0; j < height; ++j) {
- printf("%3d ", game->tiles.state[i][j]._);
- }
- printf("\n");
- }
+ PlayerPlaceCorners(game, color, 4);
+ MapClearCorners(game);
+ MapPrint(game);
}