Advertisement
Guest User

Rockets.cs

a guest
Oct 23rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Content;
  3. using Microsoft.Xna.Framework.Graphics;
  4. using Microsoft.Xna.Framework.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10.  
  11. namespace Pong
  12. {
  13. class Rockets
  14. {
  15. public Rectangle rocketUp1;
  16. public Rectangle rocketMiddle1;
  17. public Rectangle rocketDown1;
  18. public Rectangle rocketUp2;
  19. public Rectangle rocketMiddle2;
  20. public Rectangle rocketDown2;
  21.  
  22. public Texture2D rocketTexture1;
  23. public Texture2D rocketTexture2;
  24.  
  25.  
  26.  
  27. public Rockets()
  28. {
  29. rocketUp1 = new Rectangle(0, 250, 25, 25);
  30. rocketMiddle1 = new Rectangle(0, 275, 25, 25);
  31. rocketDown1 = new Rectangle(0, 300, 25, 25);
  32.  
  33. rocketUp2 = new Rectangle(775, 250, 25, 25);
  34. rocketMiddle2 = new Rectangle(775, 275, 25, 25);
  35. rocketDown2 = new Rectangle(775, 300, 25, 25);
  36. }
  37.  
  38. public void LoadContent(ContentManager Content)
  39. {
  40. rocketTexture1 = Content.Load<Texture2D>("rocket_1");
  41. rocketTexture2 = Content.Load<Texture2D>("rocket_2");
  42.  
  43. }
  44. public void Update(GameTime gameTime)
  45. {
  46. if(Keyboard.GetState().IsKeyDown(Keys.Q))
  47. {
  48. rocketUp1.Y -= 2;
  49. rocketMiddle1.Y -= 2;
  50. rocketDown1.Y -= 2;
  51. }
  52. if (Keyboard.GetState().IsKeyDown(Keys.A))
  53. {
  54. rocketUp1.Y += 2;
  55. rocketMiddle1.Y += 2;
  56. rocketDown1.Y += 2;
  57. }
  58. if (Keyboard.GetState().IsKeyDown(Keys.P))
  59. {
  60. rocketUp2.Y -= 2;
  61. rocketMiddle2.Y -= 2;
  62. rocketDown2.Y -= 2;
  63. }
  64. if (Keyboard.GetState().IsKeyDown(Keys.L))
  65. {
  66. rocketUp2.Y += 2;
  67. rocketMiddle2.Y += 2;
  68. rocketDown2.Y += 2;
  69. }
  70. if(rocketUp1.Y <= 0)
  71. {
  72. rocketUp1.Y = 0;
  73. rocketMiddle1.Y = 25;
  74. rocketDown1.Y = 50;
  75. }
  76. if (rocketUp2.Y <= 0)
  77. {
  78. rocketUp2.Y = 0;
  79. rocketMiddle2.Y = 25;
  80. rocketDown2.Y = 50;
  81. }
  82. if (rocketUp1.Y >=525)
  83. {
  84. rocketUp1.Y = 525;
  85. rocketMiddle1.Y = 550;
  86. rocketDown1.Y = 575;
  87. }
  88. if (rocketUp2.Y >= 525)
  89. {
  90. rocketUp2.Y = 525;
  91. rocketMiddle2.Y = 550;
  92. rocketDown2.Y = 575;
  93. }
  94.  
  95. }
  96. public void Draw(SpriteBatch spriteBatch)
  97. {
  98. spriteBatch.Draw(rocketTexture1, rocketUp1, Color.White);
  99. spriteBatch.Draw(rocketTexture1, rocketMiddle1, Color.White);
  100. spriteBatch.Draw(rocketTexture1, rocketDown1, Color.White);
  101.  
  102. spriteBatch.Draw(rocketTexture2, rocketUp2, Color.White);
  103. spriteBatch.Draw(rocketTexture2, rocketMiddle2, Color.White);
  104. spriteBatch.Draw(rocketTexture2, rocketDown2, Color.White);
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement