| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- 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<Model>(modelName);
- BoundingSphere = CalculateBoundingSphere();
- Position = Vector3.Down;
- fuelCellCollect = content.Load<SoundEffect>("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();
- }
- }
- }
- }
|