Пример #1
0
        /// <summary>
        /// Creates a fresh gamestate with all game objects initialized and set to inactive.
        /// </summary>
        public GameState( ResourceProvider provider )
        {
            towers = new Tower[2];
            towers[0] = new Tower(Team.BLUE, provider);
            towers[1] = new Tower(Team.RED, provider);

            characters = new Character[GameSettings.MAX_LOBBY_CAPACITY];
            for ( int i = 0; i < GameSettings.MAX_LOBBY_CAPACITY; ++i )
            {
                characters[i] = new Character( provider );
            }

            spells = new Spell[GameSettings.MAX_SPELLS];
            for ( int i = 0; i < GameSettings.MAX_SPELLS; ++i )
            {
                spells[i] = new Spell( provider );
            }

            pickups = new PickUp[GameSettings.MAX_PICKUPS];
            for ( int i = 0; i < GameSettings.MAX_PICKUPS; ++i )
            {
                pickups[i] = new PickUp( provider );
            }

            roundClock = TimeSpan.Zero;

            scores = new int[2];
            for ( int i = 0; i < scores.Length; ++i )
            {
                scores[i] = 0;
            }
        }
Пример #2
0
        public override void Activate(bool instancePreserved)
        {
            IsoTileMap world;
            Camera camera;

            if (!instancePreserved)
            {
                Color myColor = Color.FromNonPremultiplied(255, 10, 10, 128);
                Console.WriteLine(myColor);
                ContentManager content = ScreenManager.Game.Content;
                manager = GameManager.Instance;
                manager.InMultiplayer = false;

                escapePressed = new InputAction(null, new Keys[] { Keys.Escape }, true);
                uPressed = new InputAction(null, new Keys[] { Keys.U }, true);

                // Called when the screen is first activated.. can initialize here
                camera = new Camera(ScreenManager.Game);
                camera.Autonomous = false;
                manager.Camera = camera;

                world = new IsoTileMap(camera);
                world.Cursor.Active = true;
                world.Cursor.Colour = Color.Blue;
                world.LoadFromFile(content, "Content/Maps/MPMap.map");
                scorebg = content.Load<Texture2D>("UITextures/scorebg");
                scoreFont = content.Load<SpriteFont>("Fonts/GUIFont");
                gameOverFont = content.Load<SpriteFont>("Fonts/GameOverFont");
                world.SetCameraToWorldBounds();
                manager.TileMap = world;

                                // Set up a fresh game state
                GameManager.Instance.GameState = new GameState(GameManager.Instance);

                manager.GameState.Characters = new Character[26];

                Character playerChar = new Character(manager);
                manager.GameState.Characters[0] = playerChar;
                playerChar.Initialize(1, new Vector2(350, 350));
                playerChar.IsPlayer = true;
                player = playerChar;
                characters.Add(playerChar);
                actionBar = new ActionBar(player);
                playerFrame = new PlayerFrame(player);
                playerChar.Team = Team.BLUE;
                player.CurrentFocus = 25;
                player.CurrentHealth = 100;
                player.CrystalCount = 500;

                manager.MyID = 0;

                for (int i = 1; i < 26; i++)
                {
                    NPC c = new NPC(manager);
                    manager.GameState.Characters[i] = c;
                    bool canPlace = false;
                    Vector2 pos = Vector2.Zero;
                    while (!canPlace)
                    {
                        int xPos = randomizer.Next(32, manager.TileMap.GetWidthInPixels() - 32);
                        int yPos = randomizer.Next(32, manager.TileMap.GetHeightInPixels() - 32);
                        pos = new Vector2(xPos, yPos);
                        if ((pos - manager.GameState.Characters[0].WorldPosition).Length() > 1000)
                        {
                            canPlace = true;
                        }
                    }
                    c.Initialize(randomizer.Next(0, 4), pos);
                }

                /*
                NPC char1 = new NPC(manager);
                char1.Initialize(0, new Vector2(450, 350));
                characters.Add(char1);
                char1.Name = "Player1";

                NPC char2 = new NPC(manager);
                char2.Initialize(1, new Vector2(550, 350));
                characters.Add(char2);
                char2.Name = "Player2";
                char2.Team = Team.RED;
                char2.CurrentHealth = char2.MaxHealth / 2;

                NPC char3 = new NPC(manager);
                char3.Initialize(2, new Vector2(650, 350));
                characters.Add(char3);
                char3.Name = "Player3";

                NPC char4 = new NPC(manager);
                char4.Initialize(3, new Vector2(750, 350));
                characters.Add(char4);
                char4.Name = "Player4";
                char4.Team = Team.RED;
                char4.CurrentHealth = char2.MaxHealth / 2;
                */
                /*
                Random randomizer = new Random();
                for (int i = 0; i < 20; i++)
                {

                    Character chari = new Character(manager);
                    chari.Initialize(3, new Vector2(randomizer.Next(0,4000),randomizer.Next(0, 4000)));
                    characters.Add(chari);
                    chari.Name = "Player4";
                    chari.Team = Team.RED;
                    chari.CurrentHealth = char2.MaxHealth;
                    Console.WriteLine("ok");
                }
                */

                //manager.GameState.Characters = new[] { playerChar, char1, char2, char3, char4 };
                namePlates = new List<NamePlate>();
                radar = new Radar(playerChar);
                radar.Scale = 0.5f;
                radar.Alpha = 0.8f;
                radar.SnapToCorner(Radar.Corner.TopRight);

                foreach (Character c in manager.GameState.Characters)
                {
                    if (c != player)
                    {
                        NamePlate np = new NamePlate(c);
                        namePlates.Add(np);
                    }
                }

                for (int i = 0; i < 120; i++)
                {
                    PickUp pu = new PickUp(manager);
                    pickUps.Add(pu);
                    pu.Initialize(0);
                }

                bgMusic = ScreenManager.Game.Content.Load<Song>("Audio/Demo_FinalFight");
                MediaPlayer.IsRepeating = true;
                MediaPlayer.Play( bgMusic );
                MediaPlayer.Volume = 0.4f;
                cPress = new InputAction(null, new Keys[] { Keys.C }, true);
                bPress = new InputAction(null, new Keys[] { Keys.B }, true);
            }
        }