void AvatarEntity::updateKick(const float elapsedTime)
{
	//Si estamos golpeando, lo primero que tenemos que mirar es cuanto tiempo
	//llevamos realizando el golpe. Si se ha acabado ya el golpe volvemos al 
	//estado inactivo
	m_timeout -= elapsedTime;

	if(m_timeout < KICK_TIMEOUT/4*3  && m_timeout > KICK_TIMEOUT/4*2)
	{
		setAnim("kick1");
	}
	else if (m_timeout < KICK_TIMEOUT/4*2  && m_timeout > KICK_TIMEOUT/4)
	{
		setAnim("kick2");
	}
	else if (m_timeout < KICK_TIMEOUT/4  && m_timeout > 0)
	{
		setAnim("kick3");
	}
	else if (m_timeout < 0)
	{
		startIdle(); //vuelta a empezar
	}


}
void Monster::updateAnimState() {
    if (state&STATE_LEFT) {
        setAnim(anim_left);   
    } else {   
        setAnim(anim_right);
    }
}
Beispiel #3
0
void Pterodactyl::run(int x, int y) {

	
	if (this->getPositionX() > x && Xvelocity < cap) {
		Xvelocity += acceleration;
		if (isHostile()) {
			setAnim("pteraANGRYleft");
		}
		else {
			setAnim("pteraleft");
		}
	}
	else if (this->getPositionX() < x && Xvelocity > -cap) {
		Xvelocity -= acceleration;
		if (isHostile()) {
			setAnim("pteraANGRYright");
		}
		else {
			setAnim("pteraright");
		}
	}
	if (this->getPositionY() > y && Yvelocity < cap) {
		Yvelocity += acceleration;
	}
	else if (this->getPositionY() < y && Yvelocity > -cap) {
		Yvelocity -= acceleration;
	}

	this->setPositionX(this->getPositionX() - Xvelocity);
	this->setPositionY(this->getPositionY() - Yvelocity);

}
void AvatarEntity::updateLower(const float elapsedTime)
{
	//Si estamos agachados, comprobamos si se ha dejado de pulsar la tecla abajo
	//Si es asi volvemos al estado idle
	OIS::Keyboard* keyboard = Core::singleton().inputManager().getKeyboard();
	/*if(m_isStandAlone == true || (m_isStandAlone == false && m_isExternal == false && !m_automatic))
	{
		if (! keyboard->isKeyDown(keys[7]))
		{
			if(m_isStandAlone == false)
			{
				std::stringstream ss;
				ss << "loweS" << (int)m_screenPosition[0];
				Core::singleton().networkManager().send(ss.str());
			}
			if(m_lowerSoundid != -1) stopSfxSound(m_lowerSoundid);
			startIdle();
			return;
		}
	}*/

	m_timeout -= elapsedTime;

	if (m_timeout < LOWER_TIMEOUT/2)
	{
		setAnim("lower1");
	}

}
Animable::Animable(Md2Entity *entity, anim_t defaultAnim, int defaultSkin)
    : _skin(defaultSkin)
{
    _entity = new Md2Entity(*entity);
    setAnim(defaultAnim);
    _entity->setSkin(_skin);
}
Beispiel #6
0
Bomb::Bomb(const PointInt &tablePos)
: startTime(SDL_GetTicks()), pos(tablePos), remoteExploded(false)
{
    loadBomb(&bomb);
    x=pos.first*blockWidth;
    y=pos.second*blockHeight;
    setAnim(bomb);
}
void StaticObjectCoinsView::initView(StaticObjectModel* staticObjectModel)
{
	m_staticObjectModel = staticObjectModel;

	//Obtain the atlas key looking up where the mesh is. Could be any mesh.
	m_atlasKey = Core::singleton().textureManager().findAtlas("ccoins");
	addAnim("ccoins", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("ccoins"));
	setAnim("ccoins");
}
void AvatarEntity::startIdle()
{
	//Inicializar el estado inactivo
	m_state = IDLE;
	m_timeout = IDLE_TIMEOUT;
	m_direction = 0;
	setAnim("idle");
	if(m_moveSoundid != -1) stopSfxSound(m_moveSoundid);
}
Beispiel #9
0
void PlayerPawnMap::fixedGridMovement()
{
	if( isNearTile(m_nextTile) )
	{
		if( !m_wantToMove )
		{
			m_speed.set(0, 0);
		}
		else
		{
			// compute next tile depending on facing
			if( m_facing == 'u' && isWalkable(tile().x(), tile().y() - 1) )
			{
				m_nextTile.set( tile().x(), tile().y() - 1 );
				m_speed.set(0, -1);
				setAnim(Assets::instance->playerWalkU);
			}
			else if( m_facing == 'd' && isWalkable(tile().x(), tile().y() + 1) )
			{
				m_nextTile.set( tile().x(), tile().y() + 1 );
				m_speed.set(0, 1);
				setAnim(Assets::instance->playerWalkD);
			}
			else if( m_facing == 'l' && isWalkable(tile().x() - 1, tile().y() ) )
			{
				m_nextTile.set( tile().x() - 1, tile().y() );
				m_speed.set(-1, 0);
				setAnim(Assets::instance->playerWalkL);
			}
			else if( m_facing == 'r' && isWalkable(tile().x() + 1, tile().y() ) )
			{
				m_nextTile.set( tile().x() + 1, tile().y() );
				m_speed.set(1, 0);
				setAnim(Assets::instance->playerWalkR);
			}
			else
			{
				m_speed.set(0,0);
			}
		}
	}

	if( m_speed.x() == 0 && m_speed.y() == 0 )
	{
		switch( m_facing )
		{
		case 'u': setAnim(Assets::instance->playerStandU); break;
		case 'd': setAnim(Assets::instance->playerStandD); break;
		case 'l': setAnim(Assets::instance->playerStandL); break;
		case 'r': setAnim(Assets::instance->playerStandR); break;
		}
	}
}
void AvatarEntity::updateJab(const float elapsedTime)
{
	//Si estamos golpeando, lo primero que tenemos que mirar es cuanto tiempo
	//llevamos realizando el golpe. Si se ha acabado ya el golpe volvemos al 
	//estado inactivo
	m_timeout -= elapsedTime;

	if(m_timeout < JAB_TIMEOUT/3*2  && m_timeout > JAB_TIMEOUT/3)
	{
		setAnim("jab1");
	}
	else if (m_timeout < JAB_TIMEOUT/3  && m_timeout > 0)
	{
		setAnim("jab2");
	}
	else if (m_timeout < 0)
	{
		startIdle();
	}

}
Beispiel #11
0
void Erik::updateAnimState() {
    if (state&STATE_WATER) {
        if (state&STATE_LEFT) {
            if (state&STATE_MLEFT) {
                setAnim(anim_erik_swim_left);
            } else if (state&STATE_MUP) {
                setAnim(anim_erik_swim_up_left);
            //} else if (state&STATE_MDOWN) {
            //    setAnim(anim_erik_swim_down_left);
            } else {
                setAnim(anim_erik_swim_left);
            }
        } else {
            if (state&STATE_MRIGHT) {
                setAnim(anim_erik_swim_right);
            } else if (state&STATE_MUP) {
                setAnim(anim_erik_swim_up_right);
            //} else if (state&STATE_MDOWN) {
            //    setAnim(anim_erik_swim_down_right);
            } else {
                setAnim(anim_erik_swim_right);
            }
        }
    } else {
        Player::updateAnimState();
    }
}
void AvatarEntity::updateIdle(const float elapsedTime)
{
	m_timeout -= elapsedTime;
	
	if(m_timeout < IDLE_TIMEOUT/4*3  && m_timeout > IDLE_TIMEOUT/4*2)
	{
		setAnim("idle1");
	}
	else if (m_timeout < IDLE_TIMEOUT/4*2  && m_timeout > IDLE_TIMEOUT/4)
	{
		setAnim("idle2");
	}
	else if (m_timeout < IDLE_TIMEOUT/4  && m_timeout > 0)
	{
		setAnim("idle3");
	}
	else if (m_timeout < 0)
	{
		startIdle(); //vuelta a empezar
	}

}
void AvatarEntity::startMove()
{
	//Inicializar el estado agachar
	m_state = MOVE;
	m_timeout = MOVE_TIMEOUT;
	setAnim("move");
	m_moveSoundid = playSfxSound("move", m_screenPosition);
	if(m_isStandAlone == false && m_isExternal == false)
	{
		std::stringstream ss;
		ss << "move#" << (int)m_screenPosition[0];
		Core::singleton().networkManager().send(ss.str());
	}
}
void AvatarEntity::startDefense()
{
	//Inicializar el estado agachar
	m_state = DEFENSE;
	setAnim("cover");
	m_timeout = DEFENSE_TIMEOUT;
	//enviar mensaje
	if(m_isStandAlone == false && m_isExternal == false)
	{
		std::stringstream ss;
		ss << "cover" << (int)m_screenPosition[0];
		Core::singleton().networkManager().send(ss.str());
	}
}
void AvatarEntity::startJump()
{
	//Inicializar el estado agachar
	m_state = JUMP;
	m_timeout = JUMP_TIMEOUT;
	setAnim("jump");
	playSfxSound("jump", m_screenPosition);

	//enviar mensaje
	if(m_isStandAlone == false && m_isExternal == false)
	{
		std::stringstream ss;
		ss << "jump#" << (int)m_screenPosition[0];
		Core::singleton().networkManager().send(ss.str());
	}
}
Beispiel #16
0
wp_gren_proj::wp_gren_proj(spriteManager* newsm, Player* p) : massObject(newsm), owner(p)
{
	#ifdef __MDDEBUG
	className = "wp_gren_proj";
	macros::debugMessage(className, "constructor");
	#endif
	gameManager* gm = dynamic_cast<gameManager*>(sm);
	setPallete(gm->pickupSprite.palleteID);
	//GFX warning!
	giveSprite(gm->pickupSprite.spriteData, OBJ_SIZE_16X16, 8, 8, 60);
	setBounds(2, 2, 5, -1);
	setAnim(26, 27, ANIMSPEED);
	setCollision(COL_SOLID);
	setCheckCollision(true);
	setLayer(2);
}
void AvatarEntity::startKick()
{
	//Inicializar el estado golpear. Tenemos que inicializar un contador
	//para saber cuando terminar el golpe
	m_state = KICK;
	m_timeout = KICK_TIMEOUT;
	setAnim("kick");
	playSfxSound("kick", m_screenPosition);

	if(m_isStandAlone == false && m_isExternal == false)
	{
		std::stringstream ss;
		ss << "kick#" << (int)m_screenPosition[0];
		Core::singleton().networkManager().send(ss.str());
	}
}
int MD5Model::loadAnim(const char *filename) {
	// attempt to open file for reading
	std::ifstream fin(filename, std::ifstream::in);

	if (!fin.is_open()) {
		std::string msg = std::string("MD5Model::loadAnim(): unable to open ") +
			std::string(filename) + std::string(" for reading");
		throw Exception(msg);
	}

	// read in file version
	std::string str;
	getNextToken(fin, &str);

	// token must read "MD5Version"
	if (str != "MD5Version")
		throw Exception("MD5Model::loadAnim(): expected 'MD5Version'");

	// get version #
	int ver = readInt(fin);

	// must be version 10
	if (ver != 10)
		throw Exception("MD5Model::loadAnim(): MD5Version must be 10");

	Anim *anim = new Anim;
	if (!anim)
		throw Exception("MD5Model::loadAnim(): could not allocate storage for animation");

	readAnimElements(fin, *anim);

	// close file (should be done by destructor anyway)
	fin.close();

	// add to array of animations
	int animIndex = (int)anims.size();
	anims.push_back(anim);

	// build frames for this animation
	buildFrames(*anim);

	// make this the current animation
	setAnim(animIndex, 0);

	return animIndex;
}
Beispiel #19
0
MD2Model::MD2Model() {
    m_vertices =0;
    m_glcmds =0;
    m_lightnormals =0;
    num_frames =0;
    num_xyz =0;
    num_glcmds =0;
    m_texid =0;
    m_scale =1.0;
    setAnim(0);
    float ambient[4] = {1.0 , 1.0 , 1.0 , 1.0};
    float diffuse[4] = {1.0 , 1.0 , 1.0 , 1.0};
    float specular[4] = {1.0 , 1.0 , 1.0 , 1.0};
    this->setMatAmient(ambient);
    this->setMatDiffuse(diffuse);
    this->setMatSpecular(specular);
    this->setMatShininess(50.0);
}
Beispiel #20
0
wp_boomerang_proj::wp_boomerang_proj(spriteManager* newsm, Player* p, wp_boomerang* w) :
	spriteObject(newsm), weapon(w), owner(p), bReturning(false), returnx(0), returny(0)
{
	#ifdef __MDDEBUG
	className = "wp_boomerang_proj";
	macros::debugMessage(className, "constructor");
	#endif
	gameManager *gm = dynamic_cast<gameManager *>(sm);
	setPallete(gm->pickupSprite.palleteID);
	//GFX warning!
	giveSprite(gm->pickupSprite.spriteData, OBJ_SIZE_16X16, 8, 8, 60);
	setBounds(-2, 3, 3, -2);
	setAnim(20, 23, ANIMSPEED);
	setCollision(COL_SOLID);
	setLayer(2);
	#ifdef __WITHSOUND
	playSound(&gm->boomerangLoop, true);
	#endif
}
void AvatarEntity::updateJump(const float elapsedTime)
{
	//Si estamos golpeando, lo primero que tenemos que mirar es cuanto tiempo
	//llevamos realizando el golpe. Si se ha acabado ya el golpe volvemos al 
	//estado inactivo
	m_timeout -= elapsedTime;

	m_deltaX = m_direction * CELERITY * elapsedTime;
	m_terrainPosition[0] += m_deltaX;

	if(m_timeout < JUMP_TIMEOUT/7*6  && m_timeout > JUMP_TIMEOUT/7*5)
	{
		setAnim("jump1");
	}
	else if(m_timeout < JUMP_TIMEOUT/7*5  && m_timeout > JUMP_TIMEOUT/7*4)
	{
		setAnim("jump2");
	}
	else if(m_timeout < JUMP_TIMEOUT/7*4  && m_timeout > JUMP_TIMEOUT/7*3)
	{
		setAnim("jump3");
	}
	else if(m_timeout < JUMP_TIMEOUT/7*3  && m_timeout > JUMP_TIMEOUT/7*2)
	{
		setAnim("jump4");
	}
	else if(m_timeout < JUMP_TIMEOUT/7*2  && m_timeout > JUMP_TIMEOUT/7)
	{
		setAnim("jump5");
	}
	else if(m_timeout < JUMP_TIMEOUT/7  && m_timeout > 0)
	{
		setAnim("jump6");
	}
	else if (m_timeout < 0)
	{
		if(m_direction == 0)
		{
			startIdle(); //vuelta a empezar
		}
		else
		{
			startMove();
		}
	}


}
SpriteEx::SpriteEx (Game *game, SpriteType st, int x, int y, int _w, int _h, int _subtype) : Sprite (game, x, y)
{
	subtype = _subtype;
	dx = 0;
	dy = 0;
	air = true;
	spriteType = st;
	gravity = (st == ST_HEART || st == ST_HEART2 || st == ST_FOOD || st == ST_DROPZONE);
	ddy = gravity ? GRAVITY_ACC : 0;
	w = _w;
	h = _h;

	switch (spriteType)
	{
	case ST_PLAYER: setAnim(game->anims["raul"]); break;
	case ST_HEART: setAnim(game->anims["hs"]); break;
	case ST_FOOD:
		switch (subtype % 3)
		{
			case 0: setAnim(game->anims["corn"]); break;
			case 1: setAnim(game->anims["choco"]); break;
			case 2: setAnim(game->anims["tortilla"]); break;
		}
		break;
	case ST_ENEMY:
		switch (subtype % 3)
		{
			case 0: setAnim(game->anims["pepper1"]); break;
			case 1: setAnim(game->anims["pepper2"]); break;
			case 2: setAnim(game->anims["pepper3"]); break;
		}
		break;
	case ST_PLATFORM: break;
	case ST_DROPZONE: setAnim(game->anims["offering"]); break;
	case ST_HEART2: setAnim(game->anims["heart"]); break;
	case ST_FOLE: setAnim(game->anims["fole"]); break;
	}

	if (anim != NULL)
	{
		w = anim->sizex;
		h = anim->sizey;
	}

}
void AvatarEntity::updateMove(const float elapsedTime)
{
	m_timeout -= elapsedTime;

	/*if(!m_isExternal && !m_automatic)
	{
		OIS::Keyboard* keyboard = Core::singleton().inputManager().getKeyboard();

		if(keyboard->isKeyDown(keys[2]))
		{
			if(m_isStandAlone == false)
			{
				std::stringstream ss;
				ss << "moveJ" << (int)m_screenPosition[0];
				Core::singleton().networkManager().send(ss.str());
			}
			if(m_moveSoundid != -1) stopSfxSound(m_moveSoundid);
			startJump();
			return;
		}

		if (keyboard->isKeyDown(keys[4]))
		{
			m_direction =-1;
			if(m_isStandAlone == false)
			{
				std::stringstream ss;
				ss << "move-" << (int)m_screenPosition[0];
				Core::singleton().networkManager().send(ss.str());
			}

		}
		else if (keyboard->isKeyDown(keys[6]))
		{
			m_direction = 1;
			if(m_isStandAlone == false)
			{
				std::stringstream ss;
				ss << "move+" << (int)m_screenPosition[0];
				Core::singleton().networkManager().send(ss.str());
			}
		}
		else
		{
			//Core::singleton().soundManager().getChannel(m_moveSoundid)->stop();
			if(m_isStandAlone == false)
			{
				std::stringstream ss;
				ss << "moveS" << (int)m_screenPosition[0];
				Core::singleton().networkManager().send(ss.str());
			}
			//if(m_moveSoundid != -1) stopSfxSound(m_moveSoundid);
			startIdle();
		}
	}

	if(m_automatic && (distanceToEnemy < 100))
	{
		if(!m_engaged)
		{
				startIdle();
				m_engaged = !m_engaged;
		}
	}
	if(m_automatic && (distanceToEnemy > 150))
	{
		m_direction=-1;
	}
	*/
	m_deltaX = m_direction * CELERITY * elapsedTime;
	m_terrainPosition[0] += m_deltaX;

	//if movement proceed with the animations
	if(m_timeout < MOVE_TIMEOUT/5*4  && m_timeout > MOVE_TIMEOUT/5*3)
	{
		setAnim("move1");
	}
	else if (m_timeout < MOVE_TIMEOUT/5*3  && m_timeout > MOVE_TIMEOUT/5*2)
	{
		setAnim("move2");
	}
	else if (m_timeout < MOVE_TIMEOUT/5*2  && m_timeout > MOVE_TIMEOUT/5*1)
	{
		setAnim("move3");
	}
	else if (m_timeout < MOVE_TIMEOUT/5  && m_timeout > 0)
	{
		setAnim("move4");
	}
	else if (m_timeout < 0)
	{
		m_timeout=MOVE_TIMEOUT; //vuelta a empezar con la animacion
		setAnim("move1");
	}	
}
void MoveAnimComponent::update(float timeStep)
{
	if (timeStep > Math::Epsilon)
	{
		// Only calc next anim if LOD is low enough
		if (m_lod < m_LODToStopAnim)
		{
			//calculate translated distance and speed in x,z plane
			Vec3f dist = m_newPos - m_oldPos;
			dist.y = 0;
			float speed = m_speed * dist.length() / timeStep;
			static const float pi3rd = Math::Pi / 3;
		
			//if (m_runAnim)
			{
				// Currently the average speed is only used for the run animation
				m_lastSpeeds[m_currentSpeedIndex] = speed;
				m_currentSpeedIndex = (m_currentSpeedIndex + 1) % SPEED_HISTORY_SIZE;
				m_avgSpeed = 0;
				for (int i = 0; i < SPEED_HISTORY_SIZE; i++)
				{
					m_avgSpeed += m_lastSpeeds[i];
				}
				m_avgSpeed /= SPEED_HISTORY_SIZE;
			}

			// Object is moving
			if( m_avgSpeed >= m_moveThreshold && speed > 0)
			{
				AnimationSetup* nextAnim = 0x0;
				// Direction in radiants = angle of walking direction - (y-rotation of the object + rotation offset)
				float direction = atan2( -dist.x, -dist.z ) - (m_rotation.y + m_rotationOffset);
			
				// Normalize direction angle to [-PI, +PI]
				// To get less if cases
				if( direction > Math::Pi ) 
					direction = direction - Math::TwoPi;
				if( direction < -Math::Pi )
					direction = Math::TwoPi + direction;

				// Find the right move animation to play by the moving direction
				// If the exact animation is not specified, play the one for forward moving
				if (m_moveBackAnim != 0x0 && (direction >= 2*pi3rd || direction <= -2*pi3rd))
				{
					nextAnim = m_moveBackAnim;
				}
				else if (m_moveLeftAnim != 0x0 && (direction > pi3rd && direction < 2*pi3rd))
				{
					nextAnim = m_moveLeftAnim;
				}
				else if (m_moveRightAnim != 0x0 && (direction > -2*pi3rd && direction < -pi3rd))
				{
					nextAnim = m_moveRightAnim;
				}
				else if (m_runAnim != 0 && m_avgSpeed > m_runThreshold)
				{
					nextAnim = m_runAnim;
					// Reduce playback speed for run anim
					speed -= m_runThreshold - m_speed;
					//printf("Running speed: %.5f\n", speed);
				}
				else if (m_moveAnim != 0x0)
				{
					nextAnim = m_moveAnim;
				}
				// Set anim or reset everything if none found (nextAnim == 0x0)
				setAnim(nextAnim);
			}
			// Play idle animation if too slow and one is specified
			else if (m_idleAnimCount > 0)
			{
				// We weren't in idle state before or the animation time for the idle anim has passed
				if(!m_idle || m_idleTime < 0)
				{
					if(!m_randSeed)
					{
						// rand hasn't been seeded yet
						srand( (unsigned int) (100000 / timeStep) );
						m_randSeed = true;
					}
					// Choose and set new random idle animation
					int i = rand() % m_idleAnimCount; 
					setAnim( m_idleAnim[i], true );
				}
				else
				{
					// The current idle animation is still playing
					// So decrement timer
					m_idleTime -= timeStep;
				}
			}
			// We don't have an anim to play, so stop any currently playing 
			else
			{
				setAnim(0x0);
			}

			//update animation speed (only none idle animations)
			if( m_activeAnim != 0x0 && !m_idle)
			{
				GameEvent updateAnim(GameEvent::E_UPDATE_ANIM, &AnimationUpdate(m_activeAnim->JobID, GameEngineAnimParams::Speed, m_activeAnim->Speed * m_avgSpeed, 0), 0);
				if (m_owner->checkEvent(&updateAnim))
					m_owner->executeEvent(&updateAnim);
			}
		}
		// The LOD is above the critical value, so stop all current anims
		else
			setAnim(0x0);
	
		//update position
		m_oldPos = m_newPos;
	}
}
SpriteEx::SpriteEx (Game *game, SpriteType st, int x, int y, int _w, int _h, int _subtype) : Sprite (game, x, y)
{
	subtype = _subtype;
	hp = 0;
	dx = 0;
	dy = 0;
	air = true;
	spriteType = st;
	gravity = true;
	w = _w;
	h = _h;

	switch (spriteType)
	{
	case ST_PLAYER: setAnim(game->anims["Raul"]); break;
	case ST_ENEMY:
		switch (subtype % 4)
		{
			case ELECTRICAT: setAnim(game->anims["Electricat"]); break;
			case SLINKYCAT: setAnim(game->anims["Slinkycat"]); break;
			case SPIDERCAT: setAnim(game->anims["Spidercat"]); break;
			case DRAGONCAT: setAnim(game->anims["Dragoncat"]); break;
		}
		break;
	case ST_BULLET:
		switch (subtype % 4)
		{
			case Bullet::WPN_ROCK: setAnim(game->anims["Rock"]); break;
			case Bullet::WPN_ICE: setAnim(game->anims["Ice"]); break;
			case Bullet::WPN_BAZOOKA: setAnim(game->anims["Bullet"]); break;
			case Bullet::WPN_LASER: setAnim(game->anims["Laser"]); break;
		}
		break;
	case ST_ENEMY_BULLET:
		switch (subtype)
		{
			case EBullet::FIRE: setAnim(game->anims["Fire bubble"]); break;
			case EBullet::ENERGY: setAnim(game->anims["Enemy bullet"]); break;
		}
		break;
	default: /* do nothing */ break;
	}

	if (anim != NULL)
	{
		w = anim->sizex;
		h = anim->sizey;
	}

}
void MoveAnimComponent::loadFromXml(const XMLNode* description)
{
	// Get speed factor to multiply on animation speed
	m_speed = static_cast<float>(atof(description->getAttribute("speed", "1.0"))); 

	// Get animation names
	const char* move = description->getAttribute("moveAnimation", "");
	const char* idle = description->getAttribute("idleAnimation", "");
	const char* idle2 = description->getAttribute("idleAnimation2", "");
	const char* idle3 = description->getAttribute("idleAnimation3", "");
	const char* idle4 = description->getAttribute("idleAnimation4", "");
	const char* idle5 = description->getAttribute("idleAnimation5", "");
	const char* moveBack = description->getAttribute("moveBackAnimation", "");
	const char* moveLeft = description->getAttribute("moveLeftAnimation", "");
	const char* moveRight = description->getAttribute("moveRightAnimation", "");
	const char* run = description->getAttribute("runAnimation", "");

	// Get lod value from which on animation is stopped, but remove listener if not set
	m_LODToStopAnim = static_cast<int>(atoi(description->getAttribute("LODToStopAnim", "9999")));
	if (m_LODToStopAnim == 9999)
		m_owner->removeListener(GameEvent::E_AILOD_CHANGE, this);

	// Rotation offset of 180° is standard, as most characters are modeled looking towards the user from the screen
	// But walking forward is meant to be walking "into" the screen
	m_rotationOffset = degToRad((float) atof(description->getAttribute("rotationOffset", "180")));


	// Play animation on stage 10 to not disturb other animations on this model
	if( _stricmp(move, "") != 0 )
	{
		m_moveAnim = static_cast<AnimationSetup*>(AnimationSetup(move, 10, 0, -1.0f, 1.0f, 0.0f).clone());		
		m_moveAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveAnim->Animation);
	}
	if( _stricmp(moveBack, "") != 0 )
	{
		m_moveBackAnim = static_cast<AnimationSetup*>(AnimationSetup(moveBack, 10, 0, -1.0f, 1.0f, 0.0f).clone());		
		m_moveBackAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveBackAnim->Animation);
	}
	if( _stricmp(moveLeft, "") != 0 )
	{
		m_moveLeftAnim = static_cast<AnimationSetup*>(AnimationSetup(moveLeft, 10, 0, -1.0f, 1.0f, 0.0f).clone());		
		m_moveLeftAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveLeftAnim->Animation);
	}
	if( _stricmp(moveRight, "") != 0 )
	{
		m_moveRightAnim = static_cast<AnimationSetup*>(AnimationSetup(moveRight, 10, 0, -1.0f, 1.0f, 0.0f).clone());		
		m_moveRightAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_moveRightAnim->Animation);
	}

	if( _stricmp(run, "") != 0 )
	{
		m_runAnim = static_cast<AnimationSetup*>(AnimationSetup(run, 10, 0, -1.0f, 1.0f, 0.0f).clone());		
		m_runAnim->Speed = GameEngine::getAnimSpeed(m_owner->worldId(), m_runAnim->Animation);
	}

	// Threshold for the speed from which on the run animation is used,
	// also represents the translation speed at which the setted animation playback speed is applied
	m_runThreshold = static_cast<float>(atof(description->getAttribute("runThreshold", "999")));

	m_moveThreshold = static_cast<float>(atof(description->getAttribute("moveThreshold", "0.0005"))); 
	
	// Idle anims have weight of 0.01, which means that they are suppressed as soon as another animation is playing
	m_idleAnimCount = 0;
	if( _stricmp(idle, "") != 0 )
	{
		m_idleAnim[m_idleAnimCount] = static_cast<AnimationSetup*>(AnimationSetup(idle, 10, 0, -1.0f, 0.01f, 0.0f).clone());
	
		//initially start idle animation
		setAnim(m_idleAnim[m_idleAnimCount], true);
		m_idleAnimCount++;
	}
	if( _stricmp(idle2, "") != 0 )
	{
		m_idleAnim[m_idleAnimCount] = static_cast<AnimationSetup*>(AnimationSetup(idle2, 10, 0, -1.0f, 0.01f, 0.0f).clone());
		m_idleAnimCount++;
	}
	if( _stricmp(idle3, "") != 0 )
	{
		m_idleAnim[m_idleAnimCount] = static_cast<AnimationSetup*>(AnimationSetup(idle3, 10, 0, -1.0f, 0.01f, 0.0f).clone());
		m_idleAnimCount++;
	}
	if( _stricmp(idle4, "") != 0 )
	{
		m_idleAnim[m_idleAnimCount] = static_cast<AnimationSetup*>(AnimationSetup(idle4, 10, 0, -1.0f, 0.01f, 0.0f).clone());
		m_idleAnimCount++;
	}
	if( _stricmp(idle5, "") != 0 )
	{
		m_idleAnim[m_idleAnimCount] = static_cast<AnimationSetup*>(AnimationSetup(idle5, 10, 0, -1.0f, 0.01f, 0.0f).clone());
		m_idleAnimCount++;
	}
}
void EnemyStaticView::initView(AvatarModel* avatarModel)

