void BatEntity::animate(float delay) { changingDelay -= delay; if (changingDelay < 0.0f) { velocity = Vector2D(creatureSpeed); changingDelay = 0.5f + (float)(rand() % 2500) / 1000.0f; computeFacingDirection(); } if (age < 0.0f) frame = 1; else { switch (facingDirection) { case 2: frame = 0; break; case 4: frame = 2; break; case 6: frame = 4; break; case 8: frame = 6; break; } frame += ((int)(age * 5.0f)) % 2; } EnemyEntity::animate(delay); }
void SnakeEntity::animate(float delay) { if (age > 0.0f && !isAgonising) { sprite.setColor(sf::Color(255,255,255,255)); timer = timer - delay; if (timer <= 0.0f) { timer = 0.8f; if (canWalkTo(game().getPlayerPosition().x, game().getPlayerPosition().y)) { setVelocity(Vector2D(x, y).vectorTo(game().getPlayerPosition(), creatureSpeed )); computeFacingDirection(); } } switch (facingDirection) { case 2: frame = 0; break; case 4: frame = 2; break; case 6: frame = 4; break; case 8: frame = 6; break; } frame += ((int)(age * 3.0f)) % 2; if (snakeType == SnakeTypeBlood) frame += 10; } EnemyEntity::animate(delay); z = y + 15; }
void WitchEntity::collideWithEnnemy(GameEntity* collidingEntity) { EnemyEntity* entity = static_cast<EnemyEntity*>(collidingEntity); if (entity->getMovingStyle() == movWalking) { setVelocity(Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), creatureSpeed )); computeFacingDirection(); } }
void BatEntity::collideWithEnnemy(GameEntity* collidingEntity) { EnemyEntity* entity = static_cast<EnemyEntity*>(collidingEntity); if (entity->getMovingStyle() == movFlying) { setVelocity(Vector2D(entity->getX(), entity->getY()).vectorTo(Vector2D(x, y), BAT_SPEED )); computeFacingDirection(); } }
void BaseCreatureEntity::animateRecoil(float delay) { // recoil if (recoil.active) { recoil.velocity.x *= 0.97f; recoil.velocity.y *= 0.97f; recoil.timer -= delay; if (recoil.timer <= 0.0f) { recoil.active = false; computeFacingDirection(); // TODO ? } } }
SnakeEntity::SnakeEntity(float x, float y, snakeTypeEnum snakeType, bool invocated) : EnemyEntity (ImageManager::getInstance().getImage(IMAGE_SNAKE), x, y) { this->snakeType = snakeType; imagesProLine = 10; this->invocated = invocated; if (snakeType == SnakeTypeNormal) { frame = 0; dyingFrame = 8; deathFrame = FRAME_CORPSE_SNAKE; if (invocated) enemyType = EnemyTypeSnake_invocated; else enemyType = EnemyTypeSnake; hp = SNAKE_HP; creatureSpeed = SNAKE_SPEED; meleeDamages = SNAKE_DAMAGE; meleeType = ShotTypePoison; } else // snake blood { frame = 10; dyingFrame = 18; deathFrame = FRAME_CORPSE_SNAKE_BLOOD; if (invocated) enemyType = EnemyTypeSnakeBlood_invocated; else enemyType = EnemyTypeSnakeBlood; hp = SNAKE_BLOOD_HP; creatureSpeed = SNAKE_BLOOD_SPEED; meleeDamages = SNAKE_BLOOD_DAMAGE; } velocity = Vector2D(creatureSpeed); computeFacingDirection(); bloodColor = BloodRed; shadowFrame = 9; timer = -1.0f; agonizingSound = SOUND_SNAKE_DIE; resistance[ResistancePoison] = ResistanceImmune; }
void WitchEntity::collideMapBottom() { velocity.y = -velocity.y; if (recoil.active) recoil.velocity.y = -recoil.velocity.y; else computeFacingDirection(); }
void WitchEntity::collideMapLeft() { velocity.x = -velocity.x; if (recoil.active) recoil.velocity.x = -recoil.velocity.x; else computeFacingDirection(); }
void SnakeEntity::collideMapRight() { velocity.x = -velocity.x; if (recoil.active) recoil.velocity.x = -recoil.velocity.x; else computeFacingDirection(); }
void SnakeEntity::collideMapTop() { velocity.y = -velocity.y; if (recoil.active) recoil.velocity.y = -recoil.velocity.y; else computeFacingDirection(); }
void FairyEntity::animate(float delay) { z = y + height; if (game().getPlayer()->isEquiped(EQUIP_FAIRY_POWDER)) delay *= 1.75f; if (fireDelay > 0) fireDelay -= delay; float dist2 = (x - parentEntity->getX()) * (x - parentEntity->getX()) + (y - parentEntity->getY()) * (y - parentEntity->getY()); float creatureSpeed = FAIRY_SPEED; if (dist2 > 15000.0f) { float tan = (parentEntity->getX() - x) / (parentEntity->getY() - y); float angle = atan(tan); if (parentEntity->getY() > y) setVelocity(Vector2D(sin(angle) * creatureSpeed, cos(angle) * creatureSpeed)); else setVelocity(Vector2D(-sin(angle) * creatureSpeed, -cos(angle) * creatureSpeed)); viscosity = 1.0f; } else if (dist2 < 50000.0f) { viscosity = 0.96f; } if (velocity.x < 50.0f && velocity.x > -50.0f && velocity.y < 50.0f && velocity.y > -50.0f) { if (x < TILE_WIDTH * 1.3) { velocity.x = creatureSpeed; } else if (x > TILE_WIDTH * (MAP_WIDTH - 1) - TILE_WIDTH * 0.3) { velocity.x = -creatureSpeed; } if (y < TILE_HEIGHT * 1.3) { velocity.y = creatureSpeed; } else if (y > TILE_HEIGHT * (MAP_HEIGHT - 1) - TILE_HEIGHT * 0.3) { velocity.y = -creatureSpeed; } } if (game().getPlayer()->isEquiped(EQUIP_FAIRY_POWDER)) { teleportDelay -= delay; if (teleportDelay <= 0.0f) { teleportDelay = 7.0f + 0.2f * (rand() % 35); SoundManager::getInstance().playSound(SOUND_TELEPORT); for(int i=0; i < 6; i++) { game().generateStar(sf::Color(50, 50, 255, 255), x, y); game().generateStar(sf::Color(200, 200, 255, 255), x, y); } x = TILE_WIDTH + rand() % (TILE_WIDTH * (MAP_WIDTH - 2)); y = TILE_HEIGHT + rand() % (TILE_HEIGHT * (MAP_HEIGHT - 2)); for(int i=0; i < 6; i++) { game().generateStar(sf::Color(50, 50, 255, 255), x, y); game().generateStar(sf::Color(200, 200, 255, 255), x, y); } if (rand() % 60 == 0) game().getPlayer()->castTeleport(); } } checkCollisions(); if (fairyType == FamiliarFairyTarget && !game().getCurrentMap()->isCleared()) tryToFire(); else computeFacingDirection(); isMirroring = false; if (velocity.x * velocity.x + velocity.y * velocity.y > 400) frame = ((int)(age * 24.0f)) % 2; else frame = ((int)(age * 18.0f)) % 2; if (facingDirection == 8) frame += 2; else if (facingDirection == 4) frame += 4; else if (facingDirection == 6) { frame += 4; isMirroring = true; } frame += (int)(fairyType) * 6; SpriteEntity::animate(delay); }
void FairyEntity::tryToFire() { if (x < TILE_WIDTH * 1.3) return; if (y < TILE_HEIGHT * 1.3) return; if (x > TILE_WIDTH * (MAP_WIDTH - 1) - TILE_WIDTH * 0.3) return; if (y > TILE_HEIGHT * (MAP_HEIGHT - 1) - TILE_HEIGHT * 0.3) return; if (fireDelay <= 0.0f) { if (fairyType == FamiliarFairyTarget) { Vector2D target = game().getNearestEnemy(x, y); if (target.x > -1.0f) { BoltEntity* bolt = new BoltEntity(x, y, FAIRY_BOLT_LIFE, shotType, shotLevel); bolt->setDamages(fairyDamages); bolt->setFlying(true); bolt->setVelocity(Vector2D(x, y).vectorTo(target, FAIRY_BOLT_VELOCITY)); SoundManager::getInstance().playSound(SOUND_BLAST_STANDARD); fireDelay = game().getPlayer()->isEquiped(EQUIP_BELT_ADVANCED) ? fairyFireDelay * fireDelayAdvancedMult : fairyFireDelay; if ((target.x - x) * (target.x - x) > (target.y - y) *(target.y - y)) { if (target.x < x) facingDirection = 4; else facingDirection = 6; } else { if (target.y < y) facingDirection = 8; else facingDirection = 2; } } else { computeFacingDirection(); } } } else { if (fairyType == FamiliarFairyTarget) { Vector2D target = game().getNearestEnemy(x, y); if (target.x > -1.0f) { if ((target.x - x) * (target.x - x) > (target.y - y) *(target.y - y)) { if (target.x < x) facingDirection = 4; else facingDirection = 6; } else { if (target.y < y) facingDirection = 8; else facingDirection = 2; } } else computeFacingDirection(); } } }
void FairyEntity::fire(int dir) { if (x < TILE_WIDTH * 1.3) return; if (y < TILE_HEIGHT * 1.3) return; if (x > TILE_WIDTH * (MAP_WIDTH - 1) - TILE_WIDTH * 0.3) return; if (y > TILE_HEIGHT * (MAP_HEIGHT - 1) - TILE_HEIGHT * 0.3) return; if (fireDelay <= 0.0f) { switch (fairyType) { case FamiliarFairyIce: SoundManager::getInstance().playSound(SOUND_BLAST_ICE); break; case FamiliarFairyFire: SoundManager::getInstance().playSound(SOUND_BLAST_FIRE); break; default: SoundManager::getInstance().playSound(SOUND_BLAST_STANDARD); break; } fireDelay = game().getPlayer()->isEquiped(EQUIP_BELT_ADVANCED) ? fairyFireDelay * fireDelayAdvancedMult : fairyFireDelay; float velx = 0.0f; float vely = 0.0f; if (dir == 4) velx = - FAIRY_BOLT_VELOCITY; if (dir == 6) velx = + FAIRY_BOLT_VELOCITY; if (dir == 2) vely = + FAIRY_BOLT_VELOCITY; if (dir == 8) vely = - FAIRY_BOLT_VELOCITY; BoltEntity* bolt = new BoltEntity(x, y, FAIRY_BOLT_LIFE, shotType, shotLevel); bolt->setDamages(fairyDamages); bolt->setVelocity(Vector2D(velx, vely)); bolt->setFlying(true); bolt->setFromPlayer(false); if (fairyType == FamiliarFairyTarget) { Vector2D target = game().getNearestEnemy(x, y); if (target.x > -1.0f) { bolt->setVelocity(Vector2D(x, y).vectorTo(target, FAIRY_BOLT_VELOCITY)); if ((target.x - x) * (target.x - x) > (target.y - y) *(target.y - y)) { if (target.x < x) facingDirection = 4; else facingDirection = 6; } else { if (target.y < y) facingDirection = 8; else facingDirection = 2; } } } } else { if (fairyType == FamiliarFairyTarget) { Vector2D target = game().getNearestEnemy(x, y); if (target.x > -1.0f) { if ((target.x - x) * (target.x - x) > (target.y - y) *(target.y - y)) { if (target.x < x) facingDirection = 4; else facingDirection = 6; } else { if (target.y < y) facingDirection = 8; else facingDirection = 2; } } else computeFacingDirection(); } } }