Пример #1
0
 public void skin(string skin_name)
 {
     if (String.IsNullOrEmpty(skin_name))
     {
         printer("Usage: skin [skin name]");
     }
     else
     {
         State state = ServiceManager.StateManager.CurrentState;
         if (state is GamePlayState)
         {
             GamePlayState gameState   = (GamePlayState)state;
             PlayerTank    localPlayer = gameState.LocalPlayer;
             try
             {
                 Texture2D skin = ServiceManager.Resources.Load <Texture2D>(
                     String.Format(@"models\tanks\skins\{0}", skin_name));
                 localPlayer.ApplySkin(skin);
                 printer("New skin applied.");
             }
             catch (Exception)
             {
                 printer("That skin does not exist!");
             }
         }
         else
         {
             printer("You can't do that outside of a game.");
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Adds base to the game.
        /// </summary>
        /// <param name="newBase">The new base</param>
        public void AddBase(Base newBase)
        {
            bases.Add(newBase.EventId, newBase);
            bases[newBase.EventId].RenderID = ServiceManager.Scene.Add(bases[newBase.EventId], 0);

            if (bases.Count >= 6)
            {
                // Special case handler: if CTB mode, make player face next tower.
                Client.src.states.gamestate.State currentState = ServiceManager.StateManager.CurrentState;
                if (currentState is Client.src.states.gamestate.GamePlayState)
                {
                    PlayerTank localPlayer = ((Client.src.states.gamestate.GamePlayState)currentState).LocalPlayer;
                    const int  BLUE_FRONT  = 10;
                    const int  RED_FRONT   = 11;
                    Base       blueBase    = GetBase(BLUE_FRONT);
                    Base       redBase     = GetBase(RED_FRONT);

                    if (localPlayer.Team == GameSession.Alliance.RED)
                    {
                        localPlayer.Angle = (float)Math.Atan2(
                            blueBase.Position.Y - redBase.Position.Y,
                            blueBase.Position.X - redBase.Position.X);
                    }
                    else
                    {
                        localPlayer.Angle = (float)Math.Atan2(
                            redBase.Position.Y - blueBase.Position.Y,
                            redBase.Position.X - blueBase.Position.X);
                    }
                    Client.src.states.gamestate.GamePlayState game =
                        (Client.src.states.gamestate.GamePlayState)currentState;
                    game.Scene.LockCameras();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Add a projectile to the 'add later' collection, to be added to the game after a certain
        /// amount of time.
        /// </summary>
        /// <param name="projInfo">The projectile's 'add later' info.</param>
        public void AddLater(GameSession.ProjectileDamageInfo projInfo, PlayerTank owner)
        {
            ProjectileToAddLater delayedProj = new ProjectileToAddLater();

            delayedProj.owner     = owner;
            delayedProj.timestamp = (Network.Util.Clock.GetTimeMilliseconds() + projInfo.spawnTimeMilliseconds);
            delayedProj.projInfo  = projInfo;

            delayedProj.angle = (float)Math.Atan2(owner.Position.Y - projInfo.target.y,
                                                  owner.Position.X - projInfo.target.x);

            projectilesToAddLater.Add(delayedProj);
        }
Пример #4
0
        public static void PlayProjectileSound(ProjectileData data, PlayerTank owner, float angle)
        {
            Vector3 soundPos = new Vector3((float)owner.Position.X, (float)owner.Position.Y, 0);
            Vector3 velocity = new Vector3((float)((data.TerminalVelocity + 50) * Math.Cos(angle)),
                                           (float)(data.TerminalVelocity * Math.Sin(angle)), 0);

            if (soundEffectBank.ContainsKey(data.ID))
            {
                try
                {
                    if (owner.ActiveSound != null)
                    {
                        if (ServiceManager.AudioManager.SoundIsPlaying(owner.ActiveSound) && owner.Weapon.Name == "Flamethrower")
                        {
                            return;
                        }
                    }

                    GamePlayState state = (GamePlayState)ServiceManager.StateManager.CurrentState;
                    owner.ActiveSound = ServiceManager.AudioManager.Play3DSound(owner.Weapon.FiringSound,
                                                                                state.Players.GetLocalPlayer().Position, soundPos, velocity, false);
                }
                catch (Exception e)
                {
                    ServiceManager.Game.Console.DebugPrint(
                        "Warning: Current state isn't a game: {0}", e);
                }
            }
            else
            {
                if (data != null)
                {
                    ServiceManager.Game.Console.DebugPrint(
                        "Warning: Couldn't find sound effect for projectile #{0}.",
                        data.ID);
                }
                else
                {
                    ServiceManager.Game.Console.DebugPrint("Warning:  ProjectileManager received a null projectile");
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Create a missile object from the projectile data received from the server.
        /// </summary>
        /// <param name="data">Data to convert.</param>
        /// <returns>New missile object.</returns>
        public static Projectile CreateProjectileObject(
            ProjectileData data, VTankObject.Point point, float angle, PlayerTank owner)
        {
            Vector3 soundPos = new Vector3((float)owner.Position.X, (float)owner.Position.Y, 0);
            Vector3 velocity = new Vector3((float)((data.InitialVelocity + 50) * Math.Cos(angle)),
                                           (float)(data.InitialVelocity * Math.Sin(angle)), 0);

            if (soundEffectBank.ContainsKey(data.ID))
            {
                try
                {
                    GamePlayState state = (GamePlayState)ServiceManager.StateManager.CurrentState;
                    if (!String.IsNullOrEmpty(owner.Weapon.FiringSound))
                    {
                        ServiceManager.AudioManager.Play3DSound(owner.Weapon.FiringSound,
                                                                state.Players.GetLocalPlayer().Position, soundPos, velocity, false);
                    }
                }
                catch (Exception e)
                {
                    ServiceManager.Game.Console.DebugPrint(
                        "Warning: Current state isn't a game: {0}", e);
                }
            }
            else
            {
                if (data != null)
                {
                    ServiceManager.Game.Console.DebugPrint(
                        "Warning: Couldn't find sound effect for projectile #{0}.",
                        data.ID);
                }
                else
                {
                    ServiceManager.Game.Console.DebugPrint("Warning:  ProjectileManager received a null projectile");
                }
            }

            const float inflation  = -0.01f;
            float       alive      = (float)(data.Range) / (float)(data.TerminalVelocity);
            Projectile  projectile = new Projectile(owner.Position, point,
                                                    angle, data.InitialVelocity, alive + inflation, owner, data);

            if (!String.IsNullOrEmpty(owner.Weapon.MuzzleEffectName))
            {
                ParticleEmitter p = new ParticleEmitter(owner.Weapon.MuzzleEffectName, projectile.Position);
                p.Attach(owner.Turret, "Emitter0");
                p.MimicRotation(owner.Turret);
                ServiceManager.Scene.Add(p, 3);
            }

            /*
             * if(projectile.Data.IsInstantaneous)
             * {
             *  if (!String.IsNullOrEmpty(projectile.Data.ParticleEffect))
             *  {
             *      ParticleEmitter p = new ParticleEmitter(projectile.Data.ParticleEffect, projectile.Position);
             *      projectile.ParticleEmitter = p;
             *      p.MimicPosition(projectile, Vector3.Zero);
             *      ServiceManager.Scene.Add(p, 3);
             *  }
             * }*/

            // TODO: Z-index should be transformed to be attached to the turret end.
            return(projectile);
        }
Пример #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="_model">Projectile model</param>
        /// <param name="_position">Position of the missile</param>
        /// <param name="_angle">Angle at which the missile will be fired</param>
        /// <param name="_velocity">Velocity of the missile</param>
        /// <param name="_alive">Alive</param>
        /// <param name="_firedBy">Who fired the missile</param>
        public Projectile(Vector3 _position, VTankObject.Point target, double _angle, double _velocity,
                          float _alive, PlayerTank _firedBy, ProjectileData projectileData)
        {
            this.data     = projectileData;
            this.position = _position;

            position                   = _position + Vector3.UnitZ;;
            base.ZRotation             = (float)_angle;
            velocity                   = (float)_velocity;
            timeAlive                  = _alive;
            elapsed                    = 0;
            this.boundingSphere.Radius = projectileData.CollisionRadius;
            SetBoundingSpherePosition();
            owner    = _firedBy;
            RenderID = -1;
            ID       = projectileData.ID;
            origin   = position;

            if (_firedBy.Weapon.HasFiringArc)
            {
                this.usingLaunchAngle = true;

                float swivelAngle = ZRotation;
                float tiltAngle   = _firedBy.Weapon.LaunchAngle;

                float projection = DEFAULT_CANNON_LENGTH * (float)Math.Cos(tiltAngle);
                float tipX       = -projection * (float)Math.Cos(swivelAngle);
                float tipY       = -projection * (float)Math.Sin(swivelAngle);
                float tipZ       = Math.Abs(DEFAULT_CANNON_LENGTH * (float)Math.Sin(swivelAngle));
                tip = new float[] { tipX, tipY, tipZ };

                Vector3 newPosition = position + new Vector3(tipX, tipY, tipZ);
                // Calculate initial velocity based on the distance we travel.
                float distance = (float)Math.Sqrt(
                    Math.Pow(target.x - newPosition.X, 2) +
                    Math.Pow(target.y - newPosition.Y, 2));
                float maxDistance = (int)projectileData.Range;
                if (distance > maxDistance)
                {
                    distance = maxDistance;
                }

                // TODO: This is a temporary work-around until we figure out what velocity component
                // is missing from the formula.
                float offset = 1.1f;
                if (tiltAngle > MathHelper.ToRadians(45.0f))
                {
                    offset = 1.6f;
                }

                float V  = (float)Math.Sqrt(-gravity * distance * offset);
                float Vx = -V * (float)(Math.Cos(tiltAngle) * Math.Cos(swivelAngle));
                float Vy = -V * (float)(Math.Cos(tiltAngle) * Math.Sin(swivelAngle));
                float Vz = V * (float)Math.Sin(tiltAngle);

                componentVelocity = new float[] { Vx, Vy, Vz };
                elapsedDelta      = 0f;

                /*this.verticalVelocity = this.FindVerticalVelocity(_firedBy.Weapon.LaunchAngle, velocity);
                 * float flightTime = this.FindFlightTime(verticalVelocity, gravity);
                 * float horizontalVelocity = this.FindHorizontalVelocity(
                 *  distance,
                 *  flightTime);
                 * velocity = horizontalVelocity;*/
            }

            Object3 turret = owner.Turret;

            ModelBoneCollection.Enumerator collection = turret.Model.Bones.GetEnumerator();
            List <ModelBone> emitters = new List <ModelBone>();

            while (collection.MoveNext())
            {
                if (collection.Current.Name.StartsWith("Emitter"))
                {
                    emitters.Add(collection.Current);
                }
            }

            if (emitters.Count == 0)
            {
                ServiceManager.Game.Console.DebugPrint(
                    "Warning: Can't attach to owner tank, no emitter exists.");
            }
            else
            {
                int emitter = _firedBy.Weapon.GetNextEmitterIndex();
                this.Attach(turret, emitters[emitter].Name);

                this.MimicRotation(turret);
                this.Unattach();
                Vector3 forward = emitters[emitter].Transform.Forward;
                forward.Z = Math.Abs(forward.Z);
                //position *= forward;
            }

            if (!String.IsNullOrEmpty(projectileData.Model))
            {
                model = new Object3(ServiceManager.Resources.GetModel("projectiles\\" + projectileData.Model), position);
                model.MimicPosition(this, Vector3.Zero);
                model.MimicRotation(this);
                modelRenderID = ServiceManager.Scene.Add(model, 3);
            }
            else
            {
                model = null;
            }

            if (!String.IsNullOrEmpty(projectileData.ParticleEffect) && projectileData.Model == null)
            {
                ParticleEmitter.MimicPosition(this, Vector3.Zero);
                ParticleEmitter.MimicRotation(this);
                particleEmitterRenderID = ServiceManager.Scene.Add(ParticleEmitter, 3);
            }
            else if (!String.IsNullOrEmpty(projectileData.ParticleEffect))
            {
                ParticleEmitter = new ParticleEmitter(projectileData.ParticleEffect, this.Position);
                this.particleEmitterRenderID = ServiceManager.Scene.Add(ParticleEmitter, 3);
                ParticleEmitter.Follow(this);
            }
        }
Пример #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="_model">Projectile model</param>
        /// <param name="_position">Position of the missile</param>
        /// <param name="_angle">Angle at which the missile will be fired</param>
        /// <param name="_velocity">Velocity of the missile</param>
        /// <param name="_alive">Alive</param>
        /// <param name="_firedBy">Who fired the missile</param>
        public Projectile(Vector3 _position, VTankObject.Point target, double _angle, double _velocity,
            float _alive, PlayerTank _firedBy, ProjectileData projectileData)
        {
            this.data = projectileData;
            this.position = _position;

            position = _position + Vector3.UnitZ; ;
            base.ZRotation = (float)_angle;
            velocity = (float)_velocity;
            timeAlive = _alive;
            elapsed = 0;
            this.boundingSphere.Radius = projectileData.CollisionRadius;
            SetBoundingSpherePosition();
            owner = _firedBy;
            RenderID = -1;
            ID = projectileData.ID;
            origin = position;

            if (_firedBy.Weapon.HasFiringArc)
            {
                this.usingLaunchAngle = true;

                float swivelAngle = ZRotation;
                float tiltAngle = _firedBy.Weapon.LaunchAngle;

                float projection = DEFAULT_CANNON_LENGTH * (float)Math.Cos(tiltAngle);
                float tipX = -projection * (float)Math.Cos(swivelAngle);
                float tipY = -projection * (float)Math.Sin(swivelAngle);
                float tipZ = Math.Abs(DEFAULT_CANNON_LENGTH * (float)Math.Sin(swivelAngle));
                tip = new float[] { tipX, tipY, tipZ };

                Vector3 newPosition = position + new Vector3(tipX, tipY, tipZ);
                // Calculate initial velocity based on the distance we travel.
                float distance = (float)Math.Sqrt(
                    Math.Pow(target.x - newPosition.X, 2) +
                    Math.Pow(target.y - newPosition.Y, 2));
                float maxDistance = (int)projectileData.Range;
                if (distance > maxDistance)
                    distance = maxDistance;

                // TODO: This is a temporary work-around until we figure out what velocity component
                // is missing from the formula.
                float offset = 1.1f;
                if (tiltAngle > MathHelper.ToRadians(45.0f))
                    offset = 1.6f;

                float V  = (float)Math.Sqrt(-gravity * distance * offset);
                float Vx = -V * (float)(Math.Cos(tiltAngle) * Math.Cos(swivelAngle));
                float Vy = -V * (float)(Math.Cos(tiltAngle) * Math.Sin(swivelAngle));
                float Vz = V * (float)Math.Sin(tiltAngle);

                componentVelocity = new float[] { Vx, Vy, Vz };
                elapsedDelta = 0f;

                /*this.verticalVelocity = this.FindVerticalVelocity(_firedBy.Weapon.LaunchAngle, velocity);
                float flightTime = this.FindFlightTime(verticalVelocity, gravity);
                float horizontalVelocity = this.FindHorizontalVelocity(
                    distance,
                    flightTime);
                velocity = horizontalVelocity;*/
            }

            Object3 turret = owner.Turret;
            ModelBoneCollection.Enumerator collection = turret.Model.Bones.GetEnumerator();
            List<ModelBone> emitters = new List<ModelBone>();
            while (collection.MoveNext())
            {
                if (collection.Current.Name.StartsWith("Emitter"))
                {
                    emitters.Add(collection.Current);
                }
            }

            if (emitters.Count == 0)
            {
                ServiceManager.Game.Console.DebugPrint(
                    "Warning: Can't attach to owner tank, no emitter exists.");
            }
            else
            {
                int emitter = _firedBy.Weapon.GetNextEmitterIndex();
                this.Attach(turret, emitters[emitter].Name);

                this.MimicRotation(turret);
                this.Unattach();
                Vector3 forward = emitters[emitter].Transform.Forward;
                forward.Z = Math.Abs(forward.Z);
                //position *= forward;
            }

            if (!String.IsNullOrEmpty(projectileData.Model))
            {
                model = new Object3(ServiceManager.Resources.GetModel("projectiles\\" + projectileData.Model), position);
                model.MimicPosition(this, Vector3.Zero);
                model.MimicRotation(this);
                modelRenderID = ServiceManager.Scene.Add(model, 3);
            }
            else
            {
                model = null;
            }

            if (!String.IsNullOrEmpty(projectileData.ParticleEffect) && projectileData.Model == null)
            {
                ParticleEmitter.MimicPosition(this, Vector3.Zero);
                ParticleEmitter.MimicRotation(this);
                particleEmitterRenderID = ServiceManager.Scene.Add(ParticleEmitter, 3);
            }
            else if (!String.IsNullOrEmpty(projectileData.ParticleEffect))
            {
                ParticleEmitter = new ParticleEmitter(projectileData.ParticleEffect, this.Position);
                this.particleEmitterRenderID = ServiceManager.Scene.Add(ParticleEmitter, 3);
                ParticleEmitter.Follow(this);
            }
        }
Пример #8
0
        /// <summary>
        /// Detects if tank is intersecting a impassible tile
        /// </summary>
        /// <param name="tankObject">Clients Tank</param>
        /// <returns>Collision</returns>
        private bool DetectCollision(PlayerTank tankObject)
        {
            // The 3 below this comment is an offset to make sure we only check for collisions with tiles
            // adjacent to us.  Checks are done to a range of 3 tiles.
            int numTilesX = (viewportRect.X / Constants.TILE_SIZE) + 3;
            int numTilesY = (viewportRect.Y / Constants.TILE_SIZE) + 3;

            int minimumX = (int)(tankObject.Position.X / Constants.TILE_SIZE) - numTilesX;
            int minimumY = (int)(-tankObject.Position.Y / Constants.TILE_SIZE) - numTilesY;
            int maximumX = (int)(tankObject.Position.X / Constants.TILE_SIZE) + numTilesX;
            int maximumY = (int)(-tankObject.Position.Y / Constants.TILE_SIZE) + numTilesY;

            for (int y = minimumY; y < map.Height && y <= maximumY; y++)
            {
                if (y < 0)
                    continue;

                for (int x = minimumX; x < map.Width && x <= maximumX; x++)
                {
                    if (x < 0)
                        continue;

                    Options.KeyBindings keys = ServiceManager.Game.Options.KeySettings;

                    DrawableTile tile = visibleTiles[y * map.Width + x];
                    if (tankObject.Name == PlayerManager.LocalPlayerName)
                    {
                        if (!tile.Passable && (
                            (Keyboard.GetState().IsKeyDown(keys.Forward) &&
                                tankObject.FrontSphere.Intersects(tile.BoundingBox)) ||
                            (Keyboard.GetState().IsKeyDown(keys.Backward) &&
                                tankObject.BackSphere.Intersects(tile.BoundingBox))))
                        {
                            return true;
                        }
                    }
                    else
                    {
                        if (!tile.Passable &&
                            ((tankObject.FrontSphere.Intersects(tile.BoundingBox) &&
                            tankObject.DirectionMovement == VTankObject.Direction.FORWARD) ||
                             (tankObject.BackSphere.Intersects(tile.BoundingBox) &&
                             tankObject.DirectionMovement == VTankObject.Direction.REVERSE)))
                        {
                            return true;
                        }
                    }
                }
            }

            return false;
        }
Пример #9
0
 /// <summary>
 /// Initialize any components required by this state.
 /// </summary>
 public override void Initialize()
 {
     ServiceManager.Game.FormManager.ClearWindow();
     Options options = ServiceManager.Game.Options;
     RendererAssetPool.DrawShadows = GraphicOptions.ShadowMaps;
     mouseCursor = new MouseCursor(options.KeySettings.Pointer);
     mouseCursor.EnableCustomCursor();
     renderer = ServiceManager.Game.Renderer;
     fps = new FrameCounter();
     Chat = new ChatArea();
     Projectiles = new ProjectileManager();
     Tiles = new TexturedTileGroupManager();
     Utilities = new UtilityManager();
     cd = new Countdown();
     Lazers = new LazerBeamManager(this);
     Scene.Add(Lazers, 0);
     Players = new PlayerManager();
     currentGameMode = ServiceManager.Theater.GetCurrentGameMode();
     Flags = new FlagManager();
     Bases = new BaseManager();
     EnvironmentEffects = new EnvironmentEffectManager();
     buffbar = new BuffBar();
     Scores = new ScoreBoard(currentGameMode, Players);
     input = new ChatInput(new Vector2(5, ServiceManager.Game.GraphicsDevice.Viewport.Height), 300);//300 is a magic number...Create a chat width variable.
     input.Visible = false;
     hud = HUD.GetHudForPlayer(Players.GetLocalPlayer());
     localPlayer = Players.GetLocalPlayer();
     Scene.MainEntity = localPlayer;
     sky = ServiceManager.Resources.GetTexture2D("textures\\misc\\background\\sky");
     tips = new GameTips(new GameContext(CurrentGameMode, localPlayer));
     helpOverlay = new HelpOverlay();
 }
Пример #10
0
 /// <summary>
 /// Updates the HUD based on the values of the player
 /// </summary>
 /// <param name="player"></param>
 private void UpdateHUDValues(PlayerTank player)
 {
     hud.UpdateHealth(player);
     hud.UpdateSecondaryBar(player);
 }