Example #1
0
        /// <summary>
        /// Constructs a new PacMan
        /// </summary>
        /// <param name="textureAsset">The path to the texture of this pacman</param>
        /// <param name="startCell">the starting cell of this  player</param>
        /// <param name="level">Reference to the level</param>
        /// <param name="controller">The controller for this player</param>
        /// <param name="startDirection">The start heading</param>
        /// <param name="speed">Defines how fast this player can move in cells per second</param>
        /// <param name="frameSize">Sets the framesize for the players texture</param>
        public PacMan(String textureAsset, Cell startCell, Level level, Controller
            controller, Direction startDirection, float speed,
                      Point frameSize)
            : base(textureAsset, startCell, level, startDirection, speed, controller, frameSize)
        {
            framePosition = new Point(0, 0);

            position = base.CurrentCell.Position;
            this.lives = 5;
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="textureAsset">The path to the texture of this ghost</param>
        /// <param name="startCell">The starting cell for this ghost</param>
        /// <param name="level">The level</param>
        /// <param name="startDirection">The starting direction for this ghost</param>
        /// <param name="speed">The speed in cells per secon</param>
        /// <param name="frameSize">The framesize of a frame from the texture</param>
        /// <param name="color">The default color of this ghost</param>
        /// <param name="controller">A controller for this ghost</param>
        public Ghost(String textureAsset, Cell startCell, Level level, Direction startDirection, float speed, Point frameSize, Color color, Controller controller)
            : base(textureAsset, startCell, level, startDirection, speed, controller, frameSize)
        {
            framePosition = new Point(1, 1);
            position = startCell.Position;
            this.color = color;
            this.defaultColor = this.color;

            GhostBehaviour = EGhostBehaviour.Hunt;
        }
Example #3
0
        private Point CalculateCell(Direction direction, Cell pacCell)
        {
            Point lookingDirection = DirectionExtension.PointFromDirection(direction);

            Point sourcePoint = pacCell.GridPosition;

            lookingDirection.X *= 2;
            lookingDirection.Y *= 2;

            return new Point(sourcePoint.X + lookingDirection.X, sourcePoint.Y + lookingDirection.Y);
        }
Example #4
0
        protected override Point HuntBehaviour(Cell currentCell)
        {
            Point pivot = CalculateCell(pacMan.Direction, pacMan.CurrentCell);

            Point distanceToBlinky = new Point(pivot.X - blinky.CurrentCell.GridPosition.X,
                                               pivot.Y - blinky.CurrentCell.GridPosition.Y);

            Point target = new Point(pivot.X + distanceToBlinky.X, pivot.Y + distanceToBlinky.Y);

            return target;
        }
Example #5
0
        protected override Point HuntBehaviour(Cell currentCell)
        {
            Point lookingDirection = DirectionExtension.PointFromDirection(pacMan.Direction);

            Point sourcePoint = pacMan.CurrentCell.GridPosition;

            lookingDirection.X *= 4;
            lookingDirection.Y *= 4;

            return new Point(sourcePoint.X + lookingDirection.X, sourcePoint.Y + lookingDirection.Y);
        }
Example #6
0
        public GhostController(Level level, GhostAi ghostAi, int id)
            : base(id)
        {
            this.level = level;
            Name = ghostAi.Name;
            this.ghostAi = ghostAi;

            currentCell = Cell.Empty;
            lastCell = Cell.Empty;

            possibleMoves = new List<Cell>();
        }
Example #7
0
        protected override Point HuntBehaviour(Cell currentCell)
        {
            Point pacManCell = pacMan.CurrentCell.GridPosition;

            double distance = Math.Sqrt(Math.Pow(currentCell.GridPosition.X - pacManCell.X, 2) + Math.Pow(currentCell.GridPosition.Y - pacManCell.Y, 2));

            if (distance >= 8)
            {
                return pacManCell;
            }
            else
            {
                return scatterTarget;
            }
        }
Example #8
0
 public Point TargetCell(Cell currentCell, EGhostBehaviour behaviour)
 {
     switch (behaviour)
     {
         case EGhostBehaviour.Fright:
             return FrightBehaviour(currentCell);
         case EGhostBehaviour.Hunt:
             return HuntBehaviour(currentCell);
         case EGhostBehaviour.Scatter:
             return scatterTarget;
         case EGhostBehaviour.Exiting:
             return exitTarget;
         case EGhostBehaviour.Dead:
         case EGhostBehaviour.InHouse:
             return homeTarget;
         default:
             return currentCell.GridPosition;
     }
 }
Example #9
0
        /// <summary>
        /// Constructor for a movable object
        /// </summary>
        /// <param name="textureAsset">The path to the texture that this object has to load</param>
        /// <param name="startCell">The starting cell of this MO</param>
        /// <param name="level">Reference to the level</param>
        /// <param name="startDirection">The direction this MO is facing at startup</param>
        /// <param name="cellsPerSecond">How many cells per second this MO should pass</param>
        /// <param name="controller">The controller for this object</param>
        /// <param name="frameSize">The size of the frame of this MO</param>
        public MovableObject(String textureAsset, Cell startCell, Level level, Direction startDirection, float cellsPerSecond, Controller controller, Point frameSize)
            : base(textureAsset)
        {
            currentDirection = startDirection;
            lastDirection = startDirection;

            currentCell = startCell;
            this.startCell = startCell;

            this._cellsPerSecond = CalculateSpeedFactor(cellsPerSecond);
            this._defaultCellsPerSecond = this._cellsPerSecond;
            this.level = level;

            this.frameSize = frameSize;

            speedVector = Vector2.Zero;
            lastSpeedVector = Vector2.Zero;

            soundEffects = new Dictionary<string, Cue>();

            this.PowerUpTimer = 0;
            this.controller = controller;
        }
Example #10
0
        /// <summary>
        /// Updates this controller
        /// </summary>
        public override void Update(Cell CurrentCell)
        {
            KeyboardState state = Keyboard.GetState();

            if (inputState.IsNewKeyPress(Keys.Up, this.index, out this.index))
            {
                Direction = Direction.Up;
            }
            else if (inputState.IsNewKeyPress(Keys.Down, this.index, out this.index))
            {
                Direction = Direction.Down;
            }
            else if (inputState.IsNewKeyPress(Keys.Right, this.index, out this.index))
            {
                Direction = Direction.Right;
            }
            else if (inputState.IsNewKeyPress(Keys.Left, this.index, out this.index))
            {
                Direction = Direction.Left;
            }
        }
Example #11
0
 /// <summary>
 /// Returns a target Blinky wants to go to
 /// </summary>
 /// <param name="currentCell">The current cell</param>
 /// <returns>The target this AI wants to go to</returns>
 protected override Point HuntBehaviour(Cell currentCell)
 {
     return pacMan.CurrentCell.GridPosition;
 }
Example #12
0
 /// <summary>
 /// Creates a new Ghost
 /// </summary>
 /// <param name="textureAsset">The path to the texture of this ghost</param>
 /// <param name="startCell">The starting cell for this ghost</param>
 /// <param name="level">The level</param>
 /// <param name="startDirection">The starting direction for this ghost</param>
 /// <param name="speed">The speed in cells per secon</param>
 /// <param name="frameSize">The framesize of a frame from the texture</param>
 /// <param name="color">The default color of this ghost</param>
 /// <param name="ghostAi">The ghostAi for this ghost</param>
 public Ghost(String textureAsset, Cell startCell, Level level, Direction startDirection, float speed, Point frameSize, Color color, GhostAi ghostAi)
     : this(textureAsset, startCell, level, startDirection, speed, frameSize, color, new GhostController(level, ghostAi, 1))
 {
 }
Example #13
0
        /// <summary>
        /// Checks if we didn't hit a wall with our last move
        /// </summary>
        /// <param name="position">The current position</param>
        /// <param name="currentCell">Our current cell</param>
        /// <param name="direction">the current direction</param>
        /// <returns>true if we didn't hit a wall, false if we did</returns>
        private bool ValidateMove(Vector2 position, Cell currentCell, Direction direction)
        {
            Point movement = DirectionExtension.PointFromDirection(direction);

            Point[] cellsToCheck = new Point[3];
            switch (direction)
            {
                case Enums.Direction.Up:
                    for (int i = -1; i < 2; i++)
                    {
                        cellsToCheck[i + 1] = new Point(currentCell.GridPosition.X + i, currentCell.GridPosition.Y - 1);
                    }
                    break;
                case Enums.Direction.Down:
                    for (int i = -1; i < 2; i++)
                    {
                        cellsToCheck[i + 1] = new Point(currentCell.GridPosition.X + i, currentCell.GridPosition.Y + 1);
                    }
                    break;
                case Enums.Direction.Left:
                    for (int i = -1; i < 2; i++)
                    {
                        cellsToCheck[i + 1] = new Point(currentCell.GridPosition.X - 1, currentCell.GridPosition.Y + i);
                    }
                    break;
                case Enums.Direction.Right:
                    for (int i = -1; i < 2; i++)
                    {
                        cellsToCheck[i + 1] = new Point(currentCell.GridPosition.X + 1, currentCell.GridPosition.Y + i);
                    }
                    break;
            }

            foreach (Point point in cellsToCheck)
            {
                Cell cellToCheck = level.getCell(point);

                if(this.IntersectRectangle.Intersects(cellToCheck.IntersectRectangle) && cellToCheck.IsWall)
                {
                    return false;
                }
            }

            return true;
        }
Example #14
0
        public override void Update(Cell currentCell)
        {
            Direction lastDirection = controller.Direction;

            controller.Update(currentCell);

            if(Direction != lastDirection)
            {
                Send();
            }
        }
 public override void Update(Cell currentCell)
 {
     controller.Update(currentCell);
 }
Example #16
0
 public Cell GetCell(int x, int y)
 {
     Cell cell =  new Cell(new Point(x, y), false);
     cell.CellEffect = new TeleportEffectCreator(options).createEffect();
     return cell;
 }
Example #17
0
        /// <summary>
        /// Gets the cell at the specified position
        /// </summary>
        /// <param name="x">The x coordinate of the cell</param>
        /// <param name="y">The y coordinate of the cell</param>
        /// <returns>The cell at the given coordinates or a emptycell at the requested position</returns>
        public Cell getCell(int x, int y)
        {
            if (!(x < 0 || x >= Size.X || y < 0 || y >= Size.Y))
            {
                return grid[x, y];
            }

            Cell returnCell = new Cell(new Point(x, y), false);

            return returnCell;
        }
Example #18
0
 protected Point FrightBehaviour(Cell curCell)
 {
     return DirectionExtension.PointFromDirection((Direction) rand.Next(1, 4));
 }
Example #19
0
        /// <summary>
        /// Returns a Dictionary countaining the surrounding cells 
        /// </summary>
        /// <param name="currentCell">The current cell</param>
        /// <returns></returns>
        private Dictionary<Direction, Cell> GetPossibleMoves(Cell currentCell)
        {
            Dictionary<Direction, Cell> possibleMoves = new Dictionary<Direction, Cell>();
            Point currentPosition = currentCell.GridPosition;

            for (int i = 1; i <= 4; i++)
            {
                Point directionPoint = DirectionExtension.PointFromDirection((Direction)i);

                Point getCell = new Point(currentPosition.X + directionPoint.X,
                                          currentPosition.Y + directionPoint.Y);

                Cell possibleCell = Cell.Empty;

               if(!(getCell.X < 0 || getCell.X >= level.Size.X || getCell.Y < 0 || getCell.Y >= level.Size.Y))
               {
                    possibleCell = level.getCell(currentPosition.X + directionPoint.X,
                                                 currentPosition.Y + directionPoint.Y);
               }

               possibleMoves.Add((Direction)i, possibleCell);
            }

            return possibleMoves;
        }
Example #20
0
 public Cell GetCell(int x, int y)
 {
     Cell cell = new Cell(@"Sprites\LevelSprites\RightUp", new Point(x, y), true);
     cell.CellEffect = new NullEffectCreator().createEffect();
     return cell;
 }
Example #21
0
 public abstract void Update(Cell currentCell);
Example #22
0
 /// <summary>
 /// Sets the current cell to a given target
 /// </summary>
 /// <param name="target">The position of the cell in the grid</param>
 public void SetCurrentCell(Point target)
 {
     this.currentCell = level.getCell(target);
     this.position = CurrentCell.Position;
 }
Example #23
0
 public override void Update(Cell currentCell)
 {
     //Do nothing in here, since this is the empty controller
 }
Example #24
0
 protected abstract Point HuntBehaviour(Cell currentCell);
Example #25
0
 public CellHideEffect(ref Cell actualCell)
 {
     this.actualCell = actualCell;
 }
Example #26
0
 public override void Update(Cell CurrentCell)
 {
     this.Update(CurrentCell, EGhostBehaviour.Hunt);
 }
Example #27
0
 /// <summary>
 /// Replaces a cell at the specified coordinates
 /// </summary>
 /// <param name="cell">The replacement cell</param>
 /// <param name="x">The x coordinate of the cell</param>
 /// <param name="y">The y coordinate of the cell</param>
 public void setCell(Cell cell, int x, int y)
 {
     grid[y, x] = cell;
     //grid2[x][y] = cell;
 }
Example #28
0
        public void Update(Cell currentCell, EGhostBehaviour behaviour)
        {
            CurrentCell = currentCell;

            for (int i = 1; i <= 4; i++)
            {
                AddCell((Direction)i, CurrentCell.GridPosition);
            }

            for (int i = 0; i < possibleMoves.Count; i++)
            {
                Cell possibleMove = possibleMoves[i];

                Point oppsitDirection = DirectionExtension.PointFromDirection(DirectionExtension.GetOppositeDirection(lastDirection));
                Cell oppositeCell = level.getCell(CurrentCell.GridPosition.X + oppsitDirection.X,
                                                  CurrentCell.GridPosition.Y + oppsitDirection.Y);

                if(possibleMove == null)
                {
                    possibleMoves.Remove(possibleMove);
                    continue;
                }

                if (oppositeCell.GridPosition == possibleMove.GridPosition || possibleMove.GridPosition == lastCell.GridPosition)
                {
                    possibleMoves.Remove(possibleMove);
                    continue;
                }
            }

            if (possibleMoves.Count > 1)
            {
                Cell wantedCell = level.getCell(ghostAi.TargetCell(CurrentCell, behaviour));

                FindShortestPath(CurrentCell, wantedCell, ref possibleMoves);
            }

            if(possibleMoves.Count >0)
            {
                Cell nextCell = possibleMoves[0];
                Point nextMovement = new Point(nextCell.GridPosition.X - CurrentCell.GridPosition.X,
                                                nextCell.GridPosition.Y - CurrentCell.GridPosition.Y);
                Direction = DirectionExtension.DirectionFromPoint(nextMovement);
            }

            possibleMoves.Clear();
        }
Example #29
0
 public Cell GetCell(int x, int y)
 {
     Cell cell = new Cell(new Point(x, y), false);
     cell.CellEffect = new PowerUpCreator().createEffect();
     return cell;
 }
Example #30
0
        private void FindShortestPath(Cell currentCell, Cell targetCell, ref List<Cell> cells)
        {
            double shortestDistance = float.MaxValue;
            double distance = float.MaxValue;

            for(int i=0; i<cells.Count; i++)
            {
                distance = Math.Sqrt(Math.Pow(cells[i].GridPosition.X - targetCell.GridPosition.X, 2) + Math.Pow(cells[i].GridPosition.Y - targetCell.GridPosition.Y, 2));

                if(distance <= shortestDistance)
                {
                    shortestDistance = distance;
                    Cell swapper = cells[i];
                    cells.Remove(cells[i]);
                    cells.Insert(0, swapper);
                }
                else
                {
                    cells.RemoveAt(i);
                }
            }
        }