コード例 #1
0
ファイル: Bee.cpp プロジェクト: TylerSandman/marvin
Bee::Bee(TextureManager &textureManager, b2Body *enemyBody, float moveVelocity, std::vector<sf::Vector2f> waypoints, float steering) :
    Entity(enemyBody),
    mMoveVelocity(moveVelocity),
    mSteering(steering),
    mSeeking(false) {

    sf::Texture &spriteSheet = textureManager.get(TextureID::EnemiesSpriteSheet);
    Animation animation;
    animation.setSpriteSheet(spriteSheet);
    animation.addFrame(sf::IntRect(315, 353, 56, 48));
    animation.addFrame(sf::IntRect(140, 23, 61, 42));
    mAnimation = animation;
    mSprite = AnimatedSprite(sf::seconds(0.15f));
    mSprite.setAnimation(mAnimation);
    sf::FloatRect bounds = mSprite.getLocalBounds();
    mSprite.setOrigin(bounds.width/2, bounds.height/2);
    mCurrentFacingDirection = Entity::FacingDirection::Left;

    if (waypoints.empty())
        mSeeking = true;

    //Position waypoints according to the bee center
    //Rather than absolute top-left coordinates
    else {
        for (auto &waypoint : waypoints) {
            sf::Vector2f platformWaypoint(
                waypoint.x + 35.f,
                waypoint.y + PX_PER_M - bounds.height / 2.f);
            mWaypoints.push_back(platformWaypoint);
        }
        mCurrentWaypoint = mWaypoints.begin();
    }
}
コード例 #2
0
ファイル: FlashSpell.cpp プロジェクト: MORTAL2000/Cendric2
void FlashSpell::load(const SpellData& data, LevelMovableGameObject* mob, const sf::Vector2f& target) {
	setSpriteOffset(sf::Vector2f(-10.f, 0.f));
	m_mob = mob;
	
	Animation* spellAnimation = new Animation(sf::milliseconds(200));
	spellAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_spell_flash));
	spellAnimation->addFrame(sf::IntRect(0, 0, 120, 120));
	spellAnimation->addFrame(sf::IntRect(120, 0, 120, 120));

	addAnimation(GameObjectState::Idle, spellAnimation);

	// initial values
	setCurrentAnimation(getAnimation(GameObjectState::Idle), false);
	playCurrentAnimation(true);
	
	Spell::load(data, mob, target);
	m_isFlashingRight = mob->isFacingRight();
	
	m_flashingTime = FLASHING_TIME;
	m_flashDuration = FLASH_DURATION;

	sf::Vector2f position(m_mob->getPosition());
	position.x += (m_mob->getBoundingBox()->width / 2.f);
	position.y += m_mob->getBoundingBox()->height - 20;
	position.x = m_isFlashingRight ? position.x - data.range : position.x + data.range;
	loadParticleSystem();
	m_posGenerator->center = position;
}
コード例 #3
0
ファイル: UnstableTile.cpp プロジェクト: MORTAL2000/Cendric2
void UnstableTile::loadAnimation(int skinNr) {
	m_isCollidable = true;

	Animation* idleAnimation = new Animation(sf::seconds(10.f));
	idleAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_tile_unstable));
	idleAnimation->addFrame(sf::IntRect(BORDER, BORDER + ((skinNr - 1) * (TILE_SIZE + 2 * BORDER)), TILE_SIZE, TILE_SIZE));

	addAnimation(GameObjectState::Idle, idleAnimation);

	Animation* tremblingAnimation = new Animation(sf::seconds(0.1f));
	tremblingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_tile_unstable));
	tremblingAnimation->addFrame(sf::IntRect(BORDER + 1 * (2 * BORDER + TILE_SIZE), BORDER + ((skinNr - 1) * (TILE_SIZE + 2 * BORDER)), TILE_SIZE, TILE_SIZE));
	tremblingAnimation->addFrame(sf::IntRect(BORDER + 2 * (2 * BORDER + TILE_SIZE), BORDER + ((skinNr - 1) * (TILE_SIZE + 2 * BORDER)), TILE_SIZE, TILE_SIZE));

	addAnimation(GameObjectState::Trembling, tremblingAnimation);

	Animation* crumblingAnimation = new Animation();
	crumblingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_tile_destructible));
	for (int i = 1; i < 5; i++) {
		crumblingAnimation->addFrame(sf::IntRect(
			BORDER + i * (2 * BORDER + TILE_SIZE),
			BORDER,
			TILE_SIZE,
			TILE_SIZE));
	}

	addAnimation(GameObjectState::Crumbling, crumblingAnimation);

	// initial values
	m_state = GameObjectState::Idle;
	setCurrentAnimation(getAnimation(GameObjectState::Idle), false);
	playCurrentAnimation(true);
}
コード例 #4
0
ファイル: pacman.cpp プロジェクト: deipfei/MacPan
pacman::pacman(sf::Texture spr)
{
    //ctor
    xpos = 250;
    ypos = 500;
    xvel = 0;
    yvel = 0;
    text = spr;
    upan.setSpriteSheet(text);
    upan.addFrame(sf::IntRect(0, 0, 25, 25));
    upan.addFrame(sf::IntRect(75, 0, 25, 25));
    downan.setSpriteSheet(text);
    downan.addFrame(sf::IntRect(0, 0, 25, 25));
    downan.addFrame(sf::IntRect(25, 0, 25, 25));
    leftan.setSpriteSheet(text);
    leftan.addFrame(sf::IntRect(0, 0, 25, 25));
    leftan.addFrame(sf::IntRect(100, 0, 25, 25));
    rightan.setSpriteSheet(text);
    rightan.addFrame(sf::IntRect(0, 0, 25, 25));
    rightan.addFrame(sf::IntRect(50, 0, 25, 25));
    currentanim = &leftan;

    anspr = AnimatedSprite(sf::seconds(.2f), false, true);
    anspr.setPosition(sf::Vector2f(xpos, ypos));
    //std::cout << "1 pacman" << std::endl;
    anspr.play(*currentanim);


    //sprite.setPosition(xpos, ypos);
    collision_box = sprite.getGlobalBounds();
    dir = 3;
}
コード例 #5
0
ファイル: TileMap.cpp プロジェクト: StanislavGrinkov/Cendric2
void TileMap::readAnimatedTile(int tileNumber, int layerNr, int i, int j, const WorldData& data) {
	for (auto& tile : data.animatedTiles) {
		if (tile.tileID == tileNumber) {

			AnimatedTile* animatedTile = new AnimatedTile();
			
			Animation* idleAnimation = new Animation(tile.frames.at(0).second);
			idleAnimation->setSpriteSheet(m_tileset);

			for (auto& frame : tile.frames) {
				int frameTileID = frame.first - 1;
				int tu = frameTileID % (m_tileset->getSize().x / (TILE_SIZE + 2 * TILE_BORDER));
				int tv = frameTileID / (m_tileset->getSize().x / (TILE_SIZE + 2 * TILE_BORDER));

				idleAnimation->addFrame(sf::IntRect(
					tu * (TILE_SIZE + 2 * TILE_BORDER) + TILE_BORDER, 
					tv * (TILE_SIZE + 2 * TILE_BORDER) + TILE_BORDER, 
					TILE_SIZE, 
					TILE_SIZE));
			}
			
			animatedTile->addAnimation(GameObjectState::Idle, idleAnimation);

			sf::Vector2f position(i * TILE_SIZE_F, j * TILE_SIZE_F);

			// initial values
			animatedTile->playCurrentAnimation(true);
			animatedTile->setPosition(position);

			m_animatedTiles[layerNr].push_back(animatedTile);
			
			break;
		}
	}
}
コード例 #6
0
ファイル: localplayer.cpp プロジェクト: stevecotton/Aethyra
void LocalPlayer::loadTargetCursor(const std::string &filename,
                                   const int width, const int height,
                                   const bool outRange,
                                   const TargetCursorSize &size)
{
    assert(size > -1);
    assert(size < 3);

    ResourceManager *resman = ResourceManager::getInstance();

    ImageSet *currentImageSet = resman->getImageSet(filename, width, height);
    Animation *anim = new Animation();

    for (unsigned int i = 0; i < currentImageSet->size(); ++i)
    {
        anim->addFrame(currentImageSet->get(i), 75,
                      (16 - (currentImageSet->getWidth() / 2)),
                      (16 - (currentImageSet->getHeight() / 2)));
    }

    SimpleAnimation *currentCursor = new SimpleAnimation(anim);

    const int index = outRange ? 1 : 0;

    mTargetCursorImages[index][size] = currentImageSet;
    mTargetCursor[index][size] = currentCursor;
}
コード例 #7
0
ファイル: SnakeSlime.cpp プロジェクト: TylerSandman/marvin
SnakeSlime::SnakeSlime(TextureManager &textureManager, b2Body *enemyBody) : 
    Entity(enemyBody){

    sf::Texture &spriteSheet = textureManager.get(TextureID::EnemiesSpriteSheet);
    
    Animation wiggleAnimation;
    wiggleAnimation.setSpriteSheet(spriteSheet);
    wiggleAnimation.addFrame(sf::IntRect(424, 187, 53, 147));
    wiggleAnimation.addFrame(sf::IntRect(425, 40, 52, 147));
    mAnimation = wiggleAnimation;

    mSprite = AnimatedSprite(sf::seconds(0.15f));
    mSprite.setAnimation(mAnimation);
    sf::FloatRect bounds = mSprite.getLocalBounds();
    mSprite.setOrigin(bounds.width/2, bounds.height/2);
}
コード例 #8
0
ファイル: Blood.cpp プロジェクト: snosscire/Block-World
	void Blood::initialize(Engine& engine, double x, double y)
	{
		m_jumping = true;
		m_velocityX = engine.getRandomNumber(-Config::BloodMaxSpeedX, Config::BloodMaxSpeedX);
		m_velocityY = engine.getRandomNumber(-Config::BloodMaxSpeedY, Config::BloodMaxSpeedY);
		
		m_movingBehavior = new GibMovingBehavior();
		m_fallingBehavior = new DefaultFallingBehavior();
		m_collidingBehavior = new DefaultCollidingBehavior();
		
		addCollisionRectangle(new Square(x - 1.0, y - 1.0, 2.0, 2.0));
		
		m_sprite = new Sprite();
		
		int type = engine.getRandomNumber(1, 2);
		
		Image* image = NULL;
		switch (type) {
			case 2:          image = engine.loadImage("Resources/Gibs/blood-02.png"); break;
			case 1: default: image = engine.loadImage("Resources/Gibs/blood-01.png"); break;
		}
		
		Animation* defaultAnimation = new Animation();
		defaultAnimation->addFrame(new AnimationFrame(100.0, image));
		
		m_sprite->addAnimation("default", defaultAnimation);
		m_sprite->playAnimation("default");
	}
