Example #1
0
void PlayerObject::move(const Ogre::FrameEvent &evt) {
    Ogre::Vector3 initialPosition = objectNode->getPosition();
    Ogre::Vector3 destination = walkTo;
    Ogre::Real distance;
    Ogre::Real move;

    if (initialPosition != destination) {
        mDirection = destination - initialPosition;
        distance = mDirection.normalise();
        move = mWalkSpeed * evt.timeSinceLastFrame;
        distance -= move;
        rotatePlayer();

        if (distance <= 0.0f) {
            objectNode->setPosition(destination);
            setIdleAnimation();
        } // if
        else {
            objectNode->translate(mDirection * move);
            if (!withinWorld()) {
                objectNode->setPosition(initialPosition);
                walkTo = initialPosition;
                setIdleAnimation();
            } // if
            else {
                setWalkAnimation();
                SoundManager::getInstance().PLAYER_FOOTSTEP_SOUND->stop();
                SoundManager::getInstance().PLAYER_FOOTSTEP_SOUND->play();
            } // else
        } // else
    } // if
} // move
Example #2
0
Player::Player(IrrlichtDevice* irrDevice, ISceneManager* manager, IVideoDriver* videoDriver, Camera* myCamera) : device(irrDevice), smgr(manager), driver(videoDriver), camera(myCamera)
{
	lastTeleport = 0.0f;
	lastPush = 0.0f;
	lastAttack = 0.0f;
	speed = 0.2f;
	health = 100;
	mana = 100;

	mesh = smgr->getMesh("Models/sydney.md2");
	node = smgr->addAnimatedMeshSceneNode(mesh);
	node->setMaterialTexture(0, driver->getTexture("Textures/sydney.bmp"));
	node->setMaterialFlag(EMF_LIGHTING, false);
	node->setPosition(vector3df(600, 60, 600));
	node->setRotation(vector3df(0, -90, 0));
	node->addShadowVolumeSceneNode();

	camera->getNode()->updateAbsolutePosition();
	node->updateAbsolutePosition();

	camera->getNode()->setTarget(node->getAbsolutePosition());

	// Calculating forwardDirection.
	vector3df temp = vector3df(camera->getNode()->getAbsolutePosition().X, (camera->getNode()->getAbsolutePosition().Y) - (node->getAbsolutePosition().Y), camera->getNode()->getAbsolutePosition().Z);
	forwardDirection = node->getAbsolutePosition() - temp;
	forwardDirection.normalize();

	// Initially setting IDLE animation.
	setIdleAnimation();

	// Calculating cameraDistance.
	temp = node->getAbsolutePosition() - (camera->getNode()->getAbsolutePosition());
	cameraDistance = abs(temp.getLength());
}
Example #3
0
void Player::playBall()
{
	 setIdleAnimation("blue");
	 
 	 walkingAnimationDown = new Animation;
    walkingAnimationDown->setSpriteSheet(*playerTexture);
    walkingAnimationDown->addFrame(sf::IntRect(300, 0, 100, 100));
    walkingAnimationDown->addFrame(sf::IntRect(400, 0, 100, 100));
    walkingAnimationDown->addFrame(sf::IntRect(500, 0, 100, 100));

    walkingAnimationLeft = new Animation;
    walkingAnimationLeft->setSpriteSheet(*playerTexture);
    walkingAnimationLeft->addFrame(sf::IntRect(200, 0, 100, 100));
    walkingAnimationLeft->addFrame(sf::IntRect(100, 0, 100, 100));
    walkingAnimationLeft->addFrame(sf::IntRect(0, 0, 100, 100));
    walkingAnimationLeft->addFrame(sf::IntRect(100, 0, 100, 100));
    walkingAnimationLeft->addFrame(sf::IntRect(200, 0, 100, 100));

    walkingAnimationRight = new Animation;
    walkingAnimationRight->setSpriteSheet(*playerTexture);
    walkingAnimationRight->addFrame(sf::IntRect(600, 0, 100, 100));
    walkingAnimationRight->addFrame(sf::IntRect(700, 0, 100, 100));
    walkingAnimationRight->addFrame(sf::IntRect(800, 0, 100, 100));
    walkingAnimationRight->addFrame(sf::IntRect(700, 0, 100, 100));
    walkingAnimationRight->addFrame(sf::IntRect(600, 0, 100, 100));

    walkingAnimationUp = new Animation;
    walkingAnimationUp->setSpriteSheet(*playerTexture);
    walkingAnimationUp->addFrame(sf::IntRect(300, 0, 100, 100));
    walkingAnimationUp->addFrame(sf::IntRect(400, 0, 100, 100));
    walkingAnimationUp->addFrame(sf::IntRect(500, 0, 100, 100));

    currentAnimation = new Animation;
    currentAnimation = this->walkingAnimationDown;

    position = new sf::Vector2f;
    speed = new sf::Vector2f;
    acceleration = new sf::Vector2f;
    this->position->x=resWidth/2;
    this->position->y=resHeight/2;
    this->speed->x=0;
    this->speed->y=0;
}
Example #4
0
void PlayerObject::attack(const Ogre::FrameEvent &evt) {
    if (attacking && mAnimationState->hasEnded()) {
        setIdleAnimation();
        attacking = false;
        
        double dmg;
        Zone *zone = World::getInstance().getCurrentZone();

        for (EntityObject *o : zone->entities) {
            if (ObjectManager::getInstance().canReach(this, o, 1.0f)) {
                dmg = player->calculateHit();
                o->monster->takeDamage(dmg, player);
            } // if
        } // for

        for (DoodadObject *o : zone->doodads) {
            if (ObjectManager::getInstance().canReach(this, o, 0.5f)) {
                dmg = player->calculateHit();
                o->interact();
            } // if
        } // for
    } // if
} // attack