comparison ship.d @ 0:c10bc63824e7

Initial commit!
author zzzzrrr <mason.green@gmail.com>
date Fri, 20 Mar 2009 06:41:25 -0400
parents
children a40d066ebbd1
comparison
equal deleted inserted replaced
-1:000000000000 0:c10bc63824e7
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 */
30 module melee.ship;
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;
38
39 alias LinkedList!(bzShape) ShapeList;
40
41 abstract class Ship
42 {
43
44 bzBody rBody;
45 ShapeList shapes;
46 bzVec2 engineForce;
47 bzVec2 turnForce;
48 bzVec2 leftTurnPoint;
49 bzVec2 rightTurnPoint;
50
51 this() {
52 shapes = new ShapeList;
53 }
54
55 void thrust() {
56 rBody.force += engineForce.rotate(rBody.angle);
57 }
58
59 void turn(char key) {
60 switch(key) {
61 case 'd':
62 rBody.torque += bzCross(rightTurnPoint.rotate(rBody.angle),
63 turnForce.rotate(rBody.angle));
64 break;
65 case 'a':
66 rBody.torque += bzCross(leftTurnPoint.rotate(rBody.angle),
67 turnForce.rotate(rBody.angle));
68 break;
69 default:
70 break;
71 }
72 }
73 }