-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exploder.cpp
60 lines (50 loc) · 1.64 KB
/
Exploder.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
60
#include "Exploder.h"
#include "Environment.h"
#include "Animal.h"
ALLEGRO_BITMAP *Exploder::exploderShape = 0;
Exploder::Exploder() : Object(OBJ_TYPE_MONSTER) {
speed = 0.0;
activated = false;
delay = 1.0;
}
Exploder::~Exploder() {
}
void Exploder::handleStimulus(Environment *environment, double dt) {
Object *player = environment->getPlayer();
if (player) {
if (!activated) {
if (player->getPosition().distanceTo(getPosition()) < 160.0) {
activated = true;
}
} else {
delay -= dt;
if (delay <= 0.0) {
this->destroy();
if (player->getPosition().distanceTo(getPosition()) < 160.0) {
Animal *animal = (Animal *) player;
animal->addEnergy(-1000.0);
}
}
}
}
}
void Exploder::renderFeedback(Environment *environment) {
}
void Exploder::render(Environment *environment) {
if (!exploderShape) {
exploderShape = al_load_bitmap("exploder.png");
}
ALLEGRO_COLOR color = al_map_rgb(196, 0, 255);
if (activated) {
double t = 1.0 - delay;
if (t < 0.0) {
t = 0.0;
}
if (t > 1.0) {
t = 1.0;
}
color = al_map_rgb(196 + (unsigned char) (t * 59), (unsigned char) (t * 255), 255);
}
Vector2D objWindowPos = environment->getWindowPos(getPosition());
al_draw_tinted_scaled_bitmap(exploderShape, color, 0, 0, 24, 24, objWindowPos.getX() - 24, objWindowPos.getY() - 24, 48, 48, 0);
}