public override void update(GameTime gameTime) { // arm and gun updates if (fall) { headPos -= fallForces[0]; leftArmPos -= fallForces[1]; bodyPos -= fallForces[2]; leftLegPos -= fallForces[3]; rightLegPos -= fallForces[4]; holsterPos -= fallForces[5]; gun.position -= fallForces[6]; arm.joints[0] -= fallForces[7]; arm.update(gameTime, this); for (int i = 0; i < 8; i++) { fallForces[i].Y -= 0.4f; } } else if (dead) { if (deathTimer < DEATH_TIME) deathTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; else { fall = true; deathTimer = 0; } arm.update(gameTime, this); gun.update(gameTime, this); } else { if (gunWindow != null) { gunWindow.update(gameTime); } else { gun.update(gameTime, this); arm.update(gameTime, this); if (gun.thrownPosition.Y > Game1.SCREENHEIGHT && !droppedGun) { droppedGun = true; bullets = 6; textPopups.Add(new TextPopup("GUN DROPPED!", new Vector2(Game1.SCREENWIDTH / 2, Game1.SCREENHEIGHT / 2), 4f, false)); if (player == PlayerIndex.One) Game1.SOUND_DROP.Play(1f, 0, -1); else Game1.SOUND_DROP.Play(1f, 0, 1); droppedGunTimer = 0f; } } if (!dead && !won) P1Score.update(gameTime); if (droppedGun) { droppedGunTimer += (float)gameTime.ElapsedGameTime.TotalMilliseconds; if (droppedGunTimer > DROP_TIME) { droppedGun = false; dropping = false; P1Score.throwTime = (float)gameTime.TotalGameTime.TotalSeconds; gun.thrownPosition = new Vector2(dropX, 20); gun.throwVelocity = Vector2.Zero; } else if (droppedGunTimer > DROP_TIME * 3f / 4f && !dropping) { Random rand = new Random(); dropX = rand.Next(100) * (rand.Next(2) == 0 ? -1 : 1); dropX += headPos.X + (headText.Width * 0.375f / 2f) -50; dropping = true; } } } // camera update if (!gun.thrown && !gun.holstered && gunWindow == null && !dead) { camera.desiredScale = 2.0f; camera.desiredPosition.X = gun.position.X - (((float)Game1.SCREENWIDTH / 2f) / camera.getScale()); ; camera.desiredPosition.Y = gun.position.Y - (((float)Game1.SCREENHEIGHT / 2f) / camera.getScale()); } else { camera.desiredScale = 1.0f; camera.desiredPosition = Vector2.Zero; } camera.update(gameTime); // bullets' updates ArrayList removal = new ArrayList(10); foreach (Bullet b in firedBullets) { b.update(gameTime); if (b.position.X > Game1.SCREENWIDTH) { game.swapBullet(b, this); removal.Add(b); } else if (collidedWithPlayer(b) && !dead) { removal.Add(b); die(); } else if(collidedWithGun(b)) { if (!gun.holstered) { if (!gun.thrown) { gun.thrownPosition.X = gun.position.X; gun.thrownPosition.Y = gun.position.Y; } gun.grab = false; gun.justGrabbed = false; gunWindow = null; gun.thrown = true; Random rand = new Random(); gun.throwVelocity.Y = -3 * rand.Next(5)+1; gun.throwVelocity.X = (rand.Next(2) == 0 ? 1 : -1) * (rand.Next(5) + 1); P1Score.throwTime = (float)gameTime.TotalGameTime.TotalSeconds; removal.Add(b); if (player == PlayerIndex.One) Game1.SOUND_RICOCHET.Play(1, 0, -1); else Game1.SOUND_RICOCHET.Play(1, 0, 1); } } } ArrayList removalText = new ArrayList(10); foreach (TextPopup tp in textPopups) { tp.update(gameTime); if (tp.done) removalText.Add(tp); } foreach (Bullet r in removal) firedBullets.Remove(r); foreach (TextPopup rp in removalText) textPopups.Remove(rp); if (!game.getEnemyGunState(this)) gunWindow = null; base.update(gameTime); }
public override void input(GameTime time) { KeyboardState keyboardState = Keyboard.GetState(); GamePadState gamePadState = GamePad.GetState(player, GamePadDeadZone.Circular); // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || keyboardState.IsKeyDown(Keys.Escape)) game.setMode(Game1.modes.title); if (keyboardState.IsKeyDown(Keys.D1) && previousKeyboardState.IsKeyUp(Keys.D1)) game.graphics.ToggleFullScreen(); if (keyboardState.IsKeyDown(Keys.D2) && previousKeyboardState.IsKeyUp(Keys.D2) && player == PlayerIndex.One) game.debugText = !game.debugText; accellerationVector = Vector2.Zero; if (keyboardState.IsKeyDown(Keys.Left) || gamePadState.ThumbSticks.Left.X < 0) accellerationVector.X = -1 * ACCELLERATION_RATE; if (keyboardState.IsKeyDown(Keys.Right) || gamePadState.ThumbSticks.Left.X > 0) accellerationVector.X = 1 * ACCELLERATION_RATE; if (keyboardState.IsKeyDown(Keys.Up) || gamePadState.ThumbSticks.Left.Y > 0) accellerationVector.Y = -1 * ACCELLERATION_RATE; if (keyboardState.IsKeyDown(Keys.Down) || gamePadState.ThumbSticks.Left.Y < 0) accellerationVector.Y = 1 * ACCELLERATION_RATE; movementVector += accellerationVector; if (movementVector.X > MOVE_MAX) movementVector.X = MOVE_MAX; else if (movementVector.X < -1 * MOVE_MAX) movementVector.X = -1 * MOVE_MAX; if (movementVector.Y > MOVE_MAX) movementVector.Y = MOVE_MAX; else if (movementVector.Y < -1 * MOVE_MAX) movementVector.Y = -1 * MOVE_MAX; if (accellerationVector.X == 0f && movementVector.X != 0f) reduce(REDUCE_X, DECELLERATION_RATE); if (accellerationVector.Y == 0f && movementVector.Y != 0f) reduce(REDUCE_Y, DECELLERATION_RATE); if ((keyboardState.IsKeyDown(Keys.Z) && previousKeyboardState.IsKeyUp(Keys.Z)) || (gamePadState.IsButtonDown(Buttons.X) && previousGamePadState.IsButtonUp(Buttons.X))) { gun.grab = true; gun.justGrabbed = true; P1Score.totalTurns = 0; if (!droppedGun && !gun.thrown && !gun.holstered) { if (player == PlayerIndex.One) Game1.SOUND_WHIRL.Play(0.5f, 0, -1); else Game1.SOUND_WHIRL.Play(0.5f, 0, 1); } } else if(keyboardState.IsKeyUp(Keys.Z) && gamePadState.IsButtonUp(Buttons.X)) gun.grab = false; if (keyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X) || gamePadState.IsButtonDown(Buttons.Y) && previousGamePadState.IsButtonUp(Buttons.Y)) { if (!gun.thrown && !gun.holstered) { gun.thrown = true; gun.thrownPosition.X = gun.position.X; gun.thrownPosition.Y = gun.position.Y; gun.throwVelocity.Y = 3 * movementVector.Y; gun.throwVelocity.X = 0.25f * movementVector.X; P1Score.throwTime = (float)time.TotalGameTime.TotalSeconds; } } if ((keyboardState.IsKeyDown(Keys.C) && previousKeyboardState.IsKeyUp(Keys.C)) || (gamePadState.IsButtonDown(Buttons.A) && previousGamePadState.IsButtonUp(Buttons.A))) { if (!gun.holstered && !gun.thrown && gun.grab && gun.flatAngle) { if (game.getEnemyGunState(this) || won) gunWindow = new GunWindow(this); else { textPopups.Add(new TextPopup("CAN'T SHOOT AN UNARMED MAN!", new Vector2(Game1.SCREENWIDTH / 2, Game1.SCREENHEIGHT / 2), 4f, false)); if (player == PlayerIndex.One) Game1.SOUND_DROP.Play(1f, 0, -1); else Game1.SOUND_DROP.Play(1f, 0, 1); } } } else if ((keyboardState.IsKeyUp(Keys.C) && previousKeyboardState.IsKeyDown(Keys.C)) || (gamePadState.IsButtonUp(Buttons.A) && previousGamePadState.IsButtonDown(Buttons.A))) { gunWindow = null; } if(won) { if ((gamePadState.IsButtonDown(Buttons.Start) && previousGamePadState.IsButtonUp(Buttons.Start)) || (keyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))) { game.setMode(Game1.modes.title); } } // gun window controlls if (gunWindow != null) { if (gunWindow.state == GunWindow.State.STATE_NONE) { gunWindow.state = GunWindow.State.STATE_HAMMER; } else if (gunWindow.state == GunWindow.State.STATE_COCKED && (keyboardState.IsKeyDown(Keys.Left) && previousKeyboardState.IsKeyUp(Keys.Left) || gamePadState.ThumbSticks.Left.X < 0 && previousGamePadState.ThumbSticks.Left.X >= 0)) { gunWindow.state = GunWindow.State.STATE_TRIGGER; } } previousKeyboardState = keyboardState; previousGamePadState = gamePadState; }