-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestDemos.c++
179 lines (142 loc) · 4.33 KB
/
TestDemos.c++
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
//
// TestDemos.c++
// Tech1
//
// Created by Justin Hust on 12/27/13.
// Copyright (c) 2013 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include <fstream>
#include <sstream> // istringtstream, ostringstream
#include <string> // ==
#include "gtest/gtest.h"
#include "Clock.h"
#include "Reporter.h"
#include "Resource.h"
#include "Lexer.h"
#include "Parser.h"
#include "Environment.h"
#include "System.h"
#include "Util.h"
// -----------------------------------------
//TEST(demos, bombs) {
// {
// srand(0);
//
// System sys;
// sys.init(640, 480);
//
// sys.Register("images/bomb.png");
// sys.Register("sounds/explodelow.wav");
//
// int i = 0;
// bool exploded[3];
// float x[3];
// float y[3];
// float fExplodeTimer = 1.0f;
//
// while(sys.clock()->getSecsElapsed() < 4.0f) {
// sys.clock()->tick();
// fExplodeTimer -= sys.clock()->getFrameSecs();
//
// // track an explosion
// if(fExplodeTimer < 0.0f) {
// sys.playSound("sounds/explodelow.wav");
//
// exploded[i] = true;
// x[i] = random_float(100, 540);
// y[i] = random_float(100, 380);
// ++i;
//
// fExplodeTimer = 1.0f;
//
// }
//
// // draw
// for(int j=0;j<i;j++) {
// sys.draw("images/bomb.png", x[j], y[j]);
//
// }
//
// sys.presentScreen();
//
// }
//
// sys.shutdown();
//
// }
//
//}
// -----------------------------------------
TEST(demos, bomb_walk) {
{
srand(0);
System sys;
sys.init(640, 480);
sys.Register("images/mario_sprites.png");
sys.RegisterSprite("bomb_walk1", "images/mario_sprites.png", 127, 212, 127+16, 212+16);
sys.RegisterSprite("bomb_walk2", "images/mario_sprites.png", 141, 212, 141+16, 212+16);
sys.Register("images/bomb.png");
sys.Register("sounds/scurry.wav");
sys.Register("sounds/explodelow.wav");
enum bomb_state { bomb_startup, bomb_walking, bomb_exploding, bomb_exploded };
bomb_state st = bomb_startup;
float pos[3] = {100.0f, 300.0f, 0.0f};
float vel[3] = {20.0f, -20.0f, 0.0f};
float cdNextState;
float cdFrame;
float cdSound;
int iFrame;
while(sys.clock()->getSecsElapsed() < 8.0f) {
sys.clock()->tick();
switch(st) {
case bomb_startup: {
st = bomb_walking;
cdNextState = 3.0f;
pos[0] = 100.0f;
vel[0] = 300.0f;
cdFrame = 0.3f;
cdSound = 0.0f;
iFrame = 0;
} break;
case bomb_walking: {
float fFrameSecs = sys.clock()->getFrameSecs();
cdNextState -= fFrameSecs;
cdFrame -= fFrameSecs;
cdSound -= fFrameSecs;
if(cdNextState < 0.0f) {
st = bomb_exploding;
} else {
// frame transition
cdFrame -= sys.clock()->getFrameSecs();
if(cdFrame < 0.0f) {
iFrame++;
iFrame %= 2;
cdFrame = 0.3f;
}
// sound
if(cdSound < 0.0f) {
sys.playSound("sounds/scurry.wav");
cdSound = 1.0f;
}
pos[0] += vel[0] * fFrameSecs;
// pos[1] += vel[1] * fFrameSecs;
if(iFrame == 0)
sys.draw("bomb_walk1", pos[0], pos[1]);
else if(iFrame == 1)
sys.draw("bomb_walk2", pos[0], pos[1]);
}
} break;
case bomb_exploding: {
sys.playSound("sounds/explodelow.wav");
st = bomb_exploded;
} break;
case bomb_exploded: {
sys.draw("images/bomb.png", pos[0], pos[1]);
} break;
}
sys.presentScreen();
}
sys.shutdown();
}
}