Beispiel #1
0
        /// <summary>
        /// Handles player firing
        /// </summary>
        private void PlayerFiring()
        {
            fireTimer += 0.02f;

            if (Input.GetKey(playerPrefs.Controls.Ship_Fire))
            {
                for (int i = 0; i < shipConfig.Stats_Weapons.WeaponCount; i++)
                {
                    ShipWeapon w = shipConfig.Stats_Weapons.Weapons[i];
                    if (Math.Round(fireTimer % w.RateOfFire, 3) <= 0.02f)
                    {
                        if (w.Type == WeaponType.projectile)
                        {
                            GameObject proj = Instantiate(w.OutputPrefab, bulletLoc[i].transform.position, Quaternion.identity);

                            // Set up its velocity and color based on current theme (aka the ship's color)
                            Projectile behaviour = proj.GetComponentInChildren <Projectile>();
                            behaviour.Setup(Vector2.ClampMagnitude(new Vector2(bulletLoc[i].transform.right.x * w.Speed, bulletLoc[i].transform.right.y * w.Speed), w.Speed),
                                            w.Damage * shipConfig.Stats_Weapons.DamageModifier);
                            proj.GetComponentInChildren <SpriteRenderer>().material.color = sprite.material.color;

                            // Play fire sound and add recoil force
                            w.OutputSound.Play();
                            rigidbody.AddForce(-transform.right * w.Recoil);
                            rigidbody.velocity = Vector2.ClampMagnitude(rigidbody.velocity, shipConfig.Stats_Thrusters.MaxDirectionalSpeed);
                        }
                    }
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Used for updating a specific weapon when in the shipdesigner GameState
 /// </summary>
 /// <param name="wpn">The new weapon</param>
 public void UpdateWeapon(ShipWeapon wpn, int slot)
 {
     Stats_Weapons.Weapons[slot] = wpn;
 }
Beispiel #3
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);
            }
        }