Пример #1
0
        public override void Process(ShipFacade link)
        {

            if (link.thrusters != null)
            {
                link.thrusters.output_thrust = thrust;
                link.thrusters.output_torque = torque;
            }

            
            float desired_angle = Utility.Angle(weapon_target - link.pos);
            

            for (int i = 0; i < link.weapon_count; i++)
            {
                WeaponFacade weapon = link.Weapon(i);
                if (weapon.weapon_present)
                {
                    weapon.fire = firing;
                    weapon.target_angle = desired_angle - link.angle;
                }
            }
        }
Пример #2
0
        public override void Process(ShipFacade arg_link)
        {
            link = arg_link;

            if (!target.destroyed)
            {

                target_pos = target.pos + (Utility.CosSin(target.angle + MathHelper.Pi)*target.hitbox.radius*3);


                Vector2 mov;
                mov.X = x_tracker.Update(target_pos.X - link.pos.X);
                mov.Y = y_tracker.Update(target_pos.Y - link.pos.Y);


                /*
                if (mov.LengthSquared() > (0.5))
                {
                    // Ya, this version is way cooler.

                    desired_angle = Utility.Angle(mov);
                }
                */

                desired_angle = Utility.Angle(mov);

                Vector2 target_accell = target.velocity - target_ship_last_vel;


                for (int i = 0; i < link.weapon_count; i++)
                {
                    WeaponFacade weapon = link.Weapon(i);
                    if (weapon.weapon_present)
                    {
                        Vector2 weapon_pos = link.pos + Utility.Rotate(weapon.hardpoint_position, link.angle);

                        float time_estimate = (target.pos - weapon_pos).Length() / weapon.projectile_velocity;
                        Vector2 intercept = target.pos + ((target.velocity - link.velocity) * time_estimate) + (0.5f * target_accell * time_estimate*time_estimate);
                        //desired_angle = Utility.Angle(intercept - weapon_pos);

                        time_estimate = (intercept - weapon_pos).Length() / weapon.projectile_velocity;
                        intercept = target.pos + ((target.velocity - link.velocity) * time_estimate) + (0.5f * target_accell * time_estimate * time_estimate);
                        desired_angle = Utility.Angle(intercept - weapon_pos);
                         

                        float range = (intercept - link.pos).Length();


                        if ( range < (weapon.projectile_life*weapon.projectile_velocity)/2f &&  Utility.AngleWithin( desired_angle - link.angle, weapon.hardpoint_arc_min, weapon.hardpoint_arc_max ))
                        {
                            weapon.fire = true;
                            weapon.target_angle = desired_angle - link.angle;
                        }
                    }
                }

                target_ship_last_vel = target.velocity;


                float a_mov = angle_tracker.Update(Utility.AngleDelta(desired_angle, link.angle));


                mov = Utility.Rotate(mov, -link.angle);

                if (link.thrusters != null)
                {
                    link.thrusters.output_thrust.X = Utility.Clamp(mov.X);
                    link.thrusters.output_thrust.Y = Utility.Clamp(mov.Y);
                    link.thrusters.output_torque = Utility.Clamp(a_mov);
                }

            }
            else
            {
                link.thrusters.output_thrust.X = 0.0f;
                link.thrusters.output_thrust.Y = 0.0f;
                link.thrusters.output_torque = 0.0f;
            }
            
        }
Пример #3
0
 public virtual void Process( ShipFacade link )
 {
 }
Пример #4
0
        public override void Process(ShipFacade arg_link)
        {
            link = arg_link;
            
            if ((target - link.pos).Length() < target_ok_distance)
            {
                targets.Add(Utility.RandVec(target_range));
                target = targets[0];
                targets.RemoveAt(0);
                k = (k + 1) % 24;
            }
            

            Vector2 mov;
            mov.X = x_tracker.Update(target.X - link.pos.X);
            mov.Y = y_tracker.Update(target.Y - link.pos.Y);
            

            if (mov.LengthSquared() > (0.5))
            {
                // Ya, this version is way cooler.

                desired_angle = Utility.Angle(mov);
            }

            float a_mov = angle_tracker.Update(Utility.AngleDelta(desired_angle, link.angle));


            mov = Utility.Rotate(mov, -link.angle);

            if (link.thrusters != null)
            {
                link.thrusters.output_thrust.X = Utility.Clamp(mov.X);
                link.thrusters.output_thrust.Y = Utility.Clamp(mov.Y);
                link.thrusters.output_torque = Utility.Clamp(a_mov);
            }

            /*
            for (int i = 0; i < link.weapon_count; i++)
            {
                WeaponFacade weapon = link.Weapon(i);
                weapon.fire = true;
                weapon.target_angle = 0.0f;
            }
            */
            
        }
Пример #5
0
        public Ship(ShipTemplate arg_template, Universe arg_universe ) : base(arg_universe)
        {
            template = arg_template;

            hitbox = template.hitbox.Copy();

            mass = template.base_mass;
            inertia = template.base_mass * template.mass_avg_radius * template.mass_avg_radius;

            radius = template.shield_radius;
            radius_sq = radius * radius;

            sprite = ArtManager.GetSpriteResource( template.hull_art_resource ).New();
           
            weapons = new ComponentWeapon[template.weapon_ports.Count];


            facade = new ShipFacade(this);
        }