comparison melee/melee.d @ 24:441eb7672404

impleneted steer to avoid
author zzzzrrr <mason.green@gmail.com>
date Fri, 27 Mar 2009 16:05:24 -0400
parents e79347dd38a3
children 2bf818f8b005
comparison
equal deleted inserted replaced
23:e79347dd38a3 24:441eb7672404
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 module openmelee.melee.melee; 31 module openmelee.melee.melee;
32 32
33 import tango.io.Stdout; 33 import tango.io.Stdout;
34 import tango.util.container.LinkedList : LinkedList;
34 35
35 version(distrib) import tango.io.vfs.ZipFolder; 36 version(distrib) import tango.io.vfs.ZipFolder;
36 import tango.time.StopWatch; 37 import tango.time.StopWatch;
37 import fc = tango.text.convert.Float : toString; 38 import fc = tango.text.convert.Float : toString;
38 import tango.util.log.Trace; 39 import tango.util.log.Trace;
55 import openmelee.ships.planet : Planet; 56 import openmelee.ships.planet : Planet;
56 import openmelee.ships.asteroids : Asteroid; 57 import openmelee.ships.asteroids : Asteroid;
57 58
58 const ITERS_PER_SECOND = 100; 59 const ITERS_PER_SECOND = 100;
59 const k_maxContactPoints = 100; 60 const k_maxContactPoints = 100;
61
62 alias LinkedList!(Ship) ObjectList;
60 63
61 // Melee settings 64 // Melee settings
62 struct Settings { 65 struct Settings {
63 float hz = 60; 66 float hz = 60;
64 int velocityIterations = 3; 67 int velocityIterations = 3;
90 //ContactState state; 93 //ContactState state;
91 } 94 }
92 95
93 class Melee { 96 class Melee {
94 97
98 ObjectList objectList;
95 Settings settings; 99 Settings settings;
96 float timeStep; 100 float timeStep;
97 const bzVec2 gravity = bzVec2(0.0f, 0.0f); 101 const bzVec2 gravity = bzVec2(0.0f, 0.0f);
98 bool allowSleep; 102 bool allowSleep;
99 Render draw; 103 Render draw;
100 104
101 AI ai; 105 AI ai;
102 Human human; 106 Human human;
107
103 Ship ship1; 108 Ship ship1;
104 Ship ship2; 109 Ship ship2;
105 Planet planet; 110 Ship planet;
106 111
107 bool running; 112 bool running;
108 113
109 StopWatch timer; 114 StopWatch timer;
110 bzAABB worldAABB; 115 bzAABB worldAABB;
113 bzContactListener m_contactListener; 118 bzContactListener m_contactListener;
114 ContactPoint[k_maxContactPoints] points; 119 ContactPoint[k_maxContactPoints] points;
115 int pointCount; 120 int pointCount;
116 121
117 this() { 122 this() {
123
124 objectList = new ObjectList;
118 } 125 }
119 126
120 void init() { 127 void init() {
121 128
122 timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f; 129 timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f;
123 version(distrib) gui.vfs.mount(new ZipFolder("./gui.zip")); 130 version(distrib) gui.vfs.mount(new ZipFolder("./gui.zip"));
124 scope cfg = loadHybridConfig("./gui.cfg"); 131 scope cfg = loadHybridConfig("./gui.cfg");
125 scope renderer = new Renderer; 132 scope renderer = new Renderer;
126 133
127 m_boundaryListener = new BoundaryListener(this); 134 m_boundaryListener = new BoundaryListener(this);
128 m_contactListener = new ContactListener(this);
129 initWorld(); 135 initWorld();
130 running = true; 136 running = true;
131 137
132 draw = new Render(world, ship1, ship2, settings); 138 draw = new Render(world, ship1, ship2, settings);
133 human = new Human(ship1); 139 human = new Human(ship1);
134 ai = new AI(ship2, world); 140
135 141 objectList.add(planet);
142 objectList.add(ship1);
143 objectList.add(ship2);
144
145 ai = new AI(ship2, objectList);
146
136 gui.begin(cfg).retained; 147 gui.begin(cfg).retained;
137 gui.push(`main`); 148 gui.push(`main`);
138 GLViewport(`glview`).renderingHandler(&draw.draw) 149 GLViewport(`glview`).renderingHandler(&draw.draw)
139 .addHandler(&human.onClick) 150 .addHandler(&human.onClick)
140 .addHandler(&human.onMove) 151 .addHandler(&human.onMove)
188 } 199 }
189 } 200 }
190 201
191 void initWorld() { 202 void initWorld() {
192 // Define world boundaries 203 // Define world boundaries
193 worldAABB.lowerBound.set(-100.0f, -150.0f); 204 worldAABB.lowerBound.set(-400.0f, -250.0f);
194 worldAABB.upperBound.set(100.0f, 150.0f); 205 worldAABB.upperBound.set(400.0f, 250.0f);
195 world = new bzWorld(worldAABB, gravity, allowSleep); 206 world = new bzWorld(worldAABB, gravity, allowSleep);
196 world.boundaryListener = m_boundaryListener; 207 world.boundaryListener = m_boundaryListener;
197 world.contactListener = m_contactListener; 208 ship2 = new UrQuan(world);
198 ship1 = new UrQuan(world); 209 ship1 = new Orz(world);
199 ship2 = new Orz(world);
200 ship2.rBody.angle = 3.14159265/4; 210 ship2.rBody.angle = 3.14159265/4;
201 planet = new Planet(world); 211 planet = new Planet(world);
202 //auto asteroids = new Asteroid(world); 212 //auto asteroids = new Asteroid(world);
203 } 213 }
204 214