comparison ships/ship.d @ 22:4fce5596d1f6

ai work
author zzzzrrr <mason.green@gmail.com>
date Thu, 26 Mar 2009 16:56:30 -0400
parents 7f74e064dad5
children 441eb7672404
comparison
equal deleted inserted replaced
21:cad384ad349e 22:4fce5596d1f6
39 import blaze.bzWorld : bzWorld; 39 import blaze.bzWorld : bzWorld;
40 import blaze.dynamics.forces.bzAttractor: bzAttractor; 40 import blaze.dynamics.forces.bzAttractor: bzAttractor;
41 41
42 alias LinkedList!(bzShape) ShapeList; 42 alias LinkedList!(bzShape) ShapeList;
43 43
44 struct State 44 class State
45 { 45 {
46 bzVec2 position; 46 bzVec2 position;
47 bzVec2 velocity; 47 bzVec2 velocity;
48 bzVec2 up; 48 bzVec2 up;
49 bzVec2 side; 49 bzVec2 side;
50 bzVec2 forward; 50 bzVec2 forward;
51 bzVec2 target; 51 bzVec2 target;
52 float speed = 0; 52 float speed = 0;
53 float maxForce = 0; 53 float maxForce = 0;
54 bool turn; 54 bool turn;
55 55
56 float enemyAngle; 56 float radius = 0.0f;
57 float enemyAngle = 0.0f;
58 bzVec2 avoid;
57 59
58 bzVec2 predictFuturePosition(float dt) { 60 bzVec2 predictFuturePosition(float dt) {
59 return (position + velocity * dt); 61 return (position + velocity * dt);
60 } 62 }
61 } 63 }
69 bzVec2 turnForce; 71 bzVec2 turnForce;
70 bzVec2 leftTurnPoint; 72 bzVec2 leftTurnPoint;
71 bzVec2 rightTurnPoint; 73 bzVec2 rightTurnPoint;
72 State state; 74 State state;
73 75
74 float battery; 76 float battery = 0.0f;
75 float crew; 77 float crew = 0.0f;
76 78
77 float maxLinVel = 50; 79 float maxLinVel = 50;
78 float maxAngVel = 2; 80 float maxAngVel = 2;
79 81
80 this(bzWorld world) { 82 this(bzWorld world) {
81
82 this.world = world; 83 this.world = world;
83 shapes = new ShapeList; 84 shapes = new ShapeList;
85 state = new State;
84 } 86 }
85 87
86 void thrust() { 88 void thrust() {
87 rBody.force += engineForce.rotate(rBody.angle); 89 rBody.force += engineForce.rotate(rBody.angle);
88 } 90 }
122 state.speed = state.velocity.length; 124 state.speed = state.velocity.length;
123 state.position = rBody.position; 125 state.position = rBody.position;
124 state.forward = engineForce.rotate(rBody.angle); 126 state.forward = engineForce.rotate(rBody.angle);
125 } 127 }
126 128
129 void calcRadius() {
130 rBody.userData = state;
131 for (bzShape s = rBody.shapeList; s; s = s.next) {
132 if(s.sweepRadius > state.radius) {
133 state.radius = s.sweepRadius;
134 }
135 }
136 }
137
127 } 138 }