Beispiel #1
0
        /// <summary>
        /// Creates the players and sets their variables. 
        /// </summary>
        /// <param name="game">The game this player will be participating in</param>
        /// <param name="batch">the Sprite Batch that will be drawing this class.</param>
        /// <param name="numberOfPlayers">the total number of players in this game.</param>
        /// <returns>The list of all the players for this game.</returns>
        public static List<Player> CreatePlayers(Game game, SpriteBatch batch,
            int numberOfPlayers, int screenWidth, Terrain battlefield)
        {
            List<Player> players = new List<Player>();
            bool[] playerPositions = new bool[numberOfPlayers];

            for (int i = 0; i < numberOfPlayers; i++)
            {
                Player player = new Player(game, batch);

                player.position = new Vector2();

                int randomPosition = 0;
                bool isPositionTaken = true;
                while (isPositionTaken)//randomizes player order
                {
                    randomPosition = numberRandomizer.Next(0, numberOfPlayers);
                    if (!playerPositions[randomPosition])
                    {
                        playerPositions[randomPosition] = true;
                        isPositionTaken = false;
                    }
                }

                player.position.X = screenWidth / (numberOfPlayers + 1) * (randomPosition + 1);
                player.position.Y = battlefield.Contour[(int) player.position.X];
                player.isAlive = true;
                player.color = playerColors[i];
                player.angle = MathHelper.ToRadians(45);
                player.power = 100;

                players.Add(player);
            }

            return players;
        }
Beispiel #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //setting the window of the game.
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();
            Window.Title = "Wormz";

            screenWidth = graphics.GraphicsDevice.PresentationParameters.BackBufferWidth;
            screenHeight = graphics.GraphicsDevice.PresentationParameters.BackBufferHeight;

            this.battlefield = new Terrain(this, spriteBatch);//creates the terrain to be used
            Components.Add(battlefield);

            this.players = Player.CreatePlayers(this, spriteBatch, 7, screenWidth, battlefield);
            foreach (Player player in players)
            {
                Components.Add(player);
            }

            battlefield.FixTerrainBelowPlayers(ref players);//fixes the terrain to place players properly

            Components.Add(new Hud(this));
            Components.Add(new KeyboardHandler(this));

            base.Initialize();
        }