aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/all.h33
-rw-r--r--source/game.c6
-rw-r--r--source/gamemode.c6
-rw-r--r--source/raylib.c11
-rw-r--r--source/render.c20
-rw-r--r--source/update.c7
6 files changed, 57 insertions, 26 deletions
diff --git a/source/all.h b/source/all.h
index d1f2761..5aa6fd1 100644
--- a/source/all.h
+++ b/source/all.h
@@ -37,6 +37,8 @@
85*((c & GAME_BLUE)>>4), \
85*((c & GAME_OPAQUE)>>6), }
+#define FONT_SIZE 20
+
#define TEXTURE_LIMIT (3*8)
/* Spritesheets will be (128*4x128*6)
@@ -102,8 +104,8 @@ typedef struct {
i8 pickup : 4; // positive / negative pickups
// 5 bits left for extensions.
};
- } state[TILE_LENGTH_LIMIT][TILE_LENGTH_LIMIT];
- u8 color;
+ } state[TILE_LENGTH_LIMIT][TILE_LENGTH_LIMIT] aligned;
+ u8 color aligned;
Rectangle wall[2] aligned;
Rectangle explosion[2] aligned;
Rectangle powerup[8] aligned;
@@ -173,20 +175,23 @@ typedef struct {
i16 x[ENEMY_LIMIT] aligned;
i16 y[ENEMY_LIMIT] aligned;
u8 movement[ENEMY_LIMIT] aligned;
- Rectangle enemy[4];
+ Rectangle enemy[4] aligned;
} enemies_t;
#define CONFIG_STRING_LIMIT 128
typedef struct {
- u16 resolution_x, resolution_y;
- u8 fps, ups;
- char font[CONFIG_STRING_LIMIT];
- char spritesheet[CONFIG_STRING_LIMIT];
- char window_name[CONFIG_STRING_LIMIT];
- u16 spritesheet_scale;
+ u16 resolution_x aligned;
+ u16 resolution_y aligned;
+ u8 fps aligned;
+ u8 ups aligned;
+ char font[CONFIG_STRING_LIMIT] aligned;
+ char spritesheet[CONFIG_STRING_LIMIT] aligned;
+ char window_name[CONFIG_STRING_LIMIT] aligned;
+ u16 spritesheet_scale aligned;
/* --- */
- u8 player_count;
- u8 map_x, map_y;
+ u8 player_count aligned;
+ u8 map_x aligned;
+ u8 map_y aligned;
} config_t;
typedef struct {
@@ -200,8 +205,8 @@ typedef struct {
Texture spritesheet aligned;
Camera2D camera aligned;
-
- u8 client;
+ u16 time_limit aligned;
+ u8 client aligned;
} game_t;
/* game.c */
@@ -226,7 +231,7 @@ void Render(game_t * game, f64 interpolation);
void GuiLoadStyleDarkSimple(void);
Font DefaultFont(char * choice);
-void RaylibInitialize(int horizontal, int vertical, char * window_name, Font default_font);
+void RaylibInitialize(game_t * game);
void RaylibDeinitialize(void);
/* ... */
diff --git a/source/game.c b/source/game.c
index b17bf73..d98b235 100644
--- a/source/game.c
+++ b/source/game.c
@@ -21,6 +21,7 @@ void GameStart(config_t config) {
static void GameRecalculateViewport(game_t * game) {
game->config.resolution_x = GetScreenWidth();
game->config.resolution_y = GetScreenHeight();
+
game->camera = (Camera2D) {
.offset = (Vector2) { 0 },
.target = (Vector2) { 0 },
@@ -43,7 +44,7 @@ static void GameInitialize(game_t * game) {
/* Strict parameters */
#define DEFAULT(a, b) ((b) ? (b) : (a))
game->config.resolution_x = MAX(200, DEFAULT(600, game->config.resolution_x));
- game->config.resolution_y = MAX(200, DEFAULT(600, game->config.resolution_y));
+ game->config.resolution_y = game->config.resolution_x+ FONT_SIZE;
game->config.fps = MAX(1, DEFAULT(60, game->config.fps));
game->config.ups = MAX(1, DEFAULT(30, game->config.ups));
if (!*game->config.font)
@@ -114,9 +115,8 @@ static void GameInitialize(game_t * game) {
game->bombs.color[1] = GAME_RED | GAME_OPAQUE;
/* :config */
- game->font = DefaultFont(game->config.font);
+ RaylibInitialize(game);
- RaylibInitialize(game->config.resolution_x, game->config.resolution_y, game->config.window_name, game->font);
GameRecalculateViewport(game);
game->spritesheet = LoadTexture(game->config.spritesheet);
diff --git a/source/gamemode.c b/source/gamemode.c
index 9c1055a..d548773 100644
--- a/source/gamemode.c
+++ b/source/gamemode.c
@@ -14,6 +14,7 @@ void MultiPlayer(game_t * 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; */
}
}
@@ -26,13 +27,16 @@ void MultiPlayer(game_t * game) {
bzero(game->players.state, sizeof(*game->players.state) * PLAYER_LIMIT);
for (i = 0; i < MIN(PLAYER_LIMIT, game->config.player_count); ++i) {
- game->players.state[i].bomb_limit = 15;
+ 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;
game->players.state[i].alive = 1;
game->players.state[i].direction = DOWN;
}
+ game->time_limit = game->config.ups * 60 * 3;
+
float player_x[4] =
{0, (width-1), (width-1), 0 };
float player_y[4] =
diff --git a/source/raylib.c b/source/raylib.c
index 33ac72c..32cfafb 100644
--- a/source/raylib.c
+++ b/source/raylib.c
@@ -11,7 +11,7 @@
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#define RAYGUI_IMPLEMENTATION
-#include <raygui.h>
+#include "all.h"
#include <style_dark.h>
#pragma GCC diagnostic pop
@@ -32,12 +32,14 @@ Font DefaultFont(char * choice) {
return font;
}
-void RaylibInitialize(int horizontal, int vertical, char * window_name, Font default_font) {
+void RaylibInitialize(game_t * game) {
#ifdef NDEBUG
SetTraceLogLevel(LOG_NONE);
#endif
+ i16 horizontal = game->config.resolution_x;
+ i16 vertical = game->config.resolution_y;
/* SetConfigFlags(FLAG_WINDOW_RESIZABLE); */
- InitWindow(horizontal, vertical, window_name);
+ InitWindow(horizontal, vertical, game->config.window_name);
SetWindowState(FLAG_WINDOW_HIDDEN);
/* we should spawn this in the center of the screen and have our window scale to the limit of the screen */
InitAudioDevice();
@@ -47,7 +49,8 @@ void RaylibInitialize(int horizontal, int vertical, char * window_name, Font def
width/2-horizontal/2,
height/2-vertical/2);
GuiLoadStyleDarkSimple();
- GuiSetFont(default_font);
+ game->font = DefaultFont(game->config.font);
+ GuiSetFont(game->font);
}
void RaylibDeinitialize(void) {
diff --git a/source/render.c b/source/render.c
index 5af04f8..5f5fb25 100644
--- a/source/render.c
+++ b/source/render.c
@@ -3,18 +3,25 @@
static void RenderTiles(game_t * game);
static void RenderPlayers(game_t * game);
static void RenderBombs(game_t * game);
+static void RenderBottomText(game_t * game);
void Render(game_t * game, f64 interpolation) {
(void)game;
(void)interpolation;
BeginDrawing();
+
+#ifndef NDEBUG
ClearBackground(BLACK);
+#else
+ ClearBackground(COLOR_TO_RAYLIB(game->tiles.color));
+#endif
BeginMode2D(game->camera);
RenderTiles(game);
RenderBombs(game);
RenderPlayers(game);
EndMode2D();
+ RenderBottomText(game);
/* --- */
rlDrawRenderBatchActive();
SwapScreenBuffer();
@@ -23,9 +30,11 @@ void Render(game_t * game, f64 interpolation) {
void RenderTiles(game_t * game) {
for (int i = 0; i < game->config.map_x; ++i) {
for (int j = 0; j < game->config.map_y; ++j) {
+ #ifndef NDEBUG
if ((game->tiles.state[i][j]._ | 1) & PASSIBLE || game->tiles.state[i][j]._ == IMPASSIBLE_NOTHING) {
DrawRectangleRec((Rectangle) {i*game->config.spritesheet_scale, j*game->config.spritesheet_scale, game->config.spritesheet_scale, game->config.spritesheet_scale}, COLOR_TO_RAYLIB(game->tiles.color));
}
+ #endif
if (game->tiles.state[i][j]._ < 2) {
DrawTextureRec(
@@ -43,8 +52,6 @@ void RenderTiles(game_t * game) {
(Vector2) {i*game->config.spritesheet_scale, j*game->config.spritesheet_scale},
WHITE);
}
-
-
}
}
}
@@ -74,3 +81,12 @@ void RenderBombs(game_t * game) {
}
}
}
+
+static void RenderBottomText(game_t * game) {
+ BeginScissorMode(0, game->config.resolution_y - FONT_SIZE, game->config.resolution_x, FONT_SIZE);
+ ClearBackground(BLACK);
+ char center_string[128];
+ snprintf(center_string, 128, "%02d:%02d", game->time_limit / game->config.ups / 60, game->time_limit / game->config.ups % 60);
+ DrawText(center_string, game->config.resolution_x / 2 - MeasureText(center_string, FONT_SIZE) / 2, game->config.resolution_y - FONT_SIZE, FONT_SIZE, WHITE);
+ EndScissorMode();
+}
diff --git a/source/update.c b/source/update.c
index 2e8b282..610252b 100644
--- a/source/update.c
+++ b/source/update.c
@@ -36,7 +36,8 @@ static void UpdateExplosions(game_t * game) {
size_t i, j;
for (i = 0; i < game->config.map_x; ++i) {
for (j = 0; j < game->config.map_y; ++j) {
- if (game->tiles.state[i][j]._ >= PASSIBLE_EXPLOSIVE_LETHAL) {
+ if (game->tiles.state[i][j]._ >= PASSIBLE_EXPLOSIVE_LETHAL
+ && game->tiles.state[i][j]._ <= PASSIBLE_EXPLOSIVE_LETHAL_END) {
if (game->tiles.state[i][j]._ == PASSIBLE_EXPLOSIVE_LETHAL_END)
{ game->tiles.state[i][j]._ = PASSIBLE_NOTHING; }
else
@@ -156,7 +157,9 @@ static void UpdateBomb(game_t * game) {
game->tiles.state[rx][ry]._ = PASSIBLE_EXPLOSIVE_LETHAL;
} else if (game->tiles.state[rx][ry]._ == IMPASSIBLE_BREAKABLE_WALL) {
game->tiles.state[rx][ry]._ = PASSIBLE_EXPLOSIVE_LETHAL;
- block[k%4] = 1;
+ if (!game->players.state[i].pierce) {
+ block[k%4] = 1;
+ }
} else {
block[k%4] = 1;
}