comparison ai/ai.d @ 26:88cca12cc8b9

added ship explode
author zzzzrrr <mason.green@gmail.com>
date Fri, 27 Mar 2009 19:26:01 -0400
parents 441eb7672404
children
comparison
equal deleted inserted replaced
25:2bf818f8b005 26:88cca12cc8b9
65 this(Ship ship, ObjectList objectList) { 65 this(Ship ship, ObjectList objectList) {
66 this.ship = ship; 66 this.ship = ship;
67 steer = new Steer(ship, objectList); 67 steer = new Steer(ship, objectList);
68 } 68 }
69 69
70 // Elementary steering AI
70 void move(Ship enemy) { 71 void move(Ship enemy) {
71 72
72 Threat threat; 73 if(!ship) return;
73 74
74 // Elementary steering AI 75 Threat threat;
75 steer.update(); 76 steer.update();
76 steer.collisionThreat(threat); 77 steer.collisionThreat(threat);
77 st = threat.steering; 78 st = threat.steering;
78 79
79 if(st == bzVec2.zeroVect) { 80 if(st == bzVec2.zeroVect) {
95 96
96 void chase(Ship enemy) { 97 void chase(Ship enemy) {
97 98
98 ship.state.target = st; 99 ship.state.target = st;
99 st = ship.rBody.localPoint(st); 100 st = ship.rBody.localPoint(st);
100 float x = st.x;
101 float y = st.y;
102 st = -bzVec2(y,-x);
103 // Because ship's heading is 90 off rigid body's heading 101 // Because ship's heading is 90 off rigid body's heading
104 //st = st.rotate(-90); 102 st = st.rotateLeft90();
105 float angle = atan2(st.x, st.y); 103 float angle = atan2(st.x, st.y);
106 104
107 if(abs(angle) > 0.05) { 105 if(abs(angle) > 0.05) {
108 if(!ship.state.turn) { 106 if(!ship.state.turn) {
109 if(st.x >= 0) { 107 if(st.x >= 0) {
127 125
128 void avoid() { 126 void avoid() {
129 127
130 st = ship.rBody.localPoint(st); 128 st = ship.rBody.localPoint(st);
131 // Because ship's heading is 90 off rigid body's heading 129 // Because ship's heading is 90 off rigid body's heading
132 //st = st.rotate(-90); 130 st = st.rotateLeft90();
133 float x = st.x;
134 float y = st.y;
135 st = -bzVec2(y,-x);
136 float angle = atan2(st.x, st.y); 131 float angle = atan2(st.x, st.y);
137 132
138 if(st.x <= 0) { 133 if(st.x <= 0) {
139 if(!avoidRight) { 134 if(!avoidRight) {
140 ship.turnRight(); 135 ship.turnRight();