Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void CanMove(int direction, int velocity, GameTime gameTime)
- {
- switch (direction)
- {
- case 0: //Up
- Move(gameTime, new Vector2(0, -velocity));
- break;
- case 1: //Right
- Move(gameTime, new Vector2(velocity, 0));
- break;
- case 2: //Down
- Move(gameTime, new Vector2(0, velocity));
- break;
- case 3://Left
- for (int x = 0; x < Game1.map.width; x++)
- {
- for (int y = 0; y < Game1.map.height; y++)
- {
- if (Game1.map.blockedList[x, y] > 0)
- {
- if (position.X - 2 + tileSize > x * tileSize && position.X + 2 < x * tileSize + tileSize && position.Y - 2 < y * tileSize + tileSize && position.Y + 2 + tileSize > y * tileSize)
- {
- velocity = 0;
- }
- }
- }
- }
- Move(gameTime, new Vector2(-velocity, 0));
- break;
- }
- }
- public void Move(GameTime gameTime, Vector2 Motion)
- {
- if (Motion != Vector2.Zero)
- {
- Motion.Normalize();
- position.X += Motion.X * (int)gameTime.ElapsedGameTime.TotalMilliseconds / 4;
- position.Y += Motion.Y * (int)gameTime.ElapsedGameTime.TotalMilliseconds / 4;
- //Check if we're walking out of bounds.
- if (position.X < 0)
- position.X = 0;
- if (position.Y < 0)
- position.Y = 0;
- if (position.X + texture.Width > Game1.map.width * Game1.map.tileSize)
- position.X = Game1.map.width * Game1.map.tileSize - texture.Width;
- if (position.Y + texture.Height > Game1.map.height * Game1.map.tileSize)
- position.Y = Game1.map.height * Game1.map.tileSize - texture.Height;
- //Check if we're touching a blocked tile.
- for (int x = 0; x < Game1.map.width; x++)
- {
- for (int y = 0; y < Game1.map.height; y++)
- {
- if (Game1.map.blockedList[x, y] > 0)
- {
- //Check if our player intersects with block tile
- if (position.X + 48 > x * 48 && position.X < x * 48 + 48 && position.Y < y * 48 + 48 && position.Y + 64 > y * 48)
- {
- //We now intersect with the tile block
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement