public IComponent Clone() { SoundEffectComponent ret = new SoundEffectComponent(); ret.effect = effect; return ret; }
private Entity createBulletTemplate(Game game) { Entity bullet = new Entity(); //Component: Damage entities. DamageOnContactComponent damage = new DamageOnContactComponent(); damage.Damage = 1; bullet.AddComponent(damage); //Component: Has health. Used to simulate destruction on contact with an entity HealthComponent health = new HealthComponent(); health.Health = 1; bullet.AddComponent(health); //Component: Has a texture TextureComponent tex = new TextureComponent(); tex.Texture = game.Content.Load<Texture2D>("spaceArt/png/laserGreen"); tex.SourceRect = tex.Texture.Bounds; bullet.AddComponent(tex); //Component: Moves linearly LinearMovementComponent movement = new LinearMovementComponent(); bullet.AddComponent(movement); //Component: Moves at constant speed MoveSpeedComponent speed = new MoveSpeedComponent(); speed.MoveSpeed = 18; bullet.AddComponent(speed); //Component: Has a bounding box AABBComponent aabb = new AABBComponent(); aabb.Height = tex.SourceRect.Height; aabb.Width = tex.SourceRect.Width; bullet.AddComponent(aabb); //Component: Is rendered at a specific layer - just above the enemies RenderLayerComponent layer = new RenderLayerComponent(); layer.LayerID = 12; bullet.AddComponent(layer); //Component: Is destroyed when it ventures off the (right side of the) screen DestroyedWhenOffScreenComponent destroyer = new DestroyedWhenOffScreenComponent(); bullet.AddComponent(destroyer); //Component: Is destroyed when it runs out of health DestroyedWhenNoHealthComponent destroyer2 = new DestroyedWhenNoHealthComponent(); bullet.AddComponent(destroyer2); //Component: Plays a laser sound SoundEffectComponent soundEffect = new SoundEffectComponent(); soundEffect.effect = game.Content.Load<SoundEffect>("sound/39459__the-bizniss__laser"); bullet.AddComponent(soundEffect); return bullet; }
private Entity createExplosionEntity(Game game, AABBComponent parentAABB) { Entity expl = new Entity(); //Component: Has a texture TextureComponent tex = new TextureComponent(); tex.Texture = game.Content.Load<Texture2D>("explosion"); tex.SourceRect = tex.Texture.Bounds; expl.AddComponent(tex); //Component: Has an animation AnimationComponent anim = new AnimationComponent(); anim.CurrentFrameIndex = 0; anim.FrameDuration = 45; anim.Looping = false; anim.NumFrames = 12; anim.TimeSinceFrameChange = 0; expl.AddComponent(anim); //Component: Is rendered at a specific layer (just behind the player) RenderLayerComponent layer = new RenderLayerComponent(); layer.LayerID = 9; expl.AddComponent(layer); //Component: Has a bounding box AABBComponent aabb = new AABBComponent(); aabb.Height = 134; aabb.Width = 134; expl.AddComponent(aabb); //Component: Destroys itself once its animation completes DestroyedWhenAnimationCompleteComponent destructor = new DestroyedWhenAnimationCompleteComponent(); expl.AddComponent(destructor); //Component: Is offset such that it is concentric with its parent PositionDeltaComponent delta = new PositionDeltaComponent(); float deltaX = parentAABB.Width / 2.0f - aabb.Width / 2.0f; float deltaY = parentAABB.Height / 2.0f - aabb.Height / 2.0f; delta.Delta = new Vector2(deltaX, deltaY); expl.AddComponent(delta); //Component: Plays an explosion sound SoundEffectComponent soundEffect = new SoundEffectComponent(); soundEffect.effect = game.Content.Load<SoundEffect>("freesoundsorg/87529__robinhood76__01448-distant-big-explosion-2"); expl.AddComponent(soundEffect); return expl; }