void MainCharacter::doubleJump(void *userData) { MainCharacter * thisptr = (MainCharacter*) userData; if (thisptr->getState() == JUMP_STARTING) { thisptr->setFrameLoop(ANIM_FRONTFLIP); thisptr->playSoundEffect(Sounds::JUMP); thisptr->setState(DOUBLE_JUMPING); } }
void Enemy::update() { MainCharacter* character = _level->getMainCharacter(); Board* board = _level->getBoard(); vector3df characterPosition = board->getPosition( character->getPosition()); vector3df enemyPosition = board->getPosition(getPosition()); if (characterPosition.getDistanceFrom( enemyPosition) < board->getMinimalDistance()) character->injure(); Movable::update(); }
void MainCharacter::spin(void *userData) { MainCharacter * thisptr = (MainCharacter*) userData; if (thisptr->getState() != DEAD && thisptr->getState() != DYING && thisptr->getState() != JUMP_STARTING && thisptr->getState() != JUMP_ENDING && thisptr->getState() != DOUBLE_JUMPING && thisptr->getState() != ATTACK_STARTING && thisptr->getState() != ATTACK_ENDING) { thisptr->setFrameLoop(ANIM_SPIN); thisptr->playSoundEffect(Sounds::SPIN); thisptr->setAnimationSpeed(thisptr->getEquippedWeapon()->getAttackSpeed()); thisptr->setState(ATTACK_STARTING); } }
sf::Vector2f Zombie::think(MainCharacter& main) { if (m_state == charState::Dead) return sf::Vector2f(0, 0); //if (!getFOV().getGlobalBounds().intersects(main.getSprite().getGlobalBounds())) if (!getFOV().getGlobalBounds().contains(main.getPosition())) { if (m_targetChange > m_targetNext) { m_target.y = position.y - 250.0f + (rand() % 500); m_target.x = position.x - 250.0f + (rand() % 500); //target = sf::Vector2f(500.0f, 500.0f); m_targetChange = 0; m_targetNext = 1000 + (rand() % 2000); } m_targetChange += 1.0f; //return normalize(target); sf::Vector2f diff = m_target - position; if (diff.x > -5 && diff.y > -5 && diff.x < 5 && diff.y < 5) return sf::Vector2f(0, 0); m_hasTracked = false; } else { sf::Vector2f distvec = position - main.getPosition(); float dist = sqrtf(powf(distvec.x, 2.0f) + powf(distvec.y, 2.0f)); if (main.getFlashlightSwitch() || m_hasTracked || dist < 100.0f) { if (m_hasTracked == false) { scream.setPosition(position.x, position.y, 0); scream.play(); } m_hasTracked = true; m_target = main.getPosition(); } } sf::Vector2f tmp = normalize(m_target - this->getPosition()); //this->setRotation((atan2f(tmp.y, tmp.x) * 180 / 3.1415f) - 90.0f); return tmp; }
void MainCharacter::kick(void * userData) { MainCharacter * thisptr = (MainCharacter*) userData; if (thisptr->getState() != DEAD && thisptr->getState() != DYING && thisptr->getState() != JUMP_STARTING && thisptr->getState() != JUMP_ENDING && thisptr->getState() != DOUBLE_JUMPING && thisptr->getState() != ATTACK_STARTING && thisptr->getState() != ATTACK_ENDING) { thisptr->setFrameLoop(ANIM_KICK); thisptr->playSoundEffect(Sounds::KICK); thisptr->setState(ATTACK_STARTING); } }
void MainCharacter::crouch(void *userData) { MainCharacter * thisptr = (MainCharacter*) userData; if (thisptr->getState() != DEAD && thisptr->getState() != DYING && thisptr->getState() != JUMP_STARTING && thisptr->getState() != JUMP_ENDING && thisptr->getState() != DOUBLE_JUMPING && thisptr->getState() != ATTACK_STARTING && thisptr->getState() != ATTACK_ENDING && thisptr->getState() != CROUCHING) { thisptr->setFrameLoop(ANIM_CROUCH); thisptr->setLoopMode(false); thisptr->setState(CROUCHING); } }
void MainCharacter::block(void * userData) { MainCharacter * thisptr = (MainCharacter*) userData; if (thisptr->getState() != BLOCKING && thisptr->getState() != DEAD && thisptr->getState() != DYING && thisptr->getState() != JUMP_STARTING && thisptr->getState() != JUMP_ENDING && thisptr->getState() != ATTACK_STARTING && thisptr->getState() != ATTACK_ENDING) { thisptr->setFrameLoop(ANIM_BLOCK); thisptr->setState(BLOCKING); } }
void MainCharacter::getUp(void *userData) { MainCharacter * thisptr = (MainCharacter*) userData; if (thisptr->getState() != DEAD && thisptr->getState() != DYING && thisptr->getState() != JUMP_STARTING && thisptr->getState() != JUMP_ENDING && thisptr->getState() != DOUBLE_JUMPING && thisptr->getState() != ATTACK_STARTING && thisptr->getState() != ATTACK_ENDING) { thisptr->setFrameLoop(ANIM_GET_UP); thisptr->setState(STOPPING); } }
void MainCharacter::slash(void * userData) { MainCharacter * thisptr = (MainCharacter*) userData; if (thisptr->getState() != DEAD && thisptr->getState() != DYING && thisptr->getState() != JUMP_STARTING && thisptr->getState() != JUMP_ENDING && thisptr->getState() != DOUBLE_JUMPING && thisptr->getState() != ATTACK_STARTING && thisptr->getState() != ATTACK_ENDING) { thisptr->setFrameLoop(ANIM_SLASH); if (randomBetween(0,100) > 50) thisptr->playSoundEffect(Sounds::SWING1); else thisptr->playSoundEffect(Sounds::SWING2); thisptr->setAnimationSpeed(thisptr->getEquippedWeapon()->getAttackSpeed()); thisptr->setState(ATTACK_STARTING); } }
void MainCharacter::jump(void * userData) { MainCharacter * thisptr = (MainCharacter*) userData; if (thisptr->getState() == JUMP_STARTING) { doubleJump(thisptr); } if (thisptr->getState() != DEAD && thisptr->getState() != DYING && thisptr->getState() != JUMP_STARTING && thisptr->getState() != JUMP_ENDING && thisptr->getState() != DOUBLE_JUMPING && thisptr->getState() != ATTACK_STARTING && thisptr->getState() != ATTACK_ENDING) { // Disable gravity list<ISceneNodeAnimator*>::ConstIterator animatorIt = thisptr->getAnimators().getLast(); ((ISceneNodeAnimatorCollisionResponse*) *animatorIt)->setGravity(vector3df(0,0,0)); cout << "NAO CHEGUEI A SETAR"<<endl; thisptr->setAnimationSpeed(5.0 / (thisptr->getJumpHeight() / (float)JUMP_ACCELERATION) ); thisptr->setFrameLoop(ANIM_JUMP_START); thisptr->playSoundEffect(Sounds::JUMP); thisptr->setState(JUMP_STARTING); } }
void MainCharacter::stop(void *userData, vector2df direction) { MainCharacter * thisptr = (MainCharacter*) userData; thisptr->setFrameLoop(ANIM_IDLE); thisptr->setState(STOPPING); }