-
Notifications
You must be signed in to change notification settings - Fork 0
/
VisualGameObject.cpp
76 lines (65 loc) · 2.11 KB
/
VisualGameObject.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "VisualGameObject.h"
extern short timer;
extern short visObjectCount;
VisualGameObject::VisualGameObject() : GameObject("VisualGameObject"), m_predefControls(0) {
id = visObjectCount;
}
void VisualGameObject::setPos(short in_X, short in_Y) {
m_X = in_X;
m_Y = in_Y;
}
void VisualGameObject::setPos(std::array<short, 2> in_Pos) {
m_X = in_Pos[0];
m_Y = in_Pos[1];
}
std::array<short, 2> VisualGameObject::getPos() {
return {m_X, m_Y};
}
void VisualGameObject::setPredefControls(short& in_controls) {
m_predefControls = in_controls;
}
void VisualGameObject::setObjFacing(short in_Facing) {
m_currentFacing = in_Facing;
}
short VisualGameObject::getObjFacing() {
return m_currentFacing;
}
void VisualGameObject::move(short& in_controls, short interval) {
std::array<short, 2> curr_pos = getPos();
std::array<short, 2> new_pos = {0, 0};
bool alreadyMoved = false;
if (timer % interval == 0){
short controls = 0;
if (in_controls != 0) controls = in_controls;
else if (m_predefControls != 0) controls = m_predefControls;
else return;
short dx = 0, dy = 0;
if ((controls & controls::RIGHT) != 0) dx += 1;
if ((controls & controls::LEFT) != 0) dx -= 1;
if ((controls & controls::UP) != 0) dy -= 1;
if ((controls & controls::DOWN) != 0) dy += 1;
new_pos = {curr_pos[0] + dx, curr_pos[1] + dy};
setPos(new_pos);
alreadyMoved = true;
}
if (alreadyMoved && getDetailedName() == "Enemy" && timer % 5 == 0) {
srand(time(NULL));
short rnd_Dy = (rand() % 3) - 1;
setPos(new_pos[0], new_pos[1] + rnd_Dy);
}
}
void VisualGameObject::setPattern(std::wstring& in_pattern) {
m_pattern = in_pattern;
}
void VisualGameObject::setSize(short in_X, short in_Y) {
size_X = in_X;
size_Y = in_Y;
}
std::array<short, 2> VisualGameObject::getSize() {
return {size_X, size_Y};
}
std::wstring VisualGameObject::getPattern() {
return m_pattern;
}
bool VisualGameObject::isDead() { return m_markedForDeath; }
void VisualGameObject::markForDeath() { m_markedForDeath = true; }