コード例 #1
0
ファイル: Rocket.cs プロジェクト: slstrozier/Wormz
        /// <summary>
        /// Create a new rocket based on the player,angle and power.
        /// </summary>
        /// <param name="game">The current game</param>
        /// <param name="batch">the spritebatch to draw the rocket</param>
        /// <param name="player">the player for this rocket.</param>
        public Rocket(Game game, SpriteBatch batch, Player player, Texture2D foregroundTexture)
            : base(game)
        {
            spriteBatch = batch;

            position = player.Position + offset;
            angle = player.Angle;

            Vector2 up = new Vector2(0, -1);
            Matrix rotationMatrix = Matrix.CreateRotationZ(angle);
            velocity = Vector2.Transform(up, rotationMatrix);
            velocity *= player.Power / 50.0f;

            color = player.Color;
            rocketFlying = true;

            smokeList = new List<Vector2>();
            randomizer = new Random();

            this.foregroundTexture = foregroundTexture;
        }
コード例 #2
0
ファイル: Player.cs プロジェクト: slstrozier/Wormz
        /// <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;
        }