-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRocket.h
More file actions
144 lines (118 loc) · 2.01 KB
/
Rocket.h
File metadata and controls
144 lines (118 loc) · 2.01 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef __ROCKET_H__
#define __ROCKET_H__
#include "Arduboy.h"
#include "bitmaps.h"
#include "Laser.h"
#include "Global.h"
class Rocket {
private:
const int16_t ROCKET_SPPED = 1;
int16_t x;
int16_t y;
Laser* laser;
bool isEmit;
Arduboy* arduboy;
public:
Rocket(Arduboy* _arduboy);
~Rocket();
Laser* getLaser();
int16_t getLeft();
int16_t getRight();
int16_t getTop();
int16_t getBottom();
void reset();
void move();
void crash();
void shot();
void draw();
};
Rocket::Rocket(Arduboy* _arduboy)
{
x = 10;
y = 54;
isEmit = false;
arduboy = _arduboy;
laser = new Laser(arduboy);
}
Rocket::~Rocket()
{
}
Laser* Rocket::getLaser()
{
return laser;
}
int16_t Rocket::getLeft()
{
return x;
}
int16_t Rocket::getRight()
{
return x + 8;
}
int16_t Rocket::getTop()
{
return y;
}
int16_t Rocket::getBottom()
{
return y + 8;
}
void Rocket::reset()
{
x = 10;
y = 54;
isEmit = false;
laser->reset();
}
void Rocket::move()
{
// move Rocekt
if (arduboy->pressed(LEFT_BUTTON)) {
x -= ROCKET_SPPED;
if (x < 0) {
x = 0;
}
}
else if (arduboy->pressed(RIGHT_BUTTON)) {
x += ROCKET_SPPED;
if (x > GAME_PANEL_WIDTH - 8) {
x = GAME_PANEL_WIDTH - 8;
}
}
laser->move();
// Shot Laser
if (laser->getStatus() == Laser::LASER_STATUS::NOT_EMITTED) {
if (arduboy->pressed(A_BUTTON) | arduboy->pressed(B_BUTTON)) {
if (isEmit) {
shot();
isEmit = false;
}
}
else {
isEmit = true;
}
}
}
void Rocket::crash()
{
arduboy->drawRect(x + GAME_PANEL_X, y, 8, 8, 0);
arduboy->drawBitmap(x + GAME_PANEL_X, y, bitmap_explosion, 8, 8, 1);
arduboy->display();
if (music) {
arduboy->tunes.tone(300, 500);
}
delay(500);
}
void Rocket::shot()
{
laser->shot(x + 4, y);
if (music) {
arduboy->tunes.tone(400, 100);
}
}
void Rocket::draw()
{
arduboy->drawBitmap(x + GAME_PANEL_X, y, bitmap_rocket, 8, 8, 1);
laser->draw();
}
#endif __ROCKET_H__