-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
71 lines (66 loc) · 1.47 KB
/
Copy pathPlayer.cpp
File metadata and controls
71 lines (66 loc) · 1.47 KB
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
#ifndef ARDUINO_AVR_UNO
#include <iostream>
#else
#include <Arduino.h>
#include "MP3.h"
#endif
#include "Board.h"
bool inBounds(int x, int y) {
return x >= 0 && y >= 0 && x < BOARD_W && y < BOARD_H;
}
Player::Player(char id, InputMethod* im)
{
x = getRandInt(BOARD_W);
y = getRandInt(BOARD_H);
this->id = id;
this->im = im;
board[y][x].player = this;
}
bool Player::move(Direction dir, bool checkDelay) {
if (checkDelay) {
Time currT = getTime();
if (currT < lastMoveTime + moveDelayMs) {
return false;
}
lastMoveTime = currT;
}
Point vec = MOVE_VECS[dir];
int newX = x + vec.x;
int newY = y + vec.y;
if (!inBounds(newX, newY)) {
return false;
}
if (board[newY][newX].player != NULL) {
// if it's a player, we can try and push the player
if (!board[newY][newX].player->move(dir, false)) {
return false;
}
}
board[y][x].player = NULL;
x = newX;
y = newY;
board[y][x].player = this;
return true;
}
void Player::activate() {
if (startT == 0) {
startT = getTime();
songNum = x;
mp3_command(CMD_PLAY, songNum);
return;
}
Note*& note = board[y][x].note;
if (note != NULL) {
auto t = NOTE_TIMES[songNum][note->id];
auto l = 1000;//NOTE_LENGTHS[songNum][note->id];
if (currT > (t + l - LEEWAY_MS) && currT < (t + l + LEEWAY_MS)) {
score++;
}
note = NULL;
} else {
// wall/barrier placing code if we wanna do that
}
}
void Player::processInput() {
im->handle(this);
}