public void Move(Keys key, Player player) { player.SetAccelSpeed(); if (player.IsJumping) { key = jumpInitKey; if (key == Keys.Left) { futurePos.X -= (int)player.Speed; } else if (key == Keys.Right) { futurePos.X += (int)player.Speed; } } else { if (key == Keys.Left) { futurePos.X -= (int)player.Speed; } else if (key == Keys.Right) { futurePos.X += (int)player.Speed; } } blockMove = true; foreach (StaticNeutralBlock block in StaticNeutralBlock.StaticNeutralList) { if (block.IsCollidable && block.IsActive) { if (block.HitBox.Intersects(futurePos)) { if (player.FallingSpeed < 0 && player.AccelMode != 1) player.FallingSpeed = 0; blockMove = false; player.AccelMode = 1; accelTimer = 0; break; } } } if (blockMove) { foreach (ClimbableBlock block in ClimbableBlock.ClimbableBlockList) { if (block.IsCollidable && block.IsActive) { if (block.HitBox.Intersects(futurePos)) { if (player.FallingSpeed < 0 && player.AccelMode != 1) player.FallingSpeed = 0; blockMove = false; player.AccelMode = 1; accelTimer = 0; break; } } } } if (blockMove) { foreach (LaunchableBlock block in LaunchableBlock.LaunchableBlockList) { if (block.IsCollidable && block.IsActive) { if (block.HitBox.Intersects(futurePos)) { if (player.FallingSpeed < 0 && player.AccelMode != 1) player.FallingSpeed = 0; blockMove = false; player.AccelMode = 1; accelTimer = 0; break; } } } } if (blockMove) { foreach (Door block in Door.DoorList) { if (block.IsCollidable && block.IsActive && !block.IsOpen) { if (block.HitBox.Intersects(futurePos)) { if (player.FallingSpeed < 0 && player.AccelMode != 1) player.FallingSpeed = 0; blockMove = false; player.AccelMode = 1; accelTimer = 0; break; } } } } if (blockMove) { playerMove = false; float sp = player.Speed; Rectangle RightCut = new Rectangle(player.HitBox.X + (player.HitBox.Width / 2), player.HitBox.Y, player.HitBox.Width / 2, player.HitBox.Height); Rectangle LeftCut = new Rectangle(player.HitBox.X, player.HitBox.Y, player.HitBox.Width / 2, player.HitBox.Height); Rectangle RightSide = Map._rightSide.HitBox; Rectangle LeftSide = Map._leftSide.HitBox; RightSide.X += (int)sp; RightSide.Width -= (int)sp; LeftSide.Width -= (int)sp; if (RightCut.Intersects(LeftSide) || LeftCut.Intersects(RightSide)) { playerMove = true; } if (playerMove) { if (key == Keys.Left) player.MovePlayerLeft(true); else if (key == Keys.Right) player.MovePlayerRight(true); } else { if (key == Keys.Left) { player.MovePlayerLeft(false); foreach (Blocks block in Blocks.BlockList) { if (player.IsJumping) block.IncreaseCoordBlockX((int)player.SpeedInAir); else block.IncreaseCoordBlockX((int)player.Speed); } foreach (Camera cam in Camera.CamerasBlockList) { if (player.IsJumping) cam.IncreaseSpotCoordBlockX((int)player.SpeedInAir); else cam.IncreaseSpotCoordBlockX((int)player.Speed); } foreach (MovableEnnemyBlock block in MovableEnnemyBlock.MovableEnnemyList) { if (player.IsJumping) block.IncreaseCoordBlockX((int)player.SpeedInAir); else block.IncreaseCoordBlockX((int)player.Speed); } } else if (key == Keys.Right) { player.MovePlayerRight(false); foreach (Blocks block in Blocks.BlockList) { if (player.IsJumping) block.DecreaseCoordBlockX((int)player.SpeedInAir); else block.DecreaseCoordBlockX((int)player.Speed); } foreach (Camera cam in Camera.CamerasBlockList) { if (player.IsJumping) cam.DecreaseSpotCoordBlockX((int)player.SpeedInAir); else cam.DecreaseSpotCoordBlockX((int)player.Speed); } foreach (MovableEnnemyBlock block in MovableEnnemyBlock.MovableEnnemyList) { if (player.IsJumping) block.DecreaseCoordBlockX((int)player.SpeedInAir); else block.DecreaseCoordBlockX((int)player.Speed); } } } } }
public void Move(Keys key, Player player) { player.SetAccelSpeed(); if (player.IsJumping) { key = jumpInitKey; if (key == Keys.Left) { futurePos.X -= (int)player.Speed; } else if (key == Keys.Right) { futurePos.X += (int)player.Speed; } } else { if (key == Keys.Left) { futurePos.X -= (int)player.Speed; } else if (key == Keys.Right) { futurePos.X += (int)player.Speed; } } blockMove = true; foreach (StaticNeutralBlock block in StaticNeutralBlock.StaticNeutralList) { if(block.IsCollidable) { if (block.HitBox.Intersects(futurePos)) { if(player.FallingSpeed < 0 && player.AccelMode != 1) player.FallingSpeed = 0; blockMove = false; player.AccelMode = 1; accelTimer = 0; break; } } } if (blockMove) { i = 0; playerMove = false; float sp; if (player.IsJumping) { sp = player.SpeedInAir; } else { sp = player.Speed; } foreach (StaticNeutralBlock block in StaticNeutralBlock.StaticNeutralList) { i++; if (i <= 4) { if(key == Keys.Left) { if ((i == 4 && player.HitBox.X - (FirstGame.W / 2) - sp < block.HitBox.X) || (i == 2 && (player.HitBox.X + (FirstGame.W / 2) - sp - block.HitBox.Width > block.HitBox.X))) { playerMove = true; } } else if (key == Keys.Right) { if ((i == 2 && player.HitBox.X + ((FirstGame.W / 2)) - block.HitBox.Width > block.HitBox.X) || (i == 4 && player.HitBox.X - (FirstGame.W / 2) < block.HitBox.X)) { playerMove = true; } } } else { break; } } if (playerMove) { if (key == Keys.Left) player.MovePlayerLeft(true); else if (key == Keys.Right) player.MovePlayerRight(true); } else { if (key == Keys.Left) { player.MovePlayerLeft(false); foreach (Blocks block in Blocks.BlockList) { if(player.IsJumping) block.IncreaseCoordBlockX((int)player.SpeedInAir); else block.IncreaseCoordBlockX((int)player.Speed); } } else if (key == Keys.Right) { player.MovePlayerRight(false); foreach (Blocks block in Blocks.BlockList) { if (player.IsJumping) block.DecreaseCoordBlockX((int)player.SpeedInAir); else block.DecreaseCoordBlockX((int)player.Speed); } } } } }