public void Update(List <Terrain> terrain, Gun gun, Player player, MouseState mouseState, MouseState previousMState, float rot, KeyboardState kbState, GraphicsDevice GraphicsDevice, Game1 game) { //assigns amount of movement to the y direction double movementY = (Math.Round(Math.Sin(rotation) * movement.BulletSpeed));//rotation determines where bullet goes //assigns amount of movement to the x direction double movementX = (Math.Round(Math.Cos(rotation) * movement.BulletSpeed)); switch (bState) { case Bullet.BulletState.airborne: if (facingLeft == true) { //position.X -= movement.BulletSpeed; position.X -= Convert.ToInt32(movementX); position.Y -= Convert.ToInt32(movementY); } else if (facingLeft == false) { movementX = -movementX; //shifts bullet direction to resemble where the player is facing position.X += Convert.ToInt32(movementX); position.Y -= Convert.ToInt32(movementY); } for (int i = 0; i < terrain.Count; i++) { if (terrain[i] is DisappearingPlatforms) { DisappearingPlatforms plat = (DisappearingPlatforms)terrain[i]; //makes sure you can't teleport to a platform that isn't supposed to be there if ((plat.Type == DisappearingPlatforms.Disappear.Blinking && plat.Tint == Color.Transparent) || plat.Type == DisappearingPlatforms.Disappear.Intangible) { continue; } if (plat.CollisionDetected(position) == true) { // teleporting IsTeleporting = true; bState = BulletState.ready; //actual teleporting player.X = position.X; player.Y = position.Y - 40; //stops no clip player.OffsetTele(terrain, i, this); } } if (terrain[i].CollisionDetected(position) == true) //collision detection causes the bullet to disappear { // teleporting IsTeleporting = true; if (terrain[i] is DeathObject) { game.Death(); break; } if (terrain[i] is LevelGoal) { if (terrain[i].CollisionDetected(Position) == true) //////////////////// { game.PreGamestate = game.Gamestate; game.Gamestate = GameState.LevelClear; } } bState = BulletState.ready; //actual teleporting player.X = position.X; player.Y = position.Y - 40; //stops no clip player.OffsetTele(terrain, i, this); } if (terrain[i].CollisionDetected(player.Position) == true) //not working { player.OffsetTele(terrain, i, this); } } //end of for loop //handles if the bullet leaves the screen in x direction if (position.X > GraphicsDevice.Viewport.Width || position.Right < GraphicsDevice.Viewport.X) { bState = BulletState.ready; } //handles if billet leaves screen in y direction if (position.Y > GraphicsDevice.Viewport.Height || position.Y < GraphicsDevice.Viewport.Y) { bState = BulletState.ready; } //handles if player changes screen if (player.X > GraphicsDevice.Viewport.Width || player.Position.Right < GraphicsDevice.Viewport.X) { bState = BulletState.ready; } break; case Bullet.BulletState.empty: { //allows firing after changing screens if (player.X > GraphicsDevice.Viewport.Width || player.Position.Right < GraphicsDevice.Viewport.X) { bState = BulletState.ready; } } break; case Bullet.BulletState.justFired: { //sets up bullet position to be right before gun position.Y = gun.GunPosition.Top; //can't fix it with a simple hardcoded offset, due to rot if (rotation > 0) { position.Y -= Math.Abs(Convert.ToInt32(movementY / movement.BulletSpeed * 28)); } else { position.Y += Math.Abs(Convert.ToInt32(movementY / movement.BulletSpeed * 28)); } //shift bulletstate bState = BulletState.airborne; //bool that says whether it is left or right if (player.PState == Player.PlayerState.faceLeft || player.PState == Player.PlayerState.walkLeft) { facingLeft = true; position.X = gun.GunPosition.Left; // -30; //position.X = Convert.ToInt32(gun.Origin.X) - 95; position.X -= Math.Abs(Convert.ToInt32(movementX / movement.BulletSpeed * 28)); } else { facingLeft = false; position.X = gun.GunPosition.Right; position.X -= Math.Abs(Convert.ToInt32(movementY / movement.BulletSpeed * 28)); } } break; case Bullet.BulletState.ready: //fires bullet when clicking left mouse button { // reset teleporting bool IsTeleporting = false; if (mouseState.LeftButton == ButtonState.Pressed && previousMState.LeftButton == ButtonState.Released) { Fire(rot); } } break; } //end of switch statement } //end of update method
public void Update(KeyboardState kbState, KeyboardState previousKbState, List <Terrain> terrain, Gun gun, GameState gamestate, MouseState mState, Game1 game1, Bullet bullet) { // determining movement and player orientation switch (pState) { case PlayerState.faceRight: if (kbState.IsKeyDown(Keys.D)) { pState = PlayerState.walkRight; } if (kbState.IsKeyDown(Keys.A)) { pState = PlayerState.faceRightWalkLeft; } if (mState.X <= X + 25) { pState = PlayerState.faceLeft; } break; case PlayerState.faceLeft: if (kbState.IsKeyDown(Keys.A)) { pState = PlayerState.walkLeft; } if (kbState.IsKeyDown(Keys.D)) { pState = PlayerState.faceLeftWalkRight; } if (mState.X > X + 25) { pState = PlayerState.faceRight; } break; case PlayerState.walkRight: if (kbState.IsKeyDown(Keys.D)) { if (!kbState.IsKeyDown(Keys.A)) { X += movement.PlayerSpeed; } } if (kbState.IsKeyUp(Keys.D)) { pState = PlayerState.faceRight; } if (mState.X <= X + 25) { pState = PlayerState.faceLeftWalkRight; } break; case PlayerState.walkLeft: if (kbState.IsKeyDown(Keys.A)) { if (!kbState.IsKeyDown(Keys.D)) { X -= movement.PlayerSpeed; } } if (kbState.IsKeyUp(Keys.A)) { pState = PlayerState.faceLeft; } if (mState.X > X + 25) { pState = PlayerState.faceRightWalkLeft; } break; case PlayerState.faceLeftWalkRight: if (kbState.IsKeyDown(Keys.D)) { if (!kbState.IsKeyDown(Keys.A)) { X += movement.PlayerSpeed; } } if (kbState.IsKeyUp(Keys.D)) { pState = PlayerState.faceLeft; } break; case PlayerState.faceRightWalkLeft: if (kbState.IsKeyDown(Keys.A)) { if (!kbState.IsKeyDown(Keys.D)) { X -= movement.PlayerSpeed; } } if (kbState.IsKeyUp(Keys.A)) { pState = PlayerState.faceRight; } break; } bool collided = false; //collision detection for (int i = 0; i < terrain.Count; i++) { //doesn't allow collision if platform isn't there/has disappeared if (terrain[i] is DisappearingPlatforms) { justTeleported = false; DisappearingPlatforms plat = (DisappearingPlatforms)terrain[i]; if ((plat.Type == DisappearingPlatforms.Disappear.Blinking && plat.Tint == Color.Transparent) || plat.Type == DisappearingPlatforms.Disappear.Intangible) { continue; } if (plat.CollisionDetected(position) == true) { canJump = false; //stops no clip issues Offset(terrain, kbState, i, bullet, game1); //halts jumping after colliding isJumping = false; collided = true; } } if (terrain[i].CollisionDetected(position) == true) /////special terrain is causing issue still when going down-resolved { if (terrain[i] is DeathObject) { game1.Death(); } if (terrain[i] is LevelGoal) { if (terrain[i].CollisionDetected(Position) == true) { justTeleported = false; game1.PreGamestate = gamestate; game1.Gamestate = GameState.LevelClear; } } canJump = false; //stops no clip issues Offset(terrain, kbState, i, bullet, game1); //halts jumping after colliding isJumping = false; collided = true; } //fixes stuttering when moving down on a moving platform if (!(position.Left > terrain[i].Position.Right) && !(position.Right < terrain[i].Position.Left)) { if (terrain[i] is SpecialTerrain) { if (!(terrain[i] is DeathObject || terrain[i] is LevelGoal) && (Y <= terrain[i].Y - position.Height && Y >= terrain[i].Y - position.Height - movement.Gravity))//limits y range of activation { SpecialTerrain st = (SpecialTerrain)terrain[i]; if (st.MinX == -1 && isJumping == false) { onVST = true;//set standing on vertical st true onST = false; Y = st.Position.Top - position.Height; justTeleported = false; isFalling = false; isJumping = false; startingY = position.Y; collided = true; canJump = true; } //should keep you stuck to the platform else if (st.MaxY == -1) { if (kbState.IsKeyUp(Keys.A) && kbState.IsKeyUp(Keys.D) && kbState.IsKeyUp(Keys.Space)) { onST = true; onVST = false; //set standing on st true Y = st.Position.Top - position.Height; justTeleported = false; isFalling = false; isJumping = false; collided = true; canJump = true; if (st.MovingLeft == true) { X--; } else { X++; } } } } else { onST = false; onVST = false; } } } //checks if player is standing on terrain & counts that as colliding if (!(position.Left > terrain[i].Position.Right) && !(position.Right < terrain[i].Position.Left)) { if (position.Bottom == terrain[i].Position.Top) { //fixed issue where you could land on spikes if (terrain[i] is DeathObject) { game1.Death(); } if (terrain[i] is LevelGoal) { game1.PreGamestate = gamestate; game1.Gamestate = GameState.LevelClear; } if (position.Bottom <= 0) { position.Y = terrain[i].Position.Top + terrain[i].Position.Height; } justTeleported = false; isFalling = false; isJumping = false; startingY = position.Y; collided = true; canJump = true; } } }//end of loop for collision detection if (isJumping == false && collided == false) { isFalling = true; } if (isFalling == true) { //go down-gravity Gravity(); isJumping = false; //stops player from jumping while falling to slow descend canJump = false; justTeleported = false; //reset bool to false so it is only true for the frame exactly after teleporting onST = false; onVST = false; } if (isJumping == true) { position.Y -= 4; if (position.Y <= (startingY - (.75 * position.Height))) //keeps jumps to being equal to 3/4ths of the player's height { //starts the player falling after jump is complete isFalling = true; onST = false; onVST = false; } } //jump start else if (kbState.IsKeyDown(Keys.Space) && previousKbState.IsKeyUp(Keys.Space) && canJump == true) { //jump logic //go up position.Y -= 4; isJumping = true; } }//end of update method