-
Notifications
You must be signed in to change notification settings - Fork 0
/
Laser.cpp
59 lines (53 loc) · 945 Bytes
/
Laser.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
56
57
58
59
#include <vector>
#include "Laser.h"
#include "Player.h"
Sound Laser::sound("sounds/laser.wav");
void Laser::draw()
{
if (alive_)
{
surface_.put_rect(x_, y_, w_, h_, r_, g_, b_);
}
}
void Laser::move()
{
int direction;
if (player_) direction = 10;
if (!player_) direction = -10;
if (alive_)
{
surface_.put_rect(x_, y_, w_, h_, 0, 0, 0);
if (y_ > 0 && y_ <= H - h_ - 51)
{
y_ -= direction;
}
else
{
alive_ = false;
}
}
}
void Laser::build(int x, int y)
{
if (!alive_)
{
alive_ = true;
x_ = x;
y_ = y;
w_ = 2;
h_ = 20;
sound.play();
if (player_)
{
r_ = 250;
g_ = 150;
b_ = 0;
}
else if (!player_)
{
r_ = 0;
g_ = 250;
b_ = 150;
}
}
}