public override void Update(float dt) { base.Update(dt); if (!player.Health.Dead) { // Check whether we should be facing left if (player.FacingRight) { spriteEffects = SpriteEffects.None; camOffset.X += camScrollRateX * dt; if (this.CamOffset.X > maxCamOffsetX) { camOffset.X = maxCamOffsetX; } } else { spriteEffects = SpriteEffects.FlipHorizontally; camOffset.X -= camScrollRateX * dt; if (this.CamOffset.X < -maxCamOffsetX) { camOffset.X = -maxCamOffsetX; } } // Update camera this.Cam.Update(dt); this.Cam.Position = player.ScreenPosition + this.CamOffset; // Update running speed if (Math.Abs(player.PhysicsContainer.Object.body.LinearVelocity.X) < 3) { runAnimation.FrameTime = 50; } else { runAnimation.FrameTime = 25; } // First, get the state if (player.State == State.Idle) { if (player.Health.Hit) { currentAnimation = idleFrozenAnimation; } else if (player.Dashing) { currentAnimation = dashAnimation; } else if (player.WeaponActive()) { if (player.WeaponActiveAndVertical()) { currentAnimation = idleFrozenAnimation; } else { currentAnimation = idleShootAnimation; } } else { currentAnimation = idleAnimation; } } else if (player.State == State.Running) { currentAnimation = runAnimation; } else if (player.State == State.Jumping) { currentAnimation = jumpAnimation; } else if (player.State == State.Falling) { currentAnimation = fallAnimation; } // Next, check the events CheckEvents(); // Only update the animation for the current state currentAnimation.Position = player.ScreenPosition + shakePositionOffset; currentAnimation.Rotation = player.ScreenRotation; currentAnimation.Update(dt); currentAnimation.SpriteEffects = spriteEffects; // Update the eyes adjustEyesOffset(); eyesFrame.Position = player.ScreenPosition + eyesOffset + shakePositionOffset; eyesFrame.Rotation = player.ScreenRotation; eyesFrame.SpriteEffects = spriteEffects; } // Update the weapons, regardless whether the player is dead gunRepresentation.Update(dt); swordRepresentation.Update(dt); // Update the dashing trail if (player.Dashing && !player.Health.Dead) { dashTrailEmitter.Run(); } else { dashTrailEmitter.Stop(); } dashTrailEmitter.DisplayEntity = currentAnimation; dashTrailEmitter.Update(dt); }
public override void LoadContent(ContentManager content) { // Choose color if (player.PlayerIndex == PlayerIndex.One) // Green this.color = new Color(0, 255, 0); else if (player.PlayerIndex == PlayerIndex.Two) // Blue this.color = new Color(0, 255, 255); else if (player.PlayerIndex == PlayerIndex.Three) // Yellow this.color = new Color(255, 255, 0); else if (player.PlayerIndex == PlayerIndex.Four) // Pink this.color = new Color(255, 200, 255); spriteSheet = new SpriteSheet(); spriteSheet.Sheet = content.Load<Texture2D>("animationsheet"); spriteSheet.Map = content.Load<Dictionary<string, Rectangle>>("animationsheetmap"); spriteEffects = SpriteEffects.None; float spritePaddingScale = 1f; // Load animations: // idle animation int idleFrameTime = 120; idleAnimation = new Animation(); idleAnimation.Initialize(spriteSheet, Vector2.Zero, idleAnimationName, idleFrameTime, this.color, spritePaddingScale, spriteEffects, true); idleAnimation.LayerDepth = playerLayerDepth; // make this the current animation currentAnimation = idleAnimation; // idle frozen animation int idleFrozenFrameTime = 0; idleFrozenAnimation = new Animation(); idleFrozenAnimation.Initialize(spriteSheet, Vector2.Zero, idleAnimationName, idleFrozenFrameTime, this.color, spritePaddingScale, spriteEffects, false); idleFrozenAnimation.LayerDepth = playerLayerDepth; // idle shoot animation int idleShootFrameTime = 30; idleShootAnimation = new Animation(); idleShootAnimation.Initialize(spriteSheet, Vector2.Zero, idleShootAnimationName, idleShootFrameTime, this.color, spritePaddingScale, spriteEffects, false); idleShootAnimation.LayerDepth = playerLayerDepth; // running animation int runFrameTime = 25; runAnimation = new Animation(); runAnimation.Initialize(spriteSheet, Vector2.Zero, runAnimationName, runFrameTime, this.color, spritePaddingScale, spriteEffects, true); runAnimation.LayerDepth = playerLayerDepth; // dash animation int dashFrameTime = 0; dashAnimation = new Animation(); dashAnimation.Initialize(spriteSheet, Vector2.Zero, dashAnimationName, dashFrameTime, this.color, spritePaddingScale, spriteEffects, false); dashAnimation.LayerDepth = playerLayerDepth; // jumping animation int jumpFrameTime = 120; jumpAnimation = new Animation(); jumpAnimation.Initialize(spriteSheet, Vector2.Zero, jumpAnimationName, jumpFrameTime, this.color, spritePaddingScale, spriteEffects, false); jumpAnimation.LayerDepth = playerLayerDepth; // falling animation int fallFrameTime = 120; fallAnimation = new Animation(); fallAnimation.Initialize(spriteSheet, Vector2.Zero, fallAnimationName, fallFrameTime, this.color, spritePaddingScale, spriteEffects, false); fallAnimation.LayerDepth = playerLayerDepth; // gun weapon animations int gunFrameTime = 30; int gunShotFrameTime = 30; gunRepresentation = new WeaponRepresentation<PlayerWeapon>(player, player.Gun, new Vector2(gunOffsetX, gunOffsetY)); gunRepresentation.InitializeAnimation(spriteSheet, Vector2.Zero, gunAnimationName, gunFrameTime, this.color, 1, spriteEffects, false); gunRepresentation.WeaponAnimation.LayerDepth = 0.05f; gunRepresentation.InitializeBullets(spriteSheet, Vector2.Zero, gunShotAnimationName, gunShotFrameTime, this.color, 1, spriteEffects, true); gunRepresentation.BulletsLayerDepth(0.05f); // sword weapon animations int swordFrameTime = 30; int swordShotFrameTime = 30; swordRepresentation = new WeaponRepresentation<PlayerWeapon>(player, player.Sword, new Vector2(swordOffsetX, swordOffsetY)); swordRepresentation.InitializeAnimation(spriteSheet, Vector2.Zero, swordAnimationName, swordFrameTime, this.color, 1, spriteEffects, false); swordRepresentation.WeaponAnimation.LayerDepth = 0.05f; swordRepresentation.InitializeBullets(spriteSheet, Vector2.Zero, swordShotAnimationName, swordShotFrameTime, this.color, 1, spriteEffects, true); swordRepresentation.BulletsLayerDepth(0.05f); // eyes frame eyesFrame = new Frame(); eyesFrame.Initialize(spriteSheet, Vector2.Zero, eyesFrameName, Color.White, spritePaddingScale, spriteEffects); eyesFrame.LayerDepth = playerLayerDepth - 0.001f; // dash trail particle emitter dashTrailEmitter.Initialize(5, 0.05f, 0.2f); }