Exemple #1
0
        /// <summary>
        /// Called every time the ship's parent manager is updated
        /// </summary>
        /// <param name="dt">Delta time (between frames)</param>
        public void Update(float dt)
        {
            // If the shield strength is down, start recharge process
            if (Current_Defenses.ShieldStrength < Stats_Defenses.ShieldStrength)
            {
                // Increment timer
                if (rechargeDelay < Current_Defenses.ShieldDelay)
                {
                    rechargeDelay += dt;
                }

                // Increment shields
                else
                {
                    ShipDefenses updatedDef = Current_Defenses;
                    updatedDef.ShieldStrength += Current_Defenses.ShieldRecharge * dt;
                    Current_Defenses           = updatedDef;
                    EventManager.Instance.UpdateHUDElement(HUDElement.shield, Math.Round(updatedDef.ShieldStrength, 2).ToString());
                }
            }

            // Ensure shields don't go over after recharge process
            else if (Current_Defenses.ShieldStrength > Stats_Defenses.ShieldStrength)
            {
                ShipDefenses updatedDef = Current_Defenses;
                updatedDef.ShieldStrength = Stats_Defenses.ShieldStrength;
                Current_Defenses          = updatedDef;
                EventManager.Instance.UpdateHUDElement(HUDElement.shield, Math.Round(updatedDef.ShieldStrength, 2).ToString());
            }
        }
