-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameStrip.cpp
55 lines (47 loc) · 1.07 KB
/
GameStrip.cpp
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
#include "GameStrip.h"
#include <SPI.h>
#include <Adafruit_DotStar.h>
GameStrip::GameStrip(Adafruit_DotStar *strip)
: m_strip(strip), m_position(10), m_direction(rand() % 2)
{
m_strip->begin();
m_strip->clear();
m_strip->show();
}
void GameStrip::moveBomb()
{
if ((m_position == 1 && m_direction) || (m_position == 17 && !m_direction))
return;
if (m_direction) {// R iGhT//
m_strip->setPixelColor(m_position, 0);
m_strip->setPixelColor(m_position--, 0x0000FF);
} else {
m_strip->setPixelColor(m_position, 0);
m_strip->setPixelColor(m_position++, 0xFF0000);
}
m_strip->show();
}
void GameStrip::setDirection(bool right)
{
m_direction = right;
}
Arduino::byte GameStrip::isEnd()
{
if(m_position == 1 && m_direction)
{
return 1;
}
else if(m_position == 17 && !m_direction)
{
return -1;
}
else{
return 0;
}
}
void GameStrip::resetBomb()
{
m_direction = !m_direction;
m_strip->setPixelColor(m_position, 0);
m_position = 10;
}