void Player::update(float deltatime) { const sf::Vector2f gravity = { 0.f, 9.8f }; const sf::Vector2f vRight= { 1.f, 1.f }; const sf::Vector2f vLeft = { -1.f, 1.f }; handleInput(deltatime, gravity); scaleSprite(vLeft, vRight); m_velocity.y += deltatime * gravity.y; if (!onGround) { m_eAnimationType = JUMPING; } else if(onGround) { m_eAnimationType = IDLE; } if (m_eAnimationType == WALKING) { m_animatedSprite->play(*getAnimation("walking")); } else if (m_eAnimationType == JUMPING) { m_animatedSprite->play(*getAnimation("jump")); m_animatedSprite->setLooped(false); onGround = false; } else if (m_eAnimationType == IDLE) { m_animatedSprite->play(*getAnimation("idle")); } else if (m_eAnimationType == DUCKING) { m_animatedSprite->play(*getAnimation("duck")); } else if (m_eAnimationType == SHOOTING) { //something's up with this m_animatedSprite->play(*getAnimation("shooting")); } m_position += m_velocity; m_boxCollider->SetPosition(m_position); TestBodyRect.setPosition(m_position); m_animatedSprite->setPosition(m_position); m_animatedSprite->setOrigin(m_animatedSprite->getLocalBounds().width / 2, m_animatedSprite->getLocalBounds().height / 2); m_eAnimationType = IDLE; m_velocity *= 0.9f; bRight = false; bLeft = false; }
bool ArrangeSpriteOP<TBase>::onMouseDrag(int x, int y) { if (TBase::onMouseDrag(x, y)) return true; if (m_scaleOpen && m_scaling && m_scaleSelected.isValid()) { Vector pos = m_editPanel->transPosScreenToProject(x, y); scaleSprite(pos); return false; } if (m_selection->empty()) return false; Vector pos = m_editPanel->transPosScreenToProject(x, y); if (m_bRightPress) rotateSprite(pos); else translateSprite(pos - m_lastPos); m_lastPos = pos; return false; }
void drawPeople () { shufflePeople (); onScreenPerson * thisPerson = allPeople; personaAnimation * myAnim = NULL; overRegion = NULL; while (thisPerson) { if (thisPerson -> show) { myAnim = thisPerson -> myAnim; if (myAnim != thisPerson -> lastUsedAnim) { thisPerson -> lastUsedAnim = myAnim; thisPerson -> frameNum = 0; thisPerson -> frameTick = myAnim -> frames[0].howMany; if (myAnim -> frames[thisPerson -> frameNum].noise > 0) { startSound(myAnim -> frames[thisPerson -> frameNum].noise, false); thisPerson -> frameNum ++; thisPerson -> frameNum %= thisPerson -> myAnim -> numFrames; thisPerson -> frameTick = thisPerson -> myAnim -> frames[thisPerson -> frameNum].howMany; } else if (myAnim -> frames[thisPerson -> frameNum].noise) { startNewFunctionNum (- myAnim -> frames[thisPerson -> frameNum].noise, 0, NULL, noStack); thisPerson -> frameNum ++; thisPerson -> frameNum %= thisPerson -> myAnim -> numFrames; thisPerson -> frameTick = thisPerson -> myAnim -> frames[thisPerson -> frameNum].howMany; } } int fNumSign = myAnim -> frames[thisPerson -> frameNum].frameNum; int m = fNumSign < 0; int fNum = abs (fNumSign); if (fNum >= myAnim -> theSprites -> bank.total) { fNum = 0; m = 2 - m; } if (m != 2) { bool r = false; r = scaleSprite (myAnim->theSprites->bank.sprites[fNum], myAnim -> theSprites -> bank.myPalette, thisPerson, m); if (r) { if (thisPerson -> thisType -> screenName[0]) { if (personRegion.thisType != thisPerson -> thisType) lastRegion = NULL; personRegion.thisType = thisPerson -> thisType; overRegion = & personRegion; } } } } if (! -- thisPerson -> frameTick) { thisPerson -> frameNum ++; thisPerson -> frameNum %= thisPerson -> myAnim -> numFrames; thisPerson -> frameTick = thisPerson -> myAnim -> frames[thisPerson -> frameNum].howMany; if (thisPerson -> show && myAnim && myAnim -> frames) { if (myAnim -> frames[thisPerson -> frameNum].noise > 0) { startSound(myAnim -> frames[thisPerson -> frameNum].noise, false); thisPerson -> frameNum ++; thisPerson -> frameNum %= thisPerson -> myAnim -> numFrames; thisPerson -> frameTick = thisPerson -> myAnim -> frames[thisPerson -> frameNum].howMany; } else if (myAnim -> frames[thisPerson -> frameNum].noise) { startNewFunctionNum (- myAnim -> frames[thisPerson -> frameNum].noise, 0, NULL, noStack); thisPerson -> frameNum ++; thisPerson -> frameNum %= thisPerson -> myAnim -> numFrames; thisPerson -> frameTick = thisPerson -> myAnim -> frames[thisPerson -> frameNum].howMany; } } } thisPerson = thisPerson -> next; } }