diff options
author | kdx <kikoodx@paranoici.org> | 2023-01-15 05:03:51 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-01-15 05:03:51 +0100 |
commit | c2d967df8d4242778bb14d7f8cda718324b2b846 (patch) | |
tree | 65e8379d63c8353740fee181c6f34a5e98a5bf5c | |
parent | c37223185dbb6999f736f49e07c15b342dd59a91 (diff) | |
download | 005-c2d967df8d4242778bb14d7f8cda718324b2b846.tar.gz |
this is cool
-rw-r--r-- | Table.cpp | 54 | ||||
-rw-r--r-- | Table.hpp | 12 | ||||
-rw-r--r-- | input.c | 39 | ||||
-rw-r--r-- | input.h | 17 | ||||
-rw-r--r-- | main.cpp | 2 |
5 files changed, 97 insertions, 27 deletions
@@ -3,39 +3,47 @@ #include "cfg.hpp" #include "util.hpp" #include "lzr.h" +#include "input.h" #include <stdlib.h> -Table::Table() : _notes(), _strength(), _edited(-1), _prev_sample(0) +Table::Table() : _notes(), _strength(), _edited(-1), _layer(0) { } void Table::update(const Cursor& cursor) { - if (LZR_GetTick() % 20 == 0) { - const int t = LZR_GetTick() / 20 % _width; - LZR_StopSound(_prev_sample); - _prev_sample = rand() % 2; - if (_strength[t] > 0) { - const float pitch = float(_strength[t]) / CFG_DHEIGHT; - LZR_SetSoundPitch(0, 0.5 + pitch * 1.5); - LZR_PlaySound(_prev_sample, 0); + if (LZR_GetTick() % _delay == 0) { + const int t = LZR_GetTick() / _delay % _height; + 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; + LZR_SetSoundPitch(i, 0.5 + pitch * 1.5); + LZR_SetSoundPan(i, -1.0 + pan * 2.0); + LZR_PlaySound(i, 0); + } } } + if (input_pressed(K_O)) { + _layer += 1; + _layer %= _depth; + } _hovered = -1; if (cursor.y < 0) return; - const int y = cursor.y / 32; - if (y >= _width) + const int y = cursor.y / _lane; + if (y >= _height) return; if (cursor.down) { if (y == _edited) - _strength[y] += 1; + _strength[_layer][y] += 2; else - _strength[y] = 1; - _notes[y] = util::min(CFG_DWIDTH - 1, util::max(0, cursor.x)); + _strength[_layer][y] = 1; + _notes[_layer][y] = util::min(CFG_DWIDTH - 1, util::max(0, cursor.x)); _edited = y; } else if (cursor.erase) { - _strength[y] = 0; + _strength[_layer][y] = 0; _edited = -1; } else _edited = -1; @@ -44,23 +52,23 @@ void Table::update(const Cursor& cursor) void Table::draw(const Cursor& cursor) { - const int t = LZR_GetTick() / 20 % _width; - for (int i = 0; i < _width; i++) + const int t = LZR_GetTick() / _delay % _height; + for (int i = 0; i < _height; i++) { - const int x = _notes[i]; - const int y = i * 32; - const int s = _strength[i]; + const int x = _notes[_layer][i]; + const int y = i * _lane; + const int s = _strength[_layer][i]; if (i == t && (rand() & 1)) { LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); if (cursor.erase || (rand() & 3)) - LZR_DrawRectangle(true, 0, t * 32, CFG_DWIDTH, 32); + LZR_DrawRectangle(true, 0, t * _lane, CFG_DWIDTH, _lane); } if (i == _hovered) { cursor.set_color(); if (cursor.erase || (rand() & 3)) - LZR_DrawRectangle(true, 0, y, CFG_DWIDTH, 32); + LZR_DrawRectangle(true, 0, y, CFG_DWIDTH, _lane); } LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); - LZR_DrawRectangle(true, x - s / 2, y, s, 32); + LZR_DrawRectangle(true, x - s / 2, y, s, _lane); } } @@ -1,12 +1,16 @@ #pragma once #include "Cursor.hpp" +#include "cfg.hpp" class Table { private: - static const int _width = 16; - int _notes[_width]; - int _strength[_width]; - int _hovered, _edited, _prev_sample; + static const int _height = 64; + static const int _depth = 2; + static const int _delay = 8; + static const int _lane = CFG_DHEIGHT / _height; + int _notes[_depth][_height]; + int _strength[_depth][_height]; + int _hovered, _edited, _layer; public: Table(); void update(const Cursor& cursor); @@ -0,0 +1,39 @@ +#include "input.h" +#include "lzr.h" + +static const unsigned int keys[5] = {LZR_BUTTON_LEFT, LZR_BUTTON_RIGHT, + LZR_BUTTON_UP, LZR_BUTTON_DOWN, + LZR_BUTTON_O}; +static int states[5] = {0}; + +void input_update(void) +{ + int i = 5; + while (i-- > 0) + if (LZR_ButtonDown(keys[i])) + states[i] = + (states[i] == KS_UP) ? (KS_PRESSED) : (KS_DOWN); + else + states[i] = KS_UP; +} + +int input_up(unsigned int k) +{ + if (k >= 5) + return 0; + return states[k] == KS_UP; +} + +int input_down(unsigned int k) +{ + if (k >= 5) + return 0; + return states[k] == KS_DOWN || states[k] == KS_PRESSED; +} + +int input_pressed(unsigned int k) +{ + if (k >= 5) + return 0; + return states[k] == KS_PRESSED; +} @@ -0,0 +1,17 @@ +#pragma once +#ifdef __cplusplus +extern "C" { +#endif + +enum Key { K_LEFT, K_RIGHT, K_UP, K_DOWN, K_O }; + +enum KeyState { KS_UP, KS_DOWN, KS_PRESSED }; + +void input_update(void); +int input_up(unsigned int); +int input_down(unsigned int); +int input_pressed(unsigned int); + +#ifdef __cplusplus +} +#endif @@ -1,5 +1,6 @@ #include "cfg.hpp" #include "lzr.h" +#include "input.h" #include "Table.hpp" #include "Cursor.hpp" #include <string.h> @@ -25,6 +26,7 @@ int main(int argc, char **argv) Table table; while (!LZR_ShouldQuit()) { LZR_CycleEvents(); + input_update(); cursor.update(); table.update(cursor); LZR_DrawBegin(); |