summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx@42l.fr>2023-02-18 01:18:42 +0100
committerkdx <kdx@42l.fr>2023-02-18 01:18:42 +0100
commit72a6892b5b18e450d82468e7bb830687a0215eb4 (patch)
treec8126b0557161a671df47c9fed2c7f915a53298e
parent80635fd59c54d8ba4591029114bea3755cccb816 (diff)
downloadbozojam-72a6892b5b18e450d82468e7bb830687a0215eb4.tar.gz
art
-rw-r--r--Makefile5
-rw-r--r--cfg.h4
-rw-r--r--commands.c24
-rw-r--r--commands.h15
-rw-r--r--level.c39
-rw-r--r--level.h9
-rw-r--r--main.c26
-rw-r--r--res/down.bmpbin0 -> 1674 bytes
-rw-r--r--res/left.bmpbin0 -> 1674 bytes
-rw-r--r--res/right.bmpbin0 -> 1674 bytes
-rw-r--r--res/up.bmpbin0 -> 1674 bytes
11 files changed, 117 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 21cc9eb..3b7b106 100644
--- a/Makefile
+++ b/Makefile
@@ -4,8 +4,9 @@ SRC := $(wildcard *.c)
OBJ := $(patsubst %.c,%.o,$(SRC))
NAME := bozo
SDL2-CFG := sdl2-config
-CFLAGS := -Wall -Wextra -std=c99 $(shell $(SDL2-CFG) --cflags)
-LDFLAGS := $(shell $(SDL2-CFG) --libs) -lSDL2_image -lSDL2_mixer -lSDL2_gfx
+LZRFLAGS := -DLZR_DISABLE_MIXER
+CFLAGS := -Wall -Wextra -std=c99 $(shell $(SDL2-CFG) --cflags) $(LZRFLAGS)
+LDFLAGS := $(shell $(SDL2-CFG) --libs) -lSDL2_image -lSDL2_gfx
all: $(NAME)
diff --git a/cfg.h b/cfg.h
index b7e7867..78dfc87 100644
--- a/cfg.h
+++ b/cfg.h
@@ -2,7 +2,7 @@
#include "lzr.h"
enum {
- CFG_DWIDTH = 256,
+ CFG_DWIDTH = 288,
CFG_DHEIGHT = 256,
CFG_FPS = 60,
CFG_TSIZE = 16
@@ -16,5 +16,5 @@ static const LZR_Config cfg = {
"jam like nobody is watching (cause they ain't)",
0.0,
false,
- true
+ false
};
diff --git a/commands.c b/commands.c
new file mode 100644
index 0000000..83272ee
--- /dev/null
+++ b/commands.c
@@ -0,0 +1,24 @@
+#include "commands.h"
+#include "lzr.h"
+#include "cfg.h"
+
+static const unsigned int commands[COM_LEN] = {
+ COM_RIGHT,
+ COM_RIGHT,
+ COM_UP,
+ COM_DOWN,
+ COM_LEFT,
+ COM_LEFT,
+ COM_DOWN,
+ COM_UP
+};
+
+void commands_draw(void)
+{
+ LZR_DrawSetColor(1, 1, 1, 1);
+ for (int i = 0; i < COM_LEN; i++) {
+ const int dx = CFG_TSIZE / 2;
+ const int dy = CFG_TSIZE / 2 + i * (int)(CFG_TSIZE * 1.5);
+ LZR_DrawImage(commands[i], dx, dy);
+ }
+}
diff --git a/commands.h b/commands.h
new file mode 100644
index 0000000..39badc5
--- /dev/null
+++ b/commands.h
@@ -0,0 +1,15 @@
+#pragma once
+
+enum {
+ COM_LEFT,
+ COM_RIGHT,
+ COM_UP,
+ COM_DOWN,
+ _COM_COUNT
+};
+
+enum {
+ COM_LEN = 8
+};
+
+void commands_draw(void);
diff --git a/level.c b/level.c
new file mode 100644
index 0000000..2c68335
--- /dev/null
+++ b/level.c
@@ -0,0 +1,39 @@
+#include "level.h"
+#include "lzr.h"
+#include "cfg.h"
+
+static const char level[LEVEL_HEIGHT * LEVEL_WIDTH] = {
+ "000000000000"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "0..........0"
+ "000000000000"
+};
+
+void level_draw()
+{
+ LZR_DrawSetColor(1, 1, 1, 1);
+ for (int y = 0; y < LEVEL_HEIGHT; y++)
+ for (int x = 0; x < LEVEL_WIDTH; x++) {
+ const int dx = (x + 3) * CFG_TSIZE;
+ const int dy = y * CFG_TSIZE;
+ if (level_get(x, y) == '0')
+ LZR_DrawRectangle(true, dx, dy, CFG_TSIZE, CFG_TSIZE);
+ }
+}
+
+int level_get(int x, int y)
+{
+ return level[x + y * LEVEL_WIDTH];
+}
diff --git a/level.h b/level.h
new file mode 100644
index 0000000..4cd35d0
--- /dev/null
+++ b/level.h
@@ -0,0 +1,9 @@
+#pragma once
+
+enum {
+ LEVEL_WIDTH = 12,
+ LEVEL_HEIGHT = 16
+};
+
+void level_draw(void);
+int level_get(int x, int y);
diff --git a/main.c b/main.c
index c287ee0..ff11c08 100644
--- a/main.c
+++ b/main.c
@@ -1,8 +1,32 @@
#include "lzr.h"
#include "cfg.h"
+#include "level.h"
+#include "commands.h"
+#include <stdlib.h>
+
+static float rcol(void)
+{
+ return (rand() & 1) * 0.1;
+}
int main(int argc, char **argv)
{
(void)argc, (void)argv;
- return 0;
+ if (LZR_Init(cfg))
+ return LZR_Quit(), 1;
+ if (LZR_ImageLoad("res/left.bmp") < 0 ||
+ LZR_ImageLoad("res/right.bmp") < 0 ||
+ LZR_ImageLoad("res/up.bmp") < 0 ||
+ LZR_ImageLoad("res/down.bmp") < 0)
+ return LZR_Quit(), 1;
+ while (!LZR_ShouldQuit()) {
+ LZR_CycleEvents();
+ LZR_DrawBegin();
+ LZR_DrawSetColor(rcol(), rcol(), rcol(), 1);
+ LZR_DrawClear();
+ level_draw();
+ commands_draw();
+ LZR_DrawEnd();
+ }
+ return LZR_Quit(), 0;
}
diff --git a/res/down.bmp b/res/down.bmp
new file mode 100644
index 0000000..8c62b5b
--- /dev/null
+++ b/res/down.bmp
Binary files differ
diff --git a/res/left.bmp b/res/left.bmp
new file mode 100644
index 0000000..80e126c
--- /dev/null
+++ b/res/left.bmp
Binary files differ
diff --git a/res/right.bmp b/res/right.bmp
new file mode 100644
index 0000000..6beee4e
--- /dev/null
+++ b/res/right.bmp
Binary files differ
diff --git a/res/up.bmp b/res/up.bmp
new file mode 100644
index 0000000..1fbed51
--- /dev/null
+++ b/res/up.bmp
Binary files differ