Esempio n. 1
0
        public bool IsCollision(Rectangle rect, PacmanGameObject.direction direction, GameObject.GameObjectType gameObjectTyp)
        {
            switch (gameObjectTyp)
            {
                case GameObject.GameObjectType.WALLS:
                    return IsPacmanMakeCollisionWithWalls(rect, direction);
                case GameObject.GameObjectType.DOTS:
                    return IsPacmanMakeCollisionWithDots(rect, direction);
                case GameObject.GameObjectType.PILLS:
                    return IsPacmanMakeCollisionWithPills(rect, direction);

                case GameObject.GameObjectType.GHOSTS:

                    goto case GameObject.GameObjectType.MONSTERS;
                case GameObject.GameObjectType.MONSTERS:
                    return IsPacmanMakeCollisionWithMonsters(rect, direction);

            }

            return false;
        }
Esempio n. 2
0
        private bool IsPacmanMakeCollisionWithDots(Rectangle pacmanRect, PacmanGameObject.direction direction)
        {
            if (DotGameObject.VisibleDotCounter > 0)
            {
                GameCoordinates pacEnvironmet = GameCoordinates.ScreenPositionToGameCoortinates(new Vector2(pacmanRect.X, pacmanRect.Y));

                List<DotGameObject> dotsToCheck = new List<DotGameObject>();

                dotsToCheck.Add(DotGameObject.array[pacEnvironmet.X, pacEnvironmet.Y]);

                if (pacEnvironmet.X < 24 - 1 /*BoardSize*/)
                    dotsToCheck.Add(DotGameObject.array[pacEnvironmet.X + 1, pacEnvironmet.Y]);

                if (pacEnvironmet.Y < 18 - 1)
                    dotsToCheck.Add(DotGameObject.array[pacEnvironmet.X, pacEnvironmet.Y + 1]);

                if (pacEnvironmet.X < 24 - 1 /*BoardSize*/ && pacEnvironmet.Y < 18 - 1)
                    dotsToCheck.Add(DotGameObject.array[pacEnvironmet.X + 1, pacEnvironmet.Y + 1]);

                int radius = 3;

                Rectangle pacmanMiniRect = new Rectangle(pacmanRect.X + (GameObject.OBJECT_SIZE / 2) - radius,
                                                         pacmanRect.Y + (GameObject.OBJECT_SIZE / 2) - radius,
                                                         2 * radius,
                                                         2 * radius);

                foreach (DotGameObject dot in dotsToCheck)
                {
                    if (pacmanMiniRect.Intersects(dot.ScreenRectangle))
                    {

                        dot.Clear();
                        return true;
                    }

                }

            }
            return false;
        }
        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();
                }
        }
Esempio n. 4
0
        private bool IsPacmanMakeCollisionWithWalls(Rectangle pacmanRect, PacmanGameObject.direction direction)
        {
            /*Rectangle pacmanRect = new Rectangle((int)(pacman.ScreenPosition.X + move.X),
                                                 (int)(pacman.ScreenPosition.Y + move.Y),
                                                 GameObject.OBJECT_SIZE,
                                                 GameObject.OBJECT_SIZE);
            */
            switch (direction)
            {
                #region with horizontal walls

                case PacmanGameObject.direction.Down:
                    goto case PacmanGameObject.direction.Up;
                case PacmanGameObject.direction.Up:

                    foreach(GameObject wall in walls)
                    {
                        if(wall is HorizontalWallGameObject)
                        {
                            HorizontalWallGameObject horizontalWall = (HorizontalWallGameObject)wall;

                            Rectangle wallRect = new Rectangle((int)horizontalWall.Start.GetScreenPosition().X,
                                                               (int)horizontalWall.Start.GetScreenPosition().Y,
                                                               GameObject.OBJECT_SIZE*horizontalWall.Length()
                                                               , 0);

                            if (pacmanRect.Intersects(wallRect))
                                return true;

                        }
                    }

                    return false;

                #endregion

                #region with vertical walls

                case PacmanGameObject.direction.Left:
                    goto case PacmanGameObject.direction.Right;
                case PacmanGameObject.direction.Right:

                    foreach (GameObject wall in walls)
                    {
                        if (wall is VerticalWallGameObject)
                        {
                            VerticalWallGameObject verticallWall = (VerticalWallGameObject)wall;

                            Rectangle wallRect = new Rectangle((int)verticallWall.Start.GetScreenPosition().X,
                                                               (int)verticallWall.Start.GetScreenPosition().Y,
                                                               0,
                                                               GameObject.OBJECT_SIZE * verticallWall.Length());

                            if (pacmanRect.Intersects(wallRect))
                                return true;

                        }
                    }

                    return false;

                #endregion
            }

            return false;
        }
Esempio n. 5
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();
                }
            }
        }