예제 #1
0
        private void addTurret()
        {
            Turret t = new GunTurret(new Vector2(10, 0), world, game.ragdollManager);

            game.hazardManager.addHazard(t);

            Turret t2 = new LaserTurret(new Vector2(-10, 0), world, game.ragdollManager);

            game.hazardManager.addHazard(t2);
        }
예제 #2
0
        public static Projectile CreateProjectile(GunTurret fromTurret, Transform initTransform)
        {
            GameObject projectileGO = Instantiate(Inst.projectilePrefab, initTransform.position, initTransform.rotation, Inst.transform);

            projectileGO.name = "Projectile<" + fromTurret.Ship.ShipName + ">";
            Projectile projectile = projectileGO.GetComponent <Projectile>();

            projectile.Init(fromTurret);
            return(projectile);
        }
예제 #3
0
        public override void OnInspectorGUI()
        {
            GunTurret gt = (GunTurret)target;

            if (DrawDefaultInspector())
            {
                if (gt.Stabilization == false && lastStabilizeValue == true)
                {
                    // Trigger stabilization reset
                    gt.Stabilization = true;
                    gt.Stabilization = false;
                }
            }

            lastStabilizeValue = gt.Stabilization;
        }
예제 #4
0
        private void create_GunTurret()
        {
            Random    robj = new Random();
            int       x    = robj.Next(20, 450);
            GunTurret e    = new GunTurret(x, 0);

            //this.panel1.Controls.Add(e.img);
            if (enemies.LastIndexOf(null) != -1)
            {
                enemies.Insert(enemies.LastIndexOf(null), e);
            }
            else
            {
                enemies.Add(e);
            }
        }
예제 #5
0
        private GunTurret create_GunTurret(int x, int y)
        {
            GunTurret e    = new GunTurret(x, y);
            Random    robj = new Random();

            e.SetV(0, robj.NextDouble() * 2);
            //this.panel1.Controls.Add(e.img);
            if (enemies.LastIndexOf(null) != -1)
            {
                enemies.Insert(enemies.LastIndexOf(null), e);
            }
            else
            {
                enemies.Add(e);
            }
            return(e);
        }
예제 #6
0
        public override void InflictDamage(DamageZone damageZone, Projectiles.Projectile projectile, DamageParams param = default)
        {
            GunTurret turret = ((GameObject)param.oparam[0]).GetComponent <GunTurret>();

            if (PenetrationCheck(projectile, turret.TurretArmor, Vector3.Angle(damageZone.Ship.transform.forward, projectile.transform.forward)))
            {
                // Penetration effects
                EffectManager.InitProjectilePenEffect(projectile);
                damageZone.Ship.Rigidbody.AddForceAtPosition(projectile.Velocity * projectile.FromTurret.GunsCaliber * damageZone.Ship.Armament.GunTurrets[0].ShipRecoil, projectile.GetPreviousPosition(), ForceMode.Impulse);

                // Destroy Turret
                turret.Disable();
            }
            else
            {
                // Bounce effects
                EffectManager.InitProjectileBounceEffect(projectile);
            }
        }
예제 #7
0
        public override void HandleInput()
        {
            InputHelper input = game.inputManager.inputHelper;

            if (input.IsNewButtonPress(MouseButtons.LeftButton))
            {
                Vector2 position = ProjectionHelper.PixelToFarseer(input.MousePosition);

                List <Fixture> list = game.farseerManager.world.TestPointAll(position);

                GunTurret t;

                if (list.Count == 0)
                {
                    t = new GunTurret(position, game.farseerManager.world, game.ragdollManager);
                }
                else
                {
                    t = new GunTurret(position, game.farseerManager.world, game.ragdollManager, list[0]);
                }

                game.hazardManager.addHazard(t);
            }
        }
