void QSequentialAnimationGroupJob::rewindForwards(const AnimationIndex &newAnimationIndex)
{
    if (m_previousLoop > m_currentLoop) {
        // we need to fast rewind to the beginning
        for (QAbstractAnimationJob *anim = m_currentAnimation; anim; anim = anim->previousSibling()) {
            setCurrentAnimation(anim, true);
            RETURN_IF_DELETED(anim->setCurrentTime(0));
        }
        // this will make sure the current animation is reset to the end
        if (lastChild() && !lastChild()->previousSibling())   //count == 1
            // we need to force activation because setCurrentAnimation will have no effect
            activateCurrentAnimation();
        else {
            setCurrentAnimation(lastChild(), true);
        }
    }

    // and now we need to fast rewind from the current position to
    for (QAbstractAnimationJob *anim = m_currentAnimation; anim && anim != newAnimationIndex.animation; anim = anim->previousSibling()) {
        setCurrentAnimation(anim, true);
        RETURN_IF_DELETED(anim->setCurrentTime(0));
    }
    // setting the new current animation will happen later
}
示例#2
0
void FireRatEnemy::load()
{
	setBoundingBox(sf::FloatRect(0.f, 0.f, 40.f, 30.f));
	setSpriteOffset(sf::Vector2f(-5.f, -20.f));

	Animation walkingAnimation;
	walkingAnimation.setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_firerat));
	walkingAnimation.addFrame(sf::IntRect(0, 0, 50, 50));
	walkingAnimation.addFrame(sf::IntRect(50, 0, 50, 50));
	walkingAnimation.addFrame(sf::IntRect(100, 0, 50, 50));
	walkingAnimation.addFrame(sf::IntRect(50, 0, 50, 50));

	addAnimation(GameObjectState::Walking, walkingAnimation);

	Animation idleAnimation;
	idleAnimation.setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_firerat));
	idleAnimation.addFrame(sf::IntRect(50, 0, 50, 50));
	idleAnimation.addFrame(sf::IntRect(300, 0, 50, 50));

	addAnimation(GameObjectState::Idle, idleAnimation);

	Animation jumpingAnimation;
	jumpingAnimation.setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_firerat));
	jumpingAnimation.addFrame(sf::IntRect(150, 0, 50, 50));

	addAnimation(GameObjectState::Jumping, jumpingAnimation);

	Animation fightingAnimation;
	fightingAnimation.setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_firerat));
	fightingAnimation.addFrame(sf::IntRect(200, 0, 50, 50));
	fightingAnimation.addFrame(sf::IntRect(250, 0, 50, 50));

	addAnimation(GameObjectState::Fighting, fightingAnimation);

	Animation deadAnimation;
	deadAnimation.setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_firerat));
	deadAnimation.addFrame(sf::IntRect(350, 0, 50, 50));

	addAnimation(GameObjectState::Dead, deadAnimation);

	setFrameTime(sf::seconds(0.08f));

	// initial values
	m_state = GameObjectState::Idle;
	m_isFacingRight = true;
	setCurrentAnimation(getAnimation(m_state), !m_isFacingRight);
	playCurrentAnimation(true);
}
示例#3
0
Robert::Robert(double x, double y) : PhysicsSprite("images/spr_robert.png")
{
	setPosition(x, y);

	// animations:
	// 0 - standing
	// 1 - walking
	// 2 - attacking
	// 3 - get hit

	// ANIMATION SETUP //
	setNumberOfAnimations(4);
	setSpriteFrameSize(128,128);

	addSpriteAnimRow(0, 0, 256, 128, 0, 1); // standing animation - 0
	setAnimationSpeed(0, 0.1);

	addSpriteAnimRow(1, 0, 384, 128, 0, 4); // walking animation - 1
	setAnimationSpeed(1, 0.25);

	addSpriteAnimRow(2, 0, 128, 128, 0, 5); // attacking animation - 2
	setAnimationSpeed(2, 0.25);
	setAnimationLoop(2, false);

	addSpriteAnimRow(3, 0, 0, 128, 0, 2); // hit animation - 3
	setAnimationSpeed(3, 0.1);
	setAnimationLoop(3, false);

	setCurrentAnimation(0);

	// PHYSICAL PROPERTIES //
	mass = 50;
	airDrag = 0.1;
	groundFriction = 0.75;
	// (airGroundFriction and gravity are left to defaults)

	hitbox = Hitbox(40, 0, 48, 117);
	setCenter(64, 58);

	health = 3;

	// BEHAVIORAL STATE VARIABLE(S) //
	walking = false;
	attacking = false;
	gotHit = false;
	thrown = false;
	willAttack = false;
}
示例#4
0
void FireBasket::load() {
	setBoundingBox(sf::FloatRect(0, 0, 192, 800));

	Animation* idleAnimation = new Animation(sf::seconds(0.08f));
	idleAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_screen_splash_fireanimation));
	for (int i = 0; i < 38; i++) {
		idleAnimation->addFrame(sf::IntRect(192 * i, 0, 192, 800));
	}
	addAnimation(GameObjectState::Idle, idleAnimation);

	// initial values
	setCurrentAnimation(getAnimation(GameObjectState::Idle), false);
	playCurrentAnimation(true);

	m_animatedSprite.setScale(0.86f, 0.86f);
}
示例#5
0
void BossSpider::onAnimationComplete(std::string anim) {
	//cout << "BossSpider::onAnimationComplete(\"" << anim << "\")\n";
	if(anim == "die") {
		float pos_x = body->p.x;
		float pos_y = body->p.y;
		destroy();
		CollectibleEnergyBall * ball = NULL;
		ball = new CollectibleEnergyBall(pos_x-32, pos_y-16);
		ball = new CollectibleEnergyBall(pos_x, pos_y-16);
		ball = new CollectibleEnergyBall(pos_x-32, pos_y-48);
		ball = new CollectibleEnergyBall(pos_x, pos_y-48);
	}

	if(anim == "hurt") {
		setCurrentAnimation("walk");
	}
}
示例#6
0
文件: Float.cpp 项目: genail/gear
void FloatImpl::update(unsigned p_timeElapsed)
{
	m_timeFromStart += p_timeElapsed;

	// look for the next animation
	if (!m_animMap.empty()) {
		FloatImpl::TAnimationMap::iterator itor;
		for (itor = m_animMap.begin(); itor != m_animMap.end();) {
			if (itor->first <= m_timeFromStart) {
				setCurrentAnimation(itor->second);
				m_animMap.erase(itor++);
			} else {
				++itor;
			}
		}
	}

	if (m_currAnim != NULL) {

		if (m_currAnim->m_etime <= m_timeFromStart) {
			// animation should end now
			m_value = m_currAnim->m_to;

			delete m_currAnim;
			m_currAnim = NULL;

		} else {

			// make progress
			const float progress =
					(m_timeFromStart - m_currAnim->m_stime) /
					static_cast<float> (
							m_currAnim->m_etime - m_currAnim->m_stime
					);

			// this should be value between 0.0 and 1.0
			G_ASSERT(progress >= 0.0f && progress <= 1.0f);

			m_value = m_currAnim->m_easing->ease(
					m_currAnim->m_from, m_currAnim->m_to,
					progress
			);

		}
	}
}
示例#7
0
EnemyCrawler::EnemyCrawler(float x, float y)
:EnemyPatroller(x, y, 40.0f, 16.0f)
{
	setImage("crawler.png");
	walk_speed = 70.f;
	shape->u = 0.1f;

	dying = false;
	life = 2;

	setDrawOffset(33, 26);
	setFrameSize(64, 32);

	Animation * tmp;
	actorName = "Crawler";
	
	//pick a random death sound
	int sound_num = rand() % 19;
	sound_num += 1;
	std::string s;
	std::stringstream out;
	out << sound_num;
	s = out.str();

	std::string sound_file = s + "-BugSplat.ogg";
	//cout << sound_file;
	fireSound = soundCache[sound_file];
	facing_direction = Facing::Left;

	tmp = addAnimation("walk");
	tmp->addFrame(2, .2f);
	tmp->addFrame(3, .2f);
	tmp->setDoLoop(true);

	tmp = addAnimation("die");
	tmp->addFrame(8, .07f);
	tmp->addFrame(7, .07f);
	tmp->addFrame(6, .07f);
	tmp->addFrame(5, .07f);

	tmp = addAnimation("hurt");
	tmp->addFrame(4, 0.07f);

	setCurrentAnimation("walk");
}
示例#8
0
std::shared_ptr<AnimatedSprite> RenderSystem::getAnimatedSprite(entityx::Entity entity)
{
    auto render = entityx::Entity(entity).component<RenderComponent>();
    auto templateComp = entityx::Entity(entity).component<TemplateComponent>();

    if(m_animatedSprites.count(entity) == 0)
    {
        //Create the animated sprite if it doesn't exist
        auto animatedSprite = std::make_shared<AnimatedSprite>(
            m_texturesManager.requestResource(templateComp->assetsPath + "/" + render->textureName),
            render->animations
        );
        animatedSprite->setCurrentAnimation(render->currentAnimation);
        m_animatedSprites[entity] = animatedSprite;
    }

    return m_animatedSprites[entity];
}
void AureolaSpell::load(const SpellData& bean, LevelMovableGameObject* mob, const sf::Vector2f& target) {
    setSpriteOffset(sf::Vector2f(-10.f, -10.f));

    Animation* spellAnimation = new Animation(sf::seconds(0.3f));
    spellAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_spell_aureola));
    spellAnimation->addFrame(sf::IntRect(0, 0, 40, 40));
    spellAnimation->addFrame(sf::IntRect(40, 0, 40, 40));

    addAnimation(GameObjectState::Idle, spellAnimation);

    // initial values
    setCurrentAnimation(getAnimation(GameObjectState::Idle), false);
    playCurrentAnimation(true);

    m_rangeLeft = bean.range;

    Spell::load(bean, mob, target);
}
示例#10
0
void FireBallSpell::load(const SpellData& data, LevelMovableGameObject* mob, const sf::Vector2f& target) {
	setSpriteOffset(sf::Vector2f(-20.f, -20.f));

	Animation* spellAnimation = new Animation();
	spellAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_spell_fireball));
	for (int i = 0; i < 4; ++i) {
		spellAnimation->addFrame(sf::IntRect(i * 50, data.skinNr * 50, 50, 50));
	}

	addAnimation(GameObjectState::Idle, spellAnimation);

	// initial values
	setCurrentAnimation(getAnimation(GameObjectState::Idle), false);
	playCurrentAnimation(true);

	Spell::load(data, mob, target);
	g_resourceManager->playSound(m_sound, ResourceID::Sound_spell_fireball);
}
示例#11
0
void LeapOfFaithSpell::update(const sf::Time& frameTime) {
	if (m_isFacingRight != m_mob->isFacingRight()) {
		m_isFacingRight = m_mob->isFacingRight();
		setCurrentAnimation(getAnimation(GameObjectState::Idle), !m_isFacingRight);
	}

	sf::Vector2f nextPosition;
	calculatePositionAccordingToMob(nextPosition);
	setPosition(nextPosition);

	MovableGameObject::update(frameTime);

	updateTime(m_data.activeDuration, frameTime);
	if (m_data.activeDuration == sf::Time::Zero) {
		setDisposed();
	}
	m_ps->update(frameTime);
}
示例#12
0
CollectibleEnergyBall::CollectibleEnergyBall(double x, double y, int expValue)
: Collectible(x, y, 32.0f, 32.0f) {
	actorName = "EnergyBall";
	this->setImage("energyball.png");
	setDrawOffset(16, 16);
	setFrameSize(32, 32);
	experienceValue = expValue;

	Animation * tmp;
	tmp = addAnimation("anim");
	tmp->addFrame(0, .2f);
	tmp->addFrame(1, .2f);
	tmp->addFrame(2, .2f);
	tmp->addFrame(3, .2f);
	tmp->setDoLoop(true);
	setCurrentAnimation("anim");
	shape->collision_type = PhysicsType::Item;
	setShapeLayers(PhysicsLayer::Player);
}
示例#13
0
void FearSpell::load(const SpellBean& bean, LevelMovableGameObject* mob, const sf::Vector2f& target)
{
	setSpriteOffset(sf::Vector2f(-10.f, -10.f));

	Animation spellAnimation;
	spellAnimation.setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_spell_fear));
	spellAnimation.addFrame(sf::IntRect(0, 0, 30, 30));
	spellAnimation.addFrame(sf::IntRect(30, 0, 30, 30));

	addAnimation(GameObjectState::Idle, spellAnimation);

	setFrameTime(sf::seconds(0.1f));

	// initial values
	setCurrentAnimation(getAnimation(GameObjectState::Idle), false);
	playCurrentAnimation(true);

	Spell::load(bean, mob, target);
}
示例#14
0
PlayerBullet::PlayerBullet(float x, float y, int facing, float angleVariation, float lifetime):
AnimatedActor(x, y, 15.0f, 7.0f)
{
	this->setImage("xeon-bullet.png");
	this->lifetime = lifetime;
	bulletTime = 0;

	facing_direction = facing;

	float speed = 500.f;

	float angle = ((facing_direction == Facing::Right) ? 90 : -90) + (rand() % 200 - 100) * angleVariation/100;
	float speed_x = (int)(0.5f + sin(angle * 3.14159/180.0) * speed);
	float speed_y = (int)(0.5f + cos(angle * 3.14159/180.0) * speed);
	
	body->v.x = speed_x;
	body->v.y = speed_y;
	body->a = deg2rad(angle - 90);
	
	setVelocityFunc(no_gravity);
	
	// Put it in the PLayerBullets group so it doesn't collide with other PlayerBullets
	shape->group = PhysicsGroup::PlayerBullets;
	shape->layers = PhysicsLayer::Map|PhysicsLayer::PlayerBullet;
	shape->collision_type = PhysicsType::PlayerBullet;
	
	setDrawOffset(8, 13);
	setFrameSize(16, 16);
	damage = 1;

	Animation * tmp;

	tmp = addAnimation("bullet");
	tmp->addFrame(0, .1f);
	tmp->addFrame(1, .1f);
	tmp->addFrame(2, .1f);
	tmp->addFrame(3, .1f);
	tmp->addFrame(4, .1f);
	tmp->setDoLoop(true);

	setCurrentAnimation("bullet");
}
示例#15
0
BoxBot::BoxBot(double x, double y) : PhysicsSprite("images/spr_boxbot.png")
{
	setPosition(x, y);

	// animations:
	// 0 - standing
	// 1 - walking
	// 2 - attacking
	// 3 - get hit

	// ANIMATION SETUP //
	setNumberOfAnimations(4);
	setSpriteFrameSize(128,128);

	addSpriteAnimRow(0, 0, 0, 128, 0, 1); // standing animation - 0
	setAnimationSpeed(0, 0.1);

	addSpriteAnimRow(1, 0, 384, 128, 0, 2); // walking animation - 1
	setAnimationSpeed(1, 0.1);

	addSpriteAnimRow(2, 0, 128, 128, 0, 7); // attacking animation - 2
	setAnimationSpeed(2, 0.25);
	setAnimationLoop(2, false);

	addSpriteAnimRow(3, 0, 256, 128, 0, 2); // hit animation - 3
	setAnimationSpeed(3, 0.1);
	setAnimationLoop(3, false);

	setCurrentAnimation(1);

	// PHYSICAL PROPERTIES //
	mass = 50;
	airDrag = 0.1;
	groundFriction = 0.75;
	// (airGroundFriction and gravity are left to defaults)

	hitbox = Hitbox(44, 0, 30, 110);
	setCenter(35, 54);

	// BEHAVIORAL STATE VARIABLE(S) //
	walking = true;
}
示例#16
0
void ModifierTile::addModifier() {
	m_state = GameObjectState::Active;
	setCurrentAnimation(getAnimation(m_state), false);

	LevelScreen* screen = dynamic_cast<LevelScreen*>(getScreen());

	screen->getCharacterCore()->learnModifier(m_modifier);
	std::string text = g_textProvider->getText("ModifierLearned");
	text.append(": ");
	text.append(g_textProvider->getText(EnumNames::getSpellModifierTypeName(m_modifier.type)));
	text.append(", ");
	text.append(g_textProvider->getText("Level"));
	text.append(" ");
	text.append(std::to_string(m_modifier.level));
	screen->setTooltipText(text, sf::Color::Green, true);

	m_ps->emitRate = 0;

	m_lightObject->setDisposed();
	m_lightObject = nullptr;
}
示例#17
0
void LeapOfFaithSpell::load(const SpellData& bean, LevelMovableGameObject* mob, const sf::Vector2f& target) {
	m_mob = mob;
	Animation* spellAnimation = new Animation();
	spellAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_spell_leapoffaith));
	spellAnimation->addFrame(sf::IntRect(0, 0, 80, 120));

	addAnimation(GameObjectState::Idle, spellAnimation);

	m_isFacingRight = m_mob->isFacingRight();
	setCurrentAnimation(getAnimation(GameObjectState::Idle), !m_isFacingRight);
	playCurrentAnimation(false);
	
	Spell::load(bean, mob, target);
	m_mob->getMovingBehavior()->setGravityScale(m_gravityScale);
	loadParticleSystem();

	LightData lightData(LightData(
		sf::Vector2f(getBoundingBox()->width * 0.5f, getBoundingBox()->height * 0.5f), 
		sf::Vector2f(100.f, 100.f), 0.2f));
	addComponent(new LightComponent(lightData, this));
}
示例#18
0
void ModifierTile::loadAnimation(int skinNr) {
	m_isCollidable = false;
	
	sf::IntRect rect = sf::IntRect((m_modifier.level - 1) * 50, 50, 50, 50);
	m_animatedSprite.setColor(SpellModifier::getSpellModifierColor(m_modifier.type));

	Animation* idleAnimation = new Animation();
	idleAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_gems));
	idleAnimation->addFrame(rect);
	addAnimation(GameObjectState::Idle, idleAnimation);

	Animation* activatedAnimation = new Animation(sf::seconds(10.f));
	activatedAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_gems));
	activatedAnimation->addFrame(sf::IntRect()); // idle
	addAnimation(GameObjectState::Active, activatedAnimation);

	// initial values
	m_state = GameObjectState::Idle;
	setCurrentAnimation(getAnimation(m_state), false);
	playCurrentAnimation(true);
}
void QSequentialAnimationGroupJob::updateCurrentTime(int currentTime)
{
    if (!m_currentAnimation)
        return;

    const QSequentialAnimationGroupJob::AnimationIndex newAnimationIndex = indexForCurrentTime();

    // newAnimationIndex.index is the new current animation
    if (m_previousLoop < m_currentLoop
        || (m_previousLoop == m_currentLoop && m_currentAnimation != newAnimationIndex.animation && newAnimationIndex.afterCurrent)) {
            // advancing with forward direction is the same as rewinding with backwards direction
            RETURN_IF_DELETED(advanceForwards(newAnimationIndex));

    } else if (m_previousLoop > m_currentLoop
        || (m_previousLoop == m_currentLoop && m_currentAnimation != newAnimationIndex.animation && !newAnimationIndex.afterCurrent)) {
            // rewinding with forward direction is the same as advancing with backwards direction
            RETURN_IF_DELETED(rewindForwards(newAnimationIndex));
    }

    RETURN_IF_DELETED(setCurrentAnimation(newAnimationIndex.animation));

    const int newCurrentTime = currentTime - newAnimationIndex.timeOffset;

    if (m_currentAnimation) {
        RETURN_IF_DELETED(m_currentAnimation->setCurrentTime(newCurrentTime));
        if (atEnd()) {
            //we make sure that we don't exceed the duration here
            m_currentTime += m_currentAnimation->currentTime() - newCurrentTime;
            RETURN_IF_DELETED(stop());
        }
    } else {
        //the only case where currentAnimation could be null
        //is when all animations have been removed
        Q_ASSERT(!firstChild());
        m_currentTime = 0;
        RETURN_IF_DELETED(stop());
    }

    m_previousLoop = m_currentLoop;
}
void MY_DemonBoss::die(){
	if(!isDead){
		isDead = true;
		for(auto s : spewers){
			s->eventManager.listeners.at("spewComplete").clear();
		}

		while(enabledSpewers.size() > 0){
			disableSpewer(spewers.at(enabledSpewers.back())->column);
		}
		animationTimeout->stop();
		spewerTimeout->stop();
		setCurrentAnimation("die");

		animationTimeout->eventManager->listeners["complete"].clear();
		animationTimeout->eventManager->addEventListener("complete", [this](sweet::Event * _event){
			active = false;
		});
		animationTimeout->targetSeconds = 1.5f;
		animationTimeout->restart();
	}
}
示例#21
0
Chest::Chest(double x, double y) : PhysicsSprite("images/spr_chest.png")
{
	setPosition(x,y); 

	//animations:
	// 0 - open 
	// 1 - locked
	// 2 - opening

	// ANIMATION SETUP //
	
		setNumberOfAnimations(3);
		setSpriteFrameSize(64, 64);

		//Chest Opening
		addSpriteAnimRow(2, 0, 0, 64, 0, 7);
		setAnimationSpeed(0, 0.25);
		
		//Chest Locked
		addSpriteAnimRow(0, 0, 0, 64, 0, 2); 
		setAnimationSpeed(0, 0.25); 

		//Chest Opened
		addSpriteAnimRow(1, 0, 0, 64, 0, 1); 
		setAnimationSpeed(0, 0.25);

		setCurrentAnimation(0); 

		// PHYSICAL PROPERTIES //
		mass = 1; 

		//Behavioural State
		itemObtained=false; 
		locked=false; 
		opening= false; 
}
示例#22
0
void LevelEquipment::update(const sf::Time& frameTime)
{
	GameObjectState newState = m_mainChar->getState();
	if (newState == GameObjectState::Dead)
	{
		setDisposed();
		return;
	}
	bool newFacingRight = m_mainChar->getIsFacingRight();
	if (m_state != newState || newFacingRight != m_isFacingRight) 
	{
		m_state = newState;
		m_isFacingRight = newFacingRight;
		setCurrentAnimation(getAnimation(m_state), !m_isFacingRight);
	}
	if (m_mainChar->getIsUpsideDown() != m_animatedSprite.isFlippedY())
	{
		m_animatedSprite.setFlippedY(m_mainChar->getIsUpsideDown());
	}
	sf::Vector2f newPosition;
	calculatePositionAccordingToMainChar(newPosition);
	setPosition(newPosition);
	GameObject::update(frameTime);
}
示例#23
0
void Robert::update()
{
	// Is the character on the ground?
	bool grounded = (collide(&world->groups["ground"], 0, -2) != NULL);

	// check if a member of 'ground' who IS NOT the player is beside me, and if so, turn away
	Sprite * s;
	if ((s = collide(&world->groups["ground"], 2, 0)) && !s->inGroup(&world->groups["player"])) flipped = true;
	if ((s = collide(&world->groups["ground"], -2, 0)) && !s->inGroup(&world->groups["player"])) flipped = false;

	// 1/200th of a chance each frame to:
	if (!attacking)
	{
		walking = true;
		setCurrentAnimation(1);
		if (rand() % 200 == 0) {
			if (walking) {
				if (!flipped)
					flipped = true;
				else
					flipped = false;
			}
		}
		if (willAttack)
		{
			if (rand() % 100 == 0) // 1/100th chance of attacking
			{
				// Stops it from walking if it already is
				if (walking)
					walking = false;
				setCurrentAnimation(2);
				setFrame(0); // set animation to the start, as it doesn't loop
				attacking = true;
			}
		}
	}
	
	Sprite * projectile = collide(&world->groups["dboyscryptonite"],0,0);
	if (projectile)
	{
		health--;
		if (!flipped)
			velocity.x -= 10;
		else
			velocity.x += 10;

		if (!attacking)
			setCurrentAnimation(3);

		projectile->kill();
	}

	if (attacking)
	{
		if (animations[currentAnimation]->currentFrame == 5 && !thrown)
		{
			animations[currentAnimation]->nextFrame();
			thrown = true;

			// Create the box projectile
			Sprite * t;
			if (!flipped)
				t = new DBoy_proj(position.x+100, position.y+58, flipped);
			else
				t = new DBoy_proj(position.x-41, position.y+58, flipped);
			world->add(t);
		}
		else if (animations[currentAnimation]->currentFrame == 6)
		{
			setCurrentAnimation(0);
			attacking = false;
			thrown = false;
		}
	}

	if (walking) // If we are walking
	{
		if (flipped)
			contactVelocity.x += 2.5;
		else
			contactVelocity.x -= 2.5;
	}

	// Handles ground friction and acceleration due to movement //
	if (grounded) {
		applyGroundFriction();
	}
	
	if (health <= 0)
	{
		world->game->replacingCurrentWorld(levelList.constructNextLevel());
	}


	if (!willAttack)
	{
		Sprite * s = collide(&world->groups["player"]);
		if (s != NULL && static_cast<Player*>(s)->marbles == 3)
		{
			willAttack = true;
		}
	}

	// Handles air drag //
	applyAirDrag();

	// Accounts for gravity //
	netForce += gravity * mass;

	// Figure out the net acceleration from forces //
	netAcceleration += netForce / mass;

	// Move the sprite, checking for collisions //
	Vector2D delta = velocity + netAcceleration * 0.5;

	// Move, stopping upon collision with ground. Set velocity to zero when colliding.
	if (moveCollideX(delta.x, &world->groups["ground"])) velocity.x = 0;
	if (moveCollideY(delta.y, &world->groups["ground"])) velocity.y = 0;

	// update velocity to reflect acceleration //
	velocity += netAcceleration;

	// reset netForce, netAcceleration, and possibly other things for the next timestep (so they can be modified externally, if need be)
	resetPhysicsVars();
}
示例#24
0
void BoxBot::update()
{
	// Is the character on the ground?
	bool grounded = (collide(&world->groups["ground"], 0, -2) != NULL);

	if (collide(&world->groups["player"], 0, 2)) // If the player is on top of me,
	{
		walking = false; // stop
		setCurrentAnimation(0); // and Stand.
	}
	else // If not:
	{
		// check if a member of 'ground' who IS NOT thje player is beside me, and if so, turn away
		Sprite * s;
		if ((s = collide(&world->groups["ground"], 2, 0)) && !s->inGroup(&world->groups["player"])) flipped = true;
		if ((s = collide(&world->groups["ground"], -2, 0)) && !s->inGroup(&world->groups["player"])) flipped = false;

		
	}

	if (walking) // If we are walking:
	{
		if (flipped)	// and facing left (the image faces right)
			contactVelocity.x += 1.5; // move feet right (thus pushing self left);
		else			// and facing right
			contactVelocity.x -= 1.5; // move feet left (thus pushing self right);
	}

	// Handles ground friction and acceleration due to movement //
	if (grounded) {
		applyGroundFriction();
	}

	// Handles air drag //
	applyAirDrag();

	// Accounts for gravity //
	netForce += gravity * mass;

	// Figure out the net acceleration from forces //
	netAcceleration += netForce / mass;

	// Move the sprite, checking for collisions //
	Vector2D delta = velocity + netAcceleration * 0.5;

	// Push the player if moving into him
	Sprite * player = moveCollideX(delta.x, &world->groups["player"]);
	if (player) {
		double oldPPosX = player->position.x;
		player->moveCollideX(delta.x, &world->groups["ground"]);
		if (oldPPosX == player->position.x && rand() % 200 == 0) flipped = !flipped;
	}

	// Move, stopping upon collision with ground. Set velocity to zero when colliding.
	if (moveCollideX(delta.x, &world->groups["ground"])) velocity.x = 0;
	if (moveCollideY(delta.y, &world->groups["ground"])) velocity.y = 0;

	// update velocity to reflect acceleration //
	velocity += netAcceleration;

	// reset netForce, netAcceleration, and possibly other things for the next timestep (so they can be modified externally, if need be)
	resetPhysicsVars();
}
示例#25
0
	bool ModelInstance::setModel(const char* modelName,ModelNode *pNode)
	{
		IModelManager *pModelManager = getRenderEngine()->getModelManager();
		IModel *pModel = pModelManager->loadModel(modelName);
		if(!pModel)return false;

		m_pModel = pModel;
		m_pNode = pNode;

		//设置buffer		
		m_pIB = m_pModel->getIndexBuffer();
		m_pVBTexcoord = m_pModel->getTexcoordBuffer();
		m_pVBBlendWeight = m_pModel->getBlendWeightBuffer();
		m_pBlendShaderProgram = m_pModel->getBlendShaderProgram();//需要再构造SubModelInstance前设置
		m_needDrawShadow = m_pModel->needDrawShadow();

		//创建子mesh
		uint numSubModels = m_pModel->getNumSubModels();
		for(uint i = 0;i < numSubModels;i++)
		{
			ISubModel *pSubModel = m_pModel->getSubModel(i);
			SubModelInstance *pSubModelInstance = new SubModelInstance(this,pSubModel, i);
			m_subModels.push_back(pSubModelInstance);
			m_vBlendIndices.push_back( m_pModel->getBlendIndicesBuffer(i));//保存骨骼混合的索引buffer
		}

		//创建骨骼树
		if( !m_skeleton.create(m_pModel->getCoreSkeletion() ) )
		{
			return false;
		}
		//uint numBones = m_pModel->numBones();
		//for(uint i = 0;i < numBones;i++)
		//{
		//	BoneData *pData = m_pModel->getBone(i);
		//	Bone *pBone = m_skeleton.createBone(m_pNode);
		//	loadBone(pBone,pData);
		//}
		////骨骼树形结构构建
		//for(size_t i = 0;i < numBones;i++)
		//{
		//	BoneData *pBone = m_pModel->getBone(i);
		//	if(pBone->parentId != -1)
		//	{
		//		for(size_t j = 0;j < numBones;j++)
		//		{
		//			BoneData *pParent = m_pModel->getBone(j);
		//			if(pBone->parentId == pParent->objectId)
		//			{
		//				m_skeleton.getBone(i)->setParent(m_skeleton.getBone(j));
		//				break;
		//			}
		//		}
		//	}
		//	m_skeleton.getBone(i)->setPrecomputeMatrix(pBone->precomputeMtx);
		//}

		//ParticleSystem
		size_t size = m_pModel->numParticleSystem();
		for(size_t j = 0;j < size;j++)
		{
			ParticleSystem *pParticleSystem = new ParticleSystem;
			pParticleSystem->m_pData = m_pModel->getParticleSystemData(j);
			pParticleSystem->m_pBone = m_skeleton.getBone(pParticleSystem->m_pData->boneObjectId);
			pParticleSystem->m_pNode = m_pNode;
			m_vParticleSystem.push_back(pParticleSystem);
		}

		//RibbonSystem
		size = m_pModel->numRibbonSystem();
		for(size_t j = 0;j < size;j++)
		{
			RibbonSystem *pRibbonSystem = new RibbonSystem;
			pRibbonSystem->m_pData = m_pModel->getRibbonSystemData(j);
			pRibbonSystem->m_pBone = m_skeleton.getBone(pRibbonSystem->m_pData->boneObjectId);
			pRibbonSystem->m_pNode = m_pNode;
			m_vRibbonSystem.push_back(pRibbonSystem);
		}

		//MmParticleSystem
		size = m_pModel->numMmParticleSystem();
		for(size_t j = 0;j < size;j++)
		{
			MmParticleSystem *pMmPs = new MmParticleSystem;
			pMmPs->m_pData = m_pModel->getMmParticleSystem(j);
			pMmPs->m_pNode = m_pNode;
			pMmPs->m_pBone = m_skeleton.getBone(pMmPs->m_pData->bone);
			m_vMmParticleSystem.push_back(pMmPs);
		}

		if(m_pModel->getAnimationCount())
			setCurrentAnimation(pModel->getAnimation(0)->getName());

		return true;
	}
void IFPAnimationViewerWidget::animationActivated(QListWidgetItem* item)
{
	setCurrentAnimation(item->text().toLocal8Bit().constData());
}