summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx@42l.fr>2023-02-18 01:59:42 +0100
committerkdx <kdx@42l.fr>2023-02-18 01:59:42 +0100
commit3fe36da6daa688a8527c4e6b39d24db6afa7693c (patch)
tree47a4abce1369d43df8b4ede6074c25b0e584c2ff
parent77dc95bd53cb93d3b20a7ef6c9525534eaecfa3d (diff)
downloadbozojam-3fe36da6daa688a8527c4e6b39d24db6afa7693c.tar.gz
lmfao
-rw-r--r--commands.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/commands.c b/commands.c
index d93e3ad..2d58627 100644
--- a/commands.c
+++ b/commands.c
@@ -3,7 +3,8 @@
#include "cfg.h"
#include <SDL2/SDL_log.h>
-int mouse_x, mouse_y, hovered = -1, editing = -1, hovered_instr = -1;
+int mouse_x, mouse_y, hovered = -1, editing = -1, hovered_instr = -1,
+ was_down = 0;
static const unsigned int commands[COM_LEN] = {
COM_RIGHT,
@@ -17,7 +18,7 @@ static const unsigned int commands[COM_LEN] = {
COM_UP
};
-static const unsigned int instructions[_COM_COUNT][2] = {
+static unsigned int instructions[_COM_COUNT][2] = {
{COM_LEFT, COM_NOOP},
{COM_RIGHT, COM_NOOP},
{COM_UP, COM_NOOP},
@@ -31,18 +32,25 @@ void commands_update(void)
hovered = -1;
hovered_instr = -1;
const int y = (mouse_y - CFG_TSIZE / 2) / (int)(CFG_TSIZE * 1.5);
+ const int press = LZR_BUTTON(MOUSE_L) && !was_down;
if (mouse_x > CFG_TSIZE / 2 && mouse_x <= CFG_TSIZE * 2.5) {
if (y < 0 || y >= COM_LEN)
return;
hovered = y;
- if (LZR_BUTTON(MOUSE_L))
+ if (press)
editing = commands[y];
}
- if (mouse_x > CFG_DWIDTH - CFG_TSIZE * 2.5) {
+ if (editing != -1 && mouse_x > CFG_DWIDTH - CFG_TSIZE * 2.5) {
if (y < 0 || y > 1)
return;
hovered_instr = y;
+ if (press) {
+ instructions[editing][hovered_instr] += 1;
+ if (instructions[editing][hovered_instr] >= _COM_COUNT)
+ instructions[editing][hovered_instr] = 0;
+ }
}
+ was_down = LZR_BUTTON(MOUSE_L);
}
void commands_draw(void)