summaryrefslogtreecommitdiff
path: root/Table.cpp
blob: 50438b835a64287b7551b9ebf6662847dc64a0e3 (plain)
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
#include "Table.hpp"
#include "Cursor.hpp"
#include "cfg.hpp"
#include "util.hpp"
#include "lzr.h"
#include <stdlib.h>

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;
}