public ComponentShield( Ship arg_ship, float arg_size, ShieldTemplate arg_template): base(arg_ship, arg_ship.template.component_shield_pos, arg_size, arg_template) { template = arg_template; radius = arg_ship.template.shield_radius; hitbox = new HitboxCircle(radius); art = ArtManager.shields[template.art_resource].New(radius, size); shield_resistance = template.shield_resistance * SHIELD_BASE_RESISTANCE; max_integrity = (arg_template.integrity * arg_size * Utility.Sqrt(arg_size)); regen_rate = (arg_template.regen / GameConst.framerate) * arg_size; integrity = max_integrity; reform_integrity = max_integrity * template.reform_integrity; active = true; }
public virtual Intersection Intersect( Hitbox hitbox ) { return null; }
public override Intersection Intersect(Hitbox hitbox) { if (!this.WithinRadius(hitbox)) { return null; } if (hitbox is HitboxCircle) { return this.IntersectCircle((HitboxCircle)hitbox); } if (hitbox is HitboxPolygon) { return this.IntersectPolygon((HitboxPolygon)hitbox); } return null; }
// as above public bool WithinRadius(Hitbox hitbox) { float combined_radsq = radius + hitbox.radius; combined_radsq *= combined_radsq; return Vector2.DistanceSquared(pos, hitbox.pos) < (combined_radsq); }
public override Intersection Intersect(Hitbox hitbox) { if (!this.WithinRadius(hitbox)) { return null; } if (hitbox is HitboxCircle) { // if both hitboxes are circles, then the ContainsExclusion test // is the same as the collision test. // So a collision has occurred Intersection sect = new Intersection(); sect.position = ((hitbox.pos * radius) + (pos * hitbox.radius)) / (radius + hitbox.radius); sect.surface_normal = Utility.Angle(pos - hitbox.pos); sect.overlap = (radius - (sect.position - pos).Length())*2; return sect; } if ( hitbox is HitboxPolygon ) { // YEA. DO THAT. return ((HitboxPolygon)hitbox).IntersectCircle(this); } return null; }