@@ -198,67 +198,47 @@ TBool GEnemyProcess::MaybeHit() {
198
198
return EFalse;
199
199
}
200
200
201
- static const TFloat DX = 20 ,
202
- DY = 26 ;
201
+ static const TInt DX = 8 ,
202
+ DY = 8 ;
203
203
204
204
TBool GEnemyProcess::MaybeAttack () {
205
205
TRect myRect, hisRect;
206
206
mSprite ->GetRect (myRect);
207
207
mPlayerSprite ->GetRect (hisRect);
208
208
209
209
if (!mPlayerSprite ->mInvulnerable ) {
210
- if (myRect.x1 >= hisRect.x2 ) {
211
- // to right of player
212
- if (ABS (hisRect.x2 - myRect.x1 ) > DX) {
213
- mAttackTimer = 1 ;
214
- return EFalse;
215
- }
216
- if (ABS (mPlayerSprite ->y - mSprite ->y ) > DY) {
217
- mAttackTimer = 1 ;
218
- return EFalse;
219
- }
220
- if (--mAttackTimer <= 0 ) {
221
- NewState (ATTACK_STATE, DIRECTION_LEFT);
222
- }
223
- return ETrue;
224
- } else if (myRect.x2 <= hisRect.x1 ) {
225
- // to left of player
226
- if (ABS (hisRect.x1 - myRect.x2 ) > DX) {
227
- mAttackTimer = 1 ;
228
- return EFalse;
229
- }
230
- if (ABS (mPlayerSprite ->y - mSprite ->y ) > DY) {
231
- mAttackTimer = 1 ;
232
- return EFalse;
233
- }
234
- if (--mAttackTimer <= 0 ) {
235
- NewState (ATTACK_STATE, DIRECTION_RIGHT);
236
- }
237
- return ETrue;
238
- }
239
-
240
- if (myRect.y1 >= hisRect.y2 ) {
241
- // enemy below player
242
- if (ABS (mPlayerSprite ->y - mSprite ->y ) > DY) {
243
- // too far away
244
- mAttackTimer = 1 ;
245
- return EFalse;
210
+ if (myRect.y1 <= hisRect.y2 && myRect.y2 >= hisRect.y1 ) {
211
+ // vertical overlap
212
+ if (myRect.x1 >= hisRect.x2 && myRect.x1 - hisRect.x2 < DX) {
213
+ // to right of player
214
+ if (--mAttackTimer <= 0 ) {
215
+ NewState (ATTACK_STATE, DIRECTION_LEFT);
216
+ }
217
+ return ETrue;
246
218
}
247
- if (--mAttackTimer <= 0 ) {
248
- NewState (ATTACK_STATE, DIRECTION_UP);
219
+ if (myRect.x2 <= hisRect.x1 && hisRect.x1 - myRect.x2 < DX) {
220
+ // to left of player
221
+ if (--mAttackTimer <= 0 ) {
222
+ NewState (ATTACK_STATE, DIRECTION_RIGHT);
223
+ }
224
+ return ETrue;
249
225
}
250
- return ETrue;
251
- } else if (myRect.y2 <= hisRect.y1 ) {
252
- // enemy above player
253
- if (ABS (mPlayerSprite ->y - mSprite ->y ) > DY) {
254
- // too far away
255
- mAttackTimer = 1 ;
256
- return EFalse;
226
+ } else if (myRect.x1 <= hisRect.x2 && myRect.x2 >= hisRect.x1 ) {
227
+ // horizontal overlap
228
+ if (myRect.y1 >= hisRect.y2 && myRect.y1 - hisRect.y2 < DY) {
229
+ // below player
230
+ if (--mAttackTimer <= 0 ) {
231
+ NewState (ATTACK_STATE, DIRECTION_UP);
232
+ }
233
+ return ETrue;
257
234
}
258
- if (--mAttackTimer <= 0 ) {
259
- NewState (ATTACK_STATE, DIRECTION_DOWN);
235
+ if (myRect.y2 <= hisRect.y1 && hisRect.y1 - myRect.y2 < DY) {
236
+ // above player
237
+ if (--mAttackTimer <= 0 ) {
238
+ NewState (ATTACK_STATE, DIRECTION_DOWN);
239
+ }
240
+ return ETrue;
260
241
}
261
- return ETrue;
262
242
}
263
243
264
244
// player not near us
0 commit comments