Barrier.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Content;
  3. using Microsoft.Xna.Framework.Graphics;
  4. namespace FuelCell
  5. {
  6. public class Barrier : GameObject
  7. {
  8. public string BarrierType { get; set; }
  9. public Barrier()
  10. : base()
  11. {
  12. BarrierType = null;
  13. }
  14. public void LoadContent(ContentManager content, string modelName)
  15. {
  16. Model = content.Load<Model>(modelName);
  17. BarrierType = modelName;
  18. BoundingSphere = CalculateBoundingSphere();
  19. Position = Vector3.Down;
  20. BoundingSphere scaledSphere;
  21. scaledSphere = BoundingSphere;
  22. scaledSphere.Radius *= GameConstants.BarrierBoundingSphereFactor;
  23. BoundingSphere = new BoundingSphere(scaledSphere.Center, scaledSphere.Radius);
  24. }
  25. public void Draw(Matrix view, Matrix projection)
  26. {
  27. Matrix translateMatrix = Matrix.CreateTranslation(Position);
  28. Matrix worldMatrix = translateMatrix;
  29. foreach (ModelMesh mesh in Model.Meshes)
  30. {
  31. foreach (BasicEffect effect in mesh.Effects)
  32. {
  33. effect.World = worldMatrix;
  34. effect.View = view;
  35. effect.Projection = projection;
  36. effect.EnableDefaultLighting();
  37. effect.PreferPerPixelLighting = true;
  38. }
  39. mesh.Draw();
  40. }
  41. }
  42. }
  43. }