public MovementDeviceData(Worm Owner, string DeviceName) { Name = DeviceName; Carrier = Owner; Fuel = FuelMaximum = 2; Force = new Vector2(0, -300); }
public Projectile(Weapon Source) { HardCollisionWithTerrain = true; CollideWithWormsCheck = true; SourceWeapon = Source.Data; SourceWorm = Source.Carrier; RecentlyDamagedTargets.Add(Source.Carrier); RecentlyCollided.Add(Source.Carrier); }
public void Explode(bool Direct, Worm DirectTarget) { if (Direct) { DirectTarget.DoDamage(Damage); if (Velocity != Vector2.Zero) { Velocity.Normalize(); Velocity *= SourceWeapon.ProjectileForce; DirectTarget.Velocity += Velocity; } } foreach (var PlayerWorm in Level.Worms) { if (PlayerWorm == DirectTarget) { continue; // Don't damage target again } if ((Position - PlayerWorm.Position).LengthSquared() <= ExplosionRadius * ExplosionRadius + PlayerWorm.BoundigSphereRadiusSquared) { Vector2 ExplosionVelocity = Position - PlayerWorm.Position; float DistanceModifier = 1 - (ExplosionVelocity.Length() - Math.Max(PlayerWorm.ProjectileCollisionSize.X, PlayerWorm.ProjectileCollisionSize.Y)) / ExplosionRadius; if (DistanceModifier < 0) { DistanceModifier = 0; } if (DistanceModifier > 1) { DistanceModifier = 1; } if (ExplosionVelocity != Vector2.Zero) { ExplosionVelocity.Normalize(); ExplosionVelocity *= SourceWeapon.ProjectileForce * DistanceModifier; PlayerWorm.Velocity -= ExplosionVelocity; } if (!(!SourceWeapon.SelfDamage && PlayerWorm == SourceWorm)) { PlayerWorm.DoDamage(Damage * DistanceModifier); } } } Level.Explosion(Position, (int)(ExplosionRadius * Level.cExplosionGroundDestructionPercent)); Level.ProjectilesToRemove.Add(this); }
public void MouseWheelDown(object Sender, GameWindow.MouseData Mouse) { foreach (var Player in Players) { if (Player.Value.LocalMouse == Mouse) { Worm PlayerWorm = Player.Value.ControlledWorm; PlayerWorm.WeaponIndex--; if (PlayerWorm.WeaponIndex < 0) { PlayerWorm.WeaponIndex = PlayerWorm.CarriedWeapons.Count - 1; } PlayerWorm.CurrentWeapon = PlayerWorm.CarriedWeapons[PlayerWorm.WeaponIndex]; Player.Value.CreateWeaponSwapTag(PlayerWorm.CurrentWeapon); } } }
public static bool CircleIntersectsRectangle(Vector2 Position, float Radius, Worm Worm) { Rectangle rect = new Rectangle((int)(Worm.Position.X - Worm.GroundCollisionSize.X / 2), (int)(Worm.Position.Y - Worm.GroundCollisionSize.Y / 2), (int)Worm.GroundCollisionSize.X, (int)Worm.GroundCollisionSize.Y); int circleDistanceX = (int)Math.Abs(Position.X - rect.X); int circleDistanceY = (int)Math.Abs(Position.Y - rect.Y); if (circleDistanceX > (rect.Width / 2 + Radius)) { return false; } if (circleDistanceY > (rect.Height / 2 + Radius)) { return false; } if (circleDistanceX <= (rect.Width / 2)) { return true; } if (circleDistanceY <= (rect.Height / 2)) { return true; } int cornerDistance_sq = (circleDistanceX - rect.Width / 2) ^ 2 + (circleDistanceY - rect.Height / 2) ^ 2; return (cornerDistance_sq <= (Radius * Radius)); }
public void Explode(bool Direct, Worm DirectTarget) { if (Direct) { DirectTarget.DoDamage(Damage); if (Velocity != Vector2.Zero) { Velocity.Normalize(); Velocity *= SourceWeapon.ProjectileForce; DirectTarget.Velocity += Velocity; } } foreach (var PlayerWorm in Level.Worms) { if (PlayerWorm == DirectTarget) continue; // Don't damage target again if ((Position - PlayerWorm.Position).LengthSquared() <= ExplosionRadius * ExplosionRadius + PlayerWorm.BoundigSphereRadiusSquared) { Vector2 ExplosionVelocity = Position - PlayerWorm.Position; float DistanceModifier = 1 - (ExplosionVelocity.Length() - Math.Max(PlayerWorm.ProjectileCollisionSize.X, PlayerWorm.ProjectileCollisionSize.Y)) / ExplosionRadius; if(DistanceModifier < 0) DistanceModifier = 0; if (DistanceModifier > 1) DistanceModifier = 1; if (ExplosionVelocity != Vector2.Zero) { ExplosionVelocity.Normalize(); ExplosionVelocity *= SourceWeapon.ProjectileForce * DistanceModifier; PlayerWorm.Velocity -= ExplosionVelocity; } if (!(!SourceWeapon.SelfDamage && PlayerWorm == SourceWorm)) PlayerWorm.DoDamage(Damage * DistanceModifier); } } Level.Explosion(Position, (int)(ExplosionRadius * Level.cExplosionGroundDestructionPercent)); Level.ProjectilesToRemove.Add(this); }
public Weapon(Worm Owner, WeaponData WeaponData) { Data = WeaponData; Carrier = Owner; Magazine = WeaponData.MagazineSize; }
public void InitWorm(Worm NewWorm) { NewWorm.Initialize(this, cWormMass); if(EnabledWeapons) { foreach (var WeaponData in Weapons) NewWorm.CarriedWeapons.Add(new Weapon(NewWorm, WeaponData.Value)); NewWorm.CurrentWeapon = NewWorm.CarriedWeapons[0]; NewWorm.WeaponIndex = 0; } NewWorm.Respawn(new Vector2(new Random().Next(300, Level.Ground.Width - 300), 50)); NewWorm.Position = new Vector2(400, 15); NewWorm.Animation = new Animation(ResourceManager.WormAnimationData); NewWorm.Animation.SetAnimation(0); NewWorm.GroundCollisionSize = cWormSize * 0.8f; NewWorm.ProjectileCollisionSize = cWormSize; NewWorm.LifeMaximum = cLifeMaximum; NewWorm.LifeCurrent = cLifeStart; Worms.Add(NewWorm); }