diff options
author | kdx <kdx@42l.fr> | 2023-02-18 01:49:07 +0100 |
---|---|---|
committer | kdx <kdx@42l.fr> | 2023-02-18 01:49:35 +0100 |
commit | 7d1ac518b514a4debc2ee883254de17aa4747a71 (patch) | |
tree | 2037fa180f3b5d0c5f9d6b7271a46dfe5322ee74 | |
parent | 02f11f2c49378765d644edccd71ed6bb74e84cc2 (diff) | |
download | bozojam-7d1ac518b514a4debc2ee883254de17aa4747a71.tar.gz |
waitaminute
-rw-r--r-- | commands.c | 45 | ||||
-rw-r--r-- | commands.h | 3 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | res/wait.bmp | bin | 0 -> 1674 bytes |
4 files changed, 42 insertions, 9 deletions
@@ -3,7 +3,7 @@ #include "cfg.h" #include <SDL2/SDL_log.h> -int mouse_x, mouse_y, hovered = -1, editing = -1; +int mouse_x, mouse_y, hovered = -1, editing = -1, hovered_instr = -1; static const unsigned int commands[COM_LEN] = { COM_RIGHT, @@ -11,23 +11,38 @@ static const unsigned int commands[COM_LEN] = { COM_UP, COM_DOWN, COM_LEFT, + COM_NOOP, COM_LEFT, COM_DOWN, COM_UP }; +static const unsigned int instructions[_COM_COUNT][2] = { + {COM_LEFT, COM_NOOP}, + {COM_RIGHT, COM_NOOP}, + {COM_UP, COM_NOOP}, + {COM_DOWN, COM_NOOP}, + {COM_NOOP, COM_NOOP}, +}; + void commands_update(void) { LZR_MousePosition(&mouse_x, &mouse_y); hovered = -1; + hovered_instr = -1; + const int y = (mouse_y - CFG_TSIZE / 2) / (int)(CFG_TSIZE * 1.5); 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]; } + if (mouse_x > CFG_DWIDTH - CFG_TSIZE * 2.5) { + if (y < 0 || y > 1) + return; + hovered_instr = y; + } } void commands_draw(void) @@ -36,11 +51,27 @@ void commands_draw(void) const int dx = CFG_TSIZE / 2; const int dy = CFG_TSIZE / 2 + i * (int)(CFG_TSIZE * 1.5); const int cmd = commands[i]; - const int blink = hovered != i || (LZR_GetTick() & 1); - if (cmd == editing) + const int blink = hovered == i || (LZR_GetTick() & 1); + if (!blink) + ; + else if (cmd == editing) { LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); - else - LZR_DrawSetColor(blink, blink, blink, 1); - LZR_DrawImage(cmd, dx, dy); + LZR_DrawImage(cmd, dx, dy); + } else { + LZR_DrawSetColor(1, 1, 1, 1); + LZR_DrawImage(cmd, dx, dy); + } + } + if (editing != -1) { + const int dx = CFG_DWIDTH - CFG_TSIZE * 2.5; + for (int i = 0; i < 2; i++) { + const int dy = CFG_TSIZE / 2 + i * (int)(CFG_TSIZE * 1.5); + const int instr = instructions[editing][i]; + const int blink = hovered_instr == i || (LZR_GetTick() & 1); + if (!blink) + continue; + LZR_DrawSetColor(1, 1, 1, 1); + LZR_DrawImage(instr, dx, dy); + } } } @@ -5,11 +5,12 @@ enum { COM_RIGHT, COM_UP, COM_DOWN, + COM_NOOP, _COM_COUNT }; enum { - COM_LEN = 8 + COM_LEN = 9 }; void commands_update(void); @@ -17,7 +17,8 @@ int main(int argc, char **argv) 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) + LZR_ImageLoad("res/down.bmp") < 0 || + LZR_ImageLoad("res/wait.bmp") < 0) return LZR_Quit(), 1; while (!LZR_ShouldQuit()) { LZR_CycleEvents(); diff --git a/res/wait.bmp b/res/wait.bmp Binary files differnew file mode 100644 index 0000000..ac98f0e --- /dev/null +++ b/res/wait.bmp |