コード例 #9
0
Animation
ToneAnimationFactoryLoudestSmooth::createToneAnimation(unsigned int nLEDs, const ToneData& toneData)
{
  Animation animation;
  Frame frame(nLEDs);

  for (unsigned int i = 0; i < nLEDs; ++i)
  {
    double r = 0.0;
    double g = 0.0;
    double b = 0.0;

    for (const auto& toneAmplitude : toneData.currentTones)
    {
      if (toneAmplitude.first == Tone::C)
      {
        r += toneAmplitude.second;
      }
      else if (toneAmplitude.first == Tone::D)
      {
        r += toneAmplitude.second/2.0;
      }
      else if (toneAmplitude.first == Tone::E)
      {
        g += toneAmplitude.second;
      }
      else if (toneAmplitude.first == Tone::F)
      {
        g += toneAmplitude.second/2.0;
      }
      else if (toneAmplitude.first == Tone::G)
      {
        b += toneAmplitude.second;
      }
      else if (toneAmplitude.first == Tone::A)
      {
        b += toneAmplitude.second/2.0;
      }
      else if (toneAmplitude.first == Tone::B)
      {
        r += toneAmplitude.second;
      }
    }

    double norm = std::sqrt(r*r+g*g+b*b);
    int rNorm = static_cast<int>(r/norm*255);
    int gNorm = static_cast<int>(g/norm*255);
    int bNorm = static_cast<int>(b/norm*255);

    Color color(rNorm, gNorm, bNorm);

    LED led(i, color);
    frame.addLED(led);
  }

  animation.addFrame(frame);

  return animation;
}
コード例 #10
0
void EntityResourceManager::loadAnimations(Entity &entity, Json::Value &root)
{
	//Lets just confirm that the entity is an animated entity...
	AnimatedEntity *animatedEntityPtr = dynamic_cast<AnimatedEntity*>(&entity);
	//If it's null, then either the entity type is wrong or they have accidentally
	//provided an animation file for a non-animated entity
	if(animatedEntityPtr == NULL)
	{
		return;
	}

	Json::Value animations = root.get("animations", NULL);
	if(animations == NULL)
	{
		return;
	}

	std::map<std::string, Animation*> *animationListPtr = new std::map<std::string, Animation*>();
	//if the entity has no animation, size will be 0, which is a problem since it's an animated entity!
	for(unsigned int i = 0; i < animations.size(); i++)
	{
		Animation *animationPtr = new Animation();
		Json::Value animation = animations[i];
		
		std::string name = animation["name"].asString();

		//first see if there are any rows, if there isn't, size will be 0
		Json::Value rows = animation["rows"];
		for(unsigned int j = 0; j < rows.size(); j++)
		{
			Json::Value row = rows[j];
			sf::Vector2i origin(row["origin"]["x"].asInt(), row["origin"]["y"].asInt());
			unsigned int numFrames = row["frameCount"].asUInt();
			sf::Vector2i frameSize(row["frameSize"]["width"].asInt(), row["frameSize"]["height"].asInt());
			sf::Time duration = sf::milliseconds(row["frameDuration"].asInt());

			animationPtr->addRow(origin, numFrames, frameSize, duration);
		}

		//now check for any individual frames
		Json::Value frames = animation["frames"];
		for(unsigned int j = 0; j < frames.size(); j++)
		{
			Json::Value frame = frames[j];
			Json::Value rect = frame["rect"];
			
			sf::Time duration = sf::milliseconds(frame["duration"].asUInt());
			sf::IntRect frameRect(rect["left"].asInt(), rect["top"].asInt(),
				rect["width"].asInt(), rect["height"].asInt());

			animationPtr->addFrame(duration, frameRect);
		}
		(*animationListPtr)[name] = animationPtr;
		animatedEntityPtr->setFrame(animationListPtr->at(name)->getFrameAt(0)->rect);
	}

	animatedEntityPtr->initAnimation(animationListPtr);
}
コード例 #11
0
ファイル: GargoyleEnemy.cpp プロジェクト: MORTAL2000/Cendric2
void GargoyleEnemy::loadAnimation(int skinNr) {
	m_animations.clear();
	setBoundingBox(sf::FloatRect(0.f, 0.f, 50.f, 80.f));
	setSpriteOffset(sf::Vector2f(-127.f, -42.f));

	Animation* flyingAnimation = new Animation();
	flyingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_gargoyle));
	for (int i = 0; i < 8; i++) {
		flyingAnimation->addFrame(sf::IntRect(195 * i, 0, 195, 180));
	}

	addAnimation(GameObjectState::Flying, flyingAnimation);

	
	Animation* idleAnimation = new Animation();
	idleAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_gargoyle));
	for (int i = 0; i < 8; i++) {
		idleAnimation->addFrame(sf::IntRect(195 * i, 0, 195, 180));
	}

	addAnimation(GameObjectState::Idle, idleAnimation);

	// TODO: create other animations
	Animation* fightingAnimation = new Animation();
	fightingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_gargoyle));
	for (int i = 0; i < 3; i++) {
		fightingAnimation->addFrame(sf::IntRect(195 * i, 180, 195, 180));
	}
	fightingAnimation->setLooped(false);

	addAnimation(GameObjectState::Fighting, fightingAnimation);

	Animation* deadAnimation = new Animation();
	deadAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_gargoyle));
	for (int i = 0; i < 10; i++) {
		deadAnimation->addFrame(sf::IntRect(195 * i, 360, 195, 180));
	}
	deadAnimation->setLooped(false);

	addAnimation(GameObjectState::Dead, deadAnimation);

	// initial values
	setState(GameObjectState::Idle);
	playCurrentAnimation(true);
}
コード例 #12
0
ファイル: EnemyCrawler.cpp プロジェクト: harad/Last-Escape
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");
}
コード例 #13
0
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);
}
コード例 #14
0
void SkeletonEnemy::loadAnimation() {
	setBoundingBox(sf::FloatRect(0.f, 0.f, 40.f, 135.f));
	setSpriteOffset(sf::Vector2f(-35.f, -15.f));

	Animation* walkingAnimation = new Animation(sf::seconds(0.1f));
	walkingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_skeleton));
	for (int i = 0; i < 8; i++) {
		walkingAnimation->addFrame(sf::IntRect(i * 150, 0, 150, 150));
	}

	addAnimation(GameObjectState::Walking, walkingAnimation);

	Animation* jumpingAnimation = new Animation();
	jumpingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_skeleton));
	jumpingAnimation->addFrame(sf::IntRect(0, 0, 150, 150));

	addAnimation(GameObjectState::Jumping, jumpingAnimation);

	Animation* idleAnimation = new Animation();
	idleAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_skeleton));
	idleAnimation->addFrame(sf::IntRect(00, 150, 150, 150));

	addAnimation(GameObjectState::Idle, idleAnimation);

	Animation* fightingAnimation = new Animation(sf::seconds(0.05f));
	fightingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_skeleton));
	for (int i = 0; i < 8; i++) {
		fightingAnimation->addFrame(sf::IntRect(i * 150, 300, 150, 150));
	}

	addAnimation(GameObjectState::Fighting, fightingAnimation);

	Animation* deadAnimation = new Animation();
	deadAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_skeleton));
	for (int i = 0; i < 2; i++) {
		deadAnimation->addFrame(sf::IntRect(i * 150, 450, 150, 150));
	}
	deadAnimation->setLooped(false);
	addAnimation(GameObjectState::Dead, deadAnimation);

	// initial values
	setState(GameObjectState::Idle);
	playCurrentAnimation(true);
}
コード例 #15
0
ファイル: FearSpell.cpp プロジェクト: G-GFFD/Cendric2
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);
}
コード例 #16
0
ファイル: Collectible.cpp プロジェクト: jsj2008/Last-Escape
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);
}
コード例 #17
0
ファイル: Hero.cpp プロジェクト: Angryn00b/Pokesgi
void Hero::heroInit() {
    // Animations
	// Going north
    Animation backAnimation;
    backAnimation.setSpriteSheet(texture);
    backAnimation.addFrame(sf::IntRect(4, 580, tileWidth, tileHeight));
    backAnimation.addFrame(sf::IntRect(99, 579, tileWidth, tileHeight));
    backAnimation.addFrame(sf::IntRect(4, 580, tileWidth, tileHeight));
    backAnimation.addFrame(sf::IntRect(99, 579, tileWidth, tileHeight));
    animations[0] = backAnimation;
    
	//Going east
    Animation rightAnimation;
    rightAnimation.setSpriteSheet(texture);
    rightAnimation.addFrame(sf::IntRect(52, 580, tileWidth, tileHeight));
    rightAnimation.addFrame(sf::IntRect(52, 611, tileWidth, tileHeight));
    rightAnimation.addFrame(sf::IntRect(52, 580, tileWidth, tileHeight));
    rightAnimation.addFrame(sf::IntRect(52, 611, tileWidth, tileHeight));
    animations[1] = rightAnimation;
    
	// Going south
    Animation faceAnimation;
    faceAnimation.setSpriteSheet(texture);
    faceAnimation.addFrame(sf::IntRect(98, 612, tileWidth, tileHeight));
    faceAnimation.addFrame(sf::IntRect(98, 643, tileWidth, tileHeight));
    faceAnimation.addFrame(sf::IntRect(98, 612, tileWidth, tileHeight));
    faceAnimation.addFrame(sf::IntRect(98, 643, tileWidth, tileHeight));
    animations[2] = faceAnimation;
    
	// Going west
    Animation leftAnimation;
    leftAnimation.setSpriteSheet(texture);
    leftAnimation.addFrame(sf::IntRect(4, 644, tileWidth, tileHeight));
    leftAnimation.addFrame(sf::IntRect(4, 611, tileWidth, tileHeight));
    leftAnimation.addFrame(sf::IntRect(4, 644, tileWidth, tileHeight));
    leftAnimation.addFrame(sf::IntRect(4, 611, tileWidth, tileHeight));
    animations[3] = leftAnimation;
    
    // Sprite
    AnimatedSprite sprite(sf::seconds(0.2));
    sprite.setAnimation(animations[2]);
    setSprite(sprite);
}
コード例 #18
0
ファイル: FireRatEnemy.cpp プロジェクト: G-GFFD/Cendric2
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);
}
コード例 #19
0
ファイル: PlayerBullet.cpp プロジェクト: harad/Last-Escape
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");
}
コード例 #20
0
ファイル: wrap_Animation.cpp プロジェクト: JackDanger/love
	int _wrap_Animation_addFrame(lua_State * L)
	{
		Animation * t = luax_checkanimation(L, 1);
		float x = (float)luaL_checknumber(L, 2);
		float y = (float)luaL_checknumber(L, 3);
		float w = (float)luaL_checknumber(L, 4);
		float h = (float)luaL_checknumber(L, 5);
		float d = (float)luaL_checknumber(L, 6);
		t->addFrame(x, y, w, h, d);
		return 0;
	}
