BeeKeeper.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // BeeKeeper.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using Microsoft.Xna.Framework;
  12. using Microsoft.Xna.Framework.Graphics;
  13. using System.Collections.Generic;
  14. #endregion
  15. namespace HoneycombRush
  16. {
  17. /// <summary>
  18. /// Represents the beekeeper, the player's avatar.
  19. /// </summary>
  20. public class BeeKeeper : TexturedDrawableGameComponent
  21. {
  22. #region Enums
  23. /// <summary>
  24. /// Represents the direction in which the beekeeper is walking.
  25. /// </summary>
  26. enum WalkingDirection
  27. {
  28. Down = 0,
  29. Up = 8,
  30. Left = 16,
  31. Right = 24,
  32. LeftDown = 32,
  33. RightDown = 40,
  34. LeftUp = 48,
  35. RightUp = 56
  36. }
  37. #endregion
  38. #region Fields/Properties
  39. // Animation name constants
  40. const string LegAnimationKey = "LegAnimation";
  41. const string BodyAnimationKey = "BodyAnimation";
  42. const string SmokeAnimationKey = "SmokeAnimation";
  43. const string ShootingAnimationKey = "ShootingAnimation";
  44. const string BeekeeperCollectingHoneyAnimationKey = "BeekeeperCollectingHoney";
  45. const string BeekeeperDepositingHoneyAnimationKey = "BeekeeperDepositingHoney";
  46. Vector2 bodySize = new Vector2(85, 132);
  47. Vector2 velocity;
  48. Vector2 smokeAdjustment;
  49. SpriteEffects lastEffect;
  50. SpriteEffects currentEffect;
  51. // Beekeeper state variables
  52. bool needToShootSmoke;
  53. bool isStung;
  54. bool isFlashing;
  55. bool isDrawnLastStungInterval;
  56. bool isDepositingHoney;
  57. TimeSpan stungTime;
  58. TimeSpan stungDuration;
  59. TimeSpan flashingDuration;
  60. TimeSpan depositHoneyUpdatingInterval = TimeSpan.FromMilliseconds(200);
  61. TimeSpan depositHoneyUpdatingTimer = TimeSpan.Zero;
  62. TimeSpan shootSmokePuffTimer = TimeSpan.Zero;
  63. readonly TimeSpan shootSmokePuffTimerInitialValue = TimeSpan.FromMilliseconds(325);
  64. Texture2D smokeAnimationTexture;
  65. Texture2D smokePuffTexture;
  66. const int MaxSmokePuffs = 20;
  67. /// <summary>
  68. /// Contains all smoke puffs which are currently active
  69. /// </summary>
  70. public Queue<SmokePuff> FiredSmokePuffs { get; private set; }
  71. /// <summary>
  72. /// Serves as a pool of available smoke puff objects.
  73. /// </summary>
  74. Stack<SmokePuff> availableSmokePuffs;
  75. int stungDrawingInterval = 5;
  76. int stungDrawingCounter = 0;
  77. int honeyDepositFrameCount;
  78. int depositHoneyTimerCounter = -1;
  79. int collectingHoneyFrameCounter;
  80. AsyncCallback depositHoneyCallback;
  81. WalkingDirection newDirection = WalkingDirection.Up;
  82. WalkingDirection direction = WalkingDirection.Up;
  83. int lastFrameCounter;
  84. public bool IsStung
  85. {
  86. get
  87. {
  88. return isStung;
  89. }
  90. }
  91. public bool IsFlashing
  92. {
  93. get
  94. {
  95. return isFlashing;
  96. }
  97. }
  98. /// <summary>
  99. /// Mark the beekeeper as shooting or not shooting smoke.
  100. /// </summary>
  101. public bool IsShootingSmoke
  102. {
  103. set
  104. {
  105. if (!isStung)
  106. {
  107. needToShootSmoke = value;
  108. if (value)
  109. {
  110. AudioManager.PlaySound("SmokeGun_Loop");
  111. }
  112. else
  113. {
  114. shootSmokePuffTimer = TimeSpan.Zero;
  115. }
  116. }
  117. }
  118. }
  119. public override Rectangle Bounds
  120. {
  121. get
  122. {
  123. int height = (int)bodySize.Y / 10 * 8;
  124. int width = (int)bodySize.X / 10 * 5;
  125. int offsetY = ((int)bodySize.Y - height) / 2;
  126. int offsetX = ((int)bodySize.X - width) / 2;
  127. return new Rectangle((int)position.X + offsetX, (int)position.Y + offsetY, width, height);
  128. }
  129. }
  130. public override Rectangle CentralCollisionArea
  131. {
  132. get
  133. {
  134. Rectangle bounds = Bounds;
  135. int height = (int)bounds.Height / 10 * 5;
  136. int width = (int)bounds.Width / 10 * 8;
  137. int offsetY = ((int)bounds.Height - height) / 2;
  138. int offsetX = ((int)bounds.Width - width) / 2;
  139. return new Rectangle((int)bounds.X + offsetX, (int)bounds.Y + offsetY, width, height);
  140. }
  141. }
  142. public bool IsDepositingHoney
  143. {
  144. get
  145. {
  146. return isDepositingHoney;
  147. }
  148. }
  149. public bool IsCollectingHoney { get; set; }
  150. public Vector2 Position
  151. {
  152. get { return position; }
  153. }
  154. public Rectangle ThumbStickArea { get; set; }
  155. public bool IsInMotion { get; set; }
  156. #endregion
  157. #region Initialization
  158. /// <summary>
  159. /// Creates a new beekeeper instance.
  160. /// </summary>
  161. /// <param name="game">The game object.</param>
  162. /// <param name="gamePlayScreen">The gameplay screen.</param>
  163. public BeeKeeper(Game game, GameplayScreen gamePlayScreen)
  164. : base(game, gamePlayScreen)
  165. {
  166. }
  167. /// <summary>
  168. /// Initialize the beekepper.
  169. /// </summary>
  170. public override void Initialize()
  171. {
  172. // Initialize the animation
  173. AnimationDefinitions[LegAnimationKey].PlayFromFrameIndex(0);
  174. AnimationDefinitions[BodyAnimationKey].PlayFromFrameIndex(0);
  175. AnimationDefinitions[SmokeAnimationKey].PlayFromFrameIndex(0);
  176. AnimationDefinitions[ShootingAnimationKey].PlayFromFrameIndex(0);
  177. AnimationDefinitions[BeekeeperCollectingHoneyAnimationKey].PlayFromFrameIndex(0);
  178. AnimationDefinitions[BeekeeperDepositingHoneyAnimationKey].PlayFromFrameIndex(0);
  179. Point bodyAnimationFrameSize = AnimationDefinitions[LegAnimationKey].frameSize;
  180. bodySize = new Vector2(bodyAnimationFrameSize.X, bodyAnimationFrameSize.Y) * scaledSpriteBatch.ScaleVector;
  181. isStung = false;
  182. stungDuration = TimeSpan.FromSeconds(1);
  183. flashingDuration = TimeSpan.FromSeconds(2);
  184. availableSmokePuffs = new Stack<SmokePuff>(MaxSmokePuffs);
  185. FiredSmokePuffs = new Queue<SmokePuff>(MaxSmokePuffs);
  186. base.Initialize();
  187. }
  188. /// <summary>
  189. /// Loads content that will be used later on by the beekeeper.
  190. /// </summary>
  191. protected override void LoadContent()
  192. {
  193. smokeAnimationTexture = Game.Content.Load<Texture2D>("Textures/SmokeAnimationStrip");
  194. smokePuffTexture = Game.Content.Load<Texture2D>("Textures/SmokePuff");
  195. position = new Vector2(Game.GraphicsDevice.Viewport.Width / 2 - (int)bodySize.X / 2,
  196. Game.GraphicsDevice.Viewport.Height / 2 - (int)bodySize.Y / 2);
  197. // Create smoke puffs for the smoke puff pool
  198. for (int i = 0; i < MaxSmokePuffs; i++)
  199. {
  200. availableSmokePuffs.Push(new SmokePuff(Game, gamePlayScreen, smokePuffTexture));
  201. }
  202. base.LoadContent();
  203. }
  204. #endregion
  205. #region Update
  206. /// <summary>
  207. /// Updates the beekeeper's status.
  208. /// </summary>
  209. /// <param name="gameTime">Game time information</param>
  210. public override void Update(GameTime gameTime)
  211. {
  212. if (!(gamePlayScreen.IsActive && gamePlayScreen.IsStarted))
  213. {
  214. base.Update(gameTime);
  215. return;
  216. }
  217. if (IsCollectingHoney)
  218. {
  219. // We want this animation to use a sub animation
  220. // So must calculate when to call the sub animation
  221. if (collectingHoneyFrameCounter > 3)
  222. {
  223. AnimationDefinitions[BeekeeperCollectingHoneyAnimationKey].Update(gameTime, true, true);
  224. }
  225. else
  226. {
  227. AnimationDefinitions[BeekeeperCollectingHoneyAnimationKey].Update(gameTime, true, false);
  228. }
  229. collectingHoneyFrameCounter++;
  230. }
  231. else
  232. {
  233. collectingHoneyFrameCounter = 0;
  234. }
  235. if (isDepositingHoney)
  236. {
  237. if (depositHoneyUpdatingTimer == TimeSpan.Zero)
  238. {
  239. depositHoneyUpdatingTimer = gameTime.TotalGameTime;
  240. }
  241. AnimationDefinitions[BeekeeperDepositingHoneyAnimationKey].Update(gameTime, true);
  242. }
  243. // The oldest smoke puff might have expired and should therefore be recycled
  244. if ((FiredSmokePuffs.Count > 0) && (FiredSmokePuffs.Peek().IsGone))
  245. {
  246. availableSmokePuffs.Push(FiredSmokePuffs.Dequeue());
  247. }
  248. // If the beeKeeper is stung by a bee we want to create a flashing
  249. // effect.
  250. if (isStung || isFlashing)
  251. {
  252. stungDrawingCounter++;
  253. if (stungDrawingCounter > stungDrawingInterval)
  254. {
  255. stungDrawingCounter = 0;
  256. isDrawnLastStungInterval = !isDrawnLastStungInterval;
  257. }
  258. // if time is up, end the flashing effect
  259. if (stungTime + stungDuration < gameTime.TotalGameTime)
  260. {
  261. isStung = false;
  262. if (stungTime + stungDuration + flashingDuration < gameTime.TotalGameTime)
  263. {
  264. isFlashing = false;
  265. stungDrawingCounter = -1;
  266. }
  267. AnimationDefinitions[LegAnimationKey].Update(gameTime, IsInMotion);
  268. }
  269. }
  270. else
  271. {
  272. AnimationDefinitions[LegAnimationKey].Update(gameTime, IsInMotion);
  273. }
  274. if (needToShootSmoke)
  275. {
  276. AnimationDefinitions[SmokeAnimationKey].Update(gameTime, needToShootSmoke);
  277. shootSmokePuffTimer -= gameTime.ElapsedGameTime;
  278. if (shootSmokePuffTimer <= TimeSpan.Zero)
  279. {
  280. ShootSmoke();
  281. shootSmokePuffTimer = shootSmokePuffTimerInitialValue;
  282. }
  283. }
  284. base.Update(gameTime);
  285. }
  286. #endregion
  287. #region Render
  288. /// <summary>
  289. /// Renders the beekeeper.
  290. /// </summary>
  291. /// <param name="gameTime"></param>
  292. public override void Draw(GameTime gameTime)
  293. {
  294. if (!(gamePlayScreen.IsActive && gamePlayScreen.IsStarted))
  295. {
  296. base.Draw(gameTime);
  297. return;
  298. }
  299. // Make sure not to draw the beekeeper while flashing
  300. if (isStung || isFlashing)
  301. {
  302. if (stungDrawingCounter != stungDrawingInterval)
  303. {
  304. if (isDrawnLastStungInterval)
  305. {
  306. return;
  307. }
  308. }
  309. }
  310. scaledSpriteBatch.Begin();
  311. // if stung we want to show another animation
  312. if (isStung)
  313. {
  314. scaledSpriteBatch.Draw(Game.Content.Load<Texture2D>("Textures/hit"), position, Color.White);
  315. scaledSpriteBatch.End();
  316. return;
  317. }
  318. // If collecting honey, draw the appropriate animation
  319. if (IsCollectingHoney)
  320. {
  321. AnimationDefinitions[BeekeeperCollectingHoneyAnimationKey].Draw(scaledSpriteBatch, position,
  322. SpriteEffects.None);
  323. scaledSpriteBatch.End();
  324. return;
  325. }
  326. if (isDepositingHoney)
  327. {
  328. if (velocity != Vector2.Zero)
  329. {
  330. isDepositingHoney = false;
  331. AudioManager.StopSound("DepositingIntoVat_Loop");
  332. }
  333. // We want the deposit duration to sync with the deposit
  334. // animation
  335. // So we manage the timing ourselves
  336. if (depositHoneyUpdatingTimer != TimeSpan.Zero &&
  337. depositHoneyUpdatingTimer + depositHoneyUpdatingInterval < gameTime.TotalGameTime)
  338. {
  339. depositHoneyTimerCounter++;
  340. depositHoneyUpdatingTimer = TimeSpan.Zero;
  341. }
  342. AnimationDefinitions[BeekeeperDepositingHoneyAnimationKey].Draw(scaledSpriteBatch, position,
  343. SpriteEffects.None);
  344. if (depositHoneyTimerCounter == honeyDepositFrameCount - 1)
  345. {
  346. isDepositingHoney = false;
  347. depositHoneyCallback.Invoke(null);
  348. AnimationDefinitions[BeekeeperDepositingHoneyAnimationKey].PlayFromFrameIndex(0);
  349. }
  350. scaledSpriteBatch.End();
  351. return;
  352. }
  353. bool hadDirectionChanged = false;
  354. // See if the direction changed
  355. if (newDirection != direction)
  356. {
  357. hadDirectionChanged = true;
  358. direction = newDirection;
  359. }
  360. if (hadDirectionChanged)
  361. {
  362. // Update the animation
  363. lastFrameCounter = 0;
  364. AnimationDefinitions[LegAnimationKey].PlayFromFrameIndex(lastFrameCounter + (int)direction);
  365. AnimationDefinitions[ShootingAnimationKey].PlayFromFrameIndex(lastFrameCounter + (int)direction);
  366. AnimationDefinitions[BodyAnimationKey].PlayFromFrameIndex(lastFrameCounter + (int)direction);
  367. }
  368. else
  369. {
  370. // Because our animation is 8 cells, but the row is 16 cells,
  371. // we need to reset the counter after 8 rounds
  372. if (lastFrameCounter == 8)
  373. {
  374. lastFrameCounter = 0;
  375. AnimationDefinitions[LegAnimationKey].PlayFromFrameIndex(lastFrameCounter + (int)direction);
  376. AnimationDefinitions[ShootingAnimationKey].PlayFromFrameIndex(
  377. lastFrameCounter + (int)direction);
  378. AnimationDefinitions[BodyAnimationKey].PlayFromFrameIndex(lastFrameCounter + (int)direction);
  379. }
  380. else
  381. {
  382. lastFrameCounter++;
  383. }
  384. }
  385. AnimationDefinitions[LegAnimationKey].Draw(scaledSpriteBatch, position, 1f, SpriteEffects.None);
  386. if (needToShootSmoke)
  387. {
  388. // Draw the body
  389. AnimationDefinitions[ShootingAnimationKey].Draw(scaledSpriteBatch, position, 1f, SpriteEffects.None);
  390. // If true we need to draw smoke
  391. if (smokeAdjustment != Vector2.Zero)
  392. {
  393. AnimationDefinitions[SmokeAnimationKey].Draw(scaledSpriteBatch, position + smokeAdjustment, 1f,
  394. currentEffect);
  395. }
  396. }
  397. else
  398. {
  399. AnimationDefinitions[BodyAnimationKey].Draw(scaledSpriteBatch, position, 1f, SpriteEffects.None);
  400. }
  401. scaledSpriteBatch.End();
  402. base.Draw(gameTime);
  403. }
  404. #endregion
  405. #region Public Methods
  406. /// <summary>
  407. /// Checks if a given rectanlge intersects with one of the smoke puffs fired by the beekeeper.
  408. /// </summary>
  409. /// <param name="checkRectangle">The rectangle to check for collisions with smoke puffs.</param>
  410. /// <returns>One of the smoke puffs with which the supplied regtangle collides, or null if it collides with
  411. /// none.</returns>
  412. public SmokePuff CheckSmokeCollision(Rectangle checkRectangle)
  413. {
  414. foreach (SmokePuff smokePuff in FiredSmokePuffs)
  415. {
  416. if (checkRectangle.HasCollision(smokePuff.CentralCollisionArea))
  417. {
  418. return smokePuff;
  419. }
  420. }
  421. return null;
  422. }
  423. /// <summary>
  424. /// Maek the beekeeper as being stung by a bee.
  425. /// </summary>
  426. /// <param name="occurTime">The time at which the beekeeper was stung.</param>
  427. public void Stung(TimeSpan occurTime)
  428. {
  429. if (!isStung && !isFlashing)
  430. {
  431. isStung = true;
  432. isFlashing = true;
  433. stungTime = occurTime;
  434. needToShootSmoke = false;
  435. }
  436. }
  437. /// <summary>
  438. /// Updates the beekeeper's position.
  439. /// </summary>
  440. /// <param name="movement">A vector which contains the desired adjustment to
  441. /// the beekeeper's position.</param>
  442. public void SetMovement(Vector2 movement)
  443. {
  444. if (!IsStung)
  445. {
  446. velocity = movement;
  447. position += velocity;
  448. }
  449. }
  450. /// <summary>
  451. /// Makes sure the beekeeper's direction matches his movement direction.
  452. /// </summary>
  453. /// <param name="movementDirection">A vector indicating the beekeeper's movement
  454. /// direction.</param>
  455. public void SetDirection(Vector2 movementDirection)
  456. {
  457. DetermineDirection(movementDirection, ref newDirection, ref smokeAdjustment);
  458. currentEffect = GetSpriteEffect(movementDirection);
  459. }
  460. /// <summary>
  461. /// Starts the process of transferring honey to the honey vat.
  462. /// </summary>
  463. /// <param name="honeyDepositFrameCount">The amount of frames in the honey
  464. /// depositing animation.</param>
  465. /// <param name="callback">Callback to invoke once the process is
  466. /// complete.</param>
  467. public void StartTransferHoney(int honeyDepositFrameCount, AsyncCallback callback)
  468. {
  469. depositHoneyCallback = callback;
  470. this.honeyDepositFrameCount = honeyDepositFrameCount;
  471. isDepositingHoney = true;
  472. depositHoneyTimerCounter = 0;
  473. AudioManager.PlaySound("DepositingIntoVat_Loop");
  474. }
  475. /// <summary>
  476. /// Marks the honey transfer process as complete.
  477. /// </summary>
  478. public void EndTransferHoney()
  479. {
  480. isDepositingHoney = false;
  481. }
  482. #endregion
  483. #region Private Methods
  484. /// <summary>
  485. /// Shoots a puff of smoke. If too many puffs of smoke have already been fired, the oldest one vanishes and
  486. /// is replaced with a new one.
  487. /// </summary>
  488. private void ShootSmoke()
  489. {
  490. SmokePuff availableSmokePuff;
  491. if (availableSmokePuffs.Count > 0)
  492. {
  493. // Take a smoke puff from the pool
  494. availableSmokePuff = availableSmokePuffs.Pop();
  495. }
  496. else
  497. {
  498. // Take the oldest smoke puff and use it
  499. availableSmokePuff = FiredSmokePuffs.Dequeue();
  500. }
  501. Vector2 beeKeeperCenter = Bounds.Center.GetVector();
  502. Vector2 smokeInitialPosition = beeKeeperCenter;
  503. availableSmokePuff.Fire(smokeInitialPosition, GetSmokeVelocityVector());
  504. FiredSmokePuffs.Enqueue(availableSmokePuff);
  505. }
  506. /// <summary>
  507. /// Used to return a vector which will serve as shot smoke velocity.
  508. /// </summary>
  509. /// <returns>A vector which serves as the initial velocity of smoke puffs being shot.</returns>
  510. private Vector2 GetSmokeVelocityVector()
  511. {
  512. Vector2 initialVector;
  513. switch (direction)
  514. {
  515. case WalkingDirection.Down:
  516. initialVector = new Vector2(0, 1);
  517. break;
  518. case WalkingDirection.Up:
  519. initialVector = new Vector2(0, -1);
  520. break;
  521. case WalkingDirection.Left:
  522. initialVector = new Vector2(-1, 0);
  523. break;
  524. case WalkingDirection.Right:
  525. initialVector = new Vector2(1, 0);
  526. break;
  527. case WalkingDirection.LeftDown:
  528. initialVector = new Vector2(-1, 1);
  529. break;
  530. case WalkingDirection.RightDown:
  531. initialVector = new Vector2(1, 1);
  532. break;
  533. case WalkingDirection.LeftUp:
  534. initialVector = new Vector2(-1, -1);
  535. break;
  536. case WalkingDirection.RightUp:
  537. initialVector = new Vector2(1, -1);
  538. break;
  539. default:
  540. throw new InvalidOperationException("Determining the vector for an invalid walking direction");
  541. }
  542. return initialVector * 2f + velocity * 1f;
  543. }
  544. /// <summary>
  545. /// Returns an effect appropriate to the supplied vector which either does
  546. /// nothing or flips the beekeeper horizontally.
  547. /// </summary>
  548. /// <param name="movementDirection">A vector depicting the beekeeper's
  549. /// movement.</param>
  550. /// <returns>A sprite effect that should be applied to the beekeeper.</returns>
  551. private SpriteEffects GetSpriteEffect(Vector2 movementDirection)
  552. {
  553. // Checks if there is any movement input
  554. if (movementDirection != Vector2.Zero)
  555. {
  556. // If beekeeper is facing left
  557. if (movementDirection.X < 0)
  558. {
  559. lastEffect = SpriteEffects.FlipHorizontally;
  560. }
  561. else if (movementDirection.X > 0)
  562. {
  563. lastEffect = SpriteEffects.None;
  564. }
  565. }
  566. return lastEffect;
  567. }
  568. /// <summary>
  569. /// Returns movement information according to the current virtual thumbstick input.
  570. /// </summary>
  571. /// <param name="movement">Vector indicating the current beekeeper movement.</param>
  572. /// <param name="tempDirection">Enum describing the inpot direction.</param>
  573. /// <param name="smokeAdjustment">Adjustment to smoke position according to input direction.</param>
  574. private void DetermineDirection(Vector2 movement, ref WalkingDirection tempDirection,
  575. ref Vector2 smokeAdjustment)
  576. {
  577. if (movement == Vector2.Zero)
  578. {
  579. return;
  580. }
  581. if (Math.Abs(movement.X) > Math.Abs(movement.Y))
  582. {
  583. DetermineDirectionDominantX(movement, ref tempDirection, ref smokeAdjustment);
  584. }
  585. else
  586. {
  587. DetermineDirectionDominantY(movement, ref tempDirection, ref smokeAdjustment);
  588. }
  589. }
  590. /// <summary>
  591. /// Returns movement information according to the current virtual thumbstick input, given that advancement
  592. /// along the X axis is greater than along the Y axis.
  593. /// </summary>
  594. /// <param name="movement">Vector indicating the current beekeeper movement.</param>
  595. /// <param name="tempDirection">Enum describing the input direction.</param>
  596. /// <param name="smokeAdjustment">Adjustment to smoke position according to input direction.</param>
  597. private void DetermineDirectionDominantX(Vector2 movement, ref WalkingDirection tempDirection,
  598. ref Vector2 smokeAdjustment)
  599. {
  600. if (movement.X > 0)
  601. {
  602. if (movement.Y > 0.25f)
  603. {
  604. tempDirection = WalkingDirection.RightDown;
  605. smokeAdjustment = new Vector2(UIConstants.SprayRightOffset, UIConstants.SprayDownOffset);
  606. }
  607. else if (movement.Y < -0.25f)
  608. {
  609. tempDirection = WalkingDirection.RightUp;
  610. smokeAdjustment = new Vector2(UIConstants.SprayRightOffset, UIConstants.SprayUpOffset);
  611. }
  612. else
  613. {
  614. tempDirection = WalkingDirection.Right;
  615. smokeAdjustment = new Vector2(UIConstants.SprayRightOffset, UIConstants.SprayMiddleOffset);
  616. }
  617. }
  618. else
  619. {
  620. if (movement.Y > 0.25f)
  621. {
  622. tempDirection = WalkingDirection.LeftDown;
  623. smokeAdjustment = new Vector2(-UIConstants.SprayLeftOffset, UIConstants.SprayDownOffset);
  624. }
  625. else if (movement.Y < -0.25f)
  626. {
  627. tempDirection = WalkingDirection.LeftUp;
  628. smokeAdjustment = new Vector2(-UIConstants.SprayLeftOffset, UIConstants.SprayUpOffset);
  629. }
  630. else
  631. {
  632. tempDirection = WalkingDirection.Left;
  633. smokeAdjustment = new Vector2(-UIConstants.SprayLeftOffset, UIConstants.SprayMiddleOffset);
  634. }
  635. }
  636. }
  637. /// <summary>
  638. /// Returns movement information according to the current virtual thumbstick input, given that advancement
  639. /// along the Y axis is greater than along the X axis.
  640. /// </summary>
  641. /// <param name="movement">Vector indicating the current beekeeper movement.</param>
  642. /// <param name="tempDirection">Enum describing the input direction.</param>
  643. /// <param name="smokeAdjustment">Adjustment to smoke position according to input direction.</param>
  644. private void DetermineDirectionDominantY(Vector2 movement, ref WalkingDirection tempDirection,
  645. ref Vector2 smokeAdjustment)
  646. {
  647. if (movement.Y > 0)
  648. {
  649. if (movement.X > 0.25f)
  650. {
  651. tempDirection = WalkingDirection.RightDown;
  652. smokeAdjustment = new Vector2(UIConstants.SprayRightOffset, UIConstants.SprayDownOffset);
  653. }
  654. else if (movement.X < -0.25f)
  655. {
  656. tempDirection = WalkingDirection.LeftDown;
  657. smokeAdjustment = new Vector2(-UIConstants.SprayLeftOffset, UIConstants.SprayDownOffset);
  658. }
  659. else
  660. {
  661. tempDirection = WalkingDirection.Down;
  662. smokeAdjustment = Vector2.Zero;
  663. }
  664. }
  665. else
  666. {
  667. if (movement.X > 0.25f)
  668. {
  669. tempDirection = WalkingDirection.RightUp;
  670. smokeAdjustment = new Vector2(UIConstants.SprayRightOffset, UIConstants.SprayUpOffset);
  671. }
  672. else if (movement.X < -0.25f)
  673. {
  674. tempDirection = WalkingDirection.LeftUp;
  675. smokeAdjustment = new Vector2(-UIConstants.SprayLeftOffset, UIConstants.SprayUpOffset);
  676. }
  677. else
  678. {
  679. tempDirection = WalkingDirection.Up;
  680. smokeAdjustment = Vector2.Zero;
  681. }
  682. }
  683. }
  684. #endregion
  685. }
  686. }