using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace BouncyCatIsBouncy { class Pigeon : IDynamicObject { Vector2 m_position, m_offset; SpriteBatch m_batch; Animation m_animation; SoundEffect m_chirp; float m_totalTime; bool m_active = true; public Pigeon(SpriteBatch batch, PhysicsBody body, float seed) { m_batch = batch; m_position = body.Position; body.OnCollision += (unused) => OnCollision(); m_totalTime = seed; } private void OnCollision() { if (m_active) { m_active = false; m_chirp.Play(); } } public void Draw() { if (m_active) m_animation.Draw(); } public void LoadContent(ContentManager manager) { var texture = manager.Load(@"Spritesheets/pigeon"); m_chirp = manager.Load(@"Sounds/Misc/bird"); m_animation = new Animation(m_batch, texture, 128, 128); m_animation.Padding = 1; m_animation.Speed = 500f; m_animation.Animating = true; m_animation.Update(m_totalTime); } public void Update(float dt) { if (m_active) { m_totalTime += dt; m_offset.Y = (float)Math.Sin(m_totalTime / 450.0f) * 13.0f; m_animation.Center = m_position + m_offset; m_animation.Update(dt); } } } }