summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx@42l.fr>2023-02-18 01:32:22 +0100
committerkdx <kdx@42l.fr>2023-02-18 01:32:22 +0100
commit02f11f2c49378765d644edccd71ed6bb74e84cc2 (patch)
treef24711601b16fcad3b1e102c46bdeb826898f6a9
parent72a6892b5b18e450d82468e7bb830687a0215eb4 (diff)
downloadbozojam-02f11f2c49378765d644edccd71ed6bb74e84cc2.tar.gz
arter
-rw-r--r--commands.c26
-rw-r--r--commands.h1
-rw-r--r--level.c4
-rw-r--r--main.c1
-rw-r--r--res/left.bmpbin1674 -> 1674 bytes
-rw-r--r--res/right.bmpbin1674 -> 1674 bytes
6 files changed, 29 insertions, 3 deletions
diff --git a/commands.c b/commands.c
index 83272ee..df51035 100644
--- a/commands.c
+++ b/commands.c
@@ -1,6 +1,9 @@
#include "commands.h"
#include "lzr.h"
#include "cfg.h"
+#include <SDL2/SDL_log.h>
+
+int mouse_x, mouse_y, hovered = -1, editing = -1;
static const unsigned int commands[COM_LEN] = {
COM_RIGHT,
@@ -13,12 +16,31 @@ static const unsigned int commands[COM_LEN] = {
COM_UP
};
+void commands_update(void)
+{
+ LZR_MousePosition(&mouse_x, &mouse_y);
+ hovered = -1;
+ if (mouse_x > CFG_TSIZE / 2 && mouse_x <= CFG_TSIZE * 2.5) {
+ int y = (mouse_y - CFG_TSIZE / 2) / (int)(CFG_TSIZE * 1.5);
+ if (y < 0 || y >= COM_LEN)
+ return;
+ hovered = y;
+ if (LZR_BUTTON(MOUSE_L))
+ editing = commands[y];
+ }
+}
+
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);
+ const int cmd = commands[i];
+ const int blink = hovered != i || (LZR_GetTick() & 1);
+ if (cmd == editing)
+ LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1);
+ else
+ LZR_DrawSetColor(blink, blink, blink, 1);
+ LZR_DrawImage(cmd, dx, dy);
}
}
diff --git a/commands.h b/commands.h
index 39badc5..8a832b6 100644
--- a/commands.h
+++ b/commands.h
@@ -12,4 +12,5 @@ enum {
COM_LEN = 8
};
+void commands_update(void);
void commands_draw(void);
diff --git a/level.c b/level.c
index 2c68335..dbf27da 100644
--- a/level.c
+++ b/level.c
@@ -1,6 +1,7 @@
#include "level.h"
#include "lzr.h"
#include "cfg.h"
+#include <stdlib.h>
static const char level[LEVEL_HEIGHT * LEVEL_WIDTH] = {
"000000000000"
@@ -28,7 +29,8 @@ void level_draw()
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')
+ if (level_get(x, y) == '0' && ((rand() & 3) == 3 ||
+ LZR_GetTick() & 1))
LZR_DrawRectangle(true, dx, dy, CFG_TSIZE, CFG_TSIZE);
}
}
diff --git a/main.c b/main.c
index ff11c08..f4dcf38 100644
--- a/main.c
+++ b/main.c
@@ -21,6 +21,7 @@ int main(int argc, char **argv)
return LZR_Quit(), 1;
while (!LZR_ShouldQuit()) {
LZR_CycleEvents();
+ commands_update();
LZR_DrawBegin();
LZR_DrawSetColor(rcol(), rcol(), rcol(), 1);
LZR_DrawClear();
diff --git a/res/left.bmp b/res/left.bmp
index 80e126c..e180231 100644
--- a/res/left.bmp
+++ b/res/left.bmp
Binary files differ
diff --git a/res/right.bmp b/res/right.bmp
index 6beee4e..4a145bf 100644
--- a/res/right.bmp
+++ b/res/right.bmp
Binary files differ