Esempio n. 1
0
 public void Take( TankObject taker, GameTime gameTime )
 {
     if ( !Taken )
     {
         if ( Carrier != null )
         {
             if ( Carrier is ProjectileObject )
             {
                 ProjectileObject proj = ( ProjectileObject )Carrier;
                 Taken = taker.AppendProjectile( proj.GetType() );
             }
             else if ( Carrier is PowerUp )
             {
                 PowerUp powerUp = ( PowerUp )Carrier;
                 Taken = taker.AppendPowerUp( powerUp, gameTime );
             }
             else throw new ArgumentException( "Object given was not a pickupable object." );
         }
         else
         {
             if ( CarrierType.IsSubclassOf( typeof( ProjectileObject ) ) )
             {
                 Taken = taker.AppendProjectile( CarrierType );
             }
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Event to occur whenever a tank collides.
 /// </summary>
 /// <param name="tank">The tank that collides.</param>
 /// <param name="factor">The distance the tank moves - used in order to have the tank pass through the fence by returning it.</param>
 /// <returns>The distance the tank should move - for instance, 0 for an impenetrable wall.</returns>
 public virtual float OnTankCollision( TankObject tank, float factor )
 {
     if ( tank.powerUp != null )
     {
         if ( tank.powerUp.DoesGoThruFence( this ) ) return factor;
     }
     else
     {
         if ( Owner.TeamGhost && ( tank != Owner || Owner.Selfish ) && tank.TeamString == Owner.TeamString ) return factor;
     }
     return 0;
 }
Esempio n. 3
0
 public FenceObject( Vector2 p1, Vector2 p2, float width, TankObject owner, GameTime gameTime, GraphicsDevice gd )
 {
     Point1 = p1;
     Point2 = p2;
     Width = width;
     Owner = owner;
     color = Owner.RGBColor;
     gt = gameTime.TotalGameTime;
     angle = ( MathHelper.ToDegrees( Owner.Rotation ) + 90 ) % 360;
     blank = new Texture2D( gd, 2, 2, false, SurfaceFormat.Color );
     blank.SetData( Enumerable.Repeat<Color>( Color.White, 4 ).ToArray<Color>() );
 }
Esempio n. 4
0
 public override bool Update( GameTime gameTime, TankObject[] Tanks, HashSet<FenceObject> Fences, HashSet<Pickup> Pickups )
 {
     return false;
 }
Esempio n. 5
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()
        {
            NumOfPlayers = LoadSetting( "Players", 2 );
            FenceLimit = LoadSetting( "FenceLimit", 3 );
            ShotLimit = LoadSetting( "ShotLimit", 1 );
            ShotTime = LoadSetting( "ShotTimeLimit", 10000 );
            FenceTime = LoadSetting( "FenceTimeLimit", 10000 );
            TimeDelay = LoadSetting( "EndingDelay", 3000 );
            StartDelay = LoadSetting( "FreezeTime", 1000 );
            TankScale = LoadSetting( "TankScale", 2F );
            PickupTime = LoadSetting( "PickupTime", 5000 );
            PickupDuration = LoadSetting( "PickupDuration", 10000 );
            SuddenDeathTime = LoadSetting( "SuddenDeathAfter", 60 );
            BlastRadius = LoadSetting( "BlastRadius", 5F );
            TankSpeed = LoadSetting( "TankSpeed", 5F );
            BulletSpeed = LoadSetting( "BulletSpeed", 2 * TankSpeed );
            BoostFactor = LoadSetting( "SpeedBoostFactor", 4 );

            // TODO: Add your initialization logic here
            Tanks = new TankObject[ NumOfPlayers ];
            KeySet p1keys = LoadSetting( "Player1Keys", new KeySet( Keys.NumPad8, Keys.NumPad5, Keys.NumPad4, Keys.NumPad6, Keys.NumPad1, Keys.NumPad2 ) );
            KeySet p2keys = LoadSetting( "Player2Keys", new KeySet( Keys.W, Keys.S, Keys.A, Keys.D, Keys.Z, Keys.X ) );
            KeySet p3keys = LoadSetting( "Player3Keys", new KeySet( Keys.Up, Keys.Down, Keys.Left, Keys.Right, Keys.OemPeriod, Keys.OemQuestion ) );
            KeySet p4keys = LoadSetting( "Player4Keys", new KeySet( Keys.U, Keys.J, Keys.H, Keys.K, Keys.V, Keys.B ) );

            Colors p1Color = LoadSetting( "Player1Color", Colors.Green );
            Colors p2Color = LoadSetting( "Player2Color", Colors.Purple );
            Colors p3Color = LoadSetting( "Player3Color", Colors.Blue );
            Colors p4Color = LoadSetting( "Player4Color", Colors.Orange );

            string p1TeamString = LoadSetting( "Player1TeamString", "1" );
            string p2TeamString = LoadSetting( "Player2TeamString", "2" );
            string p3TeamString = LoadSetting( "Player3TeamString", "3" );
            string p4TeamString = LoadSetting( "Player4TeamString", "4" );

            string ts = LoadSetting( "TeamStatus", "None" ).ToLower();
            bool TeamShield = ts == "shield" || ts == "ghost";
            bool TeamGhost = ts == "ghost";

            ts = LoadSetting( "Selfish", "No" ).ToLower();
            bool Selfish = ts == "true" || ts == "1" || ts == "yes";

            Tanks[ 0 ] = new TankObject( new Vector2( 50, 50 ), 45, p1Color, p1keys, TankScale, ShotLimit, ShotTime, FenceLimit, FenceTime, TankSpeed, BulletSpeed, p1TeamString, TeamShield, TeamGhost, Selfish );

            if ( NumOfPlayers >= 2 )
            {
                Tanks[ 1 ] = new TankObject( new Vector2( width - 50, height - 50 ), 225, p2Color, p2keys, TankScale, ShotLimit, ShotTime, FenceLimit, FenceTime, TankSpeed, BulletSpeed, p2TeamString, TeamShield, TeamGhost, Selfish );
            }

            if ( NumOfPlayers >= 3 )
            {
                Tanks[ 2 ] = new TankObject( new Vector2( width - 50, 50 ), 135, p3Color, p3keys, TankScale, ShotLimit, ShotTime, FenceLimit, FenceTime, TankSpeed, BulletSpeed, p3TeamString, TeamShield, TeamGhost, Selfish );
            }
            if ( NumOfPlayers >= 4 )
            {
                Tanks[ 3 ] = new TankObject( new Vector2( 50, height - 50 ), 315, p4Color, p4keys, TankScale, ShotLimit, ShotTime, FenceLimit, FenceTime, TankSpeed, BulletSpeed, p4TeamString, TeamShield, TeamGhost, Selfish );
            }
            Projectiles = new HashSet<ProjectileObject>();
            Fences = new HashSet<FenceObject>();
            Pickups = new HashSet<Pickup>();
            SuddenDeaths = new SuddenDeath[] {
                new ShrinkyDeath(),
                new ExplodyDeath(),
                new GlitchyDeath(),
                new PossessyDeath(),
                new HoleyDeath(),
                new HomeyDeath(),
                new SuperNoveyDeath(),
            };
            PickupableOptions = new Type[]
            {
                typeof( Deflector ),
                typeof( Minimize ),
                typeof( Portal ),
                typeof( HomingBullet ),
                typeof( Missile ),
                typeof( Switcher ),
                typeof( BlackHole ),
                typeof( SpeedBoost ),
                typeof( Accelerator ),
                typeof( Roulette ),
                typeof( Lock ),
                typeof( ExtremeBullet ),
                typeof( ExtraLife ),
                typeof( ForceField ),
                typeof( Disabler ),
                typeof( Ghost ),
                typeof( Tripler ),
                typeof( Concealer ),
            };
            IsMouseVisible = true;
            base.Initialize();
        }
Esempio n. 6
0
        public void Update( GameTime gameTime, KeyboardState key, KeyboardState oldkey, int width, int height, TankObject[] Tanks, HashSet<ProjectileObject> Projectiles, HashSet<FenceObject> Fences, HashSet<Pickup> Pickups, GraphicsDevice gd )
        {
            if ( key.IsKeyDown( Keys.KeyPlace ) && oldkey.IsKeyUp( Keys.KeyPlace ) && ( PlacedFences < FenceLimit || FenceLimit < 0 ) )
            {
                if ( PendingPowerUp == null && IsInGame )
                {
                    PlacedFences++;
                    float dist = Vector2.Distance( Vector2.Zero, Origin );
                    Fences.Add( new BasicFence( GameTools.ReturnMove( dist / 4, angle, GameTools.ReturnMove( dist, angle + 45, Position ) ), GameTools.ReturnMove( dist / 4, angle, GameTools.ReturnMove( dist, angle - 45, Position ) ), 8, this, gameTime, gd ) );
                }
                else if ( PendingPowerUp != null )
                {
                    PendingPowerUp.Use( Tanks, Projectiles, Fences, Pickups, gameTime );
                    PendingPowerUp = null;
                }
            }
            if ( !IsInGame ) return;

            if ( AI )
            {
                TankObject ClosestTank = null;
                float dist = float.PositiveInfinity;
                foreach ( TankObject Tank in Tanks )
                {
                    float d = Vector2.Distance( Tank.Position, Position );
                    if ( d < dist && Tank.IsInGame && Tank != this )
                    {
                        dist = d;
                        ClosestTank = Tank;
                    }
                }
                if ( ClosestTank != null )
                {
                    float ang = ( ( ( float )Math.Atan2( Position.Y - ClosestTank.Position.Y, Position.X - ClosestTank.Position.X ) * 180 / ( float )Math.PI ) + 180 ) % 360;
                    /*while ( angle < 0 )
                    {
                        angle += 360;
                    }
                    angle %= 480;

                    /*
                     * If (absolute of [heading - converted angle] <= 20) then turn to converted angle;
                        Otherwise If (heading - converted angle < -20) then turn -20 degrees;
                        Otherwise If (heading - converted angel > 20) then turn 20 degrees;
                     *
                    float factor = 10;
                    if ( Math.Abs( angle - ang ) <= factor ) angle = ang;
                    else if ( angle - ang < -factor ) angle -= factor;
                    else if ( angle - ang > factor ) angle += factor;
                    */
                    angle = ang;

                    if ( ( gameTime.TotalGameTime - LastShoot ).TotalMilliseconds > 2000 )
                    {
                        Shoot( gameTime, width, height, Projectiles );
                        LastShoot = gameTime.TotalGameTime;
                    }
                    FilterMove( 5F, Fences, Pickups, gameTime );
                    return;
                }
            }

            float moveFactor = 0;

            if ( key.IsKeyDown( Keys.KeyDown ) )
            {
                IsGoingBackwards = true;
                moveFactor -= Speed;
            }
            else
            {
                IsGoingBackwards = false;
            }
            if ( key.IsKeyDown( Keys.KeyUp ) )
            {
                IsGoingBackwards = false;
                moveFactor += Speed;
            }
            if ( moveFactor != 0 )
            {
                FilterMove( moveFactor, Fences, Pickups, gameTime );
            }

            float angleFactor = 0;

            if ( key.IsKeyDown( Keys.KeyLeft ) )
            {
                angleFactor -= Speed;
            }
            if ( key.IsKeyDown( Keys.KeyRight ) )
            {
                angleFactor += Speed;
            }

            angle %= 360;
            while ( angle < 0 )
            {
                angle += 360;
            }

            FilterRotate( Fences, angleFactor );

            if ( Position.X > width + Origin.X )
                Position.X = -Origin.X;
            if ( Position.X < -Origin.X )
                Position.X = width + Origin.X;
            if ( Position.Y > height + Origin.Y )
                Position.Y = -Origin.Y;
            if ( Position.Y < -Origin.Y )
                Position.Y = height + Origin.Y;

            foreach ( Pickup pickup in Pickups )
            {
                if ( GameTools.RotRectIntersectRect( Position, Origin, Width, Height, Rotation, pickup.BoundingBox ) )
                {
                    pickup.Take( this, gameTime );
                }
            }

            if ( key.IsKeyDown( Keys.KeyShoot ) && oldkey.IsKeyUp( Keys.KeyShoot ) && ( ShotsOnBoard < ShotLimit || ShotLimit <= 0 ) && IsInGame )
            {
                Shoot( gameTime, width, height, Projectiles );
            }

            if ( powerUp != null )
            {
                if ( powerUp.Update( gameTime, Tanks, Projectiles, Fences ) )
                {
                    powerUp.Revert();
                    powerUp = null;
                }
            }
        }
Esempio n. 7
0
 public BasicFence( Vector2 p1, Vector2 p2, float width, TankObject owner, GameTime gameTime, GraphicsDevice gd )
     : base(p1, p2, width, owner, gameTime, gd)
 {
 }