#include "Cursor.hpp" #include "lzr.h" #include "cfg.hpp" #include #include #include Cursor::Cursor() : _angle(0.0), _xscale(1.0), _yscale(1.0), x(0), y(0), down(false), erase(false) { } void Cursor::update() { LZR_MousePosition(&x, &y); const bool _was_down(down || erase); down = LZR_BUTTON(MOUSE_L); erase = LZR_BUTTON(MOUSE_R); if (!_was_down && (down || erase)) LZR_PlaySound(3, 1); else if (_was_down && !(down || erase)) LZR_StopSound(3); if (erase) { _angle -= 1.0 / 16; _xscale = sin(float(LZR_GetTick()) * 2.0); _yscale = cos(float(LZR_GetTick()) * 3.0); while (_angle < -2.0) _angle += 1.0; LZR_SetSoundPitch(3, 1.5); } else if (down) { _angle += 1.0 / 16; _xscale = 2.0 * sin(float(LZR_GetTick()) * 2.0); _yscale = 2.0 * cos(float(LZR_GetTick()) * 3.0); while (_angle > 2.0) _angle -= 1.0; LZR_SetSoundPitch(3, 0.5); } else { _angle += 0.003; _xscale = sin(float(LZR_GetTick()) / 23); _yscale = sin(float(LZR_GetTick()) / 17); } } void Cursor::draw() { LZR_ImageDrawSettings stg = { 0, 0, -1, -1, 1.0, 1.0, 0.0, true, false, false }; stg.angle = _angle; stg.scale_x = _xscale; stg.scale_y = _yscale; set_color(); LZR_DrawImageEx((down || erase) ? LZR_IMAGE("res/005/cursor_down.bmp") : LZR_IMAGE("res/005/cursor_up.bmp"), x, y, stg); } void Cursor::set_color() const { if (erase) LZR_DrawSetColor(rand() & 1, 0, rand() & 1, 1); else if (down) LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); else { float color = (1.0 + fabs(sin((float)LZR_GetTick() / 32))) / 2; color *= color; LZR_DrawSetColor(1.0 - color, color, 1.0 - color, 1); } } void Cursor::set_color(int) const { if (erase) LZR_DrawSetColor(rand() & 1, 0, rand() & 1, 1); else if (down) LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); else { float color = rand() & 1; LZR_DrawSetColor(1.0 - color, color, 1.0 - color, 1); } }