Mercurial > projects > openmelee
comparison ships/ship.d @ 24:441eb7672404
impleneted steer to avoid
author | zzzzrrr <mason.green@gmail.com> |
---|---|
date | Fri, 27 Mar 2009 16:05:24 -0400 |
parents | 4fce5596d1f6 |
children | 88cca12cc8b9 |
comparison
equal
deleted
inserted
replaced
23:e79347dd38a3 | 24:441eb7672404 |
---|---|
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 class State | 44 struct 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 | |
56 float radius = 0.0f; | 55 float radius = 0.0f; |
57 float enemyAngle = 0.0f; | 56 float enemyAngle = 0.0f; |
58 bzVec2 avoid; | 57 bzVec2 avoid; |
59 | 58 |
59 Ship enemy; | |
60 | |
60 bzVec2 predictFuturePosition(float dt) { | 61 bzVec2 predictFuturePosition(float dt) { |
61 return (position + velocity * dt); | 62 return (position + velocity * dt); |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
80 float maxAngVel = 2; | 81 float maxAngVel = 2; |
81 | 82 |
82 this(bzWorld world) { | 83 this(bzWorld world) { |
83 this.world = world; | 84 this.world = world; |
84 shapes = new ShapeList; | 85 shapes = new ShapeList; |
85 state = new State; | |
86 } | 86 } |
87 | 87 |
88 void thrust() { | 88 void thrust() { |
89 rBody.force += engineForce.rotate(rBody.angle); | 89 rBody.force += engineForce.rotate(rBody.angle); |
90 } | 90 } |
125 state.position = rBody.position; | 125 state.position = rBody.position; |
126 state.forward = engineForce.rotate(rBody.angle); | 126 state.forward = engineForce.rotate(rBody.angle); |
127 } | 127 } |
128 | 128 |
129 void calcRadius() { | 129 void calcRadius() { |
130 rBody.userData = state; | |
131 for (bzShape s = rBody.shapeList; s; s = s.next) { | 130 for (bzShape s = rBody.shapeList; s; s = s.next) { |
132 if(s.sweepRadius > state.radius) { | 131 if(s.sweepRadius > state.radius) { |
133 state.radius = s.sweepRadius; | 132 state.radius = s.sweepRadius; |
134 } | 133 } |
135 } | 134 } |
136 } | 135 } |
137 | |
138 } | 136 } |