예제 #8
0
    public void SyncGames(MTSyncGame sync)
    {
        // Sync projectiles
        for (int i = 0; i < sync.NumProjectiles; i++)
        {
            Projectile p = FindProjectileByID(sync.ProjectileIDs[i]);
            if (p)
            {
                p.transform.position += (sync.ProjectilePositions[i] - p.transform.position) * 0.5f;
                p.transform.rotation  = Quaternion.Lerp(p.transform.rotation, Quaternion.Euler(sync.ProjectileRotations[i]), 0.5f);
                p.Velocity            = Vector3.Lerp(p.Velocity, sync.ProjectileVelocities[i], 0.5f);
            }
            else
            {
                Debug.LogWarning("Sync projectile: could not find id " + sync.ProjectileIDs[i]);
            }
        }

        // Sync ships
        uint waterIngressSectionsCounter = 0;
        uint gunTurretsCounter           = 0;
        uint damageZoneCounter           = 0;
        uint damageZoneDamagesCounter    = 0;

        for (int i = 0; i < sync.NumShips; i++)
        {
            Ship s = FindShipByID(sync.ShipIDs[i]);
            bool counterUpdated = false;
            if (s != null && !s.Equals(null))
            {
                if (sync.ShipsHitpoints[i] <= 0 && !s.Destroyed)
                {
                    s.DamageHull(float.MaxValue);
                }
                else if (!s.Destroyed)
                {
                    s.HullHitpoints       = Mathf.Lerp(s.HullHitpoints, sync.ShipsHitpoints[i], 0.5f);
                    s.transform.position += (sync.ShipPositions[i] - s.transform.position) * 0.5f;
                    s.transform.rotation  = Quaternion.Lerp(s.transform.rotation, Quaternion.Euler(sync.ShipRotations[i]), 0.5f);
                    s.Velocity            = Vector3.Lerp(s.Velocity, sync.ShipVelocities[i], 0.5f);
                    for (byte waterIngressSectionIndex = 0; waterIngressSectionIndex < sync.ShipsNumWaterIngressSections[i]; waterIngressSectionIndex++)
                    {
                        Ship.WaterIngressSection section = s.WaterIngressSections.Find(wis => wis.sectionID == sync.WaterIngressSectionsIDs[waterIngressSectionsCounter]);
                        section.numHoles   = Mathf.CeilToInt(Mathf.Lerp(section.numHoles, sync.WaterIngressNumHoles[waterIngressSectionsCounter], 0.5f));
                        section.waterLevel = Mathf.Lerp(section.waterLevel, sync.WaterIngressWaterLevels[waterIngressSectionsCounter++], 0.5f);
                    }
                    if (s.PlayerTag != thisPlayerTag)
                    {
                        s.Autopilot.Chadburn = sync.ShipChadburnSettings[i];
                        s.Autopilot.Course   = sync.ShipCourses[i];
                        if (sync.ShipsHasTarget[i])
                        {
                            s.Targeting.Target = FindShipByID(sync.ShipsTargetShipID[i]);
                        }
                        else
                        {
                            s.Targeting.Target = null;
                        }
                    }
                    for (byte gunTurretIndex = 0; gunTurretIndex < sync.ShipsNumGunTurrets[i]; gunTurretIndex++)
                    {
                        GunTurret t = s.Armament.GunTurrets.Find(gt => gt.ID == sync.GunTurretIDs[gunTurretsCounter]);
                        if (sync.GunTurretsDisabled[gunTurretsCounter])
                        {
                            t.Disable();
                        }
                        t.ReloadProgress       = Mathf.Lerp(t.ReloadProgress, sync.GunTurretsReloadProgress[gunTurretsCounter], 0.5f);
                        t.TurretRotation       = Mathf.Lerp(t.TurretRotation, sync.GunTurretsRotation[gunTurretsCounter], 0.5f);
                        t.TargetTurretRotation = Mathf.Lerp(t.TargetTurretRotation, sync.GunTurretsTargetRotation[gunTurretsCounter], 0.5f);
                        t.GunsElevation        = Mathf.Lerp(t.GunsElevation, sync.GunTurretsElevation[gunTurretsCounter], 0.5f);
                        t.TargetGunsElevation  = Mathf.Lerp(t.TargetGunsElevation, sync.GunTurretsTargetElevation[gunTurretsCounter], 0.5f);
                        t.StabilizationAngle   = Mathf.Lerp(t.StabilizationAngle, sync.GunTurretsStabilizationAngle[gunTurretsCounter++], 0.5f);
                    }
                    for (byte damageZoneIndex = 0; damageZoneIndex < sync.ShipNumDamageZones[i]; damageZoneIndex++)
                    {
                        DamageZone dz = s.DamageZones.Find(sdz => sdz.ID == sync.ShipDamageZoneIDs[damageZoneCounter]);
                        for (byte damageIndex = 0; damageIndex < sync.DamageZoneNumDamages[damageZoneCounter]; damageIndex++)
                        {
                            DamageType dt = sync.DamageZoneDamages[damageZoneDamagesCounter++];
                            if (!dz.Damages.Contains(dt))
                            {
                                dz.Damages.Add(dt);
                            }
                        }
                        damageZoneCounter++;
                    }
                    counterUpdated = true;
                }
            }
            else
            {
                Debug.LogWarning("Sync ship: could not find id " + sync.ShipIDs[i]);
            }

            // Update counter in case they did not get updated inside the ifs
            if (!counterUpdated)
            {
                waterIngressSectionsCounter += sync.ShipsNumWaterIngressSections[i];
                gunTurretsCounter           += sync.ShipsNumGunTurrets[i];
                for (int k = 0; k < sync.ShipNumDamageZones[i]; k++)
                {
                    damageZoneDamagesCounter += sync.DamageZoneNumDamages[damageZoneCounter];
                    damageZoneCounter++;
                }
            }
        }
    }