コード例 #21
0
ファイル: Collectible.cpp プロジェクト: harad/Last-Escape
void Collectible::init()
{
	setDrawOffset(16, 16);
	setFrameSize(32, 32);

	Animation * tmp;
	tmp = addAnimation("image");
	tmp->addFrame(0, .1f);
	setCurrentAnimation("image");
	shape->collision_type = PhysicsType::Item;
	setShapeLayers(PhysicsLayer::Player);
}
コード例 #22
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);
}
コード例 #23
0
ファイル: progressindicator.cpp プロジェクト: Ablu/invertika
ProgressIndicator::ProgressIndicator()
{
    ImageSet *images = Theme::getImageSetFromTheme("progress-indicator.png",
                       32, 32);

    Animation *anim = new Animation;
    for (ImageSet::size_type i = 0; i < images->size(); ++i)
        anim->addFrame(images->get(i), 100, 0, 0);

    mIndicator = new SimpleAnimation(anim);

    setSize(32, 32);
}
コード例 #24
0
void FireRatEnemy::loadAnimation() {
	setBoundingBox(sf::FloatRect(0.f, 0.f, 40.f, 30.f));
	setSpriteOffset(sf::Vector2f(-5.f, -20.f));

	Animation* walkingAnimation = new Animation();
	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 = new Animation();
	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 = new Animation();
	jumpingAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_firerat));
	jumpingAnimation->addFrame(sf::IntRect(150, 0, 50, 50));

	addAnimation(GameObjectState::Jumping, jumpingAnimation);

	Animation* fightingAnimation = new Animation(sf::seconds(0.08f));
	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 = new Animation();
	deadAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_enemy_firerat));
	deadAnimation->addFrame(sf::IntRect(350, 0, 50, 50));

	addAnimation(GameObjectState::Dead, deadAnimation);

	// initial values
	setState(GameObjectState::Idle);
	playCurrentAnimation(true);
}
コード例 #25
0
ファイル: CookingTile.cpp プロジェクト: MORTAL2000/Cendric2
void CookingTile::loadAnimation(int skinNr) {
	int textureHeight = 2 * TILE_SIZE;

	Animation* burningAnimation = new Animation(sf::seconds(0.15f));
	burningAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_tile_cooking));
	for (int i = 0; i < 4; ++i) {
		burningAnimation->addFrame(sf::IntRect(TILE_SIZE * i, (skinNr - 1) * textureHeight, TILE_SIZE, textureHeight));
	}

	addAnimation(GameObjectState::Burning, burningAnimation);

	// initial values
	setState(GameObjectState::Burning);
	playCurrentAnimation(true);
}
コード例 #26
0
ファイル: FireBasket.cpp プロジェクト: MORTAL2000/Cendric2
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);
}
コード例 #27
0
void TelekinesisSpell::load(const SpellData& bean, LevelMovableGameObject* mob, const sf::Vector2f& target) {
	setSpriteOffset(sf::Vector2f(-10.f, -10.f));

	Animation* spellAnimation = new Animation(sf::seconds(10.f));
	spellAnimation->setSpriteSheet(g_resourceManager->getTexture(ResourceID::Texture_spell_telekinesis));
	spellAnimation->addFrame(sf::IntRect(0, 0, 40, 30));

	addAnimation(GameObjectState::Idle, spellAnimation);

	// initial values
	setState(GameObjectState::Idle);
	playCurrentAnimation(true);

	Spell::load(bean, mob, target);
	loadParticleSystem();
}
コード例 #28
0
//animation is assumed to be a 1 frame tall and {numFrames} wide image
//the planned source frame images are taller, might edit, might not
//TODO credit sprites (from Pokemon Zeta/Omicron) or find orig source
void addAnimation(string animName, sf::Vector2i frameDim, int numFrames, string texFile){

	addTexture(animName, texFile);

	Animation a;
	a.setSpriteSheet(getTexture(animName));

	//add each 'frame' (box) from image to animation
	for (int i = 0; i < numFrames; i++){
		sf::IntRect spriteRect(i*frameDim.x, 0, frameDim.x, frameDim.y);
		a.addFrame(spriteRect);
	}

	animMap.insert(make_pair(animName, a));


}
コード例 #29
0
ファイル: BossSpider.cpp プロジェクト: harad/Last-Escape
BossSpider::BossSpider(float x, float y)
:Enemy(x, y, 56.0f, 41.0f)
{
	setImage("spider.png");
	walk_speed = 100.0f;

	dying = false;
	life = 5;

	setDrawOffset(32, 63);
	setFrameSize(64, 64);
	lastShot = 0;
	shootInterval = 0.5f;
	time = 0;

	patrolInterval = 1.5f;
	patrolTime = 0;

	Animation * tmp;

	//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];
	shape->u = 0.1f;

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

	tmp = addAnimation("die");
	tmp->addFrame(8, .2f);
	tmp->addFrame(9, .2f);
	tmp->addFrame(10, .2f);
	tmp->addFrame(11, .2f);

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

	setCurrentAnimation("walk");
}
コード例 #30
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);
}