1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#include "Cursor.hpp"
#include "lzr.h"
#include "cfg.hpp"
#include <stdlib.h>
#include <math.h>
#include <SDL2/SDL_log.h>
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);
}
}
|