using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace BouncyCatIsBouncy { class Cannon : IDynamicObject { Vector2 m_position; SpriteBatch m_batch; Animation m_animation; Input m_input; Cat m_cat; public Cannon(SpriteBatch batch, Cat cat, Input input) { m_batch = batch; m_cat = cat; m_input = input; m_position = m_cat.Position; m_cat.OnLaunch += () => m_animation.Animating = true; } public void PointAt(Vector2 point) { m_animation.Rotation = (float)Math.Atan2(point.Y - m_position.Y, point.X - m_position.X) + MathHelper.PiOver2; } public void Draw() { m_animation.Draw(); } public void LoadContent(ContentManager manager) { var texture = manager.Load(@"Spritesheets/cannon"); m_animation = new Animation(m_batch, texture, 512, 512); m_animation.Speed = 300f; m_animation.StopAtEnd = true; m_animation.Width = m_animation.Height = 128; } public void Update(float dt) { if (!m_cat.Launched) m_animation.Center = m_cat.Position; m_animation.Update(dt); PointAt(m_input.Cursor2DLocation); } } }