From c7849ff44b237bb8b7a8576569ede1f7576086ea Mon Sep 17 00:00:00 2001 From: kdx Date: Fri, 20 Jan 2023 04:30:19 +0100 Subject: layer selection (omg that so cool dog) --- Menu.cpp | 15 ++++++++++++++- Menu.hpp | 5 ++++- Table.cpp | 6 ++++++ Table.hpp | 7 ++++--- main.cpp | 3 ++- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Menu.cpp b/Menu.cpp index 7fa2448..688f7e0 100644 --- a/Menu.cpp +++ b/Menu.cpp @@ -3,7 +3,7 @@ #include "cfg.hpp" #include -Menu::Menu() : _hovered(-1) +Menu::Menu() : _was_down(false), _hovered(-1), _selected(1) { } @@ -12,21 +12,34 @@ void Menu::update(const Cursor &cursor) if (cursor.x < 0 || cursor.x >= CFG_DWIDTH || cursor.y < _ybegin || cursor.y > _yend) { _hovered = -1; + _was_down = cursor.down; return; } int x = cursor.x / _wentry; if (x > _entries) x = _entries; _hovered = x; + if (cursor.down && !_was_down) + _selected = _hovered; + _was_down = cursor.down; } void Menu::draw() const { LZR_DrawSetColor(0, 0, 0, 1); LZR_DrawRectangle(true, 0, _ybegin, CFG_DWIDTH, _yend - _ybegin); + LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, rand() & 1); + if ((rand() & 31) == 0) + LZR_DrawRectangle(true, _selected * _wentry, _ybegin, + _wentry, _yend - _ybegin + 1); if (_hovered > -1) { LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); LZR_DrawRectangle(true, _hovered * _wentry, _ybegin, _wentry, _yend - _ybegin + 1); } } + +int Menu::get_selection() const +{ + return _selected; +} diff --git a/Menu.hpp b/Menu.hpp index 957d6c4..47cd533 100644 --- a/Menu.hpp +++ b/Menu.hpp @@ -4,13 +4,16 @@ class Menu { private: - static const int _ybegin = CFG_DHEIGHT - 32; + static const int _ybegin = CFG_DHEIGHT - 24; static const int _yend = CFG_DHEIGHT; static const int _entries = 3; static const int _wentry = CFG_DWIDTH / _entries; + bool _was_down; int _hovered; + int _selected; public: Menu(); void update(const Cursor& cursor); void draw() const; + int get_selection() const; }; diff --git a/Table.cpp b/Table.cpp index be35faa..a209b13 100644 --- a/Table.cpp +++ b/Table.cpp @@ -72,3 +72,9 @@ void Table::draw(const Cursor& cursor) LZR_DrawRectangle(true, x - s / 2, y, s, _lane); } } + +void Table::set_layer(int layer) +{ + _layer = layer; + _layer %= _depth; +} diff --git a/Table.hpp b/Table.hpp index 0c3b708..339381d 100644 --- a/Table.hpp +++ b/Table.hpp @@ -4,9 +4,9 @@ class Table { private: - static const int _yend = CFG_DHEIGHT - 32; - static const int _height = 64; - static const int _depth = 2; + static const int _yend = CFG_DHEIGHT - 24; + static const int _height = 61; + static const int _depth = 3; static const int _delay = 8; static const int _lane = _yend / _height; int _notes[_depth][_height]; @@ -16,4 +16,5 @@ public: Table(); void update(const Cursor& cursor); void draw(const Cursor& cursor); + void set_layer(int layer); }; diff --git a/main.cpp b/main.cpp index 49c2474..3399d04 100644 --- a/main.cpp +++ b/main.cpp @@ -17,7 +17,7 @@ int main(int argc, char **argv) LZR_ToggleFullscreen(); char snd_path[] = "res/sample_x.wav"; char *snd_x = strchr(snd_path, 'x'); - for (int i = 0; i < 2; i++) { + for (int i = 0; i < 3; i++) { *snd_x = '0' + i; if (LZR_SoundLoad(snd_path, 1.0f) < 0) { LZR_Quit(); @@ -33,6 +33,7 @@ int main(int argc, char **argv) cursor.update(); table.update(cursor); menu.update(cursor); + table.set_layer(menu.get_selection()); LZR_DrawBegin(); LZR_DrawSetColor(0, 0, 0, 1); LZR_DrawClear(); -- cgit v1.2.3