public void Update(GameTime gameTime, KeyboardState ks, Boolean inHitstop) { Sprite.CurrentXVelocity = 0; // Might not be necessary // if (Sprite.CurrentMoveAnimation != null) { determineCurrentMove(gameTime, ks, inHitstop); } if (!inHitstop) { handlePerformCurrentMove(gameTime, ks); // This is basically for jumps as only jump movement is calculated via velocity // float time = (float)gameTime.ElapsedGameTime.TotalSeconds; Position += CurrentVelocity * time; sprite.Update(gameTime, Direction); HealthBar.Update(gameTime); SpecialBar.Update(gameTime); handleExtraMovement(); cleanUp(); } prevKeyboardState = Keyboard.GetState(); }
public virtual void DrawGauges(SpriteBatch spriteBatch) { //spriteBatch.Draw(HealthBar.HealthBarTexture, new Rectangle(HealthBar.HealthBarMargin, // 20, 425, 150), new Rectangle(0, 0, 425, 150), Color.White); //Draw the box around the health bar HealthBar.Draw(spriteBatch); SpecialBar.Draw(spriteBatch); //spriteBatch.Draw(HealthBar.HealthBarTexture, new Rectangle(HealthBar.HealthBarMargin, // 675, (int)(HealthBar.Width * ((double)CurrentSpecial / MaxSpecial)), 44), new Rectangle(0, 45, HealthBar.Width, 44), Color.Blue); //Draw the box around the health bar //spriteBatch.Draw(HealthBar.HealthBarTexture, new Rectangle(HealthBar.HealthBarMargin, // 675, HealthBar.Width, 44), new Rectangle(0, 0, HealthBar.Width, 44), Color.White); }
public void DrawHUD(SpriteBatch spriteBatch) { HealthBar.Draw(spriteBatch); SpecialBar.Draw(spriteBatch); //float perc = ((100 / GrenadeTiming.Y) * GrenadeTiming.X) / 100; //int height = (int)(perc * Game1.GrenadeIcon.Height); //spriteBatch.Draw(Game1.GrenadeIcon, // new Rectangle(40 + (480 * (int)PlayerIndex), 40 + 25 + 10 + (int)((1.0f - perc) * 24), 24, (int)(perc * 24)), // new Rectangle(0, Game1.GrenadeIcon.Height - height, Game1.GrenadeIcon.Width, height), Color.White); //spriteBatch.Draw(Game1.GrenadeIcon, new Rectangle(40 + (480 * (int)PlayerIndex), 40+25+10, 24, 24), Color.White * 0.5f); //for (int i = 0; i < Deaths; i++) //{ // spriteBatch.Draw(SkullIcon, new Vector2(40 + (480 * (int)PlayerIndex) + (32*i), 40 + 25 + 10 + 24), Color.White); //} }
public override void Update(GameTime gameTime) { PreviousPose = CurrentPose; PreviousFacing = CurrentFacing; PreviousGamePadState = CurrentGamePadState; PreviousKeyboardState = CurrentKeyboardState; PreviousMouseState = CurrentMouseState; WasShooting = IsShooting; if (Active == true) { HealthBar.Update(Health); SpecialBar.Update(new Vector2(87, 100)); foreach (Emitter emitter in FlashEmitterList) { emitter.Position.X = BarrelEnd.X; emitter.Update(gameTime); } FlashEmitterList.RemoveAll(Emitter => Emitter.Active == false); foreach (Emitter emitter in EmitterList) { //emitter.Position = Position; emitter.Update(gameTime); } EmitterList.RemoveAll(Emitter => Emitter.Active == false); #region Control States CurrentGamePadState = GamePad.GetState(PlayerIndex); CurrentKeyboardState = Keyboard.GetState(); CurrentMouseState = Mouse.GetState(); Sticks = CurrentGamePadState.ThumbSticks; MoveStick = Sticks.Left; AimStick = Sticks.Right; #endregion #region Jump if (CurrentGamePadState.IsButtonDown(CurrentJumpButton) && PreviousGamePadState.IsButtonUp(CurrentJumpButton) && DoubleJumped == false) { NumJumps++; if (InAir == true) { DoubleJumped = true; Velocity.Y -= 15f; } else { //NOT SURE ABOUT HAVING BOTH THIS AND THE SMOKE PUFF WHEN LANDING. //I LIKE THE SMOKE MORE SO I'M LEAVING THIS OUT FOR NOW //Emitter jumpEmitter1 = new Emitter(Game1.HitEffectParticle, new Vector2(Position.X + 5, Position.Y + DestinationRectangle.Height / 2), // new Vector2(90, 180), new Vector2(5, 8), new Vector2(500, 500), 1f, false, new Vector2(0, 0), // new Vector2(0, 0), new Vector2(0.1f, 0.1f), Color.White, Color.White, 0f, 0.1f, 100, 5, false, // Vector2.Zero, true, null, null, null, null, null, null, true, new Vector2(0.15f, 0.15f), null, null, null, null, null, true); //Emitter jumpEmitter2 = new Emitter(Game1.HitEffectParticle, new Vector2(Position.X + 5, Position.Y + DestinationRectangle.Height / 2), // new Vector2(0, 90), new Vector2(5, 8), new Vector2(500, 500), 1f, false, new Vector2(0, 0), // new Vector2(0, 0), new Vector2(0.1f, 0.1f), Color.White, Color.White, 0f, 0.1f, 100, 5, false, // Vector2.Zero, true, null, null, null, null, null, null, true, new Vector2(0.15f, 0.15f), null, null, null, null, null, true); //EmitterList.Add(jumpEmitter1); //EmitterList.Add(jumpEmitter2); Velocity.Y = -15f; } } #endregion if (CurrentGamePadState.IsButtonDown(Buttons.LeftStick) && PreviousGamePadState.IsButtonUp(Buttons.LeftStick)) { Health.X = 0; } #region Move stick left if (MoveStick.X < -0.15f) { AimDirection.X = -1f; CurrentFacing = Facing.Left; } #endregion #region Move stick right if (MoveStick.X > 0.15f) { AimDirection.X = 1f; CurrentFacing = Facing.Right; } #endregion if (Math.Abs(MoveStick.X) > 0.15f) { Velocity.X += (MoveStick.X * 3f); } if (CurrentPose == Pose.Standing) { Size = new Vector2(59, 98); } else { Size = new Vector2(59, 74); } Velocity.Y += Gravity * ((float)gameTime.ElapsedGameTime.TotalSeconds * 60f); base.Update(gameTime); #region Collision Reactions if (PushesBottomTile == true) { if (InAir == true) { Emitter jumpEmitter1 = new Emitter(Game1.ToonSmoke1, new Vector2(Position.X - 2, Position.Y + DestinationRectangle.Height / 2), new Vector2(110, 180), new Vector2(2, 5), new Vector2(300, 500), 1f, false, new Vector2(-7, 7), new Vector2(0, 0), new Vector2(0.03f, 0.05f), Color.White, Color.White, 0f, 0.1f, 100, 9, false, Vector2.Zero, true, null, null, null, null, null, null, false, new Vector2(0.08f, 0.08f), null, null, null, false, false, true); Emitter jumpEmitter2 = new Emitter(Game1.ToonSmoke1, new Vector2(Position.X + 2, Position.Y + DestinationRectangle.Height / 2), new Vector2(20, 90), new Vector2(2, 5), new Vector2(300, 500), 1f, false, new Vector2(-7, 7), new Vector2(0, 0), new Vector2(0.03f, 0.05f), Color.White, Color.White, 0f, 0.1f, 100, 9, false, Vector2.Zero, true, null, null, null, null, null, null, false, new Vector2(0.08f, 0.08f), null, null, null, false, false, true); EmitterList.Add(jumpEmitter1); EmitterList.Add(jumpEmitter2); } Velocity.Y = 0; InAir = false; DoubleJumped = false; } else { InAir = true; } if (PushesTopTile == true) { Velocity.Y = 0; } if (PushesLeftTile == true || PushesRightTile == true) { Velocity.X = 0; } #endregion #region Stop Moving if (MoveStick.X == 0) { if (InAir == false) { Velocity.X = 0f; } else { Velocity.X *= 0.98f; } } #endregion #region Limit Speed if (Velocity.X > MaxSpeed.X) { Velocity.X = MaxSpeed.X; } if (Velocity.X < -MaxSpeed.X) { Velocity.X = -MaxSpeed.X; } //if (Velocity.Y < -25) //{ // Velocity.Y = -25; //} //if (Velocity.Y > 25) //{ // Velocity.Y = 25; //} #endregion Shoot(gameTime); #region Grenade if (GrenadeTiming.X >= GrenadeTiming.Y) { if (CurrentGamePadState.IsButtonDown(CurrentGrenadeButton) && PreviousGamePadState.IsButtonUp(CurrentGrenadeButton)) { CreatePlayerGrenade(); GrenadeTiming.X = 0; if (CurrentGrenade != GrenadeType.Regular) { GrenadeAmmo--; if (GrenadeAmmo == 0) { CurrentGrenade = GrenadeType.Regular; } } } } else { GrenadeTiming.X += (float)gameTime.ElapsedGameTime.TotalMilliseconds; } #endregion #region Trap if (CurrentGamePadState.IsButtonDown(CurrentTrapButton) && PreviousGamePadState.IsButtonUp(CurrentTrapButton)) { if (TrapAmmo > 0) { //CreatePlaceTrap(Position, TrapType.Mine); CreatePlaceTrap(); } } #endregion #region Change Animation Direction switch (CurrentFacing) { #region Left case Facing.Left: { AimDirection = new Vector2(-1, 0); if (InAir == false) { if (Velocity.X != 0) { CurrentAnimation = RunLeftAnimation; } else { if (CurrentPose == Pose.Standing) { CurrentAnimation = StandLeftAnimation; } else { CurrentAnimation = CrouchLeftAnimation; } } } else { if (Velocity.Y > 2) { CurrentAnimation = JumpLeftDownAnimation; } else { CurrentAnimation = JumpLeftAnimation; } } } break; #endregion #region Right case Facing.Right: { AimDirection = new Vector2(1, 0); if (InAir == false) { if (Velocity.X != 0) { CurrentAnimation = RunRightAnimation; } else { if (CurrentPose == Pose.Standing) { CurrentAnimation = StandRightAnimation; } else { CurrentAnimation = CrouchRightAnimation; } } } else { if (Velocity.Y > 2) { CurrentAnimation = JumpRightDownAnimation; } else { CurrentAnimation = JumpRightAnimation; } } } break; #endregion } #endregion DestinationRectangle = new Rectangle((int)(Position.X - CurrentAnimation.FrameSize.X / 2), (int)(Position.Y - CurrentAnimation.FrameSize.Y / 2), (int)CurrentAnimation.FrameSize.X, (int)CurrentAnimation.FrameSize.Y); BoundingBox = new BoundingBox(new Vector3(Position - (CurrentAnimation.FrameSize / 2), 0), new Vector3(Position + (CurrentAnimation.FrameSize / 2), 0)); #region Update Animations if (CurrentAnimation != null) { CurrentAnimation.Position = Position; CurrentAnimation.Update(gameTime, DestinationRectangle); } #endregion #region Item Collisions if (ItemList != null) { ItemList.ForEach(Item => { bool removeItem = true; if (Item.CollisionRectangle.Intersects(CollisionRectangle)) { switch (Item.ItemType) { case ItemType.Shield: { ShieldActive = true; removeItem = true; } break; case ItemType.Shotgun: { CurrentGun = GunType.Shotgun; ShotTiming = new Vector2(0, 1000); removeItem = true; } break; case ItemType.RocketLauncher: { CurrentGun = GunType.RocketLauncher; ShotTiming = new Vector2(0, 2000); removeItem = true; } break; case ItemType.MachineGun: { ShotTiming = new Vector2(0, 200); CurrentGun = GunType.MachineGun; removeItem = true; } break; } if (removeItem == true) { ItemList.Remove(Item); } } }); } #endregion #region Trap Collisions if (TrapList != null) { TrapList.ForEach(Trap => { if (Trap.Active == true) { switch (Trap.TrapType) { case TrapType.TripMine: { if ((Trap as TripMine).SourcePlayer != this && (Trap as TripMine).Laser.Ray.Intersects(BoundingBox) != null) { //Mine was triggered. Time to explode Health.X -= 50; Trap.Active = false; } } break; } } //if (Trap.Active == true && Trap.CollisionRectangle.Intersects(CollisionRectangle)) //{ // //switch (Trap.TrapType) // //{ // //#region Fire // //case TrapType.Fire: // // { // // } // // break; // // #endregion // //} // Health.X -= 20; // Trap.Reset(); //} }); } #endregion #region Projectile Collisions if (ProjectileList != null) { ProjectileList.ForEach(Projectile => { if (Projectile.PlayerIndex != PlayerIndex && Projectile.CollisionRectangle.Intersects(CollisionRectangle)) { LastDamageSource = (int)Projectile.PlayerIndex; Projectile.Active = false; if (ShieldActive == true) { ShieldActive = false; } else { Health.X = 0; } } }); } #endregion #region Player Died if (Health.X <= 0) { //#region Flag behaviour //switch (CurrentFlagState) //{ // case FlagState.NoFlag: // break; // case FlagState.HasRed: // { // RedFlag replacementFlag = new RedFlag() { Position = Position }; // replacementFlag.Initialize(); // ItemList.Add(replacementFlag); // CurrentFlagState = FlagState.NoFlag; // } // break; // case FlagState.HasBlue: // { // BlueFlag replacementFlag = new BlueFlag() { Position = Position }; // replacementFlag.Initialize(); // ItemList.Add(replacementFlag); // CurrentFlagState = FlagState.NoFlag; // } // break; //} //#endregion Deaths++; IsShooting = false; WasShooting = false; CreatePlayerDied(); UnscrambleButtons(); } #endregion #region Debuffs if (_CurrentDebuff.Active == true) { _CurrentDebuff.Update(gameTime); //The debuff has expired based on the previous Update if (_CurrentDebuff.Active == false) { switch (_CurrentDebuff.DebuffType) { case DebuffType.ScrambleButtons: { UnscrambleButtons(); } break; } } } #endregion BarrelEnd = Position + new Vector2(AimDirection.X * 28, 10); } }