Player::Player(int id, int x, int y, char orient, char level, std::string team, float speedAnim, int sizeMapX, int sizeMapY, Ogre::ColourValue color, Ogre::SceneManager* sceneManager) { this->id = id; this->x = x; this->y = y; this->xOld = x; this->yOld = y; this->sizeMapX = sizeMapX - 1; this->sizeMapY = sizeMapY - 1; this->orient = 3; this->level = level; this->team = team; this->color = color; this->resources.push_back(0); this->resources.push_back(0); this->resources.push_back(0); this->resources.push_back(0); this->resources.push_back(0); this->resources.push_back(0); this->resources.push_back(0); this->resources.push_back(0); this->resources.push_back(0); this->sceneManager = sceneManager; this->player = sceneManager->createEntity("Player_level1.mesh"); this->player->setMaterialName("Tlevel" + Utils::intToString(level)); anim = this->player->getAnimationState("Walk"); take = this->player->getAnimationState("Take"); dead = this->player->getAnimationState("Dead"); anim->setEnabled(false); take->setEnabled(true); dead->setLoop(false); dead->setEnabled(false); take->setLoop(false); take->setTimePosition(48); dead->setTimePosition(1); anim->setLoop(true); this->speedAnim = speedAnim; /* mat = new Ogre::MaterialPtr; *mat = this->player->getSubEntity(0)->getMaterial(); (*mat)->clone(Utils::intToString(color.r) + Utils::intToString(y) + Utils::intToString(x)); // this->player->setMaterialName(Utils::intToString(color.r) + Utils::intToString(y) + Utils::intToString(x)); this->player->getSubEntity(0)->getMaterial()->setAmbient(0.01, 0.01, 0.01); this->player->getSubEntity(0)->getMaterial()->setDiffuse(color);*/ node = sceneManager->getRootSceneNode()->createChildSceneNode(Ogre::Vector3::ZERO, Ogre::Quaternion::IDENTITY); node->attachObject(this->player); resetO(); this->orient = orient; updateO(); node->scale(0.6f, 0.6f, 0.6f); node->setPosition(Ogre::Vector3(x, -0.3f, y)); }
void Player::move(int x, int y, int o) { this->xOld = this->x; this->yOld = this->y; this->x = x; this->y = y; resetO(); this->orient = o; updateO(); anim->setEnabled(true); //node->setPosition(Ogre::Vector3(x, -0.3f, y)); }
/* Callback function for when an entity is played to the battlefield. */ void dtn::GameClient::onEntityAdded(std::shared_ptr<dtn::Event> e) { EventEntityAdded* cast = dynamic_cast<EventEntityAdded*>(e.get()); std::shared_ptr<dtn::Event> rendAdd(new dtn::EventAddRenderable( dtn::Utilities::LocalBoundsToGlobalPosition(cast->bounds, m_playerID), cast->entityID, cast->renderableID)); std::shared_ptr<dtn::Event> updateLos(new dtn::EventUpdateRenderableLos(cast->entityID, cast->los)); std::shared_ptr<dtn::Event> updateO(new dtn::EventUpdateRenderableOwner(cast->entityID, cast->owner)); std::shared_ptr<dtn::Event> updateTT(new dtn::EventUpdateRenderableTooltip(cast->entityID, cast->tooltip)); dtn::GlobalEventQueue::getInstance()->pushEvent(rendAdd); dtn::GlobalEventQueue::getInstance()->pushEvent(updateLos); dtn::GlobalEventQueue::getInstance()->pushEvent(updateO); dtn::GlobalEventQueue::getInstance()->pushEvent(updateTT); }
/* Callback function for when an entity is drawn to the player's hand. */ void dtn::GameClient::onEntityDrawn(std::shared_ptr<dtn::Event> e) { dtn::EventEntityDrawn* cast = dynamic_cast<EventEntityDrawn*>(e.get()); std::shared_ptr<dtn::Event> rendAdd(new dtn::EventAddRenderable( dtn::Utilities::LocalTileToGlobal(cast->source, m_playerID), cast->entityID, cast->renderableID)); std::shared_ptr<dtn::Event> updateLos(new dtn::EventUpdateRenderableLos(cast->entityID, cast->los)); std::shared_ptr<dtn::Event> updateO(new dtn::EventUpdateRenderableOwner(cast->entityID, cast->owner)); std::shared_ptr<dtn::Event> updateTT(new dtn::EventUpdateRenderableTooltip(cast->entityID, cast->tooltip)); std::shared_ptr<dtn::Event> rendMoved(new dtn::EventMoveRenderable( cast->entityID, dtn::Utilities::LocalTileToGlobal(cast->dest, m_playerID), 400.f)); dtn::GlobalEventQueue::getInstance()->pushEvent(rendAdd); dtn::GlobalEventQueue::getInstance()->pushEvent(updateLos); dtn::GlobalEventQueue::getInstance()->pushEvent(updateO); dtn::GlobalEventQueue::getInstance()->pushEvent(updateTT); dtn::GlobalEventQueue::getInstance()->pushEvent(rendMoved); }