using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; class AnimatedGameObject : GameObject { protected Dictionary animations; protected AnimationPlayer animPlayer; public AnimatedGameObject(int layer = 0, string id = "") : base(layer, id) { animations = new Dictionary(); animPlayer = new AnimationPlayer(); } public void LoadAnimation(GameWorld gameWorld, string assetname, string id, bool looping) { animations[id] = new Animation(gameWorld, assetname, looping); } public void PlayAnimation(string id) { animPlayer.playAnimation(animations[id]); } public override void Draw(GameTime gameTime, SpriteBatch spriteBatch) { animPlayer.Mirror = velocity.X < 0; animPlayer.Draw(gameTime, spriteBatch, this.GlobalPosition); } public override Rectangle BoundingRectangle { get { int left = (int)Math.Round(GlobalPosition.X - animPlayer.Animation.Origin.X / 2); int top = (int)Math.Round(GlobalPosition.Y - animPlayer.Animation.Origin.Y); return new Rectangle(left, top, animPlayer.Animation.FrameWidth / 2, animPlayer.Animation.FrameHeight); } } }