-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestObject.cpp
104 lines (99 loc) · 3.54 KB
/
testObject.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
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
#include "testObject.h"
#include <stdlib.h>
#include "DisplayManager.h"
#include "WorldManager.h"
#include "GameManager.h"
#include "LogManager.h"
#include "EventOut.h"
#include "EventStep.h"
#include "EventMouse.h"
#include "EventKeyboard.h"
namespace df {
testObject::testObject(){
setType("testObject");
setSprite("ship");
setAltitude(0); //Puts stars in the background
setPosition(df::Vector(50, 5));
color = df::RED;
setSolidness(SOFT);
}
//Handles events
//Returns 0 when ignored
int testObject::eventHandler(const Event* p_e) {
//For checkpoint 5 test 1 (testGMRun())
if (p_e->getType() == df::STEP_EVENT) {
if (((EventStep*)p_e)->getStepCount() % 150 == 0) {
setAltitude(1);
}
if (((EventStep*)p_e)->getStepCount() % 300 == 0) {
setPosition(Vector(25, 5));
}
if (((EventStep*)p_e)->getStepCount() % 600 == 0) {
setAltitude(5);
setPosition(Vector(35, 8));
}
return 1;
}
if (p_e->getType() == df::MSE_EVENT) {//testObject moves to the cursor when clicked
EventMouse* m = (EventMouse*)p_e;
LM.writeLog(0,"Key %d", m->getMouseButton());
if (m->getMouseAction() == EventMouseAction::PRESSED) {
setPosition(Vector(m->getMousePosition().getX(), m->getMousePosition().getY()));
int x = getPosition().getX();
int y = getPosition().getY();
LM.writeLog(0, "ID: %d Position:(%d, %d)", getId(), x, y);
}
return 1;
}
if (p_e->getType() == df::KEYBOARD_EVENT) {//testObject moves to the cursor when clicked
EventKeyboard* m = (EventKeyboard*)p_e;
LM.writeLog(0,"Key %d", m->getKey());
if (m->getKey() == Keyboard::Key::NUM1 && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
color = df::RED;
}
if (m->getKey() == Keyboard::Key::NUM2 && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
color = df::GREEN;
}
if (m->getKey() == Keyboard::Key::NUM3 && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
color = df::YELLOW;
}
if (m->getKey() == Keyboard::Key::NUM4 && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
color = df::BLUE;
}
if (m->getKey() == Keyboard::Key::NUM5 && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
color = df::MAGENTA;
}
if (m->getKey() == Keyboard::Key::NUM6 && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
color = df::CYAN;
}
if (m->getKey() == Keyboard::Key::NUM7 && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
color = df::WHITE;
}
if (m->getKey() == Keyboard::Key::W && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
setPosition(Vector(getPosition().getX(), getPosition().getY() - .5));
}
if (m->getKey() == Keyboard::Key::S && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
setPosition(Vector(getPosition().getX(), getPosition().getY() + .5));
}
if (m->getKey() == Keyboard::Key::A && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
setPosition(Vector(getPosition().getX() - .5, getPosition().getY()));
}
if (m->getKey() == Keyboard::Key::D && m->getKeyboardAction() == EventKeyboardAction::KEY_DOWN) {
setPosition(Vector(getPosition().getX() + .5, getPosition().getY()));
}
return 1;
}
if (p_e->getType() == df::OUT_EVENT) {
LM.writeLog(3, "EventOut");
return 1;
}
return 0;
}
void testObject::setColor(int c) {
//color = c;
}
/*//Draws testObject
int testObject::draw() {
return DM.drawCh(getPosition(), testObject_CHAR, color);
}*/
}