// Enemy.cpp : Enemy class // // 24.11.1998 / DH - Genesis // 02.12.1998 / DH - Added Scorpion // 03.12.1998 / DH - Added more enemies // // Copyright (c) 1998 Daniel Hartmeier. All rights reserved. #include "Enemy.hpp" #include "Hero.cpp" #include // ------------------------------------------------------------------- extern "C++" Hero *hero; // ------------------------------------------------------------------- #define SPRITE_SCORPION_1 0, 0 #define SPRITE_SCORPION_2 16, 0 #define SPRITE_SCORPION_3 32, 0 #define SPRITE_SCORPION_4 48, 0 #define SPRITE_SCORPION_5 64, 0 #define SPRITE_SCORPION_6 80, 0 #define SPRITE_BEETLE_A_1 96, 0 #define SPRITE_BEETLE_A_2 112, 0 #define SPRITE_BEETLE_A_3 128, 0 #define SPRITE_BEETLE_A_4 144, 0 #define SPRITE_SPIDER_1 160, 0 #define SPRITE_SPIDER_2 176, 0 #define SPRITE_SPIDER_3 192, 0 #define SPRITE_SPIDER_4 208, 0 #define SPRITE_SPIDER_5 224, 0 #define SPRITE_DUCK_1 0, 16 #define SPRITE_DUCK_2 16, 16 #define SPRITE_BIRD_1 32, 16 #define SPRITE_BIRD_2 48, 16 #define SPRITE_SNAIL_1 64, 16 #define SPRITE_SNAIL_2 80, 16 #define SPRITE_MOSQUITO_1 96, 16 #define SPRITE_MOSQUITO_2 112, 16 #define SPRITE_MOSQUITO_3 128, 16 #define SPRITE_MOSQUITO_4 144, 16 #define SPRITE_MOSQUITO_5 160, 16 #define SPRITE_MOSQUITO_6 176, 16 #define SPRITE_LIBELLE_1 192, 16 #define SPRITE_LIBELLE_2 208, 16 #define SPRITE_LIBELLE_3 224, 16 #define SPRITE_LIBELLE_4 240, 16 #define SPRITE_BEETLE_B_1 0, 32 #define SPRITE_BEETLE_B_2 16, 32 #define SPRITE_BEETLE_B_3 32, 32 #define SPRITE_BEETLE_B_4 48, 32 #define SPRITE_BEETLE_C_1 64, 32 #define SPRITE_BEETLE_C_2 80, 32 #define SPRITE_BEETLE_C_3 96, 32 #define SPRITE_BEETLE_C_4 112, 32 #define SPRITE_ANT_A_1 128, 32 #define SPRITE_ANT_A_2 144, 32 #define SPRITE_ANT_A_3 160, 32 #define SPRITE_ANT_A_4 176, 32 #define SPRITE_ANT_B_1 192, 32 #define SPRITE_ANT_B_2 208, 32 #define SPRITE_ANT_B_3 224, 32 #define SPRITE_ANT_B_4 240, 32 #define SPRITE_RAUPE_1 0, 48 #define SPRITE_RAUPE_2 16, 48 #define SPRITE_RAUPE_3 32, 48 #define SPRITE_RAUPE_4 48, 48 #define SPRITE_MUSHROOM_1 64, 48 #define SPRITE_MUSHROOM_2 80, 48 #define SPRITE_MUSHROOM_3 96, 48 #define SPRITE_MUSHROOM_4 112, 48 #define SPRITE_MUSHROOM_5 128, 48 #define SPRITE_FLY_1 128, 160 #define SPRITE_FLY_2 128, 176 #define SPRITE_FLY_3 128, 192 #define SPRITE_FLY_4 128, 208 #define SPRITE_FLY_5 128, 224 #define SPRITE_FLY_6 128, 240 #define SPRITE_FROG_1 160, 112 #define SPRITE_FROG_2 160, 144 #define SPRITE_FROG_3 160, 176 #define SPRITE_CRAB_1 160, 208 #define SPRITE_CRAB_2 160, 224 #define SPRITE_CRAB_3 160, 240 #define SPRITE_DRAGON_1 192, 96 #define SPRITE_DRAGON_2 192, 128 #define SPRITE_DRAGON_3 192, 160 #define SPRITE_DRAGON_4 192, 192 #define SPRITE_DRAGON_5 192, 224 // ------------------------------------------------------------------- void Spider::act(unsigned long pad) { if (dying) dead = true; else { if (bottom) { direction = -direction; setSpeedX(direction*480); setSpeedY(-1048); } } return; } void Spider::draw(GsOT *ot) { step++; if (step > 25) step = 0; if (step > 20) change(SPRITE_SPIDER_5); else if (step > 15) change(SPRITE_SPIDER_4); else if (step > 10) change(SPRITE_SPIDER_3); else if (step > 5) change(SPRITE_SPIDER_2); else change(SPRITE_SPIDER_1); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Scorpion::act(unsigned long pad) { if (dying) dead = true; else { time++; if (time > 150) time = 1; if (time > 125) direction = 0; else if (time > 75) direction = -1; else if (time > 50) direction = 0; else direction = 1; setSpeedX(direction*480); } return; } void Scorpion::draw(GsOT *ot) { step++; if (step > 10) step = 1; if (direction > 0) { if (step > 5) change(SPRITE_SCORPION_2); else change(SPRITE_SCORPION_1); } else if (direction < 0) { if (step > 5) change(SPRITE_SCORPION_5); else change(SPRITE_SCORPION_6); } else { if (step > 5) change(SPRITE_SCORPION_3); else change(SPRITE_SCORPION_4); } Enemy::draw(ot); return; } // ------------------------------------------------------------------- void BeetleA::act(unsigned long pad) { if (dying) dead = true; else { time++; if (time > 128) time = 1; if (time > 64) direction = -1; else direction = 1; setSpeedX(direction*256); } return; } void BeetleA::draw(GsOT *ot) { const int speed = 7; step++; if (step > 4*speed) step = 1; if (step > 3*speed) change(SPRITE_BEETLE_A_4); else if (step > 2*speed) change(SPRITE_BEETLE_A_3); else if (step > speed) change(SPRITE_BEETLE_A_2); else change(SPRITE_BEETLE_A_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Duck::act(unsigned long pad) { if (dying) dead = true; else { setSpeedY(0); // Flying means defeating gravity if (left) direction = 1; else if (right) direction = -1; setSpeedX(direction*480); } return; } void Duck::draw(GsOT *ot) { const int speed = 5; step++; if (step > 2*speed) step = 1; if (step > speed) change(SPRITE_DUCK_2); else change(SPRITE_DUCK_1); if (direction > 0) setScale( ONE , ONE); else setScale(-ONE+1, ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Bird::act(unsigned long pad) { if (dying) dead = true; else { time++; if (time > 128) time = 1; if (time > 64) setSpeedY(128); else setSpeedY(-128); if (left) direction = 1; else if (right) direction = -1; setSpeedX(direction*360); } return; } void Bird::draw(GsOT *ot) { const int speed = 5; step++; if (step > 2*speed) step = 1; if (step > speed) change(SPRITE_BIRD_2); else change(SPRITE_BIRD_1); if (direction > 0) setScale( ONE , ONE); else setScale(-ONE+1, ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Snail::act(unsigned long pad) { if (dying) dead = true; else { if (x() < hero->x()) direction = 1; else direction = -1; setSpeedX(direction*96); } return; } void Snail::draw(GsOT *ot) { const int speed = 5; step++; if (step > 2*speed) step = 1; if (step > speed) change(SPRITE_SNAIL_2); else change(SPRITE_SNAIL_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Mosquito::act(unsigned long pad) { if (dying) dead = true; else { time++; if (time > 128) time = 1; if (time > 96) { direction = -1; setSpeedY( 512); } else if (time > 64) { direction = 1; setSpeedY( 0); } else if (time > 32) { direction = -1; setSpeedY(-512); } else { direction = 1; setSpeedY( 0); } setSpeedX(direction*512); } return; } void Mosquito::draw(GsOT *ot) { const int speed = 2; step++; if (step > 6*speed) step = 1; if (step > 5*speed) change(SPRITE_MOSQUITO_6); else if (step > 4*speed) change(SPRITE_MOSQUITO_3); else if (step > 3*speed) change(SPRITE_MOSQUITO_4); else if (step > 2*speed) change(SPRITE_MOSQUITO_3); else if (step > speed) change(SPRITE_MOSQUITO_2); else change(SPRITE_MOSQUITO_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Libelle::act(unsigned long pad) { if (dying) dead = true; else { time++; if (time > 96) time = 1; if (time > 64) { direction = 1; setSpeedY( 360); } else if (time > 32) { direction = -2; setSpeedY( 0); } else { direction = 1; setSpeedY(-360); } setSpeedX(direction*240); } return; } void Libelle::draw(GsOT *ot) { const int speed = 4; step++; if (step > 4*speed) step = 1; if (step > 3*speed) change(SPRITE_LIBELLE_4); else if (step > 2*speed) change(SPRITE_LIBELLE_3); else if (step > speed) change(SPRITE_LIBELLE_2); else change(SPRITE_LIBELLE_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void BeetleB::act(unsigned long pad) { if (dying) dead = true; else { time++; if (time > 96) time = 1; if (left) { direction = 1; time = 1; } else if (right) { direction = -1; time = 1; } else { if (time == 96) { if (x() < hero->x()) direction = 2; else direction = -2; } } setSpeedX(direction*96); } return; } void BeetleB::draw(GsOT *ot) { const int speed = 5; step++; if (step > 4*speed) step = 1; if (step > 3*speed) change(SPRITE_BEETLE_B_4); else if (step > 2*speed) change(SPRITE_BEETLE_B_3); else if (step > speed) change(SPRITE_BEETLE_B_2); else change(SPRITE_BEETLE_B_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void BeetleC::act(unsigned long pad) { if (dying) dead = true; else { time++; if (time > 96) time = 1; if (left) { direction = 1; time = 1; } else if (right) { direction = -1; time = 1; } else { if (time == 96) { if (x() < hero->x()) direction = -2; else direction = 2; } } setSpeedX(direction*96); } return; } void BeetleC::draw(GsOT *ot) { const int speed = 5; step++; if (step > 4*speed) step = 1; if (step > 3*speed) change(SPRITE_BEETLE_C_4); else if (step > 2*speed) change(SPRITE_BEETLE_C_3); else if (step > speed) change(SPRITE_BEETLE_C_2); else change(SPRITE_BEETLE_C_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); } // ------------------------------------------------------------------- void AntA::act(unsigned long pad) { if (dying) dead = true; else { time++; if (time > 200) time = 1; if (left) { direction = 1; time = 1; } else if (right) { direction = -1; time = 1; } else { if (time == 200) { direction = -direction; time = (rand() % 175) + 1; } } setSpeedX(direction*192); } return; } void AntA::draw(GsOT *ot) { const int speed = 5; step++; if (step > 4*speed) step = 1; if (step > 3*speed) change(SPRITE_ANT_A_4); else if (step > 2*speed) change(SPRITE_ANT_A_3); else if (step > speed) change(SPRITE_ANT_A_2); else change(SPRITE_ANT_A_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void AntB::act(unsigned long pad) { if (dying) dead = true; else { if (dying) dead = true; else { time++; if (time > 100) time = 1; if (left) { direction = 1; time = 1; } else if (right) { direction = -1; time = 1; } else { if (time == 100) { direction = -direction; time = (rand() % 80) + 1; } } setSpeedX(direction*256); } } return; } void AntB::draw(GsOT *ot) { const int speed = 5; step++; if (step > 4*speed) step = 1; if (step > 3*speed) change(SPRITE_ANT_B_4); else if (step > 2*speed) change(SPRITE_ANT_B_3); else if (step > speed) change(SPRITE_ANT_B_2); else change(SPRITE_ANT_B_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Raupe::act(unsigned long pad) { if (dying) dead = true; else { if (left) direction = 1; else if (right) direction = -1; setSpeedX(direction*32); } return; } void Raupe::draw(GsOT *ot) { const int speed = 8; step++; if (step > 6*speed) step = 1; if (step > 5*speed) change(SPRITE_RAUPE_2); else if (step > 4*speed) change(SPRITE_RAUPE_3); else if (step > 3*speed) change(SPRITE_RAUPE_4); else if (step > 2*speed) change(SPRITE_RAUPE_3); else if (step > speed) change(SPRITE_RAUPE_2); else change(SPRITE_RAUPE_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Mushroom::act(unsigned long pad) { if (dying) dead = true; else { } return; } void Mushroom::draw(GsOT *ot) { const int speed = 20; step++; if (step > 4*speed) step = 1; if (step > 3*speed) change(SPRITE_MUSHROOM_4); else if (step > 2*speed) change(SPRITE_MUSHROOM_3); else if (step > speed) change(SPRITE_MUSHROOM_2); else change(SPRITE_MUSHROOM_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Fly::act(unsigned long pad) { if (dying) dead = true; else { } return; } void Fly::draw(GsOT *ot) { const int speed = 5; step++; if (step > 6*speed) step = 1; if (step > 5*speed) change(SPRITE_FLY_6); else if (step > 4*speed) change(SPRITE_FLY_5); else if (step > 3*speed) change(SPRITE_FLY_4); else if (step > 2*speed) change(SPRITE_FLY_3); else if (step > speed) change(SPRITE_FLY_2); else change(SPRITE_FLY_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Frog::act(unsigned long pad) { if (dying) dead = true; else { } return; } void Frog::draw(GsOT *ot) { const int speed = 10; step++; if (step > 3*speed) step = 1; if (step > 2*speed) change(SPRITE_FROG_3); else if (step > speed) change(SPRITE_FROG_2); else change(SPRITE_FROG_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Crab::act(unsigned long pad) { if (dying) dead = true; else { time++; if (time > 30) time = 1; if (time == 1) { if (x() < hero->x()) direction = 1; else direction = -1; } if (time > 15) { setSpeedX(direction*400); } else { setSpeedX(0); } } return; } void Crab::draw(GsOT *ot) { const int speed = 10; step++; if (step > 3*speed) step = 1; if (step > 2*speed) change(SPRITE_CRAB_3); else if (step > speed) change(SPRITE_CRAB_2); else change(SPRITE_CRAB_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // ------------------------------------------------------------------- void Dragon::act(unsigned long pad) { if (dying) dead = true; else { if (x() < hero->x()) direction = 1; else direction = -1; if (bottom) { if (!(rand() % 16)) setSpeedY(-2200); } time++; if (time > 50) time = 1; if (time == 50) { Bullet *bullet = new Fireball(this); bullet->move(x()+direction*(w()-20)/2, y()); int dx = hero->x() - bullet->x(), dy = hero->y() - bullet->y(); int a = 1024-abs(dx)-abs(dy); bullet->setSpeedX(dx*a/256); bullet->setSpeedY(dy*a/256); level->addBullet(bullet); } } return; } void Dragon::draw(GsOT *ot) { const int speed = 4; step++; if (step > 8*speed) step = 1; if (step > 7*speed) change(SPRITE_DRAGON_2); else if (step > 6*speed) change(SPRITE_DRAGON_3); else if (step > 5*speed) change(SPRITE_DRAGON_4); else if (step > 4*speed) change(SPRITE_DRAGON_5); else if (step > 3*speed) change(SPRITE_DRAGON_4); else if (step > 2*speed) change(SPRITE_DRAGON_3); else if (step > speed) change(SPRITE_DRAGON_2); else change(SPRITE_DRAGON_1); if (direction > 0) setScale(-ONE+1, ONE); else setScale( ONE , ONE); Enemy::draw(ot); return; } // -------------------------------------------------------------------