0
|
1 /*
|
|
2 * Copyright (c) 2009, Mason Green (zzzzrrr)
|
|
3 *
|
|
4 * All rights reserved.
|
|
5 *
|
|
6 * Redistribution and use in source and binary forms, with or without modification,
|
|
7 * are permitted provided that the following conditions are met:
|
|
8 *
|
|
9 * * Redistributions of source code must retain the above copyright notice,
|
|
10 * this list of conditions and the following disclaimer.
|
|
11 * * Redistributions in binary form must reproduce the above copyright notice,
|
|
12 * this list of conditions and the following disclaimer in the documentation
|
|
13 * and/or other materials provided with the distribution.
|
|
14 * * Neither the name of the polygonal nor the names of its contributors may be
|
|
15 * used to endorse or promote products derived from this software without specific
|
|
16 * prior written permission.
|
|
17 *
|
|
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29 */
|
2
|
30 module openmelee.ship;
|
0
|
31
|
|
32 import tango.io.Stdout: Stdout;
|
|
33
|
|
34 import tango.util.container.LinkedList : LinkedList;
|
|
35 import blaze.dynamics.bzBody : bzBody;
|
|
36 import blaze.collision.shapes.bzShape : bzShape;
|
|
37 import blaze.common.bzMath: bzVec2, bzCross;
|
6
|
38 import blaze.bzWorld : bzWorld;
|
|
39 import blaze.dynamics.forces.bzAttractor: bzAttractor;
|
0
|
40
|
|
41 alias LinkedList!(bzShape) ShapeList;
|
|
42
|
|
43 abstract class Ship
|
|
44 {
|
6
|
45 bzWorld world;
|
0
|
46 bzBody rBody;
|
|
47 ShapeList shapes;
|
|
48 bzVec2 engineForce;
|
|
49 bzVec2 turnForce;
|
|
50 bzVec2 leftTurnPoint;
|
|
51 bzVec2 rightTurnPoint;
|
|
52
|
6
|
53 this(bzWorld world) {
|
|
54 this.world = world;
|
0
|
55 shapes = new ShapeList;
|
|
56 }
|
|
57
|
|
58 void thrust() {
|
|
59 rBody.force += engineForce.rotate(rBody.angle);
|
|
60 }
|
|
61
|
5
|
62 void turnLeft() {
|
|
63 rBody.torque += bzCross(leftTurnPoint.rotate(rBody.angle),
|
0
|
64 turnForce.rotate(rBody.angle));
|
5
|
65 }
|
|
66
|
|
67 void turnRight() {
|
|
68 rBody.torque += bzCross(rightTurnPoint.rotate(rBody.angle),
|
0
|
69 turnForce.rotate(rBody.angle));
|
|
70 }
|
6
|
71
|
|
72 void setGravity() {
|
|
73
|
|
74 float minRadius = 1;
|
|
75 float maxRadius = 30;
|
|
76 float strength = 4;
|
|
77 bzVec2 center = bzVec2(0,0);
|
|
78 auto attractor = new bzAttractor(rBody, center, strength, minRadius, maxRadius);
|
|
79 world.addForce(attractor);
|
|
80 }
|
0
|
81 }
|