void AddAnimationReference(const String& fileReference, String animationReference, int width, int height, int x, int y, int animationType, float frameDelay) { AnimationReference* a = GetAnimationReference(animationReference, true); if(a) { a->frames.push_back(AnimationFrame(x, y)); a->frameCount++; } else { a = new AnimationReference(); a->fileReference = fileReference; a->animationReference = animationReference; a->animationType = animationType; a->frameCount = 0; a->frameDelay = frameDelay; a->w = width; a->h = height; a->frames.push_back(AnimationFrame(x, y)); a->frameCount++; animationReferences[animationReference] = a; } }
Animation::Animation(std::vector<Sprite> sp, GLfloat frameDuration) : Animation() { for (int i = 0; i < sp.size(); i++) { frames.push_back(AnimationFrame(sp[i], frameDuration)); } }
VillagerC::VillagerC() { Texture* tex = textureLoader::getTexture("friendly_npcs"); AnimatedSprite sprite = AnimatedSprite(&tex->texture, 0, 0, tex->cellWidth, tex->cellHeight, 0 * tex->uSize, 5 * tex->vSize, 1 * tex->uSize, 1 * tex->vSize); *this = VillagerC((VillagerC&)sprite); type = 1; name = "villagerC"; isAnimated = false; //Setup Collider int xOffset = 18; int yOffset = 15; int width = 28; int height = 45; float uSize = 1; float vSize = 1; colliderXOffset = xOffset; colliderYOffset = yOffset; setCollider(&AABB(x + xOffset, y + yOffset, width, height)); maxSpeed = 50; isColliderDrawn = false; // Walking Animation int numFrames = 1; int timeToNextFrame = 300; std::vector<AnimationFrame> frames; frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0, 5, uSize, vSize); //frames[1] = AnimationFrame(1, 0, uSize, vSize); Animation animation_walking = Animation("Walking", frames, numFrames); animations[animation_walking.name] = AnimationData(animation_walking, timeToNextFrame, true); // Idle Animation numFrames = 1; frames.clear(); frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0, 5, uSize, vSize); Animation animation_idle = Animation("Idle", frames, numFrames); animations[animation_idle.name] = AnimationData(animation_idle, timeToNextFrame, true); //setAnimation("Walking"); }
Chicken::Chicken() { Texture* tex = textureLoader::getTexture("cucco"); AnimatedSprite sprite = AnimatedSprite(&tex->texture, 0, 0, tex->width, tex->height, 0, 0, 0.5, 1); *this = Chicken((Chicken&)sprite); type = 1; name = "cucco"; //Setup Collider int xOffset = 20; int yOffset = 25; int width = 20; int height = 20; float uSize = 0.5; float vSize = 1; colliderXOffset = xOffset; colliderYOffset = yOffset; setCollider(&AABB(x + xOffset, y + yOffset, width, height)); maxSpeed = 50; // Walking Animation int numFrames = 2; int timeToNextFrame = 300; std::vector<AnimationFrame> frames; frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0, 0, uSize, vSize); frames[1] = AnimationFrame(0.5, 0, uSize, vSize); Animation animation_walking = Animation("Walking", frames, numFrames); animations[animation_walking.name] = AnimationData(animation_walking, timeToNextFrame, true); // Idle Animation numFrames = 1; frames.clear(); frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0, 0, uSize, vSize); Animation animation_idle = Animation("Idle", frames, numFrames); animations[animation_idle.name] = AnimationData(animation_idle, timeToNextFrame, true); setAnimation("Walking"); }
void GrenadePickup::GenerateAnimationData() { std::vector<AnimationFrame> spinAnimation; spinAnimation.push_back(AnimationFrame(0, 8)); spinAnimation.push_back(AnimationFrame(1, 8)); spinAnimation.push_back(AnimationFrame(2, 8)); spinAnimation.push_back(AnimationFrame(3, 8)); spinAnimation.push_back(AnimationFrame(4, 8)); spinAnimation.push_back(AnimationFrame(5, 8)); spinAnimation.push_back(AnimationFrame(6, 8)); spinAnimation.push_back(AnimationFrame(7, 8)); m_pSprite->AddAnimation(ANIMATION_SPIN, spinAnimation); }
void Sprite::setAnimFrame(const ResAnim *resanim, int col, int row) { //OX_ASSERT(resanim); if (!resanim) { changeAnimFrame(AnimationFrame()); return; } const AnimationFrame &frame = resanim->getFrame(col, row); changeAnimFrame(frame); }
void Sprite::setResAnim(const ResAnim *resanim) { if (resanim) { if (resanim->getTotalFrames()) setAnimFrame(resanim); else { AnimationFrame fr; fr.init(0, Diffuse(), RectF(0,0,0,0), RectF(0,0,0,0), getSize()); setAnimFrame(fr); } } else setAnimFrame(AnimationFrame()); }
void Sprite::setAnimFrame(const ResAnim* resanim, int col, int row) { //OX_ASSERT(resanim); if (!resanim) { changeAnimFrame(AnimationFrame()); return; } if (resanim->getTotalFrames()) { const AnimationFrame& frame = resanim->getFrame(col, row); changeAnimFrame(frame); } else { AnimationFrame frame; frame.setSize(getSize()); changeAnimFrame(frame); } }
static AnimationFrames *LoadAnimatedImage(MythPainter *painter, // Must be a copy for thread safety ImageProperties imProps, ImageCacheMode cacheMode, // Included only to check address, could be // replaced by generating a unique value for // each MythUIImage object? const MythUIImage *parent, bool &aborted) { QString filename = QString("frame-%1-") + imProps.filename; QString frameFilename; int imageCount = 1; MythImageReader *imageReader = new MythImageReader(imProps.filename); AnimationFrames *images = new AnimationFrames(); while (imageReader->canRead() && !aborted) { frameFilename = filename.arg(imageCount); ImageProperties frameProps = imProps; frameProps.filename = frameFilename; MythImage *im = LoadImage(painter, frameProps, cacheMode, parent, aborted, imageReader); if (!im) aborted = true; images->append(AnimationFrame(im, imageReader->nextImageDelay())); imageCount++; } delete imageReader; return images; }
void Character::addNewAnimation(const CharacterInstance &seed, int animationLength, float acceptanceScale) { AnimationSequence *animation = new AnimationSequence(seed.frameID, animationLength, (int)animations.size()); auto startInstances = findInstancesRadius(seed, (float)learningParams().baseAnimationFeatureDistSq * acceptanceScale); sort(startInstances.begin(), startInstances.end()); for (CharacterInstance *instance : startInstances) { int duration = computeAnimationDuration(seed, *instance, animationLength, acceptanceScale); for (int offset = 0; offset < duration; offset++) { FrameID curFrame = instance->frameID.delta(offset); CharacterInstance *otherInstance = findInstanceAtFrame(curFrame); animation->instances.push_back(curFrame); otherInstance->animations.push_back(AnimationFrame(animation, offset)); } } cout << "New animation: length=" << animationLength << ", instances=" << startInstances.size() << endl; animations.push_back(animation); }
/*-----------------------------------------------*/ BattleKnight::BattleKnight() { Texture* tex = textureLoader::getTexture("knight_battle"); BattleSprite enemy = BattleSprite(&tex->texture, 0, 100, tex->cellWidth, tex->cellHeight, 0, 0, tex->uSize, tex->vSize); *this = BattleKnight((BattleKnight&)enemy); //isAnimated = false; //TODO Remove once animations are setup name = "knight"; level = 10; maxSpeed = 100; healFactor = 0.15; health = 200; // Setup animations float uSize = tex->uSize; float vSize = tex->vSize; // Animations int numFrames = 1; int timeToNextFrame = 100; // Idle Animation std::vector<AnimationFrame> frames; frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0 * uSize, 0 * vSize, 1 * uSize, 1 * vSize); Animation animation = Animation("Idle", frames, numFrames); animations[animation.name] = AnimationData(animation, timeToNextFrame, false); // Attack Animation numFrames = 12; frames.clear(); frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0 * uSize, 11 * vSize, 1 * uSize, 1 * vSize); frames[1] = AnimationFrame(0 * uSize, 10 * vSize, 1 * uSize, 1 * vSize); frames[2] = AnimationFrame(0 * uSize, 9 * vSize, 1 * uSize, 1 * vSize); frames[3] = AnimationFrame(0 * uSize, 8 * vSize, 1 * uSize, 1 * vSize); frames[4] = AnimationFrame(0 * uSize, 7 * vSize, 1 * uSize, 1 * vSize); frames[5] = AnimationFrame(0 * uSize, 6 * vSize, 1 * uSize, 1 * vSize); frames[6] = AnimationFrame(0 * uSize, 5 * vSize, 1 * uSize, 1 * vSize); frames[7] = AnimationFrame(0 * uSize, 4 * vSize, 1 * uSize, 1 * vSize); frames[8] = AnimationFrame(0 * uSize, 3 * vSize, 1 * uSize, 1 * vSize); frames[9] = AnimationFrame(0 * uSize, 2 * vSize, 1 * uSize, 1 * vSize); frames[10] = AnimationFrame(0 * uSize, 1 * vSize, 1 * uSize, 1 * vSize); frames[11] = AnimationFrame(0 * uSize, 0 * vSize, 1 * uSize, 1 * vSize); animation = Animation("Attack", frames, numFrames); AnimationData animData = AnimationData(animation, timeToNextFrame, false); animData.eventFrame = 7; animations[animation.name] = animData; // Damaged Animation numFrames = 13; timeToNextFrame = 30; frames.clear(); frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0 * uSize, 11 * vSize, 1 * uSize, 1 * vSize); frames[1] = AnimationFrame(0 * uSize, 12 * vSize, 1 * uSize, 1 * vSize); frames[2] = AnimationFrame(0 * uSize, 13 * vSize, 1 * uSize, 1 * vSize); frames[3] = frames[0]; frames[4] = frames[1]; frames[5] = frames[2]; frames[6] = frames[0]; frames[7] = frames[1]; frames[8] = frames[2]; frames[9] = frames[0]; frames[10] = frames[1]; frames[11] = frames[2]; frames[12] = frames[0]; animation = Animation("Damaged", frames, numFrames); animData = AnimationData(animation, timeToNextFrame, false); animations[animation.name] = animData; // Flee Animation numFrames = 1; timeToNextFrame = 1000; frames.clear(); frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0 * uSize, 11 * vSize, 1 * uSize, 1 * vSize); animation = Animation("Flee", frames, numFrames); animData = AnimationData(animation, timeToNextFrame, false); animations[animation.name] = animData; // Death Animation numFrames = 1; timeToNextFrame = 1000; frames.clear(); frames.assign(numFrames, AnimationFrame()); frames[0] = AnimationFrame(0 * uSize, 16 * vSize, 1 * uSize, 1 * vSize); animation = Animation("Death", frames, numFrames); animData = AnimationData(animation, timeToNextFrame, false); animations[animation.name] = animData; setAnimation("Idle"); }
#include "animation.h" std::map<std::string, sf::Texture> Animation::sTextures = std::map<std::string, sf::Texture>(); AnimationFrame const Animation::InvalidFrame = AnimationFrame(); AnimationNode const Animation::InvalidNode = AnimationNode(); Animation::Animation( float itimescale, float starttime): mTimeScale(itimescale), mCurrentTime(starttime) { mCurrentFrame = mFrames.end(); mAnimationLength = 0.0f; } Animation::~Animation() { } float Animation::GetCurrentTime() { return fmod(mCurrentTime, mAnimationLength); } void AnimationFrame::FlipX(bool flipLeft /* = true */) { mSprite.SetScale(-1,1); } void Animation::SeekToTime(const float& seektime) { float targettime = seektime; if (targettime < 0.0f)
virtual void onSceneLoadToMemory(){ texArrowLeft.loadFromFile("files/textures/isaydisco/arrow_left.png"); texArrowUp.loadFromFile("files/textures/isaydisco/arrow_up.png"); texArrowRight.loadFromFile("files/textures/isaydisco/arrow_right.png"); texArrowDown.loadFromFile("files/textures/isaydisco/arrow_down.png"); vecTracks.resize(1); vecTracks[0] = Track("Da_Funk", "Daft Punk", 112); vecTextures.resize(17); for(int i = 0; i < vecTextures.size(); i++){ vecTextures[i].loadFromFile("files/textures/isaydisco/"+Utils::stringify(i)+".png"); if(i != 16) animDanceAll.addFrame(AnimationFrame(&vecTextures[i], 120*2)); } texIdle.loadFromFile("files/textures/isaydisco/idle.png"); animHands.addFrame(AnimationFrame(&vecTextures[2], 120*2)); animHands.addFrame(AnimationFrame(&vecTextures[8], 120*2)); animHands.addFrame(AnimationFrame(&vecTextures[4], 120*2)); animHands.addFrame(AnimationFrame(&vecTextures[6], 120*2)); animHips.addFrame(AnimationFrame(&vecTextures[9], 120*2)); animHips.addFrame(AnimationFrame(&vecTextures[10], 120*2)); animHips.addFrame(AnimationFrame(&vecTextures[11], 120*2)); animHips.addFrame(AnimationFrame(&vecTextures[12], 120*2)); animHips.addFrame(AnimationFrame(&vecTextures[9], 120*2)); animHips.addFrame(AnimationFrame(&vecTextures[10], 120*2)); animHips.addFrame(AnimationFrame(&vecTextures[11], 120*2)); animHips.addFrame(AnimationFrame(&vecTextures[12], 120*2)); animWindmill.addFrame(AnimationFrame(&vecTextures[0], 120*2)); animWindmill.addFrame(AnimationFrame(&vecTextures[8], 120*2)); animWindmill.addFrame(AnimationFrame(&vecTextures[0], 120*2)); animWindmill.addFrame(AnimationFrame(&texIdle, 120*4)); animWindmill.addFrame(AnimationFrame(&vecTextures[6], 120*2)); animWindmill.addFrame(AnimationFrame(&vecTextures[15], 120*2)); animWindmill.addFrame(AnimationFrame(&vecTextures[6], 120*2)); vecTexturesDaftDJ.resize(8); for(int i = 0; i < vecTexturesDaftDJ.size(); i++){ vecTexturesDaftDJ[i].loadFromFile("files/textures/isaydisco/DaftPunk1_DJ"+Utils::stringify(i)+".png"); } vecTexturesDaftGuitar.resize(8); for(int i = 0; i < 4; i++){ vecTexturesDaftGuitar[i].loadFromFile("files/textures/isaydisco/DaftPunk1_GF"+Utils::stringify(i)+".png"); } for(int i = 0; i < 4; i++){ vecTexturesDaftGuitar[i+4].loadFromFile("files/textures/isaydisco/DaftPunk1_GG"+Utils::stringify(i)+".png"); } for(int i = 0; i < 4; i++){ animDJ1.addFrame(AnimationFrame(&vecTexturesDaftDJ[i], 112*2)); animGuitar1.addFrame(AnimationFrame(&vecTexturesDaftGuitar[i], 112*2)); animDJ2.addFrame(AnimationFrame(&vecTexturesDaftDJ[i+4], 112*2)); animGuitar2.addFrame(AnimationFrame(&vecTexturesDaftGuitar[i+4], 112*2)); } vecSteps.resize(4); vecSteps[0] = DanceStep(&animHands, {0,2,4,6}, {HAND_LEFT, HAND_RIGHT, HAND_LEFT, HAND_RIGHT}); vecSteps[1] = DanceStep(&animHips, {0,2,4,6}, {HIPS_LEFT, HIPS_RIGHT, HIPS_LEFT, HIPS_RIGHT}); vecSteps[2] = DanceStep(&animWindmill, {0,2,3,3,4,6}, {HAND_LEFT,HAND_LEFT,LEG_LEFT,LEG_RIGHT,HAND_RIGHT,HAND_RIGHT}); //vecSteps[3] = DanceStep(&animDanceAll, {3, 3}, {HAND_LEFT, HAND_RIGHT}); vecSteps[3] = DanceStep(&animDanceAll, {0, 4, 6, 8, 13, 15}, {HAND_LEFT,LEG_RIGHT,HAND_RIGHT,HAND_LEFT,LEG_RIGHT,HAND_RIGHT}); dbgText.move(100, 0); //martwe pixele ftw dbgText.setFont(Common::Font::Comic_Sans); vecDiscoColors.push_back(sf::Color(255, 255, 255)); vecDiscoColors.push_back(sf::Color(0, 255, 0)); vecDiscoColors.push_back(sf::Color(255, 255, 0)); vecDiscoColors.push_back(sf::Color(0 ,255,255)); //vecDiscoColors.push_back(sf::Color(238,190,67)); vecDiscoReactionsGood.push_back("WOAH!"); vecDiscoReactionsGood.push_back("Superb!"); vecDiscoReactionsGood.push_back("Smooth!"); vecDiscoReactionsGood.push_back("Fantastic!"); vecDiscoReactionsGood.push_back("COMBO x42"); vecDiscoReactionsBad.push_back("Go home, you are drunk"); vecDiscoReactionsBad.push_back("Boooooo"); vecDiscoReactionsBad.push_back("Awful"); vecDiscoReactionsBad.push_back("Absolutely Disgusting"); vecDiscoReactionsBad.push_back("Disgusting"); texBkgrnd.loadFromFile("files/textures/isaydisco/background.png"); background.setTexture(texBkgrnd); background.setScale((float)window->getSize().x/(float)texBkgrnd.getSize().x, (float)window->getSize().y/(float)texBkgrnd.getSize().y); }
AnimationFrame Animation::first() { if(priv->frames.empty()) { return AnimationFrame(nullptr, {1,1}); } return priv->frames.front(); }
void Tile::Parse(const tinyxml2::XMLNode *tileNode) { const tinyxml2::XMLElement *tileElem = tileNode->ToElement(); // Parse the attributes. id = tileElem->IntAttribute("id"); // Parse the properties if any. const tinyxml2::XMLNode *propertiesNode = tileNode->FirstChildElement( "properties"); if (propertiesNode) { properties.Parse(propertiesNode); } // Parse the animation if there is one. const tinyxml2::XMLNode *animationNode = tileNode->FirstChildElement( "animation"); if (animationNode) { isAnimated = true; const tinyxml2::XMLNode *frameNode = animationNode->FirstChildElement("frame"); unsigned int durationSum = 0; while (frameNode != NULL) { const tinyxml2::XMLElement *frameElement = frameNode->ToElement(); const int tileID = frameElement->IntAttribute("tileid"); const unsigned int duration = frameElement->IntAttribute( "duration"); frames.push_back(AnimationFrame(tileID, duration)); durationSum += duration; frameNode = frameNode->NextSiblingElement("frame"); } totalDuration = durationSum; } const tinyxml2::XMLNode *collisionNode = tileNode->FirstChildElement( "objectgroup"); if (collisionNode) { const tinyxml2::XMLNode *objectNode = collisionNode->FirstChildElement("object"); hasObjects = true; while (objectNode != NULL) { const tinyxml2::XMLElement *objectElement = objectNode->ToElement(); Object *object = new Object(); object->Parse(objectElement); objects.push_back(object); objectNode = objectNode->NextSiblingElement("object"); } } const tinyxml2::XMLNode *imageNode = tileNode->FirstChildElement("image"); if(imageNode) { image = new Image(); image->Parse(imageNode); } }
AnimationFrame Animation::last() { if(priv->frames.empty()) { return AnimationFrame(nullptr, {1,1}); } return priv->frames.back(); }
void Animation::addFrame(Texture *t, Vector frame) { priv->frames.push_back(AnimationFrame(t, frame)); }
virtual void onSceneLoadToMemory() { textScore.setFont(Common::Font::Comic_Sans); texBackground.loadFromFile("files/textures/jumper/background.png"); texBackground.setRepeated(true); background1.setTexture(texBackground); background1.setTextureRect(sf::IntRect(0, 0, texBackground.getSize().x, 1000000)); background1.setPosition(0, -1000000); background1.setScale((float)window->getSize().x/(float)texBackground.getSize().x, (float)window->getSize().y/(float)texBackground.getSize().y); texPlayerRun1.loadFromFile("files/textures/universal/playerRun1.png"), TadzikRun.addFrame(AnimationFrame(&texPlayerRun1, 500)); texPlayerRun2.loadFromFile("files/textures/universal/playerRun2.png"), TadzikRun.addFrame(AnimationFrame(&texPlayerRun2, 500)); texPlayerRun3.loadFromFile("files/textures/universal/playerRun3.png"), TadzikRun.addFrame(AnimationFrame(&texPlayerRun3, 500)); texPlayerRun4.loadFromFile("files/textures/universal/playerRun4.png"), TadzikRun.addFrame(AnimationFrame(&texPlayerRun4, 500)); texPlayerJump.loadFromFile("files/textures/universal/playerJump.png"), TadzikJump.addFrame(AnimationFrame(&texPlayerJump, 150)); texPlayerJumpSuper.loadFromFile("files/textures/jumper/playerJumpSuper.png"), TadzikJumpSuper.addFrame(AnimationFrame(&texPlayerJumpSuper, 150)); texPlayerRoll.loadFromFile("files/textures/jumper/playerRoll.png"), TadzikRoll.addFrame(AnimationFrame(&texPlayerRoll, 150)); texPlayerStand.loadFromFile("files/textures/universal/playerStand.png"), TadzikStand.addFrame(AnimationFrame(&texPlayerStand, 150)); texPlayerFall.loadFromFile("files/textures/universal/playerFall.png"), TadzikFall.addFrame(AnimationFrame(&texPlayerFall, 150)); spTadzik.setAnimation(&TadzikRun); spTadzik.sprite.setPosition(window->getSize().x/2-spTadzik.sprite.getTextureRect().width/2, window->getSize().y-spTadzik.sprite.getTextureRect().height*6); spTadzik.sprite.setScale(3, 3); spTadzik.sprite.setOrigin(spTadzik.sprite.getTextureRect().width/2, spTadzik.sprite.getTextureRect().height); texPlatform.loadFromFile("files/textures/jumper/platform.png"); tmpPlatform.setTexture(texPlatform); tmpPlatform.setPosition(0, window->getSize().y-30); tmpPlatform.setScale((double)window->getSize().x/(double)tmpPlatform.getTextureRect().width, 1); platforms.push_back(platform(tmpPlatform)); tmpPlatform.setScale((double)window->getSize().x/(double)tmpPlatform.getTextureRect().width/3, 1); tmpPlatform.move(10, -(1.0/2.0)*window->getSize().y); platforms.push_back(platform(tmpPlatform)); tmpPlatform.move(10, -(1.0/2.0)*window->getSize().y); platforms.push_back(platform(tmpPlatform)); texPowerup1.loadFromFile("files/textures/jumper/powerup1.png"); powerup1.setTexture(texPowerup1); }