Example #1
0
        public override void Update(GameTime time)
        {
            base.Update(time);

            // Find current score
            Marine player = ((WorldScreen)_Parent.Manager.GetScreen("World")).PlayerMarine;

            _Text = "Score: " + player.Score.ToString();
            //_TextLocation = _Parent.ViewPort.Transform_UnitPosition_To_PixelPosition(_Position);

            // Check for change in score
            if (player.Score != _LastScore)
            {
                _FlashRemaining = FlashTime;
                _LastScore      = player.Score;
            }

            // Update flash timers
            if (_FlashRemaining > 0)
            {
                _FlashRemaining -= time.ElapsedGameTime.Milliseconds;
            }
            if (_FlashRemaining < 0)
            {
                _FlashRemaining = 0;
            }

            // Calculate appropriate colour gradient
            float ratio = (float)_FlashRemaining / (float)FlashTime;

            _ColourOverlay = new Color(ScoreColour.ToVector4() + ratio * _ColourDiff);
        }
Example #2
0
 public Weapon(Screen parent, Marine player)
     : base(parent.Entities, player.Position, Vector3.Zero, Vector3.Zero)
 {
     _Player = player;
     _Sound  = Application.AppReference.Content.Load <SoundEffect>("Audio/Effects/Bullet01");
     _Ammo   = _ClipSize;
 }
Example #3
0
        public WorldScreen(ScreenManager manager, String worldMap)
            : base(manager, "World")
        {
            // Load world
            _WorldMap = worldMap;
            FileStream   fs  = File.OpenRead(_WorldMap);
            BinaryReader bin = new BinaryReader(fs);

            _TileRows       = bin.ReadInt32();
            _TileCols       = bin.ReadInt32();
            Tile.TileWidth  = bin.ReadSingle();
            Tile.TileHeight = bin.ReadSingle();

            for (int row = 0; row < TileRows; row++)
            {
                for (int col = 0; col < TileCols; col++)
                {
                    int index = bin.ReadInt32();
                    Tile.TileGen[index](this, new Vector3(col * Tile.TileWidth, row * Tile.TileHeight, 0));
                }
            }
            bin.Close();
            fs.Close();

            // Create player
            PlayerMarine = new Marine(this, new Vector3(TileCols * Tile.TileWidth / 2, TileRows * Tile.TileHeight / 2, 0));
            //PlayerMarine.DrawO

            // Create crosshair
            _Crosshair      = new Crosshair(this);
            _Crosshair.Hide = false;

            // Create aliens
            for (int i = 0; i < NumDrones; i++)
            {
                int index = Application.AppReference.Random.Next(SpawnLocations.Length);
                new Drone(this, SpawnLocations[index], _PlayerEntity);
            }


            // Setup screen behavior
            _Depth           = 0.9f;
            _FadeInTime      = 0.0f;
            _FadeOutTime     = 0.0f;
            _MessageFont     = Application.AppReference.Content.Load <SpriteFont>("Fonts/DefaultFont");
            _MessageColour   = Color.White;
            _DynamicLighting = true;

            // Create loadport
            LoadPort = new LoadPort(this, Vector2.Zero, new Vector2(1050, 750), 100f);

            // Play music
            MediaPlayer.Play(Application.AppReference.Content.Load <Song>("Audio/Music/GameMusic01"));

            // Start dynamic lighting thread
            StartBackgroundThread();
        }
Example #4
0
        public override void Update(GameTime time)
        {
            base.Update(time);
            Marine player = ((WorldScreen)_Parent.Manager.GetScreen("World")).PlayerMarine;
            int    hp     = player.CurrentHP <= 0 ? 0 : player.CurrentHP;

            _HPText        = hp.ToString();
            _PercentHP     = (float)hp / (float)Marine.MaxHP;
            _ColourOverlay = new Color(1f - _PercentHP, _PercentHP, 0f, 0.45f);
            _ActualColour  = _ColourOverlay;
            //_TextLocation = _Parent.ViewPort.Transform_UnitPosition_To_PixelPosition(_Position + TextOffset);
        }
Example #5
0
        private bool FindAliens(Entity ent, object batch, object player, object p3)
        {
            SpriteBatch spriteBatch   = batch as SpriteBatch;
            Marine      marine        = player as Marine;
            float       scalingFactor = 0.1f;
            float       dFactor       = 0.05f;

            if (ent as Drone == null)
            {
                return(true);
            }

            Vector3 diff      = ent.Position - marine.Position;
            Vector3 worldLoc  = _Position + (dFactor * diff);
            Vector3 pixelLoc  = _Parent.ViewPort.Transform_UnitPosition_To_PixelPosition(worldLoc);
            Vector3 pixelSize = _Parent.ViewPort.Transform_UnitSize_To_PixelSize(ent.Size * scalingFactor);

            spriteBatch.Draw(_BlipTex, new Rectangle((int)pixelLoc.X, (int)pixelLoc.Y, (int)pixelSize.X, (int)pixelSize.Y), Color.White);

            return(true);
        }
