Ejemplo n.º 1
0
        private void DrawEnd(GameCoordinates gameCoordinates)
        {
            Vector2 position = gameCoordinates.GetScreenPosition();

            Color color = new Color(255, 255, 255, 255);

            //topRight
            GameObject.SpriteBatch.Draw(sprite,
                                        new Rectangle((int)(position.X),
                                                      (int)(position.Y - LINE_TICKNESS * SCALE),
                                                      LINE_TICKNESS * SCALE,
                                                      LINE_TICKNESS * SCALE),
                                        topRight,
                                        color);


            //bottomRight
            GameObject.SpriteBatch.Draw(sprite,
                                        new Rectangle((int)(position.X),
                                                      (int)(position.Y),
                                                      LINE_TICKNESS * SCALE,
                                                      LINE_TICKNESS * SCALE),
                                        bottomRight,
                                        color);
        }
Ejemplo n.º 2
0
        private void DrawLine(GameCoordinates gameCoordinates)
        {
            Vector2 position = gameCoordinates.GetScreenPosition();

            Color color = new Color(255, 255, 255, 255);

            GameObject.SpriteBatch.Draw(sprite,
                                        new Rectangle((int)(position.X), (int)position.Y - (LINE_TICKNESS * SCALE), OBJECT_SIZE * SCALE, LINE_TICKNESS * SCALE),
                                        top,
                                        color);

            GameObject.SpriteBatch.Draw(sprite,
                                        new Rectangle((int)(position.X), (int)position.Y, OBJECT_SIZE * SCALE, LINE_TICKNESS * SCALE),
                                        bottom,
                                        color);
        }
Ejemplo n.º 3
0
        public void LoadContent()
        {
            if (mode == Mode.Demo)
            {
                pacmans.Add(new PacmanGameObject(-1, 0));

                monsters.Add(new MonsterGameObject(-3, 0, MonsterGameObject.MonsterGameObjectColor.Blue));
                monsters.Add(new MonsterGameObject(-4, 0, MonsterGameObject.MonsterGameObjectColor.Pink));
                monsters.Add(new MonsterGameObject(-5, 0, MonsterGameObject.MonsterGameObjectColor.Green));
                monsters.Add(new MonsterGameObject(-6, 0, MonsterGameObject.MonsterGameObjectColor.Red));

                listOfAllGameObjects.Add(pacmans);
                listOfAllGameObjects.Add(monsters);
            }
            else if (mode == Mode.Normal)
            {
                monsters.Add(new MonsterGameObject(MonsterGameObject.MonsterGameObjectColor.Blue));
                monsters.Add(new MonsterGameObject(MonsterGameObject.MonsterGameObjectColor.Green));
                monsters.Add(new MonsterGameObject(MonsterGameObject.MonsterGameObjectColor.Pink));
                monsters.Add(new MonsterGameObject(MonsterGameObject.MonsterGameObjectColor.Red));


                Viewport viewport = ScreenManager.GraphicsDevice.Viewport;

                GameCoordinates topLeftArena     = new GameCoordinates(0, 0);
                GameCoordinates bottomRightArena = new GameCoordinates();

                //TODO:remove magic number
                bottomRightArena.X = viewport.Width / 24 - 2;
                bottomRightArena.Y = viewport.Height / 24 - 2;

                walls = board.Walls;

                //borders
                if (
                    //false
                    true
                    )
                {
                    walls.Add(new HorizontalWallGameObject(topLeftArena.Y, topLeftArena.X, bottomRightArena.X));
                    walls.Add(new HorizontalWallGameObject(bottomRightArena.Y, topLeftArena.X, bottomRightArena.X));

                    walls.Add(new VerticalWallGameObject(topLeftArena.X, topLeftArena.Y, bottomRightArena.Y));
                    walls.Add(new VerticalWallGameObject(bottomRightArena.X, topLeftArena.Y, bottomRightArena.Y));
                }

                dots = DotGameObject.Generate(bottomRightArena.X, bottomRightArena.Y);


                listOfAllGameObjects.Add(dots);

                pills = MagicPillGameObject.Generate();

                listOfAllGameObjects.Add(pills);
                listOfAllGameObjects.Add(walls);
                listOfAllGameObjects.Add(portals);
                listOfAllGameObjects.Add(fruits);

                pacman = new PacmanGameObject();
                pacmans.Add(pacman);
                listOfAllGameObjects.Add(pacmans);
                listOfAllGameObjects.Add(monsters);

                List <GameObject> other = new List <GameObject>();
                other.Add(toolBarGameObject = new ToolBarGameObject());
                listOfAllGameObjects.Add(other);

                /*
                 * List<GameObject> monsterHouses = new List<GameObject>();
                 * monsterHouses.Add(monsterHouse);
                 * listOfAllGameObjects.Add(monsterHouses);
                 */
            }


            collisionManager = CollisionManager.getInstance();
            collisionManager.Initialize(walls, portals, monsterHouses,
                                        dots, pills, fruits,
                                        pacmans, monsters);


            GameObject.LoadStaticContent();

            foreach (List <GameObject> list in listOfAllGameObjects)
            {
                foreach (GameObject gameObject in list)
                {
                    gameObject.LoadContent();
                }
            }
        }
