public bool CanMoveRight(TileMap myMap, int squaresAcross, int squaresDown) { int tileColumn = (int)(((Camera.Location.X + Position.X) / 32)); int tileRow = (int)((Camera.Location.Y + Position.Y) / 32); if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Floor"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Cracked Floor"]) { return true; } else if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Empty"] && myMap.Rows[tileRow + 1].Columns[tileColumn].TileID == myMap.Tiles["Empty"]) { return true; } else if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Cracked Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Left Wall Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Wall Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Right Wall Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Transparent Front Ladder"]) { return true; } else if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Trap Door"]) { return true; } else if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Seweage Man Hole"]) { return true; } else if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Ceiling"]) { return true; } return false; }
public static void Update(TileMap myMap, int squaresAcross, int squaresDown, Vector2 PlayerPos, Vector2 ScreenSize) { keyState=Keyboard.GetState(); if (keyState.IsKeyDown(Keys.Left)) { if(PlayerPos.X < ScreenSize.X / 3) Camera.Location.X = MathHelper.Clamp(Camera.Location.X--, 0, (myMap.MapWidth - squaresAcross) * 32); } if (keyState.IsKeyDown(Keys.Right)) { if(PlayerPos.X > (ScreenSize.X / 3) * 2) Camera.Location.X = MathHelper.Clamp(Camera.Location.X++, 0, (myMap.MapWidth - squaresAcross) * 32); } if (keyState.IsKeyDown(Keys.Up)) { if(PlayerPos.Y < ScreenSize.Y / 3) Camera.Location.Y = MathHelper.Clamp(Camera.Location.Y--, 0, (myMap.MapHeight - squaresDown) * 32); } if (keyState.IsKeyDown(Keys.Down)) { if(PlayerPos.Y > (ScreenSize.Y / 3) * 2) Camera.Location.Y = MathHelper.Clamp(Camera.Location.Y++, 0, (myMap.MapHeight - squaresDown) * 32); } oldKeyState = keyState; }
public bool Update(GraphicsDevice graphicsDevice, TileMap myMap, int squaresAcross, int squaresDown, Vector2 ScreenSize) { KeyboardState kbState = Keyboard.GetState(); playerRectangle = new Rectangle((int)Math.Round(Position.X), (int)Math.Round(Position.Y), (int)(width/3), (int)(height/3)); if (kbState.IsKeyDown(Keys.Right)) { //if(CanMoveRight(myMap, squaresAcross, squaresDown)) //{ if (playerRectangle.X <= (ScreenSize.X / 3) * 2) { Position.X += playerSpeed; if (Animation != "Walking") Animation = "Walking"; } else { pushCharacter("Right", myMap, squaresAcross, squaresDown); } //} } else if (kbState.IsKeyDown(Keys.Left)) { //if (CanMoveLeft(myMap, squaresAcross, squaresDown)) //{ if (playerRectangle.X >= (ScreenSize.X / 3)) { Position.X -= playerSpeed; if (Animation != "Walking") Animation = "Walking"; //} } else { pushCharacter("Left", myMap, squaresAcross, squaresDown); } } else if (kbState.IsKeyDown(Keys.Down)) { //if (CanMoveDown(myMap, squaresAcross, squaresDown)) //{ if (playerRectangle.Y <= (ScreenSize.Y / 3) * 2) { Position.Y += playerSpeed; if (Animation != "Crouch") Animation = "Crouch"; } else { pushCharacter("Down", myMap, squaresAcross, squaresDown); } //} } else if (kbState.IsKeyDown(Keys.Up)) { //if (CanMoveUp(myMap, squaresAcross, squaresDown)) //{ if (playerRectangle.X >= (ScreenSize.X / 3)) { Position.Y -= playerSpeed; if (Animation != "Climb") Animation = "Climb"; } else { pushCharacter("Up", myMap, squaresAcross, squaresDown); } // } } else if (kbState.IsKeyDown(Keys.Space)) { if (Animation != "Jump") Animation = "Jump"; } else if (kbState.IsKeyDown(Keys.F)) { if (Animation != "Fire") Animation = "Fire"; } else if (kbState.IsKeyDown(Keys.A)) { if (Animation != "Knife") Animation = "Knife"; } else { if (Animation != "Idle") Animation = "Idle"; } if (Animation == "Fire") { return true; } return false; }
public void pushCharacter(string directionToPush, TileMap myMap, int squaresAcross, int squaresDown) { if (directionToPush == "Left") { Camera.Location.X = MathHelper.Clamp(Camera.Location.X - 2, 0, (myMap.MapWidth - squaresAcross) * 32); } if (directionToPush == "Right") { Camera.Location.X = MathHelper.Clamp(Camera.Location.X + 2, 0, (myMap.MapWidth - squaresAcross) * 32); } if (directionToPush == "Up") { Camera.Location.Y = MathHelper.Clamp(Camera.Location.Y - 2, 0, (myMap.MapHeight - squaresDown) * 32); } if (directionToPush == "Down") { Camera.Location.Y = MathHelper.Clamp(Camera.Location.Y + 2, 0, (myMap.MapHeight - squaresDown) * 32); } }
public void Collision(TileMap myMap, int squaresAcross, int squaresDown) { KeyboardState kbState = Keyboard.GetState(); int tileColumn = (int) (((Camera.Location.X+Position.X)/32)); int tileRow = (int)((Camera.Location.Y+Position.Y) / 32); if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Floor"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Cracked Floor"]) { pushCharacter("Up", myMap, squaresAcross, squaresDown); } else if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Empty"] && myMap.Rows[tileRow + 1].Columns[tileColumn].TileID == myMap.Tiles["Empty"]) { pushCharacter("Down", myMap, squaresAcross, squaresDown); } else if(myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Cracked Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Left Wall Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Wall Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Right Wall Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Transparent Front Ladder"]) { if(kbState.IsKeyDown(Keys.Up)) { pushCharacter("Up",myMap,squaresAcross,squaresDown); } if (kbState.IsKeyDown(Keys.Down)) { pushCharacter("Down", myMap, squaresAcross, squaresDown); } } else if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Trap Door"]) { pushCharacter("Down", myMap, squaresAcross, squaresDown); } else if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Seweage Man Hole"]) { if (kbState.IsKeyDown(Keys.E)) { if (kbState.IsKeyDown(Keys.Up)) { pushCharacter("Up", myMap, squaresAcross, squaresDown); } if (kbState.IsKeyDown(Keys.Down)) { pushCharacter("Down", myMap, squaresAcross, squaresDown); } } } else if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Ceiling"]) { pushCharacter("Down", myMap, squaresAcross, squaresDown); } else if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Ceiling"]) { } }
public bool CanMoveUp(TileMap myMap, int squaresAcross, int squaresDown) { int tileColumn = (int)(((Camera.Location.X + Position.X) / 32)); int tileRow = (int)((Camera.Location.Y + Position.Y) / 32); if (myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Cracked Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Left Wall Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Wall Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Right Wall Ladder"] || myMap.Rows[tileRow].Columns[tileColumn].TileID == myMap.Tiles["Transparent Front Ladder"]) { return true; } return false; }