public override void Update(GameTime dt) { base.Update(dt); if (Selected) { scaleTimer += gttf(dt) * ScaleSpeed; if (scaleTimer > 1) { scaleTimer = 1.0f; } UniformScale = JabMath.MoveTowards(UniformScale, ScaleOnHover, gttf(dt) * 5.0f, 0.01f); } else { scaleTimer -= gttf(dt) * ScaleSpeed; if (scaleTimer < 0) { scaleTimer = 0.0f; } UniformScale = JabMath.MoveTowards(UniformScale, RegularScale, gttf(dt) * 5.0f, 0.01f); } //UniformScale = JabMath.LinearInterpolate(RegularScale, ScaleOnHover, scaleTimer); }
void SetScale() { float posx = PosX; float targetX = targetAreaPos.X; float originX = originPos.X; if (posx < originX) { posx = originX; } else if (posx > targetX) { posx = targetX; } float distBetween = Math.Abs(targetX - originX); targetX -= originX; posx -= originX; posx /= targetX; if (UniformWorldScale > JabMath.LinearInterpolate(scaleAtTarget, scaleAtTarget, posx)) { UniformWorldScale = JabMath.LinearInterpolate(scaleAtTarget, scaleAtTarget, posx); } else if (UniformWorldScale < maxCamScale) { UniformWorldScale = JabMath.MoveTowards(UniformWorldScale, maxCamScale, 0.05f, 0.01f);// JabMath.LinearInterpolate(UniformWorldScale, maxCamScale, posx); //maxCamScale; } targetPos.Y = JabMath.LinearInterpolate(originPos.Y, targetPos.Y, posx); }
public override void Update(GameTime gameTime) { base.Update(gameTime); distTravelled += Body.LinearVelocity.Length(); if (AsType.UniformScale < 0.69f) { AsType.UniformScale = JabMath.MoveTowards(AsType.UniformScale, 0.7f, 0.25f); } else { AsType.UniformScale = 0.7f; } if (distTravelled > 32) { Body.CollisionGroup = 0; } if (destructionTimer > 0) { destructionTimer -= gttf(gameTime); if (destructionTimer < 0) { RaiseFlag(Jabber.Flags.DELETE); Explosion exp = new Explosion(10, 300, 1.0f, 0.7f, scene.World, Position); Body.IgnoreRayCast = true; exp.Initialize(Jabber.BaseGame.Get.Content); exp.Position = Position; scene.AddNode(exp); RaiseFlag(Jabber.Flags.DELETE); Body.IgnoreRayCast = false; AudioQueue.PlayOnce("Sounds/Explode_Chicken"); } else { float val = destructionTimer; Colour = new Color(1.0f, val, val, 1.0f); // AsType.UniformScale = (float)Math.Sin(destructionTimer * 5.0f * JabMath.PI) + 1; AsType.UniformScale = JabMath.LinearInterpolate(0.8f, 0.85f, (float)Math.Sin(destructionTimer * 5.0f * JabMath.PI) + 1); DoDimensions = false; int k = 0; } } if (Body.LinearVelocity.Length() < 0.001f) { noMoveTimer += gttf(gameTime); if (noMoveTimer > 1.0f && destructionTimer < 0) { destructionTimer = 1.0f; } } else { noMoveTimer = 0.0f; } }
public override void Update(GameTime dt) { base.Update(dt); currentPlayPos = AudioManager.PlayingMusicPosition; for (int i = 0; i < frames.Count; i++) { frames[i].sprite.PosX = i * BaseGame.Get.BackBufferWidth + shiftx; } shiftx = JabMath.MoveTowards(shiftx, newShiftXTarget, gttf(dt) * 3.0f, 150); if (shiftx == newShiftXTarget && shiftWhen.Count == 0) { RaiseFlag(Flags.DELETE); WorldSelectScreen s = new WorldSelectScreen(); s.Initialize(Content); s.SetCurrentCountry("uluru"); ScreenManager.Get.AddScreen(s); } timer += gttf(dt); if (shiftWhen.Count > 0) { if (currentPlayPos > shiftWhen[0] || (!AudioManager.MusicPlaying && timer > shiftWhen[0]))// || (shiftx == 0 && timer > 4.6f)) { shiftWhen.RemoveAt(0); newShiftXTarget -= BaseGame.Get.BackBufferWidth; } } lastPlayPos = AudioManager.PlayingMusicPosition; }
public override void Update(GameTime dt) { base.Update(dt); GlobalXFudge = 55.0f / 2.0f * ScaleFactor; return; if (!CheckFlag(Flags.FADE_OUT)) { GlobalXFudge = JabMath.MoveTowards(GlobalXFudge, 55.0f / 2.0f * ScaleFactor, gttf(dt) * 2.5f, 1.5f); float totalDistToTravel = (-100.0f / 2.0f * ScaleFactor) - (55.0f / 2.0f * ScaleFactor); totalDistToTravel = Math.Abs(totalDistToTravel); float distTravelled = (-100.0f / 2.0f * ScaleFactor) - GlobalXFudge; distTravelled = Math.Abs(distTravelled); Colour = Color.White * (distTravelled / totalDistToTravel); } else { GlobalXFudge = JabMath.MoveTowards(GlobalXFudge, -100.0f / 2.0f * ScaleFactor, gttf(dt) * 2.5f, 1.5f); float totalDistToTravel = (-100.0f / 2.0f * ScaleFactor) - (55.0f / 2.0f * ScaleFactor); totalDistToTravel = Math.Abs(totalDistToTravel); float distTravelled = (-100.0f / 2.0f * ScaleFactor) - GlobalXFudge; distTravelled = Math.Abs(distTravelled); Colour = Color.White * (1.0f - (distTravelled / totalDistToTravel)); } }
public override void Update(GameTime dt) { base.Update(dt); Timer += gttf(dt) * 5.0f; if (Timer > 1.0f) { RaiseFlag(Flags.DELETE); Timer = 1.0f; } Colour = Color.White * (1.0f - Timer); Width = Height = JabMath.MoveTowards(Width, maxRadius, gttf(dt) * 20.0f) * maxRadiusScale; }
public override void Update(GameTime dt) { base.Update(dt); if (CheckFlag(Flags.FADE_OUT)) { fadeTimer = JabMath.MoveTowards(fadeTimer, 0, gttf(dt) * 4); } else if (CheckFlag(Flags.FADE_IN)) { fadeTimer = JabMath.MoveTowards(fadeTimer, 1, gttf(dt) * 6); } }
public override void Update(GameTime dt) { base.Update(dt); fadeInTimer += gttf(dt); if (fadeInTimer > 1) { fadeInTimer = 1.0f; } Colour = Color.Black * 1 * 0.4f; Height = JabMath.MoveTowards(Height, BaseGame.Get.BackBufferHeight, gttf(dt) * 15, 10); }
public override void Update(GameTime dt) { base.Update(dt); if (lastPos != targetPos && !LevelSelect) { float totalLength = (lastPos - targetPos).Length(); float curLength = (Position - targetPos).Length(); float prop = 1.0f - curLength / totalLength; float interp = JabMath.Sin(curLength * JabMath.PI / totalLength); if (curLength == 0 && UniformWorldScale != minScale) { if (lastcurLength != 0) { lastcurLength = 0; UniformWorldScale = minScale; } else { UniformWorldScale = JabMath.MoveTowards(UniformWorldScale, minScale, gttf(dt) * 5.0f, 0.001f); } } else if (curLength != 0) { lastcurLength = curLength; if (totalLength < 300) { UniformWorldScale = JabMath.LinearInterpolate(minScale, 1.5f, interp); } else { UniformWorldScale = JabMath.LinearInterpolate(minScale, 0.8f, interp); } } } else if (LevelSelect) { UniformWorldScale = JabMath.MoveTowards(UniformWorldScale, targetScale, gttf(dt) * 5.0f, 0.001f); } else { UniformWorldScale = JabMath.MoveTowards(UniformWorldScale, minScale, gttf(dt) * 5.0f, 0.001f); } Position = JabMath.MoveTowards(Position, targetPos, gttf(dt) * 5.0f, 5.0f); }
public override void Update(GameTime dt) { base.Update(dt); Dictionary <float, float> dic = new Dictionary <float, float>(); dic.Add(-0.1f * BaseGame.Get.BackBufferWidth, 3); dic.Add(0.0f * BaseGame.Get.BackBufferWidth, 3); dic.Add(0.1f * BaseGame.Get.BackBufferWidth, 3); for (int i = 0; i < stars.Count; i++) { stars[i].PosX = stars[i].TargetPos.X; stars[i].PosY = JabMath.MoveTowards(stars[i].PosY, stars[i].TargetPos.Y, gttf(dt) * dic[stars[i].PosX], 3); } }
public override void Update(GameTime gameTime) { base.Update(gameTime); Body.UserData = this; if (health <= 0) { health = 0; if (!SplintersCreated) { CreateSplinters(); SplintersCreated = true; } RaiseFlag(Jabber.Flags.DELETE); Body.CollisionGroup = BodyNoneCollisionGroup; Body.IgnoreRayCast = true; } if (InFan) { Body.LinearVelocity = new Vector2(Body.LinearVelocity.X, 0); if (!InBentFan) { Body.LinearDamping = 150.0f; } if (fanTimer == 0) { fanTimer = RandomFloat * 2.0f * JabMath.PI; } fanTimer += gttf(gameTime) * 2.0f; Body.PosY += JabMath.Sin(fanTimer) / 3.0f; } else { Body.BodyState = JabActor.BodyType.DYNAMIC; //Body.AngularDamping = Body.LinearDamping = 0.5f; Body.LinearDamping = Body.AngularDamping = JabMath.MoveTowards(Body.LinearDamping, 0.75f, gttf(gameTime) * 3.0f); } if (InFan || InBentFan) { Body.AngularDamping = 20.0f; } InFan = false; InBentFan = false; }
public override void Update(GameTime dt) { base.Update(dt); PosY = -13.0f * ScaleFactor; if (CheckFlag(Jabber.Flags.FADE_IN) && !CheckFlag(Jabber.Flags.FADE_OUT)) { fadeTimer += gttf(dt) * 2.0f; if (fadeTimer > 1) { fadeTimer = 1; } UniformWorldScale = JabMath.MoveTowards(UniformWorldScale, 0.99f, gttf(dt) * 6); if (UniformWorldScale <= 1.0f) { UniformWorldScale = 1.0f; LowerFlag(Jabber.Flags.FADE_IN); } } else if (CheckFlag(Jabber.Flags.FADE_OUT)) { LowerFlag(Jabber.Flags.FADE_IN); UniformWorldScale = JabMath.MoveTowards(UniformWorldScale, 3.1f, gttf(dt) * 6); if (UniformWorldScale >= 3.0f) { UniformWorldScale = 3.0f; LowerFlag(Jabber.Flags.FADE_OUT); OnFadeOutComplete(); } } if (pressingDown) { xOffset = targetDrag * BaseGame.Get.BackBufferWidth; } else { xOffset = JabMath.MoveTowards(xOffset, targetDrag * BaseGame.Get.BackBufferWidth, gttf(dt) * 5); } Camera.Get.PosX = -xOffset; }
public override void Update(GameTime dt) { inRoutine = !CheckFlag(Flags.FADE_OUT); if (!inRoutine && !firstDroppedBelow) { inRoutine = true; } if (fadeInTimer != 1 && CheckFlag(Flags.FADE_IN)) { fadeInTimer = JabMath.MoveTowards(fadeInTimer, 1.0f, gttf(dt) * 6, 0.01f); if (fadeInTimer == 1.0f) { OnFadeInComplete(); } } else if (fadeInTimer != 0 && CheckFlag(Flags.FADE_OUT) && !inRoutine) { fadeInTimer = JabMath.MoveTowards(fadeInTimer, 0.0f, gttf(dt) * 3, 0.01f); } if (CheckFlag(Flags.FADE_OUT) && feathers.Count == 0) { OnFadeOutComplete(); RaiseFlag(Flags.DELETE); } for (int i = 0; i < feathers.Count; i++) { feathers[i].Update(dt); } if (CheckFlag(Flags.FADE_OUT) && !inRoutine) { featherFadeOutAlpha -= gttf(dt) / 5.0f * ScaleFactor; if (featherFadeOutAlpha < 0) { featherFadeOutAlpha = 0; } } if (StateFlag == Jabber.StateFlag.FADE_OUT_COMPLETE) { LowerFlag(Flags.FADE_IN); fadeInTimer = JabMath.MoveTowards(fadeInTimer, 0.0f, gttf(dt) * 3, 0.01f); } }
public override void Update(GameTime dt) { base.Update(dt); updatecalled = true; if (CheckFlag(Flags.FADE_OUT)) { timer = JabMath.MoveTowards(timer, 0, gttf(dt) * 4.5f, 0.001f); if (timer == 0) { RaiseFlag(Flags.DELETE); } } else { timer = JabMath.MoveTowards(timer, 1.0f, gttf(dt) * 1.5f); } Colour = new Color(timer, timer, timer, timer); }
public override void Update(GameTime dt) { base.Update(dt); if (CheckFlag(Flags.FADE_OUT) && fadeOutTimer != 0) { fadeOutTimer -= gttf(dt) * 6.0f; if (fadeOutTimer < 0) { fadeOutTimer = 0.0f; OnFadeOutComplete(); } } for (int i = 0; i < texts.Count; i++) { if (texts[i].isSelected) { texts[i].text.UniformScale = JabMath.MoveTowards(texts[i].text.UniformScale, ScaleFactor / 1.75f, gttf(dt) * textMoveSpeed, 0.01f); } else { texts[i].text.UniformScale = JabMath.MoveTowards(texts[i].text.UniformScale, ScaleFactor / 2.0f, gttf(dt) * textMoveSpeed, 0.01f); } } chickenCurrentX = JabMath.MoveTowards(chickenCurrentX, chickenTargetX, gttf(dt) * chickenMoveSpeed); float targetWidth = BaseGame.Get.BackBufferWidth * 0.15f; currentWidth = JabMath.MoveTowards(currentWidth, targetWidth, gttf(dt) * widthMoveSpeed, 10 * ScaleFactor); for (int i = texts.Count - 1; i >= 0; i--) { texts[i].text.PosX = JabMath.MoveTowards(texts[i].text.PosX, textTargetX, gttf(dt) * textMoveSpeed); int mirror = texts.Count - i; texts[i].text.PosY = BaseGame.Get.HalfBackBufferHeight * mirror / texts.Count - 150.0f * ScaleFactor; texts[i].text.PosY *= 1.2f; } }
public override void Update(GameTime dt) { if (NumSlide > 0) { slide.Volume = JabMath.MoveTowards(slide.Volume, 1.0f, gttf(dt) * 2.0f); } else { slide.Volume = JabMath.MoveTowards(slide.Volume, 0.0f, gttf(dt) * 2.0f); } base.Update(dt); for (int i = 0; i < breakSounds.Count; i++) { breakSounds[i].lastPlayed -= gttf(dt); if (breakSounds[i].lastPlayed < 0) { breakSounds.RemoveAt(i); --i; } } for (int i = 0; i < hitSounds.Count; i++) { hitSounds[i].lastPlayed -= gttf(dt); if (hitSounds[i].lastPlayed < 0) { hitSounds.RemoveAt(i); --i; } } breakSounds.Clear(); hitSounds.Clear(); // if an explosion sfx is playing don't play any other sfx! bool AnyExplosion = false; for (int i = 0; i < ToPlay.Count; i++) { String dir = ToPlay[i].Dir; if (dir == "Sounds/Explode_Chicken" || dir == "Sounds/Explosion") { SoundInst inst = GetInst(dir); if (!inst.IsPlaying) { inst.Play(ToPlay[i].Volume); } else { AudioManager.PlayOnce(dir); } AnyExplosion = true; break; } } if (!AnyExplosion) { for (int i = 0; i < ToPlay.Count; i++) { String dir = ToPlay[i].Dir; if (ShouldSoundPlay(dir)) { SoundInst inst = GetInst(dir); if (!inst.IsPlaying) { inst.Play(ToPlay[i].Volume); } } } } ToPlay.Clear(); }
public override void Update(GameTime dt) { base.Update(dt); if (MediaPlayer.PlayPosition.TotalSeconds > 6) { timer1 = 1; } if (MediaPlayer.PlayPosition.TotalSeconds > 11) { RaiseFlag(Flags.DELETE); WorldSelectScreen s = new WorldSelectScreen(); s.Initialize(BaseGame.Get.Content); s.SetCurrentCountry("vesuvius"); ScreenManager.Get.AddScreen(s); return; } if (timer1 < 1 || !AudioManager.MusicPlaying) { timer1 += gttf(dt) / 3.0f; } else if (timer2 < 1) { longstrip.PosX = JabMath.LinearMoveTowards(longstrip.PosX, -Jabber.BaseGame.Get.BackBufferWidth / 2.0f, gttf(dt) * 200 * ScaleFactor); if (Math.Abs(longstrip.PosX - -Jabber.BaseGame.Get.BackBufferWidth / 2.0f) < 400 * ScaleFactor) { float f = longstrip.Colour.ToVector4().W; f = JabMath.MoveTowards(f, 0, gttf(dt) * 1.3f); longstrip.Colour = Color.White * f; if (f == 0) { timer2 = 1.0f; } } if (longstrip.PosX == -Jabber.BaseGame.Get.BackBufferWidth / 2.0f) { timer2 += gttf(dt) / 4.0f; } } if (Math.Abs(longstrip.PosX - -Jabber.BaseGame.Get.BackBufferWidth / 2.0f) < 400 * ScaleFactor) { finalimage.PosX = JabMath.LinearMoveTowards(finalimage.PosX, 0, gttf(dt) * 150 * ScaleFactor); if (finalimage.PosX == 0)//-Jabber.BaseGame.Get.BackBufferWidth / 3.0f) { timer3 += gttf(dt) / 5.5f; } if (timer3 > 1.0f) { RaiseFlag(Flags.DELETE); WorldSelectScreen s = new WorldSelectScreen(); s.Initialize(BaseGame.Get.Content); s.SetCurrentCountry("vesuvius"); ScreenManager.Get.AddScreen(s); } } }
public override void Update(GameTime gameTime) { if (!hasCollidedOnce) { featherTrail.Add(CreateFeather()); } if (Body.LinearVelocity.Length() < 0.5f && IsSliding) { IsSliding = false; AudioQueue.PlaySlide(false); } if (Body.LinearVelocity.Length() < 0.5f) { AsType.CurrentAnim.Speed = 0; } else { AsType.CurrentAnim.Speed = 20; } hitTimer -= gttf(gameTime); if (launchInst.Volume != 1.0f) { launchInst.Volume = JabMath.MoveTowards(launchInst.Volume, 0.0f, gttf(gameTime) * 5.0f); } if (hasHitContact) { targetDamping = 1.5f; hasHitContact = true; if (Body.PosX > scene.GetRightMaxPos() + 5000 || Body.PosY < -10 || Body.PosX < scene.startPos.X - 5000) { RaiseFlag(Jabber.Flags.DELETE); } //if (Body.LinearVelocity.Length() > 4.0f) { //Vector2 vel = Body.LinearVelocity; //vel.Normalize(); //vel *= 4.0f; //Body.LinearVelocity = vel; } } //Body.LinearDamping = JabMath.MoveTowards(Body.LinearDamping, targetDamping, gttf(gameTime) * 50, 0.03f); base.Update(gameTime); //Body.Restitution = oldRestitution; if (Body.LinearVelocity.Length() > 0.5f) { AsType.Animation = AccelerateAnimation; Vector2 dir = Body.LinearVelocity; dir.Normalize(); AsType.Rot = (float)Math.Atan2((float)dir.X, (float)dir.Y); /* * if (firstUpdate) * AsType.Rot = (float)Math.Atan2((float)dir.X, (float)dir.Y); * else * AsType.Rot = JabMath.MoveTowards(Rot, (float)Math.Atan2((float)dir.X, (float)dir.Y), gttf(gameTime) * 3.0f);*/ } else { AsType.Rot = Body.Rot;// JabMath.MoveTowards(Rot, 0, gttf(gameTime) * 3.0f); } // Check to see if chicken should be made to be in-active (if it is currently active).. if (active) { if (Body.LinearVelocity.Length() <= 0.00001f) { zeroTimer += gttf(gameTime); if (zeroTimer > 1) { active = false; } } else { zeroTimer = 0; } } firstUpdate = false; }
public override void Update(GameTime gameTime) { base.Update(gameTime); if (CheckFlag(Flags.FADE_OUT)) { float a = Colour.A / 255.0f; float d = JabMath.MoveTowards(a, 0.0f, gttf(gameTime) * 2.0f, 0.001f); Colour = Color.White * d; if (d == 0) { RaiseFlag(Flags.DELETE); } return; } if (PosX > world.GetRightMaxPos() + 1000 || PosX < world.startPos.X - 1000) { Rot = 0.5f * JabMath.PI; } if (Math.Abs(Rot) > 0.45f * JabMath.PI) { deathTimer += gttf(gameTime) * 5.0f; while (deathTimer > 1.0f && numDonutsMade < 5) { deathTimer -= 1.0f; Donut d = new Donut(world); AudioQueue.PlayOnce("Sounds/pop"); d.Initialize(BaseGame.Get.Content); d.Position = Position + new Vector2(RandomFloatInRange(-0.5f, 0.5f) * Width, RandomFloatInRange(-0.5f, 0.5f) * Height); d.Chosen = true; world.AddNode(d); deathTimer -= 1.0f; ++numDonutsMade; float oldWidth = Body.Width; float oldHeight = Body.Height; Vector2 oldPos = Body.Position; float oldRot = Body.Rot; oldWidth *= 0.9f; oldHeight *= 0.9f; Vector2 linearVelocity = Body.LinearVelocity; float angularVelocity = Body.AngularVelocity; Body.RaiseFlag(Flags.DELETE); Body.CollisionGroup = Donut.DonutCollisionGroup; Body = world.World.CreateBox(new Vector2(oldWidth, oldHeight), oldPos, JabActor.BodyType.DYNAMIC); Body.Rot = oldRot; Body.LinearVelocity = linearVelocity; Body.AngularVelocity = angularVelocity; //Sprite.Width = oldWidth; //Sprite.Height = oldHeight; } if (numDonutsMade > 4) { RaiseFlag(Flags.DELETE); } //Colour = Color.White * ((5.0f - numDonutsMade) / 5.0f); } Sprite.Width = JabMath.MoveTowards(Sprite.Width, Body.Width, gttf(gameTime) * 1.0f); Sprite.Height = JabMath.MoveTowards(Sprite.Height, Body.Height, gttf(gameTime) * 1.0f); // Body.LinearDamping = 0.15f; // Body.AngularDamping = 0.3f; }
public void FreeCamDrag(GameTime dt) { SetScale(); #if WINDOWS_PHONE || IPHONE if (InputManager.Get.Finger1Valid && InputManager.Get.Finger2Valid && Finger1ValidLastFrame && Finger2ValidLastFrame) { Vector2 thisFinger1Pos = InputManager.Get.Finger1Pos; Vector2 thisFinger2Pos = InputManager.Get.Finger2Pos; float distThisPos = (thisFinger1Pos - thisFinger2Pos).Length(); float distLastPos = (lastFinger2Pos - lastFinger1Pos).Length(); if (validScrollLastFrame) { DoZoom((distThisPos - distLastPos) / 2.0f); UniformWorldScale = oldScale; } validScrollLastFrame = true; } else { validScrollLastFrame = false; } if (InputManager.Get.Finger2Valid) { //if (!Finger2ValidLastFrame) { lastFinger2Pos = InputManager.Get.Finger2Pos; } Finger2ValidLastFrame = true; } else { Finger2ValidLastFrame = false; } if (InputManager.Get.Finger1Valid) { if (Finger1ValidLastFrame && !(screen.CameraFollowingChicken || screen.CannonBeingDragged) && screen.IsTopScreen && !InputManager.Get.Finger2Valid) { Vector2 thispos = InputManager.Get.Finger1Pos; draggingThisFrame = true; Vector2 lastPos = ScreenToWorld(lastFinger1Pos); thispos = ScreenToWorld(InputManager.Get.Finger1Pos); float absoluteFarRightAllowed = RightMostWherePosXIs(targetAreaPos.X); float absoluteFarLeftAllowed = LeftMostWherePosXIs(originPos.X); if (ScreenToWorld(new Vector2(1, 0)).X > absoluteFarRightAllowed) { TargetPos = TargetPos + (lastPos - thispos) * 1.0f; } else if (ScreenToWorld(Vector2.Zero).X < absoluteFarLeftAllowed) { TargetPos = TargetPos + (lastPos - thispos) * 1.0f; } else { TargetPos = TargetPos + (lastPos - thispos) * 3.0f; } } else if (Finger1ValidLastFrame && Finger2ValidLastFrame) { if (Finger1And2ValidLastFrame) { Vector2 Finger1And2Center = (InputManager.Get.Finger1Pos + InputManager.Get.Finger2Pos) / 2.0f; Vector2 lastPos = ScreenToWorld(Finger1And2CenterLastFrame); Vector2 thispos = ScreenToWorld(Finger1And2Center); float absoluteFarRightAllowed = RightMostWherePosXIs(targetAreaPos.X); float absoluteFarLeftAllowed = LeftMostWherePosXIs(originPos.X); if (ScreenToWorld(new Vector2(1, 0)).X > absoluteFarRightAllowed) { TargetPos = TargetPos + (lastPos - thispos) * 1.0f; } else if (ScreenToWorld(Vector2.Zero).X < absoluteFarLeftAllowed) { TargetPos = TargetPos + (lastPos - thispos) * 1.0f; } else { TargetPos = TargetPos + (lastPos - thispos) * 10.0f; } } } Finger1And2ValidLastFrame = Finger1ValidLastFrame && Finger2ValidLastFrame; if (Finger1And2ValidLastFrame) { Finger1And2CenterLastFrame = (lastFinger1Pos + lastFinger2Pos) / 2.0f; } } else { draggingThisFrame = false; } if (InputManager.Get.Finger1Valid) { Finger1ValidLastFrame = true; lastFinger1Pos = InputManager.Get.Finger1Pos; } else { Finger1ValidLastFrame = false; } #endif CapOverflow(); float farRightAllowed = RightMostWherePosXIs(targetAreaPos.X); float farLeftAllowed = LeftMostWherePosXIs(originPos.X); // manage left/right overflow.. float rightMostPos = Camera.Get.ScreenToWorld(new Vector2(1, 0)).X; float leftMostPos = Camera.Get.ScreenToWorld(Vector2.Zero).X; if (farRightAllowed < rightMostPos && !draggingThisFrame) { float rms = PosXWhereRightMostIs(farRightAllowed); TargetPos = new Vector2(rms, TargetPos.Y); } // todo: fix left overflow else if (farLeftAllowed > leftMostPos && !draggingThisFrame) { if (PosX < originPos.X) { TargetPos = originPos; } //float lms = PosXWhereLeftMostIs(screen.leftMostPos); // TargetPos = new Vector2(lms, TargetPos.Y); } //UniformWorldScale = 0.3f; // move camera towards target position if (TargetPos != Position) { PosX = JabMath.MoveTowards(PosX, TargetPos.X, gttf(dt) * 3.0f, 5);// (TargetPos.X - PosX) * gttf(dt) * 3.0f; PosY = JabMath.MoveTowards(PosY, TargetPos.Y, gttf(dt) * 3.0f, 5); //PosY += (TargetPos.Y - PosY) * gttf(dt) * 3.0f; } CapOverflow(); }
public override void Update(GameTime dt) { base.Update(dt); /* * if (scaleUp) * { * scaleTimer += gttf(dt) * 6.0f; * if (scaleTimer >= 1.5f) * { * scaleUp = false; * } * } * else * { * scaleTimer -= gttf(dt); * } * Colour = new Color(scaleTimer, scaleTimer, scaleTimer, scaleTimer); * * if (scaleTimer <= 0 && !scaleUp) * { * scaleTimer = 0; * RaiseFlag(Flags.DELETE); * } * Colour = Color.White * scaleTimer; */ scaleTimer += gttf(dt) * 5.0f; if (scaleTimer < 1.0f) { UniformScale = scaleTimer * 2.0f; } else if (scaleTimer < 4.0f) { UniformScale = 2.0f; } else { /* Vector2 targetPos = board.ScaledPos;// +new Vector2(board.text.Width * board.text.ScaleX / 2.0f, 0); * Position = JabMath.MoveTowards(Position, targetPos, gttf(dt) * 10); * UniformScale = board.ScaledScale;// JabMath.MoveTowards(UniformScale, board.text.UniformScale, gttf(dt)); * * float a = Colour.A / 255.0f; * a -= gttf(dt); * Colour = new Color(a, a, a, a); * * if (a == 0) * { * RaiseFlag(Flags.DELETE); * } * if ((Position - targetPos).Length() < 5) * { * RaiseFlag(Flags.DELETE); * } * */ UniformScale = JabMath.MoveTowards(UniformScale, 0.0f, gttf(dt) * 4.0f, 0.001f); if (UniformScale == 0.0f) { RaiseFlag(Flags.DELETE); } } }
void FollowChicken(GameTime dt) { if (UniformWorldScale == maxCamScale) { // return; } List <Chicken> chicks = screen.withChicks.GetChicks(); if (!FollowingChicken) { FollowingChicken = true; lastPosBeforeFire = Position; lastScaleBeforeFire = UniformWorldScale; } Chicken activeChicken = screen.withChicks.ActiveChicken; if (activeChicken == null) { //activeChicken = screen.withChicks.LastChicken; } if (activeChicken == null) { screen.ForceChickenInActive(); return; } float maxAllowedRight = RightMostWherePosXIs(targetAreaPos.X); if (activeChicken.PosX > maxAllowedRight) { activeChicken.Deactivate(); followingChickenLastFrame = false; return; } if (activeChicken.PosX > furthestLeft && ScaleOnFire != maxCamScale) { targetPos = targetAreaPos; if (activeChicken.PosY < mostHigh && activeChicken.PosY + 200 < Camera.Get.ScreenToWorld(Vector2.Zero).Y) { UniformWorldScale = JabMath.MoveTowards(UniformWorldScale, scaleAtTarget, gttf(dt) * 3.0f); } else { float targetScale = ScaleToCoverVerticalArea(activeChicken.PosY + 200, ScreenToWorld(Vector2.One).Y); if (targetScale < 0.1f) { targetScale = 0.1f; } else if (targetScale > scaleAtTarget) { targetScale = scaleAtTarget; } UniformWorldScale = JabMath.MoveTowards(UniformWorldScale, targetScale, gttf(dt) * 3.0f); //targetScale; } } else { float targetScale = ScaleToCoverVerticalArea(activeChicken.PosY + 200, ScreenToWorld(Vector2.One).Y); if (targetScale < 0.1f) { targetScale = 0.1f; } else if (targetScale > 0.5f) { targetScale = 0.5f; } targetPos.Y = (PosY + activeChicken.PosY) / 2.0f; if (ScaleOnFire != maxCamScale) { targetPos.X = PosXWhereLeftMostIs(activeChicken.PosX - 100); } } if (ScreenToWorld(new Vector2(0, 0.2f)).Y < activeChicken.PosY) { float targetScale = ScaleToCoverVerticalArea(activeChicken.PosY + 200, ScreenToWorld(Vector2.One).Y); if (targetScale < 0.1f) { targetScale = 0.1f; } else if (targetScale > scaleAtTarget) { targetScale = scaleAtTarget; } UniformWorldScale = JabMath.MoveTowards(UniformWorldScale, targetScale, gttf(dt) * 3.0f); } if (PosX > targetAreaPos.X) { PosX = targetAreaPos.X; } if (TargetPos != Position) { PosX = JabMath.MoveTowards(PosX, TargetPos.X, gttf(dt) * 3.0f, 10); PosY = JabMath.MoveTowards(PosY, TargetPos.Y, gttf(dt) * 3.0f, 10); } followingChickenLastFrame = true; if (UniformWorldScale > ScaleOnFire) { UniformWorldScale = ScaleOnFire; } }