AI.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // AI.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region File Information
  10. //-----------------------------------------------------------------------------
  11. // AI.cs
  12. //
  13. // Microsoft XNA Community Game Platform
  14. // Copyright (C) Microsoft Corporation. All rights reserved.
  15. //-----------------------------------------------------------------------------
  16. #endregion
  17. #region Using Statements
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using Microsoft.Xna.Framework;
  23. using Microsoft.Xna.Framework.Graphics;
  24. #endregion
  25. namespace CatapultGame
  26. {
  27. class AI : Human
  28. {
  29. #region Fields
  30. Random random;
  31. #endregion
  32. #region Initialization
  33. public AI(Game game)
  34. : base(game)
  35. {
  36. }
  37. public AI(Game game, SpriteBatch screenSpriteBatch)
  38. : base(game, screenSpriteBatch, PlayerSide.Right)
  39. {
  40. Catapult = new Catapult(game, screenSpriteBatch,
  41. "Textures/Catapults/Red/redIdle/redIdle",
  42. new Vector2(600, 332), SpriteEffects.FlipHorizontally, true);
  43. }
  44. public override void Initialize()
  45. {
  46. //Initialize randomizer
  47. random = new Random();
  48. IsAI = true;
  49. //Catapult.Initialize();
  50. base.Initialize();
  51. }
  52. #endregion
  53. #region Update
  54. public override void Update(GameTime gameTime)
  55. {
  56. // Check if it is time to take a shot
  57. if (Catapult.CurrentState == CatapultState.Aiming &&
  58. !Catapult.AnimationRunning)
  59. {
  60. // Fire at a random strength
  61. float shotVelocity =
  62. random.Next((int)MinShotStrength, (int)MaxShotStrength);
  63. Catapult.ShotStrength = (shotVelocity / MaxShotStrength);
  64. Catapult.ShotVelocity = shotVelocity;
  65. }
  66. base.Update(gameTime);
  67. }
  68. #endregion
  69. }
  70. }