summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-03-17 13:45:20 +0100
committerkdx <kikoodx@paranoici.org>2023-03-17 13:46:20 +0100
commitf3f3100dbd1f8ff31c3e6fd2acfd2c6edffcc181 (patch)
treeee2d07262e282120eb1776f3491272c91336e8eb
parentb6e8281daa60e60e2ae81569b5547f1e3ac3a72b (diff)
downloadhyperultra-f3f3100dbd1f8ff31c3e6fd2acfd2c6edffcc181.tar.gz
cringe
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/background.c8
-rw-r--r--src/cfg.h2
-rw-r--r--src/entity.c4
-rw-r--r--src/game.c2
-rw-r--r--src/main.c3
-rw-r--r--src/map.c48
-rw-r--r--src/map.h5
-rw-r--r--src/player.c16
9 files changed, 77 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 19bb98b..1937e8c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,6 +15,7 @@ set(SOURCES
src/game.c
src/lzy.c
src/main.c
+ src/map.c
src/player.c
)
diff --git a/src/background.c b/src/background.c
index 623f5e0..4d17af3 100644
--- a/src/background.c
+++ b/src/background.c
@@ -46,8 +46,8 @@ void
background_draw(void)
{
tick += 1;
- LZY_DrawSetColor(0, 0, 0);
- draw_square(64 * sin((double)tick / 50), (double)tick / 40);
- draw_square(64 * sin((double)tick / 40), (double)tick / 30);
- draw_square(64 * sin((double)tick / 30), (double)tick / 20);
+ LZY_DrawSetColor(BLACK);
+ draw_square(300 * sin((double)tick / 50), (double)tick / 40);
+ draw_square(300 * sin((double)tick / 40), (double)tick / 30);
+ draw_square(300 * sin((double)tick / 30), (double)tick / 20);
}
diff --git a/src/cfg.h b/src/cfg.h
index fc23d86..9c85435 100644
--- a/src/cfg.h
+++ b/src/cfg.h
@@ -4,3 +4,5 @@
#define DISPLAY_WIDTH 400
#define DISPLAY_HEIGHT 224
#define TSIZE 16
+#define WHITE 255, 255, 255
+#define BLACK 0, 0, 0
diff --git a/src/entity.c b/src/entity.c
index da7662e..94c0a47 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -1,5 +1,6 @@
#include "entity.h"
#include "game.h"
+#include "map.h"
#include "cfg.h"
bool
@@ -10,7 +11,8 @@ entity_collide(Entity *this, Game *g, int ox, int oy)
const int y0 = this->pos[1] - this->height / 2 + oy;
const int x1 = x0 + this->width - 1;
const int y1 = y0 + this->height - 1;
- return (x0 < 0 || y0 < 0 || x1 >= DISPLAY_WIDTH || y1 >= DISPLAY_HEIGHT);
+ return (map_get_px(x0, y0) == '0' || map_get_px(x0, y1) == '0' ||
+ map_get_px(x1, y0) == '0' || map_get_px(x1, y1) == '0');
}
void
diff --git a/src/game.c b/src/game.c
index 2a3ceeb..7adbae0 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1,4 +1,5 @@
#include "game.h"
+#include "map.h"
#include <string.h>
void
@@ -26,6 +27,7 @@ game_update(Game *this)
void
game_draw(Game *this)
{
+ map_draw();
for (int i = 0; i < MAX_ENTITIES; i++) {
Entity *const e = &this->entities[i];
if (e->type != ET_NONE && e->draw != NULL)
diff --git a/src/main.c b/src/main.c
index f03fffa..2c240e0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2,6 +2,7 @@
#include "game.h"
#include "player.h"
#include "background.h"
+#include "cfg.h"
#include <stdio.h>
#include <stdlib.h>
@@ -27,7 +28,7 @@ int main(void)
game_update(game);
LZY_DrawBegin();
- LZY_DrawSetColor(255, 255, 255);
+ LZY_DrawSetColor(WHITE);
LZY_DrawClear();
background_draw();
game_draw(game);
diff --git a/src/map.c b/src/map.c
new file mode 100644
index 0000000..dcc02f7
--- /dev/null
+++ b/src/map.c
@@ -0,0 +1,48 @@
+#include "map.h"
+#include "lzy.h"
+#include "cfg.h"
+
+static const char *map =
+ "0000000000000000000000000"
+ "0 0"
+ "0 0"
+ "0 0"
+ "0 0"
+ "0 0"
+ "0 0"
+ "0 0"
+ "0 0"
+ "0 0"
+ "00000000000000000000 0"
+ "0 0"
+ "0 0"
+ "0000000000000000000000000"
+;
+
+int
+map_get(int x, int y)
+{
+ if (x < 0 || y < 0 || x >= 25 || y >= 14)
+ return 0;
+ return map[x + y * 25];
+}
+
+int
+map_get_px(int x, int y)
+{
+ if (x < 0 || y < 0)
+ return 0;
+ return map_get(x / TSIZE, y / TSIZE);
+}
+
+void
+map_draw(void)
+{
+ for (int y = 0; y < 14; y++)
+ for (int x = 0; x < 25; x++)
+ if (map[x + y * 25] == '0') {
+ LZY_DrawSetColor(BLACK);
+ LZY_DrawRect(x*16, y*16, 16, 16);
+ LZY_DrawFillRect(x*16, y*16, 16, 16);
+ }
+}
diff --git a/src/map.h b/src/map.h
new file mode 100644
index 0000000..344a48f
--- /dev/null
+++ b/src/map.h
@@ -0,0 +1,5 @@
+#pragma once
+
+int map_get(int x, int y);
+int map_get_px(int x, int y);
+void map_draw(void);
diff --git a/src/player.c b/src/player.c
index 9778746..dc60dbb 100644
--- a/src/player.c
+++ b/src/player.c
@@ -2,6 +2,7 @@
#include "entity.h"
#include "game.h"
#include "lzy.h"
+#include "cfg.h"
#include <string.h>
static void
@@ -16,18 +17,21 @@ static void
player_draw(Entity *this, Game *g)
{
(void)g;
- LZY_DrawSetColor(0, 0, 0);
- LZY_DrawFillRect(this->pos[0] - this->width / 2,
- this->pos[1] - this->height / 2,
- this->width, this->height);
+ LZY_DrawSetColor(BLACK);
+ LZY_DrawRect(this->pos[0] - this->width / 2,
+ this->pos[1] - this->height / 2,
+ this->width, this->height);
+ LZY_DrawRect(this->pos[0] - this->width / 2 + 1,
+ this->pos[1] - this->height / 2 + 1,
+ this->width - 2, this->height - 2);
}
void
player_init(Entity *this)
{
memset(this, 0, sizeof(*this));
- this->pos[0] = 16;
- this->pos[1] = 16;
+ this->pos[0] = 32;
+ this->pos[1] = 32;
this->type = ET_PLAYER;
this->update = player_update;
this->draw = player_draw;