예제 #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public GameplayScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);

            playBehaviour = new PlayBehaviour();
            deathBehaviour = new DeathBehaviour();
        }
예제 #2
0
        /// <summary>
        /// Instantiates all the classes needed for the game
        /// </summary>
        public override void Initialize()
        {
            //generate Level from file
            var parser = new LevelParser();
            level = parser.GenerateLevel(ScreenManager.Content.Load<List<String[]>>(@"Levels\level1"));

            //create a camer, for we want to see the game
            camera = new Camera(0.4f, Vector2.Zero, 0, true, null);

            Point size = new Point(49, 49);

            PlayerController playerController = new PlayerController(Direction.None, "PacMa", 1, PlayerIndex.One,
                                                                     MovObjType.LocalPacMan, ScreenManager.Input);

            //Create a player object
            PacMan player = new PacMan(@"Sprites\PacMan", level.getCell(1, 1), level,
                                                new PlayerController(Direction.None, "Player 1",1, PlayerIndex.One, MovObjType.LocalPacMan, ScreenManager.Input), Direction.None, 3f, size);

            //Create all ghosts for the game

            Ghost blinky = new Ghost(@"Sprites\GhostBase", level.getCell(26, 1), level, Direction.Down, 3f, size, Color.Red, new Blinky(player, new Point(0, 0), new Point(15, 15), new Point(16, 16)));
            Ghost pinky = new Ghost(@"Sprites\GhostBase", level.getCell(26, 29), level, Direction.None, 3f, size, Color.Pink, new Pinky(player, new Point(0, 28), new Point(15, 15), new Point(16, 16)));
            Ghost inky = new Ghost(@"Sprites\GhostBase", level.getCell(26, 14), level, Direction.None, 3f, size, Color.Blue,
                                   new Inky(player, blinky, new Point(31, 0), new Point(15, 15), new Point(16, 16)));
            Ghost clyde = new Ghost(@"Sprites\GhostBase", level.getCell(12, 17), level, Direction.None, 3f, size, Color.Yellow,
                                    new Clyde(player, new Point(31, 28), new Point(15, 15), new Point(16, 16)));

            //Initialize the list of gui elements
            guiElements = new List<GUIElement>();
            GUIString stringElement = new GUIString(player, Color.White, new Vector2(0, 0), new Vector2(10, 10));

            guiElements.Add(stringElement);

            //Store everything inside the gameStateManager
            gameStateManager = new GameStateManager();
            gameStateManager.GameState = GameState.Loading;

            gameStateManager.AddPlayers(player, blinky, pinky, inky, clyde);

            gameStateManager.Level = level;

            //            movOb.Add(player);
            //            movOb.Add(blinky);
            //            movOb.Add(pinky);
            //            movOb.Add(inky);
            //            movOb.Add(clyde);

            //Initialize the gameplay behaviours
            playBehaviour = new PlayBehaviour();
            deathBehaviour = new DeathBehaviour();

            gameStateManager.GetAllOfType<PacMan>();
            gameStateManager.GetAllOfType<Ghost>();
        }
예제 #3
0
        public GameLoop(int idleTimer)
        {
            playBehaviour = new PlayBehaviour();
            deathBehaviour = new DeathBehaviour();

            this.idleTimer = idleTimer;
            this.defaultIdleTimer = idleTimer;

            InputQueue = new Queue<Command>();

            simulationState = SimulationState.Idling;
        }