Ejemplo n.º 4
0
        public override bool makeMove()
        {
            bool      stillThisSameGamePosition = (startLastMovePosition.X == GameVectorPosition.X && startLastMovePosition.Y == GameVectorPosition.Y);
            bool      wantsChangeDirection      = nextMove != movementDirection;
            direction lastMoveBackUp            = nextMove;


            //System.Console.WriteLine("wantsChangeDirection: " + wantsChangeDirection.ToString() +
            //                       "\nstillThisSameGamePosition: " + stillThisSameGamePosition.ToString());


            if (wantsChangeDirection &&//we want to take a turn
                (stillThisSameGamePosition && moved))
            {
                nextMove = movementDirection;
            }
            //else
            //  System.Console.WriteLine("turn from " + lastMoveBackUp.ToString() + " to " +lastMove.ToString());

            Vector2 move = CalculateMove(nextMove, updateDelta, STEP);

            moved = false;

            //calculate how far coordinate is from Path and compere it with Torerance
            int  moduloY          = ((int)(screenVectorPosition.Y + move.Y)) % GameObject.OBJECT_SIZE;
            bool onHorizontalPath = GameObject.OBJECT_SIZE / 2 - Math.Abs(moduloY - GameObject.OBJECT_SIZE / 2) <= TOLERANCE;

            int  moduloX        = ((int)(screenVectorPosition.X + move.X)) % GameObject.OBJECT_SIZE;
            bool onVerticalPath = GameObject.OBJECT_SIZE / 2 - Math.Abs(moduloX - GameObject.OBJECT_SIZE / 2) <= TOLERANCE;



            //changing move direction
            if (((onVerticalPath && !WasOnVerticalPath()) || onHorizontalPath && !WasOnHorizontalPath()) &&
                !CollisionManager.getInstance().IsCollision(roundRectangleToPath(this.ScreenRectanglePosition, move, nextMove, onHorizontalPath, onVerticalPath), nextMove, GameObjectType.WALLS))
            {
                this.screenVectorPosition   += new Vector2((int)move.X, (int)move.Y);
                this.ScreenRectanglePosition = roundRectangleToPath(this.ScreenRectanglePosition, move, movementDirection, onHorizontalPath, onVerticalPath);

                if (movementDirection != nextMove)
                {
                    startLastMovePosition = GameVectorPosition;
                }

                movementDirection = nextMove;


                moved = true;
            }
            else if (!CollisionManager.getInstance().IsCollision(roundRectangleToPath(this.ScreenRectanglePosition,
                                                                                      move = CalculateMove(movementDirection, updateDelta, STEP),
                                                                                      movementDirection, onHorizontalPath, onVerticalPath), movementDirection, GameObjectType.WALLS))
            {
                this.screenVectorPosition   += new Vector2((int)move.X, (int)move.Y);
                this.ScreenRectanglePosition = roundRectangleToPath(this.ScreenRectanglePosition, move, movementDirection, onHorizontalPath, onVerticalPath);
                moved = true;
            }

            if (!moved)
            {
                if (nextMoveAlternativeNumber < 3)
                {
                    nextMove = nextMoveAlternative[nextMoveAlternativeNumber];
                    nextMoveAlternativeNumber++;
                    makeMove();
                }
            }
            else
            {
                if (nextMoveAlternativeNumber != 0)
                {
                    System.Console.WriteLine("Move number" + nextMoveAlternativeNumber.ToString());
                }

                nextMoveAlternativeNumber = 0;
            }



            return(moved);
        }
