void Sprite::playAnimation(s16 x, s16 y, u16 anim) { if(!m_animations[anim]->isPlaying) { resetAnimation(anim); startAnimation(anim); m_animations[anim]->isPlaying = true; } if(animationAtEnd(anim)) { resetAnimation(anim); startAnimation(anim); } u16 animToDraw = m_animations[anim]->tabAnim[(u16)(m_animations[anim]->timer.time() / m_animations[anim]->delay)]; drawFrame(x, y, animToDraw); }
/* animateAttack Parameters: animationClock: Clock used to determine if the animation should move to the next frame sprite: The sprite where the attack animation is contained returnToDefault: Determines if the sprite should return to the default frame (used to add "oomph" to the last attack in a string, for example). This method simply animates the attack. It returns true if the attack is still in the process of animating, false if the attack has finished animating. */ bool Attack::animateAttack(sf::Sprite* sprite, sf::Clock* clock, bool reset) { int spriteLeft = sprite->getTextureRect().left; if (reset) { resetAnimation(sprite, clock); return true; } if (spriteLeft / width < numFrames && spriteLeft / width != activeFrame && clock->getElapsedTime().asMilliseconds() > frameDelay) advanceFrame(sprite, clock); else if (spriteLeft / width == activeFrame && clock->getElapsedTime().asMilliseconds() > activeFrameDelay) { if (activeFrameDelay == specialHitStun) Game::camera->emphasisZoomOut(); advanceFrame(sprite, clock); } else if (spriteLeft / width == numFrames && clock->getElapsedTime().asMilliseconds() > finalFrameDelay) { clock->restart(); left = defaultLeft; activeFrameDelay = hitStun; return false; } return true; }
PassRefPtr<SVGPropertyBase> SVGAnimatedTypeAnimator::startAnimValAnimation(const WillBeHeapVector<RawPtrWillBeMember<SVGElement> >& list) { ASSERT(isAnimatingSVGDom()); SVGElement::InstanceUpdateBlocker blocker(m_contextElement); return resetAnimation(list); }
void Sprite::playAnimation(s16 x, s16 y, u16 anim) { // If the animation is not playing if(!m_animations[anim]->isPlaying) { resetAnimation(anim); // Reset animation timer startAnimation(anim); // Start animation timer m_animations[anim]->isPlaying = true; // Set isPlaying boolean to true } // If the animation is at end if(animationAtEnd(anim)) { resetAnimation(anim); // Reset animation timer startAnimation(anim); // Start animation timer } // This variable contains the number of the animation's frame to draw u16 animToDraw = m_animations[anim]->tabAnim[(u16)(m_animations[anim]->timer.time() / m_animations[anim]->delay)]; drawFrame(x, y, animToDraw); // Draw the frame }
bool PawnMovementAnimation::animate(const Real& timeSinceLastFrame) { Real distanceMoved = MOVEMENT_SPEED * timeSinceLastFrame; Vector3 path = mDestination - mAnimatedNode->getPosition(); if (path.length() > distanceMoved) { if (path.length() < 280 && mAttackDuration > 0) { if (!mParticleNode) { createBlasts(); mAnimationManager->addAnimation( AnimationFactory::createDyingAnimation( mTargetPiece, mSceneMgr, 2, 1.5)); mAnimationManager->addAnimation( AnimationFactory::createBleedingAnimation( mTargetPiece, mSceneMgr, 1, 1.5)); } if (mParticleNode->getPosition().y + mTargetPiece->getPosition().y >= 0) { if (mParticleNode->getPosition().y < 200) { mTargetPiece->translate(0, -timeSinceLastFrame * 600, 0); mParticleNode->translate(0, -timeSinceLastFrame * 400, 0); } else { mParticleNode->translate(0, -timeSinceLastFrame * 1000, 0); } } else { playAnimation("eat", timeSinceLastFrame, false, mParticleNode, false); } mAttackDuration -= timeSinceLastFrame; } else { // Normalising the vector so the speed remains constant. path.normalise(); mAnimatedNode->translate(path * distanceMoved); Vector3 src = mAnimatedNode->getOrientation() * Vector3::UNIT_Z; mAnimatedNode->rotate(src.getRotationTo(path)); playAnimation("walk", timeSinceLastFrame); } return true; // Animation still running. } resetAnimation("walk"); mAnimatedNode->setPosition(mDestination); mAnimatedNode->setOrientation(mAnimatedNode->getInitialOrientation()); return false; // Animation finished. }
void init_lvlOnePickups() { healthPickup = entity_new(); healthPickup->sprite = loadSpriteGraphics("images/health.png","text/health.anim",20,20,4); resetAnimation(healthPickup,0); healthPickup->bounds.x = 0; healthPickup->bounds.y = 0; healthPickup->bounds.w = 20; healthPickup->bounds.h = 21; healthPickup->touch = pickup_Health; pistolAmmoPickup = entity_new(); pistolAmmoPickup->sprite = loadSpriteGraphics("images/pistolAmmo_sheet.png","text/pistol.anim",19,17,4); pistolAmmoPickup->bounds.x = 0; pistolAmmoPickup->bounds.y = 0; pistolAmmoPickup->bounds.w = 19; pistolAmmoPickup->bounds.h = 17; pistolAmmoPickup->touch = pickup_PistolAmmo; shotgunAmmoPickup = entity_new(); shotgunAmmoPickup->sprite = loadSpriteGraphics("images/shotgunAmmo_sheet.png","text/pistol.anim",20,18,4); shotgunAmmoPickup->bounds.x = 0; shotgunAmmoPickup->bounds.y = 0; shotgunAmmoPickup->bounds.w = 20; shotgunAmmoPickup->bounds.h = 18; shotgunAmmoPickup->touch = pickup_ShotgunAmmo; machinegunAmmoPickup = entity_new(); machinegunAmmoPickup->sprite = loadSpriteGraphics("images/machinegunAmmo_sheet.png","text/pistol.anim",17,18,4); machinegunAmmoPickup->bounds.x = 0; machinegunAmmoPickup->bounds.y = 0; machinegunAmmoPickup->bounds.w = 17; machinegunAmmoPickup->bounds.h = 18; machinegunAmmoPickup->touch = pickup_MachinegunAmmo; pistolPickup = entity_new(); shotgunPickup = entity_new(); machinegunPickup = entity_new(); heavyMachinegunPickup = entity_new(); healthPickup->position.x = 50; healthPickup->position.y = 400; pistolAmmoPickup->position.x = 100; pistolAmmoPickup->position.y = 400; shotgunAmmoPickup->position.x = 150; shotgunAmmoPickup->position.y = 400; machinegunAmmoPickup->position.x = 200; machinegunAmmoPickup->position.y = 400; }
void Player::handle_event(SDL_Event& event) { if (event.type == SDL_KEYDOWN && event.key.repeat == 0) { switch(event.key.keysym.sym) { case SDLK_LEFT: movementVector.dx -= m_speed; m_currentAnimation = PlayerAnimationStep::RUN_LEFT; resetAnimation(); break; case SDLK_RIGHT: movementVector.dx += m_speed; m_currentAnimation = PlayerAnimationStep::RUN_RIGHT; resetAnimation(); break; case SDLK_UP: if (!m_airbourne) { movementVector.dy -= 20; m_airbourne = true; // Mix_PlayChannel(-1, m_jumpSound, 0); } break; } } if (event.type == SDL_KEYUP && event.key.repeat == 0) { switch(event.key.keysym.sym) { case SDLK_LEFT: movementVector.dx += m_speed; break; case SDLK_RIGHT: movementVector.dx -= m_speed; break; } } }
/*! * Resets the content of the grid. * Hides all the ball items from the board and removes them * from the internal structure. */ void GridItem::reset() { resetAnimation(); for (int row = 0; row < m_dimension; ++row) { for (int col = 0; col < m_dimension; ++col) { BallItem * pBall = m_balls[row][col]; if (pBall) { pBall->setVisible(false); pBall->setParentItem(0); delete m_balls[row][col]; m_balls[row][col] = reinterpret_cast<BallItem*>(0); } } } }
/*! \internal \fn void SelectedItem::setCurrent(GridItem *gridItem,bool animate = true); Changes the current GridItem object, and causes it to start animating. The item may be 0, indicating that no item is currently selected. Emits the selectionChanged signal. */ void SelectedItem::setCurrent(GridItem *item,bool animate) { currentItem = item; resetAnimation(); // Resize this object. resize(); // Now we are current - tell the world. mConnector->triggerSelectionChanged(currentItem); if ( currentItem && animate ) { // When a new item is current (i.e. a move is finished, or the view has been shown) we animate // the SelectdItem. startAnimating(); } }
/*! \internal \fn void SelectedItem::updateImages() Updates all the Pixmaps for all the GridItem objects. */ void SelectedItem::updateImages() { // The images have changed. First, get the SelectedItem to disconnect from the movie. detachAnimation(); // Get all the GridItem objects to rebuild their pixmaps. for ( int row = 0; row <= table.topRow(); row++ ) { for ( int col = 0; col <= table.topColumn(); col++ ) { GridItem *item = table.item(row,col); if ( item ) { item->updateImages(); } } } // SelectedItem now has to grab the revised movie. resetAnimation(); }
/** * @brief Moves the character on screen. * @param direction specifies which direction the character moves. */ void moveCharacter(int direction, Entity *entity) { resetAnimation(entity,1); switch(direction) { case DIR_UP: if(entity->position.y < 245) { return; } entity->position.y -= 3; break; case DIR_LEFT: entity->facingLeft = 1; if(entity->position.x < 0) { return; } entity->position.x -= 3; break; case DIR_RIGHT: entity->facingLeft = 0; entity->position.x += 3; break; case DIR_DOWN: if(entity->position.y > 475-64) { return; } entity->position.y += 3; break; } }
int levelTwo() { moving = 0; SDL_RenderClear(gt_graphics_get_active_renderer()); ResetBuffer(); backOffset = ((int)camera.x+3200)%3200; offset = ((int)camera.x+1600)%1600; drawSprite(moonBack,0,vec2d(0,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoBackTrees,0,vec2d(-backOffset,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoFrontTrees,0,vec2d(-offset,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoFloor,0,vec2d(-offset,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoFrontTrees,0,vec2d(-offset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoBackTrees,0,vec2d(-backOffset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); drawSprite(levelTwoFloor,0,vec2d(-offset+1600,0),vec2d(1,1),0,gt_graphics_get_active_renderer()); entity_think_all(); entity_touch_all(); entity_update_all(); entity_draw_all(); if(player->position.x >= 300) { camera.x = player->position.x - 300; } if(player->position.x < 300) { camera.x = 0; } if(xDistance == 12000.00) { done = 1; } healthBar(); NextFrame(); SDL_PumpEvents(); diff = (gt_graphics_now - gt_graphics_then); if(playerData.shotTimer>0) { playerData.shotTimer -= diff; } keys = SDL_GetKeyboardState(NULL); if(keys[SDL_SCANCODE_ESCAPE]) { done = 1; } else if(keys[SDL_SCANCODE_W]) { moving = 1; moveCharacter(DIR_UP,player); yDistance = player->position.y; } else if(keys[SDL_SCANCODE_A]) { moving = 1; moveCharacter(DIR_LEFT,player); xDistance = player->position.x; } else if(keys[SDL_SCANCODE_D]) { moving = 1; moveCharacter(DIR_RIGHT,player); xDistance = player->position.x; } else if(keys[SDL_SCANCODE_S]) { moving = 1; moveCharacter(DIR_DOWN,player); yDistance = player->position.y; } else if(keys[SDL_SCANCODE_1]) { fire_Pistol(); } else if(keys[SDL_SCANCODE_2]) { fire_Shotgun(); } else if(keys[SDL_SCANCODE_3]) { fire_Machinegun(); } else if(keys[SDL_SCANCODE_4]) { fire_Heavy_Machinegun(); } else if(keys[SDL_SCANCODE_P]) { saveState(); } else if(keys[SDL_SCANCODE_O]) { loadState(); } if(moving == 0) { resetAnimation(player, 0); } return 0; }
void Viewer::keyPressedEvent(sf::Event& e) { switch (e.key.code) { case sf::Keyboard::C: changeCameraMode(); break; case sf::Keyboard::F1: m_helpDisplayed = !m_helpDisplayed; break; case sf::Keyboard::F2: takeScreenshot(); break; case sf::Keyboard::F3: reloadShaderPrograms(); break; case sf::Keyboard::F4: if( m_animationIsStarted ) stopAnimation(); else startAnimation(); break; case sf::Keyboard::F5: resetAnimation(); for(RenderablePtr r : m_renderables) r->keyPressedEvent(e); break; case sf::Keyboard::W: if( e.key.control ) m_applicationRunning = false; break; case sf::Keyboard::Q: keyboard.left = true; keyboard.direction.x = -1; break; case sf::Keyboard::S: keyboard.backward = true; keyboard.direction.z = -1; break; case sf::Keyboard::D: keyboard.right = true; keyboard.direction.x = 1; break; case sf::Keyboard::Z: keyboard.forward = true; keyboard.direction.z = 1; break; case sf::Keyboard::Space: keyboard.fast = true; break; case sf::Keyboard::LShift: keyboard.slow = true; break; default: for(RenderablePtr r : m_renderables) r->keyPressedEvent(e); break; } }
PassRefPtr<SVGPropertyBase> SVGAnimatedTypeAnimator::resetAnimValToBaseVal(const WillBeHeapVector<RawPtrWillBeMember<SVGElement> >& list) { SVGElement::InstanceUpdateBlocker blocker(m_contextElement); return resetAnimation(list); }
void GLWidget::updateCatmullRomSpline() { if (controlPoints.size() >= 4) { this->catmullRomSpline = CatmullRomSpline(controlPoints); resetAnimation(); } }