-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStar.cpp
49 lines (40 loc) · 1.03 KB
/
Star.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
//
// Star.cpp
//
#include <stdlib.h> // for rand()
// Engine includes.
#include "DisplayManager.h"
#include "EventOut.h"
#include "LogManager.h"
// Game includes.
#include "Star.h"
Star::Star() {
setType("Star");
setSolidness(df::SPECTRAL);
setVelocity(df::Vector((float) -1.0 /(rand()%9 + 2), 0));
setAltitude(0); // Make them in the background.
df::Vector p((float) (rand()%(int)DM.getHorizontal()),
(float) (rand()%(int)DM.getVertical()));
setPosition(p);
}
int Star::draw() {
DM.drawCh(getPosition(), STAR_CHAR, df::WHITE);
return 0;
}
// Handle event.
// Return 0 if ignored, else 1.
int Star::eventHandler(const df::Event *p_e) {
if (p_e->getType() == df::OUT_EVENT) {
out();
return 1;
}
// If get here, have ignored this event.
return 0;
}
// If Star moved off screen, move back to far right.
void Star::out() {
df::Vector pos((float) (DM.getHorizontal() + rand()%20),
(float) (rand() % DM.getVertical()));
setPosition(pos);
setVelocity(df::Vector((float) -1.0 /(rand()%9 + 2), 0));
}