using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace BouncyCatIsBouncy { class Chandelier : IDynamicObject { SpriteBatch m_batch; Vector2 m_position, m_origin; bool m_isHit; float m_rotation, m_totalTime; Texture2D m_chandelier; SoundEffect m_glass; public Chandelier(SpriteBatch batch, PhysicsBody body) { m_batch = batch; body.OnCollision += (unused) => OnCollision(); m_position = body.Position; } private void OnCollision() { m_isHit = true; m_glass.Play(); } public void Update(float dt) { if (!m_isHit) return; m_totalTime += dt; m_rotation = (float)Math.Sin(m_totalTime / 1000.0f) / 2.0f; } public void Draw() { m_batch.Draw(m_chandelier, m_position, null, Color.White, m_rotation, m_origin, .75f, SpriteEffects.None, 1.0f); } public void LoadContent(ContentManager manager) { m_chandelier = manager.Load(@"Spritesheets/chandelier"); m_glass = manager.Load(@"Sounds/Misc/glass"); m_origin = new Vector2(m_chandelier.Width / 2.0f, 0.0f); m_position.Y -= m_chandelier.Height / 4.0f; } } }