AI.cs 2.0 KB

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