예제 #4
0
        /// <summary>
        /// Initializes the current screen
        /// </summary>
        public override void Initialize()
        {
            //Store everything inside the gameStateManager
            gameStateManager = new GameStateManager();
            gameStateManager.GameState = GameState.Loading;
            gameStateManager.Level = level;

            //Initialize the gameplay behaviours
            playBehaviour = new PlayBehaviour();
            deathBehaviour = new DeathBehaviour();

            var parser = new LevelParser();

            gameStateManager.Level = parser.GenerateLevel(ScreenManager.Content.Load<List<String[]>>(@"Levels\level1"));
            guiElements = new List<GamePlayScreens.GUI.GUIElement>();

            //camera = new Camera(1, Vector2.Zero, 0);
            camera = new Camera(0.4f, Vector2.Zero, 0, true, null);

            // ask server for List of connected and waiting clients
            networkManager.sendMessage("getPlayers");

            // wait for the response to the request of available players
            NetIncomingMessage msg;
            bool waitingForServer = true;
            while (waitingForServer)
            {
                // check for messages as long the incoming messages queue has messages stored
                while ((msg = networkManager.getMessage()) != null)
                {
                    switch (msg.MessageType)
                    {
                        case NetIncomingMessageType.Data:
                            string msgStr = msg.ReadString();

                            // check if the message is the response to the request
                            string[] clients = msgStr.Split(';');
                            if (clients[0] == "getPlayers")
                            {
                                int i = 1;
                                foreach (string player in clients)
                                {
                                    if (player != "" && player != "getPlayers")
                                    {
                                        string[] values = player.Split('/');
                                        int localUID = networkManager.getUID();
                                        int remoteUID = Convert.ToInt32(values[0]);

                                        switch (values[1])
                                        {
                                            case "1": // Player is a PacMan
                                                // Check if it is a local or remote controlled gameobject
                                                if (localUID == remoteUID) // local controlled
                                                {
                                                    PlayerController playerController = new PlayerController(
                                                        Direction.None, values[0], remoteUID, PlayerIndex.One,
                                                        MovObjType.LocalPacMan, ScreenManager.Input);

                                                    NetworkController networkController =
                                                        new NetworkController(playerController.ID, playerController,
                                                                              networkManager);

                                                    gameStateManager.AddPlayers(new PacMan(@"Sprites\PacMan",
                                                        gameStateManager.Level.getCell(1, 1), gameStateManager.Level, networkController, Direction.None, 1.3f, new Point(50, 50)));
                                                }
                                                else // remote controlled
                                                {
                                                    EmptyController emptyController = new EmptyController(Direction.None,
                                                                                                          values[0],
                                                                                                          remoteUID,
                                                                                                          MovObjType.
                                                                                                              NetPacMan);

                                                    gameStateManager.AddPlayers(new PacMan(@"Sprites\PacMan",
                                                        gameStateManager.Level.getCell(1, 1), gameStateManager.Level,
                                                        new NetworkController(emptyController.ID, emptyController, networkManager),
                                                        Direction.None, 1.3f, new Point(50, 50)));
                                                }

                                                GUIString stringElement = new GUIString(gameStateManager.MovableObjects.Last(), Color.White, new Vector2(0, 0), new Vector2(10, i * 10));
                                                guiElements.Add(stringElement);

                                                break;

                                            case "2": // Player is a Ghost

                                                Blinky blinky = new Blinky(gameStateManager.GetAllOfType<PacMan>()[0],
                                                                           new Point(0, 0), new Point(15, 15),
                                                                           new Point(17, 17));

                                                GhostController ghostController = new GhostController(level,
                                                                                                      blinky,
                                                                                                      remoteUID);

                                                NetworkGhostController ghostNetworkController =
                                                    new NetworkGhostController(networkManager, ghostController,
                                                                               ghostController.ID);
                                                gameStateManager.AddPlayers(new Ghost(@"Sprites\GhostBase", gameStateManager.Level.getCell(26, 1), gameStateManager.Level,
                                                    Direction.Down, 0.8f, new Point(50, 50), Color.Crimson, ghostNetworkController));

                                                //                                            else
                                                //                                            {
                                                //
                                                //
                                                //                                                gameStateManager.AddPlayers(new Ghost(@"Sprites\GhostBase", gameStateManager.Level.getCell(26, 1), gameStateManager.Level,
                                                //                                                    Direction.Down, 0.8f, new Point(50, 50), Color.Crimson, new NetworkController(Direction.None, values[0], Convert.ToInt32(values[0]),
                                                //                                                        PlayerIndex.One, MovObjType.NetGhost, ScreenManager.Input, networkManager)));
                                                //                                            }
                                                break;
                                        }
                                        i += 10;
                                    }
                                }
                                // All mvable objects are initialized, start game
                                waitingForServer = false;
                            }

                            break;
                    }
                }
            }

            gameStateManager.CreateTimestamp(0);
        }