summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kdx@42l.fr>2023-01-20 04:16:36 +0100
committerkdx <kdx@42l.fr>2023-01-20 04:16:36 +0100
commit300846ce9fb939ddc6e56e670312dd9026f019be (patch)
treecfcc8aef12b65ff61ea23559c020dbf3aae69103
parent4d46c2bc8a01d3d28e84a3164640a7447f19773b (diff)
download005-300846ce9fb939ddc6e56e670312dd9026f019be.tar.gz
menu kinda fucked lol
-rw-r--r--Menu.cpp32
-rw-r--r--Menu.hpp16
-rw-r--r--Table.cpp4
-rw-r--r--Table.hpp3
-rw-r--r--main.cpp4
5 files changed, 56 insertions, 3 deletions
diff --git a/Menu.cpp b/Menu.cpp
new file mode 100644
index 0000000..7fa2448
--- /dev/null
+++ b/Menu.cpp
@@ -0,0 +1,32 @@
+#include "Menu.hpp"
+#include "lzr.h"
+#include "cfg.hpp"
+#include <stdlib.h>
+
+Menu::Menu() : _hovered(-1)
+{
+}
+
+void Menu::update(const Cursor &cursor)
+{
+ if (cursor.x < 0 || cursor.x >= CFG_DWIDTH ||
+ cursor.y < _ybegin || cursor.y > _yend) {
+ _hovered = -1;
+ return;
+ }
+ int x = cursor.x / _wentry;
+ if (x > _entries)
+ x = _entries;
+ _hovered = x;
+}
+
+void Menu::draw() const
+{
+ LZR_DrawSetColor(0, 0, 0, 1);
+ LZR_DrawRectangle(true, 0, _ybegin, CFG_DWIDTH, _yend - _ybegin);
+ if (_hovered > -1) {
+ LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1);
+ LZR_DrawRectangle(true, _hovered * _wentry, _ybegin,
+ _wentry, _yend - _ybegin + 1);
+ }
+}
diff --git a/Menu.hpp b/Menu.hpp
new file mode 100644
index 0000000..957d6c4
--- /dev/null
+++ b/Menu.hpp
@@ -0,0 +1,16 @@
+#pragma once
+#include "Cursor.hpp"
+#include "cfg.hpp"
+
+class Menu {
+private:
+ static const int _ybegin = CFG_DHEIGHT - 32;
+ static const int _yend = CFG_DHEIGHT;
+ static const int _entries = 3;
+ static const int _wentry = CFG_DWIDTH / _entries;
+ int _hovered;
+public:
+ Menu();
+ void update(const Cursor& cursor);
+ void draw() const;
+};
diff --git a/Table.cpp b/Table.cpp
index 8449948..be35faa 100644
--- a/Table.cpp
+++ b/Table.cpp
@@ -17,8 +17,8 @@ void Table::update(const Cursor& cursor)
for (int i = 0; i < _depth; i++) {
LZR_StopSound(i);
if (_strength[i][t] > 0) {
- float pitch = float(_strength[i][t]) / CFG_DHEIGHT;
- float pan = float(_notes[i][t]) / CFG_DHEIGHT;
+ float pitch = float(_strength[i][t]) / _yend;
+ float pan = float(_notes[i][t]) / _yend;
LZR_SetSoundPitch(i, 0.5 + pitch * 1.5);
LZR_SetSoundPan(i, -1.0 + pan * 2.0);
LZR_PlaySound(i, 0);
diff --git a/Table.hpp b/Table.hpp
index 266f950..0c3b708 100644
--- a/Table.hpp
+++ b/Table.hpp
@@ -4,10 +4,11 @@
class Table {
private:
+ static const int _yend = CFG_DHEIGHT - 32;
static const int _height = 64;
static const int _depth = 2;
static const int _delay = 8;
- static const int _lane = CFG_DHEIGHT / _height;
+ static const int _lane = _yend / _height;
int _notes[_depth][_height];
int _strength[_depth][_height];
int _hovered, _edited, _layer;
diff --git a/main.cpp b/main.cpp
index 1e7c074..49c2474 100644
--- a/main.cpp
+++ b/main.cpp
@@ -3,6 +3,7 @@
#include "input.h"
#include "Table.hpp"
#include "Cursor.hpp"
+#include "Menu.hpp"
#include <string.h>
int main(int argc, char **argv)
@@ -25,15 +26,18 @@ int main(int argc, char **argv)
}
Cursor cursor;
Table table;
+ Menu menu;
while (!LZR_ShouldQuit()) {
LZR_CycleEvents();
input_update();
cursor.update();
table.update(cursor);
+ menu.update(cursor);
LZR_DrawBegin();
LZR_DrawSetColor(0, 0, 0, 1);
LZR_DrawClear();
table.draw(cursor);
+ menu.draw();
cursor.draw();
LZR_DrawEnd();
}