diff options
author | kdx <kikoodx@paranoici.org> | 2023-01-15 03:55:54 +0100 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-01-15 03:56:57 +0100 |
commit | c37223185dbb6999f736f49e07c15b342dd59a91 (patch) | |
tree | 326d22a6d7585011b2a5001f4aea3eb471d85c5b | |
parent | d519ce684ece884475adf00f67353013c299a74f (diff) | |
download | 005-c37223185dbb6999f736f49e07c15b342dd59a91.tar.gz |
purrfect
-rw-r--r-- | Table.cpp | 46 | ||||
-rw-r--r-- | Table.hpp | 2 | ||||
-rw-r--r-- | lzr.c | 20 | ||||
-rw-r--r-- | lzr.h | 1 | ||||
-rw-r--r-- | main.cpp | 10 | ||||
-rw-r--r-- | res/sample_0.wav | bin | 0 -> 62676 bytes | |||
-rw-r--r-- | res/sample_1.wav | bin | 0 -> 47472 bytes |
7 files changed, 63 insertions, 16 deletions
@@ -5,46 +5,62 @@ #include "lzr.h" #include <stdlib.h> -Table::Table() : _notes(), _strength(), _edited(-1) +Table::Table() : _notes(), _strength(), _edited(-1), _prev_sample(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); + } + } _hovered = -1; - if (cursor.x < 0) + if (cursor.y < 0) return; - const int x = cursor.x / 32; - if (x >= _width) + const int y = cursor.y / 32; + if (y >= _width) return; if (cursor.down) { - if (x == _edited) - _strength[x] += 1; + if (y == _edited) + _strength[y] += 1; else - _strength[x] = 1; - _notes[x] = util::min(CFG_DHEIGHT - 1, util::max(0, cursor.y)); - _edited = x; + _strength[y] = 1; + _notes[y] = util::min(CFG_DWIDTH - 1, util::max(0, cursor.x)); + _edited = y; } else if (cursor.erase) { - _strength[x] = 0; + _strength[y] = 0; _edited = -1; } else _edited = -1; - _hovered = x; + _hovered = y; } void Table::draw(const Cursor& cursor) { + const int t = LZR_GetTick() / 20 % _width; for (int i = 0; i < _width; i++) { - const int x = i * 32; - const int y = _notes[i]; + const int x = _notes[i]; + const int y = i * 32; const int s = _strength[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); + } if (i == _hovered) { cursor.set_color(); if (cursor.erase || (rand() & 3)) - LZR_DrawRectangle(true, x, 0, 32, CFG_DHEIGHT); + LZR_DrawRectangle(true, 0, y, CFG_DWIDTH, 32); } LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); - LZR_DrawRectangle(true, x, y - s / 2, 32, s); + LZR_DrawRectangle(true, x - s / 2, y, s, 32); } } @@ -6,7 +6,7 @@ private: static const int _width = 16; int _notes[_width]; int _strength[_width]; - int _hovered, _edited; + int _hovered, _edited, _prev_sample; public: Table(); void update(const Cursor& cursor); @@ -911,6 +911,26 @@ int LZR_SetSoundPan(int id, float pan) #endif } +int LZR_SetSoundPitch(int id, float pitch) +{ +#ifdef LZR_ENABLE_MIXER + if (id < 0) { + SDL_Log("id is negative"); + return -1; + } + if (id >= LZR_MAX_SOUNDS || sounds[id].ptr == NULL) { + SDL_Log("no sound with id %d", id); + return -1; + } + cm_set_pitch(sounds[id].ptr, pitch); + return 0; +#else + (void)id, (void)pitch; + SDL_Log("LZR MIXER module is disabled"); + return -1; +#endif +} + void LZR_ToggleFullscreen(void) { static int fullscreen = 0; @@ -97,6 +97,7 @@ int LZR_PlaySound(int id, int loops); void LZR_StopSound(int id); int LZR_SetSoundVolume(int id, float volume); int LZR_SetSoundPan(int id, float pan); +int LZR_SetSoundPitch(int id, float pitch); void LZR_ToggleFullscreen(void); uint64_t LZR_GetTick(void); void LZR_ScreenTransform(int *x, int *y); @@ -2,6 +2,7 @@ #include "lzr.h" #include "Table.hpp" #include "Cursor.hpp" +#include <string.h> int main(int argc, char **argv) { @@ -11,6 +12,15 @@ int main(int argc, char **argv) LZR_Quit(); return 1; } + char snd_path[] = "res/sample_x.wav"; + char *snd_x = strchr(snd_path, 'x'); + for (int i = 0; i < 2; i++) { + *snd_x = '0' + i; + if (LZR_SoundLoad(snd_path, 1.0f) < 0) { + LZR_Quit(); + return 1; + } + } Cursor cursor; Table table; while (!LZR_ShouldQuit()) { diff --git a/res/sample_0.wav b/res/sample_0.wav Binary files differnew file mode 100644 index 0000000..e223dc7 --- /dev/null +++ b/res/sample_0.wav diff --git a/res/sample_1.wav b/res/sample_1.wav Binary files differnew file mode 100644 index 0000000..4734c19 --- /dev/null +++ b/res/sample_1.wav |