using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace FuelCell { public class FuelCell : GameObject { public bool Retrieved { get; set; } private SoundEffect fuelCellCollect; public FuelCell() : base() { Retrieved = false; } public void LoadContent(ContentManager content, string modelName) { Model = content.Load(modelName); BoundingSphere = CalculateBoundingSphere(); Position = Vector3.Down; fuelCellCollect = content.Load("Audio/fuelcell-collect"); BoundingSphere scaledSphere; scaledSphere = BoundingSphere; scaledSphere.Radius *= GameConstants.FuelCellBoundingSphereFactor; BoundingSphere = new BoundingSphere(scaledSphere.Center, scaledSphere.Radius); } public void Draw(Matrix view, Matrix projection) { Matrix translateMatrix = Matrix.CreateTranslation(Position); Matrix worldMatrix = translateMatrix; if (!Retrieved) { foreach (ModelMesh mesh in Model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = worldMatrix; effect.View = view; effect.Projection = projection; effect.EnableDefaultLighting(); effect.PreferPerPixelLighting = true; } mesh.Draw(); } } } internal void Update(BoundingSphere vehicleBoundingSphere) { if (vehicleBoundingSphere.Intersects(this.BoundingSphere) && !this.Retrieved) { this.Retrieved = true; fuelCellCollect.Play(); } } } }