コード例 #1
0
ファイル: PacMan.cs プロジェクト: Rosthouse/Multi-Pac
        /// <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;
        }
コード例 #2
0
ファイル: Ghost.cs プロジェクト: Rosthouse/Multi-Pac
        /// <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;
        }
コード例 #3
0
ファイル: Inky.cs プロジェクト: Rosthouse/Multi-Pac
        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);
        }
コード例 #4
0
ファイル: Inky.cs プロジェクト: Rosthouse/Multi-Pac
        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;
        }
コード例 #5
0
ファイル: Pinky.cs プロジェクト: Rosthouse/Multi-Pac
        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);
        }
コード例 #6
0
ファイル: AiController.cs プロジェクト: Rosthouse/Multi-Pac
        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>();
        }
コード例 #7
0
ファイル: Clyde.cs プロジェクト: Rosthouse/Multi-Pac
        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;
            }
        }
コード例 #8
0
ファイル: GhostAi.cs プロジェクト: Rosthouse/Multi-Pac
 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;
     }
 }
コード例 #9
0
ファイル: MovableObject.cs プロジェクト: Rosthouse/Multi-Pac
        /// <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;
        }
コード例 #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;
            }
        }
コード例 #11
0
ファイル: Blinky.cs プロジェクト: Rosthouse/Multi-Pac
 /// <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;
 }
コード例 #12
0
ファイル: Ghost.cs プロジェクト: Rosthouse/Multi-Pac
 /// <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))
 {
 }
コード例 #13
0
ファイル: Ghost.cs プロジェクト: Rosthouse/Multi-Pac
        /// <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;
        }
コード例 #14
0
        public override void Update(Cell currentCell)
        {
            Direction lastDirection = controller.Direction;

            controller.Update(currentCell);

            if(Direction != lastDirection)
            {
                Send();
            }
        }
コード例 #15
0
 public override void Update(Cell currentCell)
 {
     controller.Update(currentCell);
 }
コード例 #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;
 }
コード例 #17
0
ファイル: Level.cs プロジェクト: Rosthouse/Multi-Pac
        /// <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;
        }
コード例 #18
0
ファイル: GhostAi.cs プロジェクト: Rosthouse/Multi-Pac
 protected Point FrightBehaviour(Cell curCell)
 {
     return DirectionExtension.PointFromDirection((Direction) rand.Next(1, 4));
 }
コード例 #19
0
ファイル: PacMan.cs プロジェクト: Rosthouse/Multi-Pac
        /// <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;
        }
コード例 #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;
 }
コード例 #21
0
ファイル: Controller.cs プロジェクト: Rosthouse/Multi-Pac
 public abstract void Update(Cell currentCell);
コード例 #22
0
ファイル: MovableObject.cs プロジェクト: Rosthouse/Multi-Pac
 /// <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;
 }
コード例 #23
0
 public override void Update(Cell currentCell)
 {
     //Do nothing in here, since this is the empty controller
 }
コード例 #24
0
ファイル: GhostAi.cs プロジェクト: Rosthouse/Multi-Pac
 protected abstract Point HuntBehaviour(Cell currentCell);
コード例 #25
0
ファイル: CellHideEffect.cs プロジェクト: Rosthouse/Multi-Pac
 public CellHideEffect(ref Cell actualCell)
 {
     this.actualCell = actualCell;
 }
コード例 #26
0
ファイル: AiController.cs プロジェクト: Rosthouse/Multi-Pac
 public override void Update(Cell CurrentCell)
 {
     this.Update(CurrentCell, EGhostBehaviour.Hunt);
 }
コード例 #27
0
ファイル: Level.cs プロジェクト: Rosthouse/Multi-Pac
 /// <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;
 }
コード例 #28
0
ファイル: AiController.cs プロジェクト: Rosthouse/Multi-Pac
        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();
        }
コード例 #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;
 }
コード例 #30
0
ファイル: AiController.cs プロジェクト: Rosthouse/Multi-Pac
        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);
                }
            }
        }