{	m_avatarModel = avatarModel;

	//Obtain the atlas key looking up where the mesh is. Could be any mesh.
	m_atlasKey = Core::singleton().textureManager().findAtlas("mage-walk-side-0");

	//MOVE

	//set anim for lateral movement
	addAnim("walk-side-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-side-0"));
	addAnim("walk-side-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-side-1"));
	addAnim("walk-side-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-side-2"));
	addAnim("walk-side-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-side-3"));
	
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_MOVE_LEFT, "walk-side-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_MOVE_LEFT, EnemyStaticModel::MOVE_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_MOVE_LEFT, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_MOVE_LEFT, true);
	
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_MOVE_RIGHT, "walk-side-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_MOVE_RIGHT, EnemyStaticModel::MOVE_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_MOVE_RIGHT, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_MOVE_RIGHT, false);

	//anim for lateral and upwards
	addAnim("walk-diago-up-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-diago-up-0"));
	addAnim("walk-diago-up-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-diago-up-1"));
	addAnim("walk-diago-up-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-diago-up-2"));
	addAnim("walk-diago-up-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-diago-up-3"));
	addAnim("walk-diago-up-4", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-diago-up-4"));
	
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP_LEFT, "walk-diago-up-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP_LEFT, EnemyStaticModel::MOVE_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP_LEFT, 5);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP_LEFT, true);

	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP_RIGHT, "walk-diago-up-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP_RIGHT, EnemyStaticModel::MOVE_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP_RIGHT, 5);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP_RIGHT, false);

	//lateral and downwards
	addAnim("walk-diago-down-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-diago-down-0"));
	addAnim("walk-diago-down-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-diago-down-1"));
	addAnim("walk-diago-down-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-diago-down-2"));
	addAnim("walk-diago-down-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-diago-down-3"));
	addAnim("walk-diago-down-4", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-diago-down-4"));
	
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN_LEFT, "walk-diago-down-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN_LEFT, EnemyStaticModel::MOVE_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN_LEFT, 5);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN_LEFT, true);

	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN_RIGHT, "walk-diago-down-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN_RIGHT, EnemyStaticModel::MOVE_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN_RIGHT, 5);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN_RIGHT, false);

	//up
	addAnim("walk-up-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-up-0"));
	addAnim("walk-up-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-up-1"));
	addAnim("walk-up-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-up-2"));
	addAnim("walk-up-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-up-3"));
	addAnim("walk-up-4", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-up-4"));
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP, "walk-up-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP, EnemyStaticModel::MOVE_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP, 5);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_MOVE_UP, false);

	//down
	addAnim("walk-down-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-down-0"));
	addAnim("walk-down-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-down-1"));
	addAnim("walk-down-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-down-2"));
	addAnim("walk-down-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-walk-down-3"));
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN, "walk-down-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN, EnemyStaticModel::MOVE_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_MOVE_DOWN, false);

	//ATTACK

	//set anim for lateral attak
	addAnim("cast-side-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-side-0"));
	addAnim("cast-side-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-side-1"));
	addAnim("cast-side-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-side-2"));
	addAnim("cast-side-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-side-3"));
	
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_LEFT, "cast-side-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_LEFT, EnemyStaticModel::ATTACK_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_LEFT, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_LEFT, true);
	
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_RIGHT, "cast-side-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_RIGHT, EnemyStaticModel::ATTACK_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_RIGHT, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_RIGHT, false);

	//anim for lateral and upwards attack
	addAnim("cast-diago-up-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-diago-up-0"));
	addAnim("cast-diago-up-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-diago-up-1"));
	addAnim("cast-diago-up-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-diago-up-2"));
	addAnim("cast-diago-up-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-diago-up-3"));
	
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP_LEFT, "cast-diago-up-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP_LEFT, EnemyStaticModel::ATTACK_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP_LEFT, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP_LEFT, true);

	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP_RIGHT, "cast-diago-up-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP_RIGHT, EnemyStaticModel::ATTACK_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP_RIGHT, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP_RIGHT, false);

	//lateral and downwards attack
	addAnim("cast-diago-down-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-diago-down-0"));
	addAnim("cast-diago-down-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-diago-down-1"));
	addAnim("cast-diago-down-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-diago-down-2"));
	addAnim("cast-diago-down-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-diago-down-3"));
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN_LEFT, "cast-diago-down-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN_LEFT, EnemyStaticModel::ATTACK_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN_LEFT, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN_LEFT, true);

	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN_RIGHT, "cast-diago-down-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN_RIGHT, EnemyStaticModel::ATTACK_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN_RIGHT, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN_RIGHT, false);

	//upwards attack
	addAnim("cast-up-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-up-0"));
	addAnim("cast-up-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-up-1"));
	addAnim("cast-up-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-up-2"));
	addAnim("cast-up-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-up-3"));
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP, "cast-up-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP, EnemyStaticModel::ATTACK_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_UP, false);

	//down
	addAnim("cast-down-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-down-0"));
	addAnim("cast-down-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-down-1"));
	addAnim("cast-down-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-down-2"));
	addAnim("cast-down-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-cast-down-3"));
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN, "cast-down-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN, EnemyStaticModel::ATTACK_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN, 4);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_ATTACK_DOWN, false);

	//DIE
	addAnim("dead-0", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-dead-0"));
	addAnim("dead-1", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-dead-1"));
	addAnim("dead-2", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-dead-2"));
	addAnim("dead-3", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-dead-3"));
	addAnim("dead-4", Core::singleton().textureManager().getTextureAtlas(m_atlasKey)->mesh("mage-dead-4"));
	setAnimString(AvatarModel::AvatarState::AVATAR_STATE_DIE, "dead-");
	setAnimTimeout(AvatarModel::AvatarState::AVATAR_STATE_DIE, EnemyStaticModel::DIE_TIMEOUT);
	setNumAnim(AvatarModel::AvatarState::AVATAR_STATE_DIE, 5);
	setAnimFlipped(AvatarModel::AvatarState::AVATAR_STATE_DIE, false);

	setAnim("walk-side-0");
	m_avatarModel->setPixelWidth(m_curAnim->width());
	m_avatarModel->setPixelHeight(m_curAnim->height());
	 
}
Beispiel #28
0
MapEntity::MapEntity(Vec2f position, Matrix2Di::SharedPtr map, Animation::SharedPtr anim)
	: m_position(position), m_map(map)
{
	setAnim(anim);
}
void Object::resetAnimState() {
    setAnim(anim_orig);
    animation->setBasePos(&pos);
    animation->runAnim();
}