コード例 #1
0
        public void BombardFire()
        {
            var numRockets  = 4;
            var angleOffset = 0.3f;

            if (FlightShip.HasUpgrade <BombardOverload>())
            {
                numRockets  = 8;
                angleOffset = 1.1f;
            }
            if (_bombardCooldown.Completed)
            {
                var guns = FlightShip.Topology.AllSections
                           .Where(x => x.Module is BombardModule);
                var shipTransform = Transform;
                foreach (var gun in guns)
                {
                    if (!FlightShip.TryTakeEnergy(1))
                    {
                        return;
                    }
                    for (var i = 0; i < numRockets; i++)
                    {
                        var flightNode    = FlightShip.GetNodeForSection(gun.GridLocation);
                        var rotation      = (float)((-gun.Rotation - 2) * Math.PI / 3 + angleOffset * Random.NextDouble() - angleOffset / 2f);
                        var rotationQuat  = Quaternion.CreateFromYawPitchRoll(rotation, 0, 0);
                        var nodeTransform = flightNode.Entity.Get <Transform>();
                        var location      = Vector3.Transform(Vector3.Zero, nodeTransform.WorldTransform * shipTransform.WorldTransform);
                        var shell         = Entity.EntityManager.Create();
                        shell.Add(new Transform
                        {
                            Location = location + new Vector3((float)Random.NextDouble() * 0.3f, 0, (float)Random.NextDouble() * 0.3f)
                        });

                        var rotationMatrix = Matrix.CreateFromYawPitchRoll(rotation, 0, 0)
                                             * Matrix.CreateFromQuaternion(shipTransform.Rotation);

                        shell.Add(
                            new RocketProjectile(
                                FlightShip.ShipGuid,
                                FlightShip.Velocity,
                                Vector3.Transform(Vector3.Transform(Vector3.Forward, rotationQuat), shipTransform.Rotation),
                                rotationMatrix
                                )
                            );
                    }
                }

                _bombardCooldown.Restart();
            }
        }
コード例 #2
0
ファイル: FlightNode.cs プロジェクト: sami016/EnterTheVoid
        public void OnHit(FlightNode node, FlightShip ship, Point gridLocation, Vector3 nodeLocation, Section section)
        {
            //var otherLocation = node.Entity.Get<Transform>().Location;
            //var direction = (otherLocation - Transform.Location);
            // Handle identical location with random impulse.
            var shipDirection = (_ship.GetCenterGlobalLocation() - ship.GetCenterGlobalLocation());

            if (shipDirection.LengthSquared() == 0)
            {
                shipDirection = new Vector3((float)Random.NextDouble() - 0.5f, (float)Random.NextDouble() - 0.5f, (float)Random.NextDouble() - 0.5f);
            }
            shipDirection.Normalize();
            _ship.Damage(GridLocation, 2);
            _ship.Velocity = (shipDirection) * 5f;
            //_ship.Push(direction, 10f);
        }
コード例 #3
0
        public void StandardFire()
        {
            if (_lightweightCooldown.Completed)
            {
                var guns = FlightShip.Topology.AllSections
                           .Where(x => x.Module is BlasterModule);
                var shipTransform = Transform;
                var any           = false;
                foreach (var gun in guns)
                {
                    any = true;
                    var flightNode    = FlightShip.GetNodeForSection(gun.GridLocation);
                    var rotation      = (float)((-gun.Rotation - 2) * Math.PI / 3);
                    var rotationQuat  = Quaternion.CreateFromYawPitchRoll(rotation, 0, 0);
                    var nodeTransform = flightNode.Entity.Get <Transform>();
                    var location      = Vector3.Transform(Vector3.Zero, nodeTransform.WorldTransform * shipTransform.WorldTransform);
                    var shell         = Entity.EntityManager.Create();
                    shell.Add(new Transform
                    {
                        Location = location
                    });
                    shell.Add(
                        new LightBlasterProjectile(
                            FlightShip.ShipGuid,
                            FlightShip.Velocity,
                            Vector3.Transform(Vector3.Transform(Vector3.Forward, rotationQuat), shipTransform.Rotation),
                            false
                            )
                        );
                }
                if (any)
                {
                    SoundEffects.Get("Shot")?.Play();
                }

                if (FlightShip.HasUpgrade <RapidFire>())
                {
                    _lightweightCooldown.ChangeTarget(TimeSpan.FromSeconds(0.3f));
                    _lightweightCooldown.Complete();
                }
                _lightweightCooldown.Restart();
            }
        }
コード例 #4
0
        public void RocketBlast()
        {
            if (!FlightShip.HasUpgrade <BlastRocketry>())
            {
                return;
            }
            if (_blastRocketCooldown.Completed)
            {
                var guns = FlightShip.Topology.AllSections
                           .Where(x => x.Module is RocketModule);
                var shipTransform = Transform;
                foreach (var gun in guns)
                {
                    var flightNode    = FlightShip.GetNodeForSection(gun.GridLocation);
                    var rotation      = (float)((-gun.Rotation - 2) * Math.PI / 3);
                    var rotationQuat  = Quaternion.CreateFromYawPitchRoll(rotation, 0, 0);
                    var nodeTransform = flightNode.Entity.Get <Transform>();
                    var location      = Vector3.Transform(Vector3.Zero, nodeTransform.WorldTransform * shipTransform.WorldTransform);
                    var shell         = Entity.EntityManager.Create();
                    shell.Add(new Transform
                    {
                        Location = location
                    });

                    var rotationMatrix = Matrix.CreateFromYawPitchRoll(rotation, 0, 0)
                                         * Matrix.CreateFromQuaternion(shipTransform.Rotation);

                    shell.Add(
                        new BlastRocketProjectile(
                            FlightShip.ShipGuid,
                            FlightShip.Velocity,
                            Vector3.Transform(Vector3.Transform(Vector3.Forward, rotationQuat), shipTransform.Rotation),
                            rotationMatrix
                            )
                        );
                }

                _blastRocketCooldown.Restart();
            }
        }
コード例 #5
0
        public void ShieldDeploy()
        {
            if (_bubbleShieldCooldown.Completed)
            {
                var guns = FlightShip.Topology.AllSections
                           .Where(x => x.Module is ShieldBubbleGeneratorModule);
                var shipTransform = Transform;
                foreach (var gun in guns)
                {
                    if (!FlightShip.TryTakeEnergy(1))
                    {
                        return;
                    }
                    var flightNode   = FlightShip.GetNodeForSection(gun.GridLocation);
                    var rotation     = (float)((-gun.Rotation - 2) * Math.PI / 3);
                    var rotationQuat = Quaternion.CreateFromYawPitchRoll(rotation, 0, 0);
                    //var nodeTransform = flightNode.Entity.Get<Transform>();
                    var location = flightNode.GlobalLocation;
                    var shell    = Entity.EntityManager.Create();
                    shell.Add(new Transform
                    {
                        Location = location
                    });
                    shell.Add(
                        new BubbleShieldProjectile(
                            FlightShip.ShipGuid,
                            FlightShip.GetNodeForSection(gun.GridLocation),
                            FlightShip.Velocity,
                            Vector3.Transform(Vector3.Transform(Vector3.Forward, rotationQuat), shipTransform.Rotation),
                            FlightShip.HasUpgrade <ShieldAmplification>(),
                            FlightShip.HasUpgrade <ShieldFortification>()
                            )
                        );
                }

                _bubbleShieldCooldown.Restart();
            }
        }
コード例 #6
0
        public void HeavyFire()
        {
            if (_heavyweightCooldown.Completed)
            {
                var guns = FlightShip.Topology.AllSections
                           .Where(x => x.Module is BlasterModule);
                var shipTransform = Transform;
                foreach (var gun in guns)
                {
                    if (!FlightShip.TryTakeEnergy(1))
                    {
                        return;
                    }
                    var flightNode   = FlightShip.GetNodeForSection(gun.GridLocation);
                    var rotation     = (float)((-gun.Rotation - 2) * Math.PI / 3);
                    var rotationQuat = Quaternion.CreateFromYawPitchRoll(rotation, 0, 0);
                    //var nodeTransform = flightNode.Entity.Get<Transform>();
                    var location = flightNode.GlobalLocation;
                    var shell    = Entity.EntityManager.Create();
                    shell.Add(new Transform
                    {
                        Location = location
                    });
                    shell.Add(
                        new HeavyBlasterProjectile(
                            FlightShip.ShipGuid,
                            FlightShip.Velocity,
                            Vector3.Transform(Vector3.Transform(Vector3.Forward, rotationQuat), shipTransform.Rotation),
                            false
                            )
                        );
                }
                SoundEffects.Get("HeavyShot")?.Play();

                _heavyweightCooldown.Restart();
            }
        }
コード例 #7
0
ファイル: FlightNode.cs プロジェクト: sami016/EnterTheVoid
 public FlightNode(FlightShip ship, Point gridPosition, ShipTopology shipTopology)
 {
     _ship         = ship;
     GridLocation  = gridPosition;
     _shipTopology = shipTopology;
 }
コード例 #8
0
 public FlightCameraControl(Entity shipEntity)
 {
     _shipEntity    = shipEntity;
     _shipTransform = _shipEntity.Get <Transform>();
     _flightShip    = shipEntity.Get <FlightShip>();
 }
コード例 #9
0
 public EnemyHarness(FlightShip playerShip)
 {
     _playerShip = playerShip;
 }
コード例 #10
0
        public void Tick(TickContext context)
        {
            float passiveAccel          = 0.45f;
            float passiveAccelBackwards = 0.25f;
            float rocketAccel           = 0.9f;
            float rotationPenalty       = 1f;
            float rotationSpeedBase     = 1f;

            //float rotationLimit = (float)Math.PI;// * 2 / 6;

            if (FlightShip.HasUpgrade <EnhancedRotation>())
            {
                rotationSpeedBase += 1f;
                rotationPenalty    = 0f;
                //rotationLimit = (float)Math.PI;
            }
            if (FlightShip.HasUpgrade <PrecisionRocketry>())
            {
                passiveAccel          += 0.3f;
                passiveAccelBackwards += 0.3f;
            }

            //TODO - exclude damanged/destroyed.
            _accelerationCapabilities[0] = 0;
            _accelerationCapabilities[1] = 0;
            _accelerationCapabilities[2] = 0;
            _accelerationCapabilities[3] = 0;
            _accelerationCapabilities[4] = 0;
            _accelerationCapabilities[5] = 0;

            var rocketModuleSections = new List <Section>();

            // Accumulate acceleration capability.
            var rotationCapabilities = 0;
            var sectionCount         = 0;

            foreach (var section in _topology.AllSections)
            {
                sectionCount++;
                if (section.Module is RocketModule rocketModule)
                {
                    _accelerationCapabilities[section.Rotation]++;
                    rocketModule.On = false;
                    rocketModuleSections.Add(section);
                }
                if (section.Module is RotaryEngine)
                {
                    rotationCapabilities++;
                }
            }


            var acceleration = Vector3.Zero;

            if (RocketControl.Forwards)
            {
                acceleration += Vector3.Forward * (passiveAccel + rocketAccel * _accelerationCapabilities[(int)OffDirection.South]);

                // Activate rockets for effects.
                foreach (var section in rocketModuleSections)
                {
                    if (section.Rotation == (int)OffDirection.South)
                    {
                        (section.Module as RocketModule).On = true;
                    }
                }
            }
            if (RocketControl.Left)
            {
                acceleration += Vector3.Left * (passiveAccel + rocketAccel * (_accelerationCapabilities[(int)OffDirection.SouthEast] + _accelerationCapabilities[(int)OffDirection.NorthEast]) * Sin60);
                acceleration += Vector3.Forward * rocketAccel * _accelerationCapabilities[(int)OffDirection.SouthEast] * Sin30;
                acceleration += Vector3.Backward * rocketAccel * _accelerationCapabilities[(int)OffDirection.NorthEast] * Sin30;

                // Activate rockets for effects.
                foreach (var section in rocketModuleSections)
                {
                    if (section.Rotation == (int)OffDirection.SouthEast ||
                        section.Rotation == (int)OffDirection.NorthEast)
                    {
                        (section.Module as RocketModule).On = true;
                    }
                }
            }
            if (RocketControl.Right)
            {
                acceleration += Vector3.Right * (passiveAccel + rocketAccel * (_accelerationCapabilities[(int)OffDirection.SouthWest] + _accelerationCapabilities[(int)OffDirection.NorthWest]) * Sin60);
                acceleration += Vector3.Forward * rocketAccel * _accelerationCapabilities[(int)OffDirection.SouthWest] * Sin30;
                acceleration += Vector3.Backward * rocketAccel * _accelerationCapabilities[(int)OffDirection.NorthWest] * Sin30;

                // Activate rockets for effects.
                foreach (var section in rocketModuleSections)
                {
                    if (section.Rotation == (int)OffDirection.SouthWest ||
                        section.Rotation == (int)OffDirection.NorthWest)
                    {
                        (section.Module as RocketModule).On = true;
                    }
                }
            }
            if (RocketControl.Backwards)
            {
                acceleration += Vector3.Backward * (passiveAccel + rocketAccel * _accelerationCapabilities[(int)OffDirection.South]);

                // Activate rockets for effects.
                foreach (var section in rocketModuleSections)
                {
                    if (section.Rotation == (int)OffDirection.North)
                    {
                        (section.Module as RocketModule).On = true;
                    }
                }
            }

            var rotationDiff        = 0f;
            var rotationCoefficient = Math.Max(rotationSpeedBase + rotationCapabilities - sectionCount * rotationPenalty * 0.05f, 0.5f);

            if (RocketControl.RotatePort)
            {
                rotationDiff = 1 * context.DeltaTimeSeconds * 0.3f * rotationCoefficient;
            }
            else if (RocketControl.RotateStarboard)
            {
                rotationDiff = -1 * context.DeltaTimeSeconds * 0.3f * rotationCoefficient;
            }
            else
            {
                //if (Math.Abs(rotation) < 0.001)
                //{
                //    rotation = 0;
                //}
                //else
                //{
                //    rotation += -1 * context.DeltaTimeSeconds * 0.2f * rotationCoefficient * (float)Math.Sin((Math.PI / 2) * rotation / Math.PI);
                //}
            }
            if (rotationDiff > Math.PI)
            {
                rotationDiff = -(float)Math.PI * 2;
            }
            if (rotationDiff < -Math.PI)
            {
                rotationDiff = (float)Math.PI * 2;
            }



            FlightShip.Update(() =>
            {
                FlightShip.Rotation += rotationDiff;
                var velocity         = FlightShip.Velocity + context.DeltaTimeSeconds * Vector3.Transform(acceleration, Transform.Rotation);
                FlightShip.Velocity  = velocity;
            });
        }