public IComponent Clone() { AnimationComponent ret = new AnimationComponent(); ret.CurrentFrameIndex = CurrentFrameIndex; ret.TimeSinceFrameChange = TimeSinceFrameChange; ret.FrameDuration = FrameDuration; ret.NumFrames = NumFrames; ret.Looping = Looping; return ret; }
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; }