Mercurial > projects > openmelee
diff ships/ship.d @ 26:88cca12cc8b9
added ship explode
author | zzzzrrr <mason.green@gmail.com> |
---|---|
date | Fri, 27 Mar 2009 19:26:01 -0400 |
parents | 441eb7672404 |
children | da11cc30423f |
line wrap: on
line diff
--- 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; + } + } + } + }