Example #1
0
 public bool Bounce(Wall wall, Character player)
 {
     // check if player is bouncing off a wall
     if (new Rectangle(wall.XPos, wall.YPos, Constants.TILE_WIDTH, Constants.TILE_HEIGHT).Intersects(
         new Rectangle(player.XPos, player.YPos, Constants.TILE_WIDTH, Constants.TILE_HEIGHT)))
     {
         return true;
     }
     else { return false; }
 }
Example #2
0
        /// <summary>
        /// AF
        /// Method for adding in all walls and their positions. 
        /// Returns a list of Wall objects
        /// </summary>
        /// <returns></returns>
        public List<Wall> SetWalls()
        {
            //AF -Adding walls to list
            for (int i = 0; i < Constants.ARRAYY; i++)
            {
                for (int j = 0; j < Constants.ARRAYX; j++)
                {
                    if (position[i, j] == '=')
                    {
                        Wall w = new Wall(j * Constants.GRIDPOSITION, i * Constants.GRIDPOSITION);
                        walls.Add(w);
                    }
                }
            }

            return walls;
        }
Example #3
0
        // works with Bounce, currently buggly & making workaround
        public Character SolidWall(Wall wall, Character player)
        {
            // prevent player from moving through a collided wall
            int dX = (wall.XPos - player.XPos);
            int dY = (wall.YPos - player.YPos);
            if (dX > dY) {
                if (player.XPos < wall.XPos)
                {
                    player.XPos = (wall.XPos - Constants.TILE_WIDTH);
                }
                if (player.XPos > wall.XPos)
                {
                    player.XPos = (wall.XPos + Constants.TILE_WIDTH);
                }
                player.XSpeed = 0;
                player.YSpeed = -(player.YSpeed);
            }
            if (dY > dX) {
                if (player.YPos < wall.YPos)
                {
                    player.YPos = (wall.YPos - Constants.TILE_HEIGHT);
                }
                if (player.YPos > wall.YPos)
                {
                    player.YPos = (wall.YPos + Constants.TILE_HEIGHT);
                }
                player.YSpeed = 0;
                player.XSpeed = -(player.XSpeed);
            }

            return player;
        }