1 /*
2 Copyright (C) 2009 Facundo Domínguez
3
4 This file is part of Spacejunk.
5
6 Spacejunk is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Foobar is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <assert.h>
21 #include "collisionengine.h"
22 #include "cmask.h"
23 #include "resourcemanager.h"
24 #include <iostream>
25
26 using namespace std;
27
fillLoaderList(list<RLoader * > & rl)28 void fillLoaderList(list<RLoader*> & rl) {
29 rl.push_back(Singleton<PaletteLoader>::getInstance());
30 rl.push_back(Singleton<ImageSetLoader>::getInstance());
31 rl.push_back(Singleton<CMaskLoader>::getInstance());
32 rl.push_back(Singleton<MusicLoader>::getInstance());
33 rl.push_back(Singleton<SoundLoader>::getInstance());
34 rl.push_back(Singleton<FontLoader>::getInstance());
35 }
36
37
TestCollision()38 void TestCollision(){
39 // load resources
40 list<RLoader*> rl;
41 fillLoaderList(rl);
42 readResources("data/resources.xml",rl);
43
44 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) != 0) {
45 cerr<<"Unable to initialize SDL: "<<SDL_GetError()<<"\n";
46 exit(1);
47 }
48
49 Graphic::set_video_mode(640,480);
50 GameBody g1("planet1"),g2("planet1");
51 Vector2d normal;
52 real t;
53
54 g1.setPosition(0,0); g2.setPosition(0,0);
55 g1.lastTestPos=Vector2d(0,0); g2.lastTestPos=Vector2d(0,0);
56 assert(circle_swept_collision(&g1,&g2,&t,&normal));
57
58 g1.setPosition(0,0); g2.setPosition(20,0);
59 g1.lastTestPos=Vector2d(0,0); g2.lastTestPos=Vector2d(-20,0);
60 assert(!circle_swept_collision(&g1,&g2,&t,&normal));
61
62 g1.setPosition(0,20); g2.setPosition(20,0);
63 g1.lastTestPos=Vector2d(0,-20); g2.lastTestPos=Vector2d(-20,0);
64 assert(!circle_swept_collision(&g1,&g2,&t,&normal));
65
66 g1.setPosition(0,60); g2.setPosition(0,0);
67 g1.lastTestPos=Vector2d(0,0); g2.lastTestPos=Vector2d(-60,0);
68 assert(!circle_swept_collision(&g1,&g2,&t,&normal));
69
70 g1.setPosition(0,40); g2.setPosition(0,0);
71 g1.lastTestPos=Vector2d(0,0); g2.lastTestPos=Vector2d(0,-40);
72 assert(!circle_swept_collision(&g1,&g2,&t,&normal));
73
74 g1.setPosition(0,40); g2.setPosition(0,0);
75 g1.lastTestPos=Vector2d(0,0); g2.lastTestPos=Vector2d(0,40);
76 assert(circle_swept_collision(&g1,&g2,&t,&normal));
77
78 SDL_Quit();
79 }
80