Advertisement
adolciaaa

ARKANOID

Oct 16th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.60 KB | None | 0 0
  1. KLOCEK
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using Microsoft.Xna.Framework;
  8.  
  9. namespace arkanoid
  10. {
  11. class klocek : Microsoft.Xna.Framework.Game
  12. {
  13.  
  14. public double wytrzymalosc;
  15. public double pozycjax;
  16. public double pozycjay;
  17. public Color kolor;
  18.  
  19. public klocek(double roz, double pozx, double pozy)
  20. {
  21. wytrzymalosc = roz;
  22. pozycjax = pozx;
  23. pozycjay = pozy;
  24. kolor = Color.Black;
  25. }
  26.  
  27. void oberwanie()
  28. {
  29. wytrzymalosc--;
  30. }
  31.  
  32.  
  33. public void zmienkolor()
  34. {
  35. wytrzymalosc--;
  36.  
  37. if (wytrzymalosc == 2)
  38. {
  39. kolor = Color.Black;
  40. }
  41. if (wytrzymalosc == 1)
  42. {
  43. kolor = Color.White;
  44.  
  45. }
  46.  
  47.  
  48. }
  49. }
  50.  
  51. }---------------------------------------------------------------------------
  52. Kulka
  53.  
  54. using System;
  55. using System.Collections.Generic;
  56. using System.Linq;
  57. using System.Text;
  58.  
  59. namespace arkanoid
  60. {
  61. class kula
  62. {
  63. public double x;
  64. public double y;
  65. public double rozmiar;
  66. public double kat;
  67. public double predkosc;
  68. public kula(double a, double b, double c, double d, double e)
  69. {
  70. x = a;
  71. y = b;
  72. rozmiar = c;
  73. kat = d;
  74. predkosc = e;
  75. }
  76.  
  77. }
  78. }
  79. -------------------------------------------------------------------------------
  80. GRACZ
  81.  
  82. using System;
  83. using System.Collections.Generic;
  84. using System.Linq;
  85. using System.Text;
  86.  
  87. namespace arkanoid
  88. {
  89. class Gracz
  90. {
  91. public int rozmiar;
  92. public int pozycjax;
  93. public int pozycjay;
  94. public static int ilosczyc;
  95.  
  96. public Gracz(int roz, int pozx, int pozy)
  97. {
  98. rozmiar = roz;
  99. pozycjax = pozx;
  100. pozycjay = pozy;
  101. ilosczyc = 3;
  102. }
  103. }
  104. }
  105. -------------------------------------------------------------------------------------
  106. GAME
  107. using System;
  108. using System.Collections.Generic;
  109. using System.Linq;
  110. using Microsoft.Xna.Framework;
  111. using Microsoft.Xna.Framework.Audio;
  112. using Microsoft.Xna.Framework.Content;
  113. using Microsoft.Xna.Framework.GamerServices;
  114. using Microsoft.Xna.Framework.Graphics;
  115. using Microsoft.Xna.Framework.Input;
  116. using Microsoft.Xna.Framework.Media;
  117.  
  118. namespace arkanoid
  119. {
  120. /// <summary>
  121. /// This is the main type for your game
  122. /// </summary>
  123. public class Game1 : Microsoft.Xna.Framework.Game
  124. {
  125. GraphicsDeviceManager graphics;
  126. int wynik = 0;
  127.  
  128. int a, b;
  129. SpriteBatch spriteBatch;
  130. SpriteFont font;
  131. Gracz player;
  132. kula bala;
  133. Texture2D grac, pilka, kloc;
  134. List<klocek> klocki;
  135. Rectangle g;
  136. Rectangle p;
  137. Rectangle k;
  138. string cos = "aa";
  139. public Game1()
  140. {
  141. graphics = new GraphicsDeviceManager(this);
  142. Content.RootDirectory = "Content";
  143. graphics.PreferredBackBufferHeight = 800;
  144. graphics.PreferredBackBufferWidth = 600;
  145. graphics.IsFullScreen = true;
  146.  
  147. }
  148.  
  149. /// <summary>
  150. /// Allows the game to perform any initialization it needs to before starting to run.
  151. /// This is where it can query for any required services and load any non-graphic
  152. /// related content. Calling base.Initialize will enumerate through any components
  153. /// and initialize them as well.
  154. /// </summary>
  155. protected override void Initialize()
  156. {
  157. // TODO: Add your initialization logic here
  158.  
  159. base.Initialize();
  160. player = new Gracz(100, (GraphicsDevice.Viewport.Width / 2), (GraphicsDevice.Viewport.Height * 7 / 8));
  161. bala = new kula((GraphicsDevice.Viewport.Width / 2), (GraphicsDevice.Viewport.Height / 2), 100, 45, 5);
  162. klocki = new List<klocek>();
  163. tworzenieklockow();
  164. }
  165.  
  166. /// <summary>
  167. /// LoadContent will be called once per game and is the place to load
  168. /// all of your content.
  169. /// </summary>
  170. protected override void LoadContent()
  171. {
  172. // Create a new SpriteBatch, which can be used to draw textures.
  173. spriteBatch = new SpriteBatch(GraphicsDevice);
  174. font = Content.Load<SpriteFont>(@"Spritefont1");
  175. grac = Content.Load<Texture2D>(@"stat");
  176. pilka = Content.Load<Texture2D>(@"kulka");
  177. kloc = Content.Load<Texture2D>(@"klocek");
  178.  
  179. // TODO: use this.Content to load your game content here
  180. }
  181.  
  182. /// <summary>
  183. /// UnloadContent will be called once per game and is the place to unload
  184. /// all content.
  185. /// </summary>
  186. protected override void UnloadContent()
  187. {
  188. // TODO: Unload any non ContentManager content here
  189. }
  190.  
  191. /// <summary>
  192. /// Allows the game to run logic such as updating the world,
  193. /// checking for collisions, gathering input, and playing audio.
  194. /// </summary>
  195. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  196. protected override void Update(GameTime gameTime)
  197. {
  198.  
  199. // Allows the game to exit
  200. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  201. this.Exit();
  202. if (Keyboard.GetState().IsKeyDown(Keys.Escape) == true) { this.Exit(); }
  203. if (Keyboard.GetState().IsKeyDown(Keys.Right) == true) { player.pozycjax += 16; }
  204. if (Keyboard.GetState().IsKeyDown(Keys.Left) == true) { player.pozycjax -= 16; }
  205. // TODO: Add your update logic here
  206. bala.y -= 10 * (Math.Cos(bala.kat * MathHelper.Pi / 180));
  207. bala.x += 10 * (Math.Sin(bala.kat * MathHelper.Pi / 180));
  208. base.Update(gameTime);
  209.  
  210. p = new Rectangle((int)bala.x, (int)bala.y, 30, 30);
  211. for (int i = 0; i < klocki.Count(); i++)
  212. {
  213. k = new Rectangle((int)klocki[i].pozycjax, (int)klocki[i].pozycjay, 100, 30);
  214.  
  215. if (p.Intersects(k))
  216. {
  217.  
  218. klocki[i].zmienkolor();
  219. if (klocki[i].wytrzymalosc == 0)
  220. {
  221. klocki.RemoveAt(i);
  222. }
  223. bala.kat = 180 - bala.kat;
  224.  
  225. wynik++;
  226.  
  227. }
  228. }
  229. if (bala.y < 0)
  230. {
  231. bala.kat = 180 - bala.kat;
  232. }
  233. if (bala.x > GraphicsDevice.Viewport.Width - 35)
  234. {
  235. bala.kat = 360 - bala.kat;
  236.  
  237. }
  238. if (bala.x < 10)
  239. {
  240. bala.kat = 360 - bala.kat;
  241.  
  242. }
  243. g = new Rectangle(player.pozycjax, player.pozycjay, 100, 30);
  244. if (g.Intersects(p))
  245. {
  246. bala.kat = ((int)bala.x - (player.pozycjax + 35));
  247. }
  248. }
  249.  
  250. /// <summary>
  251. /// This is called when the game should draw itself.
  252. /// </summary>6
  253. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  254. protected override void Draw(GameTime gameTime)
  255. {
  256. GraphicsDevice.Clear(Color.CornflowerBlue);
  257. spriteBatch.Begin();
  258. spriteBatch.DrawString(font, ("wynik :" + wynik.ToString()), new Vector2(100, 100), Color.Black);
  259. spriteBatch.DrawString(font, cos, new Vector2(200, 200), Color.Black);
  260. spriteBatch.Draw(grac, new Rectangle(player.pozycjax, player.pozycjay, 100, 20), Color.White);
  261. spriteBatch.Draw(pilka, new Rectangle((int)bala.x, (int)bala.y, 30, 30), Color.White);
  262.  
  263. foreach (klocek klo in klocki)
  264. {
  265. spriteBatch.Draw(kloc, new Rectangle((int)klo.pozycjax, (int)klo.pozycjay, 100, 30), klo.kolor);
  266. }
  267.  
  268. spriteBatch.End();
  269.  
  270. // TODO: Add your drawing code here
  271.  
  272. base.Draw(gameTime);
  273. }
  274. void tworzenieklockow()
  275. {
  276. for (int i = 0; i < 10; i++)
  277. {
  278. for (int j = 0; j < 4; j++)
  279. {
  280.  
  281. klocek kl = new klocek(2, (GraphicsDevice.Viewport.Width / 11 * i), (GraphicsDevice.Viewport.Height / 15 * j));
  282. klocki.Add(kl);
  283. }
  284. }
  285.  
  286. }
  287.  
  288.  
  289.  
  290. }
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement