Example #1
0
        public void Update(ShipCommands commands)
        {
            if (commands.TurnLeft)
            {
                TurnLeft(Direction.FromRadian(ShipParameters.RotationSpeed));
            }
            if (commands.TurnRight)
            {
                TurnRight(Direction.FromRadian(ShipParameters.RotationSpeed));
            }
            if (commands.Accelerate)
            {
                AccelerateAlongHeading(ShipParameters.AccelerationSpeed);
            }
            if (commands.Decelerate)
            {
                DecelerateAlongHeading(ShipParameters.AccelerationSpeed);
            }
            if (commands.Fire)
            {
                Fire();
                commands.Fire = false;
            }

            this.Energy += ShipParameters.EnergyRegen;
            if (Energy > ShipParameters.Energy)
            {
                Energy = ShipParameters.Energy;
            }

            var newLocation = new WrappingLocation(this.Location, Movement);

            this.Location = newLocation;
        }
Example #2
0
        public Ship(WrappingLocation location, Color color, ShipParameters parameters = null) : base(location)
        {
            this.ShipParameters = parameters ?? ShipParameters.Default();
            this.bodyBehavior   = new BodyBaseBehavior(ShipParameters.MaximumSpeed);

            this.Color  = color;
            this.Size   = ShipParameters.Size;
            this.Energy = ShipParameters.Energy;
        }
Example #3
0
        private void Fire()
        {
            if (this.Energy > ShipParameters.MinEnergyToFire)
            {
                this.Energy -= ShipParameters.EnergyToFire;

                var orthogonalDirection = Direction.FromRadian(Heading.InRadians + radian.FromDegree(-90));

                var rightInFront = new WrappingLocation(this.Location, Heading, new Distance(2000.0d));
                var bitLeft      = new WrappingLocation(rightInFront, orthogonalDirection, new Distance(1000.0d));
                var bitRight     = new WrappingLocation(rightInFront, orthogonalDirection, new Distance(-1000.0d));

                var fireVector   = new vector(Heading, ShipParameters.BulletVelocity);
                var bulletVector = this.Movement + fireVector;

                var bulletLeft  = new Bullet(bitLeft, bulletVector, ShipParameters.BulletSize, ShipParameters.BulletDamage, ShipParameters.BulletLifetime);
                var bulletRight = new Bullet(bitRight, bulletVector, ShipParameters.BulletSize, ShipParameters.BulletDamage, ShipParameters.BulletLifetime);
                bulletLeft.Update();
                bulletRight.Update();

                Game.Subscribe(bulletLeft);
                Game.Subscribe(bulletRight);
            }
        }