public static HealthComponent CreateDefaultHealth(GameObject owner, int maxHealth, TimeSpan hitDuration, TimeSpan deathParticleTimeToLive) { var hc = new HealthComponent(owner) { MaxHealth = maxHealth }; hc.OnHit += (damage) => { hc.MakeInvincible(hitDuration); }; hc.OnDeath += (damage) => { DeathConfetti confetti = new DeathConfetti(); confetti.Spatial.CopyFrom(owner.Spatial); confetti.AutoDestruct.DestructionDelay = deathParticleTimeToLive; Global.Game.AddGameObject(confetti); Global.Game.RemoveGameObject(owner); }; return(hc); }
private void OnDeath(int damage) { Global.Game.RemoveGameObject(this); DeathConfetti confetti = new DeathConfetti(); confetti.Spatial.CopyFrom(this.Spatial); confetti.AutoDestruct.DestructionDelay = TimeSpan.FromSeconds(5.0f); confetti.ParticleEmitter.Emitter.MaxNumParticles = 4096; // TODO(manu): Somehow, this doesn't work... confetti.ParticleEmitter.Emitter.MaxParticleSpeed = 200.0f; Global.Game.AddGameObject(confetti); }
private void OnCollision(Fixture ourFixture, Fixture theirFixture, VelcroPhysics.Collision.ContactSystem.Contact contact) { Body ourBody = ourFixture.Body; Body theirBody = theirFixture.Body; Debug.Assert(ourBody == BodyComponent.Body); //Global.HandleDefaultHit(theirBody, ourBody.Position, Damage, ForceOnImpact); Global.HandleDefaultHit(theirBody, ourBody.Position, Damage, 0); DeathConfetti confetti = new DeathConfetti(); confetti.Spatial.CopyFrom(this.Spatial); confetti.AutoDestruct.DestructionDelay = TimeSpan.FromSeconds(ConfettiTimeToLive); confetti.ParticleEmitter.Emitter.MaxNumParticles = 16; Vector2 g = -2.5f * BodyComponent.Body.LinearVelocity; confetti.ParticleEmitter.Emitter.Gravity = g; Global.Game.AddGameObject(confetti); Global.Game.RemoveGameObject(this); }
public static GameObject CreateKnown(KnownGameObject type) { GameObject go = new GameObject(); switch (type) { case KnownGameObject.Owliver: { go = new Owliver(); } break; case KnownGameObject.Shop: { go = new Shop(); } break; case KnownGameObject.Slurp: { go = new Slurp(); } break; case KnownGameObject.Tankton: { go = new Tankton(); } break; case KnownGameObject.DeathConfetti: { go = new DeathConfetti(); } break; case KnownGameObject.Projectile: { go = new Projectile(); } break; case KnownGameObject.BackgroundScreen: { go = new BackgroundScreen(); } break; case KnownGameObject.Gate: { go = new Gate(); } break; case KnownGameObject.Flora_Fir: case KnownGameObject.Flora_FirAlt: case KnownGameObject.Flora_Conifer: case KnownGameObject.Flora_ConiferAlt: case KnownGameObject.Flora_Oak: case KnownGameObject.Flora_Orange: case KnownGameObject.Flora_Bush: { FloraType floraType = (FloraType)(type - KnownGameObject.Flora_Fir); go = new Flora() { TreeType = floraType, }; } break; case KnownGameObject.Bonbon_Gold: case KnownGameObject.Bonbon_Red: { BonbonType bonbonType = (BonbonType)(type - KnownGameObject.Bonbon_Gold); go = new BonbonPickup() { BonbonType = bonbonType, }; } break; case KnownGameObject.Key_Gold: { KeyType keyType = (KeyType)(type - KnownGameObject.Key_Gold); go = new KeyPickup() { KeyType = keyType, }; } break; case KnownGameObject.ShopItem_FruitBowl: case KnownGameObject.ShopItem_FishingRod: case KnownGameObject.ShopItem_Stick: { ShopItemType itemType = (ShopItemType)(type - KnownGameObject.ShopItem_FruitBowl); go = new ShopItem() { ItemType = itemType }; } break; case KnownGameObject.Random_FirTree: { FloraType floraType = _random.Choose(FloraType.Fir, FloraType.Conifer); go = new Flora() { TreeType = floraType, }; } break; case KnownGameObject.Random_FirTreeAlt: { FloraType floraType = _random.Choose(FloraType.FirAlt, FloraType.ConiferAlt); go = new Flora() { TreeType = floraType, }; } break; case KnownGameObject.Random_OakTree: { FloraType floraType = _random.Choose(FloraType.Oak, FloraType.Orange); go = new Flora() { TreeType = floraType, }; } break; default: throw new ArgumentException("Unknown game object type."); } int instanceID = _knownCreationCount[(int)type]++; go.Name = $"{type}_{instanceID}"; return(go); }