Example #6
0
        /// <summary>
        /// Applies damage to the marine.
        /// </summary>
        /// <param name="player">Reference to the player controlled marine.</param>
        protected virtual void AttackPlayer(Marine player)
        {
            // Apply damage to marine
            player.CurrentHP -= DamagePerHit;

            // Shake screen
            Parent.ViewPort.Shake(3.0f, 0.8f, 0.95f);

            // Create blood explosion
            for (int i = 0; i < Marine.BloodParticles[Application.AppReference.GfxLevel]; i++)
            {
                new Blood(_Parent, player.Position, Marine.BloodColour, Marine.BloodSizeBase, Marine.BloodSizeVar, Marine.BloodSpeedBase,
                          Marine.BloodSpeedVar, Marine.BloodSpeedDamp, Marine.BloodLifeTime);
            }

            // Calculate angle difference
            Vector3 diff  = _Position - player.Position;
            double  angle = Math.Atan2(diff.Y, diff.X);

            // Knockback marine
            player.SetXPosition((float)(_Position.X + ((player.CollisionRadius + _CollisionRadius) * -Math.Cos(angle) * MarineKnockback)));
            player.SetYPosition((float)(_Position.Y + ((player.CollisionRadius + _CollisionRadius) * -Math.Sin(angle) * MarineKnockback)));
        }
Example #7
0
        /// <summary>
        /// This method handles the player input for this world.
        /// </summary>
        /// <param name="bind">The bind who's state has changed.</param>
        protected override void HandleInputActive(Bind bind)
        {
            base.HandleInputActive(bind);

            // Process move forward bind
            if (bind.Name.CompareTo("FWD") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.MoveForward = true;
                }
                else
                {
                    PlayerMarine.MoveForward = false;
                }
            }
            // Process move back bind
            else if (bind.Name.CompareTo("BAC") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.MoveBack = true;
                }
                else
                {
                    PlayerMarine.MoveBack = false;
                }
            }
            // Process move left bind
            else if (bind.Name.CompareTo("LFT") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.MoveLeft = true;
                }
                else
                {
                    PlayerMarine.MoveLeft = false;
                }
            }
            // Process move right bind
            else if (bind.Name.CompareTo("RHT") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.MoveRight = true;
                }
                else
                {
                    PlayerMarine.MoveRight = false;
                }
            }
            // Switch movement style (relative/absolute)
            else if (bind.Name.CompareTo("MOV") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    _Manager.Input.AbsoluteMovement = !_Manager.Input.AbsoluteMovement;
                }
            }
            // Switch on/off flashlight
            else if (bind.Name.CompareTo("FLI") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.FlashLight.Active = !PlayerMarine.FlashLight.Active;
                }
            }
            // Primary fire
            else if (bind.Name.CompareTo("PRI") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.CurrentWeapon.IsFiring = true;
                }
                else
                {
                    PlayerMarine.CurrentWeapon.IsFiring = false;
                }
            }
            // Secondary fire
            else if (bind.Name.CompareTo("SEC") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    if (PlayerMarine.Disposed)
                    {
                        PlayerMarine = new Marine(this, new Vector3(TileCols * Tile.TileWidth / 2, TileRows * Tile.TileHeight / 2, 0));
                    }
                }
            }
            // Reload
            else if (bind.Name.CompareTo("RLD") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.CurrentWeapon.Reload();
                }
            }
            // Night vision on/off
            else if (bind.Name.CompareTo("NVI") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.NightVision.Active = !PlayerMarine.NightVision.Active;
                }
            }
            // Toggle fps display
            else if (bind.Name.CompareTo("FPS") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    if (_FPSDisplay)
                    {
                        _FPSDisplay = false;
                        _Message    = _HelpMessage;
                    }
                    else
                    {
                        _FPSDisplay = true;
                    }
                }
            }
            // Load world editor
            else if (bind.Name.CompareTo("EDI") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    // Remove world gui
                    _Manager.GetScreen("WorldGUI").Remove();

                    // Remove world screen
                    Remove();

                    // Add editor screen
                    _Manager.AddScreen(new EditorScreen(_Manager));

                    // Add editor gui
                    _Manager.AddScreen(new EditorGUI(_Manager));
                }
            }
            // Exit game
            else if (bind.Name.CompareTo("ESC") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Up)
                {
                    //Application.AppReference.Exit();
                    throw new Exception("LOL: " + PlayerEntity.Position.X + ":" + PlayerEntity.Position.Y);
                }
            }

            /*
             * else if (bind.Name.CompareTo("WP1") == 0)
             * {
             *  if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
             *  {
             *      if (Player.weaponList.Count > 0)
             *      {
             *          Player.currentWeapon = Player.weaponList[0];
             *      }
             *  }
             * }
             * else if (bind.Name.CompareTo("WP2") == 0)
             * {
             *  if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
             *  {
             *      if (Player.weaponList.Count > 1)
             *      {
             *          Player.currentWeapon = Player.weaponList[1];
             *      }
             *  }
             * }
             * else if (bind.Name.CompareTo("WP3") == 0)
             * {
             *  if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
             *  {
             *      if (Player.weaponList.Count > 2)
             *      {
             *          Player.currentWeapon = Player.weaponList[2];
             *      }
             *  }
             * }
             * else if (bind.Name.CompareTo("WP4") == 0)
             * {
             *  if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
             *  {
             *      if (Player.weaponList.Count > 3)
             *      {
             *          Player.currentWeapon = Player.weaponList[3];
             *      }
             *  }
             * }
             * else if (bind.Name.CompareTo("WP5") == 0)
             * {
             *  if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
             *  {
             *      if (Player.weaponList.Count > 4)
             *      {
             *          Player.currentWeapon = Player.weaponList[4];
             *      }
             *  }
             * }*/
        }