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