Exemple #2
0
        /// <summary>
        /// Applies damage to the ship
        /// </summary>
        /// <param name="damageTaken">The incoming amount of damage to take</param>
        public bool TakeDamage(float damageTaken)
        {
            ShipDefenses updatedDef = Current_Defenses;

            if (updatedDef.ShieldStrength <= 0)
            {
                updatedDef.ArmorStrength -= damageTaken;
            }

            else
            {
                if ((updatedDef.ShieldStrength - damageTaken) <= 0)
                {
                    updatedDef.ShieldStrength = 0;
                }

                else
                {
                    updatedDef.ShieldStrength -= damageTaken;
                }
            }

            Current_Defenses = updatedDef;
            rechargeDelay    = 0;

            if (Current_Defenses.ArmorStrength > 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #3
0
 /// <summary>
 /// Used for updating defense config when in the shipdesigner GameState
 /// </summary>
 /// <param name="def">The new defenses that replaces Stats_Defenses and Current_Defenses</param>
 public void UpdateDefenseConfig(ShipDefenses def)
 {
     if (EventManager.Instance.CurrState == GameState.shipdesigner)
     {
         Stats_Defenses   = def;
         Current_Defenses = def;
     }
 }
Exemple #4
0
 /// <summary>
 /// Creates a ShipConfiguration with the specified parameters
 /// </summary>
 /// <param name="wpn">Ship's weapons</param>
 /// <param name="def">Ship's defenses</param>
 /// <param name="thr">Ship's thrusters</param>
 /// <param name="mas">Ship's mass</param>
 /// <param name="col">Ship's colliders</param>
 /// <param name="spr">Ship's body sprite</param>
 public ShipConfiguration(ShipWeaponry wpn, ShipDefenses def, ShipThrusters thr, float mas, Vector2[] col, Sprite spr)
 {
     Stats_Weapons    = wpn;
     Stats_Defenses   = def;
     Current_Defenses = def;
     Stats_Thrusters  = thr;
     Mass             = mas;
     ColliderForm     = col;
     BodySprite       = spr;
 }
Exemple #5
0
        /// <summary>
        /// Creates a basic, otherwise blank ship config
        /// </summary>
        /// <param name="spr">The sprite for the ship</param>
        /// <param name="e">A reference to the EventManager in the scene</param>
        public ShipConfiguration(Sprite spr)
        {
            BodySprite = spr;

            ShipWeaponry w = new ShipWeaponry();

            w.WeaponCount = 3;
            w.Weapons     = new List <ShipWeapon>();
            w.Rotations   = new List <Vector3>();
            w.Positions   = new List <Vector3>();
            w.SlotStatus  = new List <WeaponSlotStatus>();
            Stats_Weapons = w;

            ShipDefenses d = new ShipDefenses();

            Stats_Defenses   = d;
            Current_Defenses = d;

            ShipThrusters t = new ShipThrusters();

            Stats_Thrusters = t;
        }
Exemple #6
0
        /// <summary>
        /// Called before the first frame update
        /// </summary>
        private void Start()
        {
            ShipDefenses  defenses  = new ShipDefenses();
            ShipThrusters thrusters = new ShipThrusters();
            ShipWeaponry  weapons   = new ShipWeaponry();

            Vector2[] colliders = null;

            #region Setup

            defenses.ArmorStrength    = 50f;
            defenses.ShieldRecharge   = 1f;
            defenses.ShieldStrength   = 15f;
            defenses.ShieldDelay      = 5f;
            defenses.DamageResistance = 15f;

            thrusters.DampenerStrength     = 0.5f;              // Equivalent to rigidbody linear drag set before this temp code (shipDragRate was unused)
            thrusters.ForwardThrusterForce = 10f;               // Equivalent to shipAccRate set in the old player class ResetPlayer()
            thrusters.MaxDirectionalSpeed  = 10f;               // Equivalent to shipMaxSpd set in old player class
            thrusters.RecoilCompensation   = 0.9f;
            thrusters.ReverseThrusterForce = 3f;
            thrusters.RotationalSpeed      = 5f;                // Equivalent to shipRotSpd set in old player class

            ShipWeapon basicBlaster = new ShipWeapon();
            basicBlaster.Damage       = 5f;                     // Original hardcoded value in prototyped Projectile was 5
            basicBlaster.Name         = "Basic Blaster";
            basicBlaster.OutputPrefab = bulletPrefab;           // The prefabs and sounds will eventually be handled/stored outside Player
            basicBlaster.OutputSound  = bulletSound;
            basicBlaster.RateOfFire   = 0.35f;                  // Originally fireRate in old Player
            basicBlaster.Recoil       = 15f;                    // Originally -shipAcc * 5f when handling recoil in old Player
            basicBlaster.Speed        = 200f;                   // Originally projectileSpeed in old Player
            basicBlaster.Type         = WeaponType.projectile;
            ShipWeapon secondBlaster = new ShipWeapon();
            secondBlaster.Damage       = 1f;
            secondBlaster.Name         = "Secondary Blaster";
            secondBlaster.OutputPrefab = bulletPrefab;
            secondBlaster.OutputSound  = bulletSound2;
            secondBlaster.RateOfFire   = 0.2f;
            secondBlaster.Recoil       = 5f;
            secondBlaster.Speed        = 100f;
            secondBlaster.Type         = WeaponType.projectile;

            weapons.DamageModifier = 1;
            weapons.RateModifier   = 1;
            weapons.WeaponCount    = 3;
            weapons.Positions      = new List <Vector3>()
            {
                new Vector3(0.35f, 0, 0),
                new Vector3(0.25f, 0.21f, 0),
                new Vector3(0.25f, -0.21f, 0)
            };
            weapons.Rotations = new List <Vector3>
            {
                { new Vector3(0, 0, 0) },
                { new Vector3(0, 0, 10f) },
                { new Vector3(0, 0, -10f) }
            };
            weapons.SlotStatus = new List <WeaponSlotStatus>
            {
                { WeaponSlotStatus.enabled },
                { WeaponSlotStatus.enabled },
                { WeaponSlotStatus.enabled }
            };
            weapons.Weapons = new List <ShipWeapon>
            {
                { basicBlaster },
                { secondBlaster },
                { secondBlaster }
            };

            colliders = new Vector2[]                           // This is based off of what was in the PolygonCollider2D in old Player
            {
                new Vector2(0.25f, 0),
                new Vector2(-0.25f, 0.25f),
                new Vector2(-0.125f, 0),
                new Vector2(-0.25f, -0.25f)
            };

            #endregion

            ShipConfiguration tempShipConfig = new ShipConfiguration(weapons, defenses, thrusters, 1, colliders, sprite.sprite);

            // This may seem redundant, accessing what was set in the previous Setup region, but that will eventually disappear once actual ships are defined
            rigidbody.drag  = tempShipConfig.Stats_Thrusters.DampenerStrength;
            rigidbody.mass  = tempShipConfig.Mass;
            collider.points = colliders;
            sprite.sprite   = tempShipConfig.BodySprite; // This, like the bulletPrefab and bulletSound, will be handled/stored outside player, so the back-and-fourth setting seen here won't be present eventually

            for (int i = 0; i < weapons.WeaponCount; i++)
            {
                ShipWeapon w   = weapons.Weapons[i];
                GameObject obj = new GameObject(w.Name);
                obj.transform.parent   = gameObject.transform;
                obj.transform.position = weapons.Positions[i];
                obj.transform.rotation = Quaternion.Euler(weapons.Rotations[i]);
                bulletLoc.Add(obj);
            }
        }