-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.cpp
319 lines (295 loc) · 10.3 KB
/
game.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#include "test.h"
#include "Manager.h"
#include "LogManager.h"
#include "GameManager.h"
#include "WorldManager.h"
#include "DisplayManager.h"
#include "InputManager.h"
#include "ResourceManager.h"
#include "SpriteResourceManager.h"
#include "Object.h"
#include "ObjectList.h"
#include "ObjectListIterator.h"
#include "Saucer.h"
#include "Star.h"
#include "testObject.h"
#include "ViewObject.h"
#include "Vector.h"
#include "utillity.h"
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <stdio.h>
#include <stdarg.h>
#include <iostream>
#include <Windows.h>
#pragma comment(lib, "winmm.lib")
df::test T;
#define TEST(test_name) \
if (test_name) \
pass++; \
else \
fail++;
int main(int argc, char* argv[]) {
//While many tests are run when run_engine=true, others tests need to be run seperately
//Only one of the booleans below can be true
bool run_engine = false; //Runs the engine
//2b
bool testInputManager = false; //Tests the InputManager's startUp and shutDown functions
bool testGetInput = false; //Tests the getInput function
bool testGMRun = false; //Tests the GameManager's run for step events
bool testWindowSpaces = false;//Tests the DisplayManager's getHorizontal() and getVertical spaces
bool testWindowPixels = false;//Tests the DisplayManager's getHorizontal() and getVertical pixels
bool testDrawingFunctions = false; //Tests draw() and the DisplayManagers's startUp(), shutDown, drawCH(), and drawString()
bool testVelocityAndCollisions = false; //Tests the velocity and collision functions
bool testEventMouseAndEventKeyboard = false; //Tests EventMouse's and EventKeyboard's getters and setters
//2c
bool testGood();
bool testBad();
bool testBigBad();
bool testFrameDraw = false; //Tests Frame's draw function
bool testSpriteResourceManager = false;//Tests provided with the SpriteResourceManager
bool testSpriteFrames = false; //Test Sprite addFrame and getFrame
bool testAnimationDraw = false; //Tests the Animation draw()
bool testObjectDraw = false; //Tests the Object draw()
bool testBox = false; //Tests the Box's getters and setters
bool testBoundingBoxes = false; //Tests the object's bounding box
bool testBoxIntersectBox = false;//Tests boxIntersectBox
bool testWMDraw = false;//Tests the world manager's draw function
bool testBoundaryBoxCollision = false;//Tests collisions for objects with boundary boxes
bool testWMSetViewFollowing = false; //Tests WorldManager's setViewFollowing()
bool testAudio = false; //Tests the sound and music class and the ResourceManager's audio functions
bool testViewObjects = true; //Tests ViewObject with GM's run
if(run_engine){
if (GM.startUp()) {
LM.writeLog(10, "Error starting game manager!");
}
else {
if (T.doTests()) {
WM.setView(df::Box(df::Vector(0, 0), 80, 24));
RM.loadSprite("sprites/saucer-spr.txt", "saucer");
LM.setFlush(true);//Set flush of logfile during development
df::Saucer* s1 = new df::Saucer();
LM.writeLog("Box width %f height %f", s1->getBox().getHorizontal(), s1->getBox().getVertical());
s1->setVelocity(df::Vector(.25, .25));
s1->setPosition(df::Vector(50, 5));
df::Saucer* s2 = new df::Saucer();
s2->setVelocity(df::Vector(-.10, .25));
s2->setPosition(df::Vector(25, 5));
df::Saucer* s3 = new df::Saucer();
s3->setVelocity(df::Vector(.75, -.10));
df::Saucer* s4 = new df::Saucer();
s4->setVelocity(df::Vector(0, -.25));
df::Saucer* s5 = new df::Saucer();
s5->setVelocity(df::Vector(.25, 0));
GM.run();
}
GM.shutDown();
}
}
else if(testInputManager){
LM.startUp();
T.testInputManager();
LM.writeLog("InputManager test passed");
LM.shutDown();
}
//Change color by pressing 1-9, or move with W, A, S, and D
//Click to have testObject move to your cursor
else if (testGetInput) {
LM.startUp();
DM.startUp();
IM.startUp();
int i = 0;
df::testObject* t = new df::testObject();
t->setPosition(df::Vector(DM.getHorizontal()/2, DM.getVertical()/ 2));
while (i < 900) {
IM.getInput();
WM.draw();
DM.swapBuffers();
i++;
}
IM.shutDown();
DM.shutDown();
LM.shutDown();
}
else if (testGMRun) {
T.testGMRun();
}
else if (testDrawingFunctions) {
LM.startUp();
T.testDraw();
LM.shutDown();
}
else if (testWindowSpaces) {
LM.startUp();
T.testGetHorizontalVertical();
LM.shutDown();
}
else if (testWindowPixels) {
LM.startUp();
T.testGetHorizontalVerticalPixels();
LM.shutDown();
}
else if (testVelocityAndCollisions || testWMDraw) {
if (GM.startUp()) {
LM.writeLog(10, "Error starting game manager!");
}
else {
RM.loadSprite("sprites/saucer-spr.txt", "saucer");
LM.setFlush(true);//Set flush of logfile during development
df::Saucer* s1 = new df::Saucer();
LM.writeLog("Box width %f height %f", s1->getBox().getHorizontal(), s1->getBox().getVertical());
s1->setVelocity(df::Vector(.25, .25));
s1->setPosition(df::Vector(50, 5));
df::Saucer* s2 = new df::Saucer();
s2->setVelocity(df::Vector(-.10, .25));
s2->setPosition(df::Vector(25, 5));
df::Saucer* s3 = new df::Saucer();
s3->setVelocity(df::Vector(.75, -.10));
df::Saucer* s4 = new df::Saucer();
s4->setVelocity(df::Vector(0, -.25));
df::Saucer* s5 = new df::Saucer();
s5->setVelocity(df::Vector(.25, 0));
GM.run();
GM.shutDown();
}
}
else if (testEventMouseAndEventKeyboard) {//Will run for 30 seconds
//Click A to change the sprite's colors
//click on the display to have the testObject move there
GM.startUp();
LM.setFlush(true);
T.testMouseKeyboard();
new df::testObject;
new df::Saucer();
GM.run();
LM.writeLog("GM Ran");
GM.shutDown();
}
else if (testFrameDraw) {
T.testFrameDraw();
}
else if(testSpriteResourceManager){
// Start up LogManager.
if (LM.startUp()) {
LM.writeLog("main(): Error starting log manager!");
return 1;
}
// Start up ResourceManager.
if (RM.startUp()) {
LM.writeLog("main(): Error starting resource manager!");
return 1;
}
// Run tests.
int pass = 0, fail = 0;
TEST(testGood());
TEST(testBad());
TEST(testBigBad());
LM.writeLog("----------------------");
LM.writeLog("Summary: %d of %d tests pass.",
pass, pass + fail);
if (fail != 0)
LM.writeLog("FAILURE");
else
LM.writeLog("SUCCESS");
LM.writeLog("----------------------");
// Shut everything down.
RM.shutDown();
LM.shutDown();
}
else if (testSpriteFrames) {
T.testSpriteFrames();
}
else if (testAnimationDraw){
T.testAnimationDraw();
}
else if (testObjectDraw) {
T.testObjectDraw();
}
else if(testBox){
T.testBox();
}
else if (testBoundingBoxes) {
T.testBoundingBoxes();
}
else if (testBoxIntersectBox) {
T.testBoxIntersectBox();
}
else if (testWMSetViewFollowing) {
GM.startUp();
T.testWMSetViewFollowing();
GM.shutDown();
}
else if (testBoundaryBoxCollision) {
if (GM.startUp()) {
LM.writeLog(10, "Error starting game manager!");
}
else {
RM.loadSprite("sprites/saucer-spr.txt", "saucer");
LM.setFlush(true);//Set flush of logfile during development
df::Saucer* s1 = new df::Saucer();
s1->setPosition(df::Vector(30, 5));
s1->setVelocity(df::Vector(0, 0));
df::Saucer* s2 = new df::Saucer();
s2->setPosition(df::Vector(55, 5));
s2->setVelocity(df::Vector(-.25, 0));
df::Saucer* s3 = new df::Saucer();
s3->setPosition(df::Vector(30, 13));
s3->setVelocity(df::Vector(0,-.25));
df::utillity u;
if (u.boxIntersectsBox(s1->getBox(), s3->getBox())) {
LM.writeLog("Intersection");
}
else {
LM.writeLog("Not Box Intersect");
}
GM.run();
GM.shutDown();
}
}
else if (testAudio) {
T.testSound();
T.testMusic();
T.testRMSound();
T.testRMMusic();
}
else if (testViewObjects) {
T.testViewObject();
}
else {
LM.startUp();
LM.writeLog("Nothing ran");
LM.shutDown();
}
return 0;
}
// Load good sprite.
// Return TRUE if test passes, else FALSE.
bool testGood() {
if (RM.loadSprite("sprites/good-spr.txt", "good") != 0) {
LM.writeLog("%s: FAIL - Error loading good sprite!", __FUNCTION__);
return false;
}
LM.writeLog("%s: PASS", __FUNCTION__);
return true;
}
// Load bad sprite.
// Return TRUE if test passes, else FALSE.
bool testBad() {
if (RM.loadSprite("sprites/bad-spr.txt", "bad") == 0) {
LM.writeLog("%s: FAIL - Loaded bad sprite, but should not have!",
__FUNCTION__);
return false;
}
LM.writeLog("%s: PASS", __FUNCTION__);
return true;
}
// Load large, bad sprite.
// Return TRUE if test passes, else FALSE.
bool testBigBad() {
if (RM.loadSprite("sprites/map-spr.txt", "map") == 0) {
LM.writeLog("%s: FAIL - Loaded map sprite, but should not have!", __FUNCTION__);
return false;
}
LM.writeLog("%s: PASS", __FUNCTION__);
return true;
}