summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-01-15 03:55:54 +0100
committerkdx <kikoodx@paranoici.org>2023-01-15 03:56:57 +0100
commitc37223185dbb6999f736f49e07c15b342dd59a91 (patch)
tree326d22a6d7585011b2a5001f4aea3eb471d85c5b
parentd519ce684ece884475adf00f67353013c299a74f (diff)
download005-c37223185dbb6999f736f49e07c15b342dd59a91.tar.gz
purrfect
-rw-r--r--Table.cpp46
-rw-r--r--Table.hpp2
-rw-r--r--lzr.c20
-rw-r--r--lzr.h1
-rw-r--r--main.cpp10
-rw-r--r--res/sample_0.wavbin0 -> 62676 bytes
-rw-r--r--res/sample_1.wavbin0 -> 47472 bytes
7 files changed, 63 insertions, 16 deletions
diff --git a/Table.cpp b/Table.cpp
index dc731a8..868e5e6 100644
--- a/Table.cpp
+++ b/Table.cpp
@@ -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);
}
}
diff --git a/Table.hpp b/Table.hpp
index f73ca56..5ee0b2b 100644
--- a/Table.hpp
+++ b/Table.hpp
@@ -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);
diff --git a/lzr.c b/lzr.c
index 89ef073..1608cd6 100644
--- a/lzr.c
+++ b/lzr.c
@@ -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;
diff --git a/lzr.h b/lzr.h
index b12bde5..f1b6a4b 100644
--- a/lzr.h
+++ b/lzr.h
@@ -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);
diff --git a/main.cpp b/main.cpp
index c6fb228..0ff2e8f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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
new file mode 100644
index 0000000..e223dc7
--- /dev/null
+++ b/res/sample_0.wav
Binary files differ
diff --git a/res/sample_1.wav b/res/sample_1.wav
new file mode 100644
index 0000000..4734c19
--- /dev/null
+++ b/res/sample_1.wav
Binary files differ