Ejemplo n.º 5
0
        public override void HandleInput(KeyboardState keyboardState)
        {
            if (dead)
            {
            }
            if (true)
            {
                List <GameCoordinates> pacmansPositions = PacmanGameObject.PacmansPositions;

                float min = float.MaxValue;


                if (ghost)
                {
                    if (!fakePacmanPositionSet)
                    {
                        gameCoordinatesOfNearestPacman = new GameCoordinates(random.Next(23), random.Next(17));
                        fakePacmanPositionSet          = true;
                    }
                }
                else
                {
                    gameCoordinatesOfNearestPacman = pacmansPositions[0];
                    foreach (GameCoordinates gc in pacmansPositions)
                    {
                        float tmp = Vector2.Distance(new Vector2(gc.X, gc.Y), new Vector2(GameVectorPosition.X, GameVectorPosition.Y));
                        if (tmp < min)
                        {
                            min = tmp;
                            gameCoordinatesOfNearestPacman = gc;
                        }
                    }
                }
                bool equal = Math.Abs(gameCoordinatesOfNearestPacman.X - GameVectorPosition.X) ==
                             Math.Abs(gameCoordinatesOfNearestPacman.Y - GameVectorPosition.Y);

                if ((equal && random.Next(2) == 0) ||
                    (Math.Abs(gameCoordinatesOfNearestPacman.X - GameVectorPosition.X) >
                     Math.Abs(gameCoordinatesOfNearestPacman.Y - GameVectorPosition.Y)))
                {//closer by X
                    nextMove = (gameCoordinatesOfNearestPacman.X > GameVectorPosition.X) ? direction.Right : direction.Left;
                    nextMoveAlternative[0] = (gameCoordinatesOfNearestPacman.Y > GameVectorPosition.Y) ? direction.Down : direction.Up;
                    nextMoveAlternative[1] = (gameCoordinatesOfNearestPacman.X > GameVectorPosition.X) ? direction.Left : direction.Right;
                    nextMoveAlternative[2] = (gameCoordinatesOfNearestPacman.Y > GameVectorPosition.Y) ? direction.Up : direction.Down;
                }
                else
                {
                    nextMove = (gameCoordinatesOfNearestPacman.Y > GameVectorPosition.Y) ? direction.Down : direction.Up;
                    nextMoveAlternative[0] = (gameCoordinatesOfNearestPacman.X > GameVectorPosition.X) ? direction.Right : direction.Left;
                    nextMoveAlternative[1] = (gameCoordinatesOfNearestPacman.Y > GameVectorPosition.Y) ? direction.Up : direction.Down;
                    nextMoveAlternative[2] = (gameCoordinatesOfNearestPacman.X > GameVectorPosition.X) ? direction.Left : direction.Right;
                }
            }
            else
            {
                // Otherwise move the player position.
                Vector2 movement = Vector2.Zero;

                if (keyboardState.IsKeyDown(Keys.Left))
                {
                    movement.X--;
                    nextMove = direction.Left;
                }

                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    movement.X++;
                    nextMove = direction.Right;
                }

                if (keyboardState.IsKeyDown(Keys.Up))
                {
                    movement.Y--;
                    nextMove = direction.Up;
                }

                if (keyboardState.IsKeyDown(Keys.Down))
                {
                    movement.Y++;
                    nextMove = direction.Down;
                }

                if (movement.Length() > 1)
                {
                    movement.Normalize();
                }
            }
        }
Ejemplo n.º 6
0
 public HorizontalWallGameObject(int y, int startX, int endX)
 {
     Start = new GameCoordinates(startX, y);
     End   = new GameCoordinates(endX, y);
 }
Ejemplo n.º 7
0
 public VerticalWallGameObject(int x, int startY, int endY)
 {
     Start = new GameCoordinates(x, startY);
     End   = new GameCoordinates(x, endY);
 }