Mercurial > projects > openmelee
changeset 26:88cca12cc8b9
added ship explode
author | zzzzrrr <mason.green@gmail.com> |
---|---|
date | Fri, 27 Mar 2009 19:26:01 -0400 |
parents | 2bf818f8b005 |
children | d63faa81a5e4 |
files | ai/ai.d ai/human.d ai/steer.d melee/melee.d render/render.d ships/ship.d |
diffstat | 6 files changed, 73 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/ai/ai.d Fri Mar 27 16:25:17 2009 -0400 +++ b/ai/ai.d Fri Mar 27 19:26:01 2009 -0400 @@ -67,11 +67,12 @@ steer = new Steer(ship, objectList); } + // Elementary steering AI void move(Ship enemy) { - Threat threat; + if(!ship) return; - // Elementary steering AI + Threat threat; steer.update(); steer.collisionThreat(threat); st = threat.steering; @@ -97,11 +98,8 @@ ship.state.target = st; st = ship.rBody.localPoint(st); - float x = st.x; - float y = st.y; - st = -bzVec2(y,-x); // Because ship's heading is 90 off rigid body's heading - //st = st.rotate(-90); + st = st.rotateLeft90(); float angle = atan2(st.x, st.y); if(abs(angle) > 0.05) { @@ -129,10 +127,7 @@ st = ship.rBody.localPoint(st); // Because ship's heading is 90 off rigid body's heading - //st = st.rotate(-90); - float x = st.x; - float y = st.y; - st = -bzVec2(y,-x); + st = st.rotateLeft90(); float angle = atan2(st.x, st.y); if(st.x <= 0) {
--- a/ai/human.d Fri Mar 27 16:25:17 2009 -0400 +++ b/ai/human.d Fri Mar 27 19:26:01 2009 -0400 @@ -34,13 +34,15 @@ import xf.input.KeySym; import openmelee.ships.ship; +import openmelee.melee.melee : Melee; class Human { - + Melee melee; Ship ship; - this(Ship ship) { + this(Ship ship, Melee melee) { + this.melee = melee; this.ship = ship; } @@ -69,6 +71,13 @@ break; case KeySym.Down: break; + case KeySym.Delete: + melee.ship2.explode(); + melee.objectList.remove(melee.ship2); + melee.world.destroyBody(melee.ship2.rBody); + melee.ship2 = null; + melee.draw.ship2 = null; + melee.ai.ship = null; default: break; }
--- a/ai/steer.d Fri Mar 27 16:25:17 2009 -0400 +++ b/ai/steer.d Fri Mar 27 19:26:01 2009 -0400 @@ -437,8 +437,7 @@ // estimated position of quarry at intercept bzVec2 target = quarry.predictFuturePosition(etl); - - return target; //steerForSeek (target); + return target; } // ------------------------------------------------------------------------
--- a/melee/melee.d Fri Mar 27 16:25:17 2009 -0400 +++ b/melee/melee.d Fri Mar 27 19:26:01 2009 -0400 @@ -58,7 +58,7 @@ const ITERS_PER_SECOND = 100; const k_maxContactPoints = 100; -const NUM_ASTROIDS = 15; +const NUM_ASTROIDS = 12; alias LinkedList!(Ship) ObjectList; @@ -137,7 +137,7 @@ running = true; draw = new Render(world, ship1, ship2, settings); - human = new Human(ship1); + human = new Human(ship1, this); objectList.add(planet); objectList.add(ship1); @@ -171,10 +171,10 @@ jobHub.addPostFrameJob( { // Limit velocity - ship1.limitVelocity(); - ship2.limitVelocity(); - ship1.updateState(); - ship2.updateState(); + foreach(o; objectList) { + o.limitVelocity(); + o.updateState(); + } gui.begin(cfg); gui.push(`main`); @@ -182,7 +182,7 @@ running = false; } - if(human.thrust) { + if(human.thrust && ship1) { ship1.thrust(); } @@ -210,7 +210,6 @@ ship1 = new Orz(world); ship2.rBody.angle = 3.14159265/4; planet = new Planet(world); - for(int i; i < NUM_ASTROIDS; i++) { auto asteroid = new Asteroid(world); objectList.add(asteroid);
--- a/render/render.d Fri Mar 27 16:25:17 2009 -0400 +++ b/render/render.d Fri Mar 27 19:26:01 2009 -0400 @@ -353,13 +353,17 @@ void draw(vec2i screenSize, GL gl) { - - vec2 point1 = vec2.from(ship1.rBody.position); - vec2 point2 = vec2.from(ship2.rBody.position); - vec2 range = point1 - point2; - zoom = bzClamp(1000/range.length, 2, 60); - viewCenter = point1 - (range * 0.5f); - + if(ship2) { + vec2 point1 = vec2.from(ship1.rBody.position); + vec2 point2 = vec2.from(ship2.rBody.position); + vec2 range = point1 - point2; + zoom = bzClamp(1000/range.length, 2, 60); + viewCenter = point1 - (range * 0.5f); + } else { + viewCenter = vec2.from(ship1.rBody.position); + zoom = 10; + } + this.screenSize = screenSize; gl.LoadIdentity(); @@ -378,21 +382,12 @@ gl.LoadIdentity(); gl.Clear(GL_COLOR_BUFFER_BIT); - vec2 pp1 = vec2.from(ship2.rBody.position); - vec2 pp2 = vec2.from(ship2.state.target); - - //gl.drawSegment(pp1, pp2, Color(0, 1, 0)); - // Draw dynamic bodies if (settings.drawShapes) { for (bzBody b = world.bodyList; b; b = b.next) { - - for (bzShape shape = b.shapeList; shape; shape = shape.next) { - bzShape s = shape; bzXForm xf = b.xf; - if (b.isStatic) { gl.drawShape(s, xf, Color(0.5f, 0.9f, 0.5f), settings.drawCoreShapes); }else if (b.isSleeping) {
--- a/ships/ship.d Fri Mar 27 16:25:17 2009 -0400 +++ b/ships/ship.d Fri Mar 27 19:26:01 2009 -0400 @@ -31,16 +31,23 @@ module openmelee.ships.ship; import tango.io.Stdout: Stdout; +import tango.math.Math : PI; import tango.util.container.LinkedList : LinkedList; import blaze.dynamics.bzBody : bzBody; -import blaze.collision.shapes.bzShape : bzShape; +import blaze.collision.shapes.bzShape : bzShape, bzShapeDef, bzMassData; +import blaze.collision.shapes.bzShapeType; import blaze.common.bzMath: bzVec2, bzCross, bzClamp; import blaze.bzWorld : bzWorld; import blaze.dynamics.forces.bzAttractor: bzAttractor; +import blaze.dynamics.bzBodyDef : bzBodyDef; +import blaze.collision.shapes.bzPolygon : bzPolyDef, bzPolygon; +import blaze.collision.shapes.bzCircle : bzCircleDef; alias LinkedList!(bzShape) ShapeList; +import openmelee.ai.utilities : randomRange; + struct State { bzVec2 position; @@ -104,7 +111,7 @@ void setPlanetGravity() { float minRadius = 0.1; float maxRadius = 10; - float strength = 4.0; + float strength = 0.75; bzVec2 center = bzVec2(0,0); auto attractor = new bzAttractor(rBody, center, strength, minRadius, maxRadius); world.addForce(attractor); @@ -133,4 +140,33 @@ } } } + + void explode() { + for(bzShape shape = rBody.shapeList; shape; shape = shape.next) { + auto bodyDef = new bzBodyDef; + switch(shape.type) { + case bzShapeType.POLYGON: + auto s = cast(bzPolygon) shape; + auto shapeDef = new bzPolyDef; + shapeDef.vertices = s.vertices; + shapeDef.density = s.density; + bodyDef.position = s.worldCenter; + bodyDef.angle = randomRange(-PI, PI); + bodyDef.allowFreeze = false; + bodyDef.allowSleep = false; + auto shrapnel = world.createBody(bodyDef); + shrapnel.createShape(shapeDef); + bzMassData massData; + massData.mass = 5.0f; + shrapnel.setMass(massData); + float x = randomRange(-300, 300); + float y = randomRange(-300, 300); + shrapnel.linearVelocity = bzVec2(x, y); + break; + default: + break; + } + } + } + }