From 72a6892b5b18e450d82468e7bb830687a0215eb4 Mon Sep 17 00:00:00 2001 From: kdx Date: Sat, 18 Feb 2023 01:18:42 +0100 Subject: art --- Makefile | 5 +++-- cfg.h | 4 ++-- commands.c | 24 ++++++++++++++++++++++++ commands.h | 15 +++++++++++++++ level.c | 39 +++++++++++++++++++++++++++++++++++++++ level.h | 9 +++++++++ main.c | 26 +++++++++++++++++++++++++- res/down.bmp | Bin 0 -> 1674 bytes res/left.bmp | Bin 0 -> 1674 bytes res/right.bmp | Bin 0 -> 1674 bytes res/up.bmp | Bin 0 -> 1674 bytes 11 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 commands.c create mode 100644 commands.h create mode 100644 level.c create mode 100644 level.h create mode 100644 res/down.bmp create mode 100644 res/left.bmp create mode 100644 res/right.bmp create mode 100644 res/up.bmp 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 + +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 Binary files /dev/null and b/res/down.bmp differ diff --git a/res/left.bmp b/res/left.bmp new file mode 100644 index 0000000..80e126c Binary files /dev/null and b/res/left.bmp differ diff --git a/res/right.bmp b/res/right.bmp new file mode 100644 index 0000000..6beee4e Binary files /dev/null and b/res/right.bmp differ diff --git a/res/up.bmp b/res/up.bmp new file mode 100644 index 0000000..1fbed51 Binary files /dev/null and b/res/up.bmp differ -- cgit v1.2.3