Пример #1
0
        NewGame _modalNewGame = new NewGame();//to access map values

        #region Startup
        /// <summary>
        /// Initializes main form members.
        /// </summary>
        private void InitializeMembers(string XMLValue)
        {
            // initialize the level
            _lvGameLevel = new Level(XMLValue);

            // reset pause flag
            _bGamePaused = false;

            // initialize players
            PlayerData p1 = new PlayerData(PlayerNumber.One);
            PlayerData p2 = new PlayerData(PlayerNumber.Two);

            // initialize abstract inputs
            AbstractInput a1 = new AbstractInput(PlayerNumber.One);
            AbstractInput a2 = new AbstractInput(PlayerNumber.Two);

            // tank 1 starts at a random spawn point
            PointF startP1 = _lvGameLevel._respawnPoints[_rng.Next(0, _lvGameLevel._respawnPoints.Count)];

            // tank 2 starts as far from player 1 as possible
            PointF startP2 = GetFurthestSpawn(startP1);

            // initialize the tanks
            Tank t1 = new Tank(startP1, _cPlayer1Color, PlayerNumber.One);
            Tank t2 = new Tank(startP2, _cPlayer2Color, PlayerNumber.Two);

            // add inputs to input list
            _lPlayerInputs = new List <AbstractInput> {
                a1, a2
            };

            // add player data to data list
            _lPlayerData = new List <PlayerData> {
                p1, p2
            };

            // add tank shapes to dynamic shape list
            _lDynShapes = new List <DynamicShape> {
                t1, t2
            };

            // make wall list a copy of the level's walls
            _lWalls = new List <Wall>(_lvGameLevel.Walls);

            // make wall list a copy of the level's walls
            _lBrushes = new List <Brush>(_lvGameLevel.SlowFloors);

            // make ammo drops a copy of the level's ammo drops
            _lAmmoDrops = new List <Ammo>(_lvGameLevel._ammoDrops);

            // make power up drops a copy of the level's power up drops
            _lPowerUpDrops = new List <PowerUp>(_lvGameLevel._powerUpDrops);

            // make healing packs a copy of the level's healing packs
            _lHealingPacks = new List <Heal>(_lvGameLevel._healPacks);

            _lMinesDrops = new List <Mines>(_lvGameLevel._mineDrops);

            // start background input processing thread
            _tBackgroundProcessing = new Thread(TBackground);
        }
Пример #2
0
        /// <summary>
        /// Sets Tank X and Y speeds based on current input.
        /// </summary>
        /// <param name="input">
        /// Player input.
        /// </param>
        /// <param name="tank">
        /// Player tank.
        /// </param>
        private void SetTranslation(AbstractInput input, Tank tank)
        {
            // can't translate during rotations
            if (input.Rotate)
            {
                return;
            }

            // check up AND down
            if (input.Up && input.Down)
            {
                // trigger motor interlock
                tank.YSpeed = 0;
            }

            // check up OR down
            else
            {
                // moving straight up
                if (input.Up && !(input.Left || input.Right))
                {
                    tank.YSpeed = -Tank.Speed;
                }

                // moving straight down
                else if (input.Down && !(input.Left || input.Right))
                {
                    tank.YSpeed = Tank.Speed;
                }

                // moving up diagonally
                else if (input.Up && (input.Left || input.Right))
                {
                    double angle = 45 * Math.PI / 180;
                    tank.YSpeed = -(float)Math.Sqrt(Math.Pow(Tank.Speed, 2) -
                                                    Math.Pow(Tank.Speed * Math.Sin(angle), 2));
                }

                // moving down diagonally
                else if (input.Down && (input.Left || input.Right))
                {
                    double angle = 45 * Math.PI / 180;
                    tank.YSpeed = (float)Math.Sqrt(Math.Pow(Tank.Speed, 2) -
                                                   Math.Pow(Tank.Speed * Math.Sin(angle), 2));
                }

                // no vertical movement input
                else
                {
                    tank.YSpeed = 0;
                }
            }

            // Check left AND right
            if (input.Right && input.Left)
            {
                // trigger motor interlock
                tank.XSpeed = 0;
            }

            // Check left OR right
            else
            {
                // moving straight right
                if (input.Right && !(input.Up || input.Down))
                {
                    tank.XSpeed = Tank.Speed;
                }

                // moving straight left
                else if (input.Left && !(input.Up || input.Down))
                {
                    tank.XSpeed = -Tank.Speed;
                }

                // moving right diagonally
                else if (input.Right && (input.Up || input.Down))
                {
                    double angle = 45 * Math.PI / 180;
                    tank.XSpeed = (float)Math.Sqrt(Math.Pow(Tank.Speed, 2) -
                                                   Math.Pow(Tank.Speed * Math.Cos(angle), 2));
                }

                // moving left diagonally
                else if (input.Left && (input.Up || input.Down))
                {
                    double angle = 45 * Math.PI / 180;
                    tank.XSpeed = -(float)Math.Sqrt(Math.Pow(Tank.Speed, 2) -
                                                    Math.Pow(Tank.Speed * Math.Cos(angle), 2));
                }

                // no horizontal movement input
                else
                {
                    tank.XSpeed = 0;
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Resets player data IsAlive flag, and creates a new tank
 /// at the spawn point furthest from the opponent.
 /// </summary>
 private void IssueRespawn(List <DynamicShape> movingShapes, Tank playerTank, PointF opponentTankLoc)
 {
     // add new tank for the playerTank's player, in a location far away from the shooter
     movingShapes.Add(new Tank(GetFurthestSpawn(opponentTankLoc),
                               playerTank.Color, playerTank.Player));
 }