// ---------------------------------- /// <summary> /// Inflicts damage upon the character- if HP reaches 0, the character dies. Oh no! /// </summary> /// <param name="Attacker">The attacker</param> /// <param name="damage">The raw damage value to inflict</param> /// <param name="hit_direction">The direction in which this projectile was moving</param> /// <param name="type">The type of damage inflicted</param> /// <param name="projectile">Projectile sender</param> public void Damage( Character Attacker, int damage, Vector2 hit_velocity, Shared.Type type = Shared.Type.MUNDANE, Projectile projectile = null) { Health_Points -= damage; Set_Invulnerability(); Particles.Do_Bloodspurt(this, 5); // Only allows the entity to be knocked and interrupted if this attacker is strong enough // ----------------------------------- Interrupt(); Shared.SFX_Sounds["Hit"].Play(); // Determine Knockback // ----------------------------------- float knock_value = 0f; if (projectile != null) { knock_value = projectile.Knockback; } else { knock_value = Attacker.Knockback; } if (knock_value > 50) { knock_value = 50; } if (knock_value < 0) { knock_value = 0; } Vector2 knockback_velocity = Vector2.Zero; knockback_velocity.X = knock_value; if (hit_velocity.X < 0f) { knockback_velocity.X = -knock_value; } // Ensures that we don't rack up a swap of hits and break the sound barrier // ---------------------------------- if (!(Math.Abs(External_Velocity.X) >= Math.Abs(knockback_velocity.X))) { External_Velocity.X += knockback_velocity.X; } if (!(Math.Abs(External_Velocity.Y) >= Math.Abs(knockback_velocity.Y))) { External_Velocity.Y += knockback_velocity.Y; } }
/// <summary> /// After a new projectile is created based on an available effect mold, it's finally given life /// </summary> /// <param name="lifespan">The duration this effect should live for</param> /// <param name="location">The raw X & Y coordinates of the effect</param> /// <param name="follow_source">Whether or not this effect should move with its source emitter</param> /// <param name="source">The source emitter of the effect</param> /// <param name="velocity">The velocity of the projectile</param> /// <param name="damage">Projectile damage</param> /// <param name="knockback">Projectile Knockback</param> /// <param name="damage_team">The damage team of the characters this projectile can harm</param> /// <param name="damage_type">The type of damage this projectile inflicts</param> /// <param name="spawn_frame">The frame in which this projecile spawns in its source's animation</param> public void Create_Projectile( float lifespan, Vector2 offset, bool follow_source, Character source, Vector2 velocity, int damage, float knockback, Shared.Damage_Team damage_team, Shared.Type damage_type, int spawn_frame) { this.lifespan = lifespan; this.Velocity = velocity; this.Damage = damage; this.Knockback = knockback; this.Damage_team = damage_team; this.Damage_type = damage_type; this.spawn_frame = spawn_frame; this.position = source.Position; this.Source_Offset = offset; if (source == null) { this.direction = Shared.Direction.RIGHT; follow_source = false; this.position = offset; this.Source_Offset = Vector2.Zero; } else { this.follow_source = follow_source; this.Source = source; this.direction = source.Direction; this.position = source.Position; this.Source_Offset = offset; } if (!follow_source) { position += Source_Offset; } }
// ------------------------------- /// <summary> /// Emites a new projectile from the available effect molds /// </summary> /// <param name="name">The name of the projectile</param> /// <param name="lifespan">The duration this effect should live for</param> /// <param name="source_offset">The X & Y offsets this projectile should spawn from</param> /// <param name="velocity">Velocity of the projectile</param> /// <param name="damage_team">Damage team this projectile should hurt</param> /// <param name="damage_type">The type of damage to inflict</param> /// <param name="spawn_frame">The frame in which this projectile should be fired in animation. Defaults to first frame.</param> /// <param name="follow_source">Whether or not this effect should move with its source emitter Defaults to false.</param> /// <param name="source">The source emitter of the effect. Defaults to null.</param> public static void Do_Projectile( string name, float lifespan, Vector2 source_offset, Vector2 velocity, int damage, float knockback, Shared.Damage_Team damage_team = Shared.Damage_Team.NEUTRAL, Shared.Type damage_type = Shared.Type.MUNDANE, int spawn_frame = 0, bool follow_source = false, Character source = null) { if (Effects.ContainsKey(name)) { Projectile projectile = new Projectile ( Effects[name].Image, Effects[name].Dimensions, Effects[name].Animation, Effects[name].Anim_length, Effects[name].Flippable, Effects[name].Name ); // Special Attributes // ------------------------- projectile.overlay_color = Effects[name].Overlay_color; projectile.do_collision = Effects[name].Do_collision; projectile.do_gravity = Effects[name].Do_gravity; projectile.do_rotation = Effects[name].Do_rotation; projectile.Resistance = Effects[name].Resistance; // ------------------------- projectile.Create_Projectile(lifespan, source_offset, follow_source, source, velocity, damage, knockback, damage_team, damage_type, spawn_frame); Active_Projectiles.Add(projectile); } else { Console.WriteLine("Projectile named '" + name + "' does not exist!"); } }