22
|
1 /*
|
|
2 * Copyright (c) 2009 Blaze Contributors http://www.dsource.org/projects/blaze
|
|
3 * Maintained by Mason Green (zzzzrrr)
|
|
4 *
|
|
5 * This software is provided 'as-is', without any express or implied
|
|
6 * warranty. In no event will the authors be held liable for any damages
|
|
7 * arising from the use of this software.
|
|
8 *
|
|
9 * Permission is granted to anyone to use this software for any purpose,
|
|
10 * including commercial applications, and to alter it and redistribute it
|
|
11 * freely, subject to the following restrictions:
|
|
12 *
|
|
13 * 1. The origin of this software must not be misrepresented; you must not
|
|
14 * claim that you wrote the original software. If you use this software
|
|
15 * in a product, an acknowledgment in the product documentation would be
|
|
16 * appreciated but is not required.
|
|
17 *
|
|
18 * 2. Altered source versions must be plainly marked as such, and must not be
|
|
19 * misrepresented as being the original software.
|
|
20 *
|
|
21 * 3. This notice may not be removed or altered from any source
|
|
22 * distribution.
|
|
23 */
|
|
24 module openmelee.ships.asteroids;
|
|
25
|
|
26 import blaze.dynamics.bzBody : bzBody;
|
|
27 import blaze.bzWorld: bzWorld;
|
|
28 import blaze.dynamics.bzBodyDef;
|
|
29 import blaze.collision.shapes.bzCircle : bzCircleDef;
|
|
30 import blaze.collision.shapes.bzPolygon : bzPolyDef;
|
|
31 import blaze.collision.shapes.bzShape : bzShapeDef;
|
|
32 import blaze.common.bzMath: bzVec2, bzMul, bzXForm;
|
|
33 import blaze.dynamics.forces.bzAttractor: bzAttractor;
|
|
34
|
25
|
35 import openmelee.ships.ship: Ship;
|
22
|
36 import openmelee.ai.utilities;
|
|
37
|
|
38 const PI = 3.141593;
|
|
39
|
25
|
40 class Asteroid : Ship
|
22
|
41 {
|
|
42
|
|
43 bzBodyDef bd;
|
25
|
44 bzShapeDef sd;
|
22
|
45
|
|
46 this(bzWorld world) {
|
25
|
47 super(world);
|
22
|
48 init();
|
25
|
49 calcRadius();
|
22
|
50 }
|
|
51
|
|
52 void init() {
|
|
53 {
|
|
54 float radius = 0.5f;
|
|
55 float density = 5.0f;
|
|
56 auto sd1 = new bzCircleDef(density, radius);
|
|
57 sd1.localPosition.set(-0.5f, 0.5f);
|
|
58
|
|
59 density = 0.0f;
|
|
60 auto sd2 = new bzCircleDef(density, radius);
|
|
61 sd2.localPosition.set(0.5f, 0.5f);
|
|
62
|
25
|
63 float x = randomRange(-100f, 100f);
|
|
64 float y = randomRange(-100f, 100f);
|
|
65 bzVec2 position = bzVec2(x , y);
|
|
66 float angle = randomRange(-PI, PI);
|
|
67 bd = new bzBodyDef(position, angle);
|
|
68 bd.allowFreeze = false;
|
|
69 bd.allowSleep = false;
|
|
70 rBody = world.createBody(bd);
|
|
71 rBody.createShape(sd1);
|
|
72 rBody.createShape(sd2);
|
|
73 rBody.setMassFromShapes();
|
|
74 rBody.linearVelocity = bzVec2(x, y);
|
22
|
75 }
|
|
76 }
|
|
77 }
|