#include "Table.hpp" #include "Cursor.hpp" #include "cfg.hpp" #include "util.hpp" #include "lzr.h" #include Table::Table() : _notes(), _strength(), _edited(-1), _layer(0) { } void Table::update(const Cursor& cursor) { 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]) / _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); } } } _hovered = -1; if (cursor.y < 0) return; const int y = cursor.y / _lane; if (y >= _height) return; if (cursor.erase) { _strength[_layer][y] = 0; _edited = -1; } else if (cursor.down) { if (y == _edited) _strength[_layer][y] += 2; else _strength[_layer][y] = 1; _notes[_layer][y] = util::min(CFG_DWIDTH - 1, util::max(0, cursor.x)); _edited = y; } else _edited = -1; _hovered = y; } void Table::draw(const Cursor& cursor) { const int t = LZR_GetTick() / _delay % _height; for (int i = 0; i < _height; 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 * _lane, CFG_DWIDTH, _lane); } if (i == _hovered) { cursor.set_color(int()); if (cursor.erase || (rand() & 3)) 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, _lane); } } void Table::set_layer(int layer) { _layer = layer; _layer %= _depth; }