The Game Engine  1
LevelFns.h
Go to the documentation of this file.
1 #ifndef __LEVELFNS_H__
2 #define __LEVELFNS_H__
3 #include "Game.h"
4 #include "Level.h"
5 #include "Text.h"
6 #include "Input.h"
7 #include "Behaviors.h"
8 #include "Player.h"
9 #include "Collision.h"
10 #include <SDL/SDL_ttf.h>
11 #include "Audio.h"
13 
15 }
16 
18 }
19 
20 
22 // Continuous input testing //
24 void handleKeyReleases(SDLKey k, SDLMod m){
25  if(k||m)
26  cout<<"KeyUp!"<<endl;
27 }
28 
29 void handleKeyPress(SDLKey k, SDLMod m){
30  if(k||m)
31  cout<<"KeyDown!"<<endl;
32 }
33 
35  if(!m.pressed)
36  cout<<"MouseUp!"<<endl;
37 }
38 
40  if(m.pressed)
41  cout<<"MouseDown!"<<endl;
42 }
43 
45  cout<<"mouse at:"<<m.pos<<endl;
46  cout<<"mouse relative:"<<m.relPos<<endl;
47 }
48 
49 void handleJoyButtonDown(Uint8 jp, JoyButton b){
50  cout<<"Joy pad:"<<jp<<endl;
51  cout<<"Button Pressed:"<<b<<endl;
52 }
53 
54 void handleJoyButtonUp(Uint8 jp, JoyButton b){
55  cout<<"Joy pad:"<<jp<<endl;
56  cout<<"Button Released:"<<b<<endl;
57 }
58 
59 void handleJoyMove(Uint8 jp, JoyStick s, Point2D pos){
60  cout<<"Joy pad:"<<jp<<endl;
61  cout<<"Stick:"<<s<<endl;
62  cout<<"("<<pos.x<<","<<pos.y<<")"<<endl;
63 }
64 
65 //variables for testing
66 int success=0;
67 int failed=0;
69 bool testsDone = false;
70 void printSuccess(string s){
71  cout<<success++ + failed<<" "<<s<<" Success!"<<endl;
72 }
73 
74 void printFailed(string s){
75  cout<<failed++ + success<<" "<<s<<" failed!"<<endl;
76 }
77 
79 // callback removal testing //
82  try{
84  printSuccess("removed MouseMove");
85  }
86  catch(exception e){
87  printFailed(e.what());
88  }
89 }
90 
91 void removeself2(Uint8, JoyButton j){
92  try{
94  printSuccess("removed JoybuttonUp");
95  }
96  catch(exception e){
97  printFailed(e.what());
98  }
99 }
100 
101 void removeself3(Uint8, JoyButton j){
102  try{
104  printSuccess("removed JoybuttonDown");
105  }
106  catch(exception e){
107  printFailed(e.what());
108  }
109 }
110 
112  try{
114  printSuccess("removed Joy Move");
115  }
116  catch(exception e){
117  printFailed(e.what());
118  }
119 }
120 
122  try{
124  printSuccess("removed MouseDown");
125  }
126  catch(exception e){
127  printFailed(e.what());
128  }
129 }
130 
132  try{
134  printSuccess("removed MouseUp");
135  }
136  catch(exception e){
137  printFailed(e.what());
138  }
139 }
140 
141 void removeself7(SDLKey, SDLMod){
142  try{
144  printSuccess("removed KeyDown");
145  }
146  catch(exception e){
147  printFailed(e.what());
148  }
149 }
150 
151 void removeself8(SDLKey, SDLMod){
152  try{
154  printSuccess("removed KeyUp");
155  }
156  catch(exception e){
157  printFailed(e.what());
158  }
159 }
160 
162 
163 void TestLoad() {
164  Game* g = Game::game();
165  Level* l = g->LoadingLevel;
166 
167  l->setMaxNumPlayers(2);
168 
170  // Test player generation //
172  Player* p1 = new Player("configFileName");
173  // check each of the player's bits
174  Player* p2 = new Player("ConfigFileName2");
175  // do it again with the other config.
176 
177  Player* p3 = new Player("ConfigFileName2");
178  // duplicate test (should be fine and be the same as player 2 settings wise
179 
180 
181 
183  // Test player addition to level //
185  l->addPlayer(p1);
186  if(l->getNumPlayers()==1)
187  {
188  printSuccess(" Added player check");
189  }
190  else{
191  printFailed("Added player check");
192  }
193  l->addPlayer(p2);
194  if(l->getNumPlayers()==2)
195  {
196  printSuccess("Added second player");
197  }
198  else{
199  printFailed("Added second player");
200  }
201  l->addPlayer(p3);
202  if(l->getNumPlayers()==2)
203  {
204  printSuccess("Added too many players");
205  }
206  else{
207  printFailed("Added too many players");
208  }
209 
211  l->setBackground(new Background("default", "bg.bmp"));//mBackground = LoadImage("Backgrounds/bg.bmp");
212  //background tests here
213 
215  Sprite* vikings1 = new Sprite("viking1", g->getAnimation("viking.anim"));
216  vikings1->setPosition(0,0);
217  vikings1->setSpeed(1);
218  if(vikings1->getSpeed() == 1)
219  {
220  printSuccess("SetSpeed");
221  }
222  else{
223  printFailed("SetSpeed");
224  }
225  g->mCamera.follow(vikings1);// check later
226  p1->Control(vikings1);//check in update loop
227 
228 
229  Sprite* vikings2 = new Sprite("viking2", g->getAnimation("viking.anim"));
230  vikings2->setPosition(350,300);
231  if(vikings2->getPosition().x == 350 && vikings2->getPosition().y == 300)
232  {
233  printSuccess("SetPos");
234  }
235  else{
236  printFailed("SetPos");
237  }
238  vikings2->setSpeed(1.5);
239  if(vikings2->getSpeed() == 1.5)
240  {
241  printSuccess("SetSpeed");
242  }
243  else{
244  printFailed("SetSpeed");
245  }
246 
247  Sprite* sun = new Sprite("sun", g->getAnimation("sun.anim"));
248  sun->setCenterPosition(0,0);
249  sun->setSpeed(1);
250 
251  ParticleSystem* p = new ParticleSystem("spawner", Point2D(15,15), g->getAnimation("sun.anim")->Frames[0]->tex);
254  p->SetTexture(vikings1->getAnimation());
255 
256  cout<<"Device checks"<<endl;
257  auto val = Input::getDeviceCounts();
258  cout << val.first<<","<<val.second<<endl;
259 
260  cout << Input::getNumJoysticks() <<endl;
261 
262  cout<<"Input counts"<<endl;
263  cout<<Input::getNumInputs()<<endl;
264  Input* in = new Input();
265  cout<<Input::getNumInputs()<<endl;
266  Input::removeInput(in);
267  cout<<Input::getNumInputs()<<endl;
268 
278 
288 
289  cout<<"mousepos"<<endl<<Input::getMousePos()<<endl;
290  cout<<Input::getMouseRelPos()<<endl;
291 
294  sun->setAcceleration(Point2D(.25, .25));
295 
296  vikings2->setVelocity(-1,-1);
297 }
298 
299 void TestUpdate() {
300  Game* g = Game::game();
301  Level* l = g->getCurrentLevel();
302 
303  Sprite* player = l->findSprite("viking1");
304 
305  Background* bg = l->getBackground();
307  Player* p1 = l->getPlayer(0);
308  Player* p2 = l->getPlayer(1);
309 
310  ParticleSystem* psys = l->findParticleSystem("spawner");
311 
312  auto res = Collision::collider()->getCollisions(player,l->findSprite("sun"));
313  if(res){
314  cout<<res->size()<<endl;
315  }
316 
317  Input* in = Input::getInput(0);
318  Input* in2 = Input::getInput(1);
319 
320  if(player&&in) {
322  }
323  player = l->findSprite("viking2");
324  if(bg&&in&&player) {
326  }
327  if(in&&in->pressed(SDLK_9)){
328  Sprite* s = new Sprite("asdf",g->getAnimation("sun.anim"));
329  s->setPosition(rand()%800,rand()%600);
330  }
331  if(in&&in->pressed(SDLK_8)){
332  l->removeAllSprites("asdf");
333  }
334 
335  if(in&&in->pressed(SDLK_5)){
336  psys->SpawnParticles(100);
337  }
338  if(in){
341  cout<<"Accept triggered!"<<endl;
343  cout<<"deny pressed!"<<endl;
344  if(in->doubleTapped(MouseLeft))
345  cout<<"DOUBLE MOUSE CLICKED! YES!"<<endl;
346  }
347  if(p1){
349  cout<<"DOUBLE CLICKED! YES!"<<endl;
350  }
351  if(in && in->doubleTapped(SDLK_1))
352  {
353  cout<<"SDL_key double tapped"<<endl;
354  }
355  if(in2 && in2->doubleTapped(A))
356  {
357  cout<<"Joy button double tapped"<<endl;
358  }
359  if(in && in->doubleTapped(MouseLeft))
360  {
361  cout<<"Mouse double tapped"<<endl;
362  }
363  if(in && in->getAllPressed(B))
364  {
365  cout<<"AllJoyPressed"<<endl;
366  }
367 
368  if(in && in->getAllTriggered(B))
369  {
370  cout<<"AllJoyTriggered "<<endl;
371  }
372  if(in2){
373  cout<<in2->getJoyMovement(JoyLeft)<<endl;
374  }
375 
376  if(in && in->pressed(SDLK_1)){
377  Sprite* sun = l->findSprite("sun");
378  if(sun)
379  {
380  sun->setPosition(0,0);
381  }
382  }
383 
384  if(in&&in->pressed(SDLK_4)){
385  int index = beattone.LoadAudio("Level1AudioTest","ArtAssets\\Music\\beat.wav");
386  beattone.play(index);
387  }
388  if(testsDone){
389  cout<<success+failed<<" tests run "<<success<<" Succeeded "<<failed<<" failed"<<endl;
390  string s;
391  cout<<"Press any key to quit"<<endl;
392  cin>>s;
393  g->stop();
394  }
395 }
396 
397 #endif