desdemona

gm1

May 13th, 2012
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 58.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>
  12. using ScrollingBackgroundSpace;
  13. using CameraSpace;
  14. using PlayerNamespace;
  15. using tut1;
  16. using TerrainNamespace;
  17. using enemy;
  18. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>
  19.  
  20. namespace tut1
  21. {
  22. public class obiect
  23. {
  24. public Vector2 position;
  25. public virtual void Update(GameTime theGameTime, Vector2 theSpeed, Vector2 theDirection)
  26. {
  27.  
  28. if (theDirection.X > 0)
  29. {
  30. position += theDirection * theSpeed * (float)theGameTime.ElapsedGameTime.TotalSeconds;
  31. }
  32. else
  33. {
  34. if (position.X > 0)
  35. {
  36. position += theDirection * theSpeed * (float)theGameTime.ElapsedGameTime.TotalSeconds;
  37. }
  38. }
  39.  
  40.  
  41. }
  42.  
  43.  
  44. }
  45.  
  46. public class animation
  47. {
  48. public animation(int total)
  49. {
  50. this.total_frames = total;
  51. this.current_frame = 0;
  52. this.previous_framechange = 0;
  53. }
  54.  
  55. public int total_frames;
  56. public int current_frame;
  57. public float previous_framechange;
  58. }
  59.  
  60.  
  61. /// <summary>
  62. /// This is the main type for your game
  63. /// </summary>
  64. public class Game1 : Microsoft.Xna.Framework.Game
  65. {
  66. public int gameState = 0;//stan gry
  67. public int tocontinue = 0;//0 menu, 1- continuemenu
  68. public int current_stage = 1;
  69. int score = 0;
  70. const int introMenu = 0, gameRunning = 1,hiscores = 2, credits = 3, paused = 4,settings = 5, pausesettings = 6;//Stany gry
  71. //Tu można dodać menu
  72. MenuComponent menu;
  73. MenuComponent gameMenu;
  74. MenuComponent continueMenu;
  75. MenuComponent settingsMenu;//do deklaracji potem
  76. MenuComponent settingsPauseMenu;//do deklaracji potem
  77. MenuComponent hiscoreMenu;//do deklaracji potem
  78. MenuComponent creditsMenu;
  79. string[] onoff = { "on", "off" };
  80.  
  81. //Dźwięki tu ładować
  82. SoundEffect menuSound;
  83. SoundEffect gameSound;
  84. SoundEffect pauseSound;
  85. SoundEffect shootSound;
  86. SoundEffectInstance menuInstance;//instancje można stopować i pauzować, do dzwięku trzeba zrobić instancje
  87. SoundEffectInstance gameInstance;
  88. SoundEffectInstance pauseInstance;
  89. SoundEffectInstance shootInstance;
  90.  
  91. //lista strzałów
  92. public List<shoot> enemyBullets;
  93. List<shoot> bulletsList;
  94. public int soundEnabled;//1 no, 0 yes
  95. //grafika
  96. GraphicsDeviceManager graphics;
  97. SpriteBatch spriteBatch;
  98. GraphicsDevice device;
  99.  
  100. private ScrollingBackground MyBackground;
  101.  
  102. public List<level> stages;
  103.  
  104. //textury tu
  105. Texture2D Clouds;
  106. Texture2D foregroundTexture;
  107. Texture2D playerTexture;
  108. Texture2D heartTexture;
  109. Texture2D bulletTexture;
  110. Texture2D menuBackground;
  111. Texture2D gameMenuBackground;
  112. Texture2D settingsBackground;
  113. Texture2D creditsBackground;
  114. Texture2D hiscoresBackground;
  115. Texture2D enemy_texture;
  116. Texture2D tileset;
  117. Texture2D food_texture;
  118. Texture2D pusia;
  119. Texture2D spikes_texture;
  120. Texture2D heart_b;
  121.  
  122.  
  123. //pozycje
  124. public float RightScreenCoor;//kooordynaty prawego boku ekranu, poczatkowo rowne screenwidth, zmieniaja sie wraz z przesuwaniem ekranu
  125. public int screenWidth;
  126. public int screenHeight;
  127. //czcionki
  128. SpriteFont font;
  129. SpriteFont pauseFont;
  130. //gracz
  131. player mandy;
  132. //klawiatura
  133. KeyboardState keybStateOld = Keyboard.GetState();
  134. KeyboardState oldKeyboardState1 = Keyboard.GetState();
  135. KeyboardState oldKeyboardState2 = Keyboard.GetState();
  136. KeyboardState oldKeyboardState3 = Keyboard.GetState();
  137. //poziomy
  138. level stage1;
  139. level stage2;
  140. level stage3;
  141.  
  142.  
  143. public Game1()
  144. {
  145. graphics = new GraphicsDeviceManager(this);
  146. Content.RootDirectory = "Content";
  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()//podstawowe żeczy w grze
  156. {
  157. // TODO: Add your initialization logic here
  158. graphics.PreferredBackBufferWidth = 800;
  159. graphics.PreferredBackBufferHeight = 600;
  160. graphics.IsFullScreen = false;
  161. graphics.ApplyChanges();
  162. Window.Title = "PROJECT 404";
  163. Camera.Initialize(screenWidth, screenHeight);
  164.  
  165.  
  166. base.Initialize();
  167. }
  168.  
  169. /// <summary>
  170. /// LoadContent will be called once per game and is the place to load
  171. /// all of your content.
  172. /// </summary>
  173. protected override void LoadContent()//ładowanie:
  174. {
  175. // TODO: use this.Content to load your game content here
  176. // Napisy w menu
  177. string[] menuItems = { "New Game", "High Scores", "Settings" , "Credits" , "End Game" };
  178. string[] menuItems2 = { "Continue", "New Game", "High Scores", "Settings", "Credits", "End Game" };
  179. string[] gameMenuItems = { "Resume", "Main Menu", "Settings", "Exit" };
  180. string[] creditsItems = { "Back" };
  181. //sptitebatch
  182. spriteBatch = new SpriteBatch(GraphicsDevice);
  183.  
  184. //menusy
  185. try
  186. {
  187.  
  188. menu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), menuItems);
  189. Components.Add(menu);
  190. gameMenu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), gameMenuItems);
  191. Components.Add(gameMenu);
  192. continueMenu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), menuItems2);
  193. Components.Add(continueMenu);
  194. creditsMenu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), creditsItems);
  195. Components.Add(creditsMenu);
  196. string[] hiscores = { "Back" };
  197. hiscoreMenu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), hiscores);
  198. Components.Add(hiscoreMenu);
  199. string[] settingsItems = { "Sound " + onoff[soundEnabled], "return" };
  200. settingsMenu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), settingsItems);
  201. Components.Add(settingsMenu);
  202. string[] pauseSettingsItems = { "Sound " + onoff[soundEnabled], "return" };
  203. settingsPauseMenu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), pauseSettingsItems);
  204. Components.Add(settingsPauseMenu);
  205.  
  206. //Dźwięki
  207. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  208. gameSound = Content.Load<SoundEffect>("gameSound");
  209. menuSound = Content.Load<SoundEffect>("menuSound");
  210. pauseSound = Content.Load<SoundEffect>("pauseSound");
  211. shootSound = Content.Load<SoundEffect>("laser");
  212. gameInstance = gameSound.CreateInstance();
  213. gameInstance.IsLooped = true;
  214. menuInstance = menuSound.CreateInstance();
  215. menuInstance.IsLooped = true;
  216. pauseInstance = pauseSound.CreateInstance();
  217. pauseInstance.IsLooped = true;
  218. shootInstance = shootSound.CreateInstance();
  219.  
  220. //strzały
  221. bulletsList = new List<shoot>();
  222.  
  223. soundEnabled = 0;
  224. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  225.  
  226.  
  227. spriteBatch = new SpriteBatch(GraphicsDevice);
  228. device = graphics.GraphicsDevice;
  229. screenWidth = device.PresentationParameters.BackBufferWidth;
  230. screenHeight = device.PresentationParameters.BackBufferHeight;
  231. RightScreenCoor = screenWidth;
  232. MyBackground = new ScrollingBackground();
  233. //tekstury
  234. Clouds = Content.Load<Texture2D>("ch62");
  235. MyBackground.Load(Clouds, screenWidth);
  236. foregroundTexture = Content.Load<Texture2D>("sand2");
  237. playerTexture = Content.Load<Texture2D>("msprite");
  238. heartTexture = Content.Load<Texture2D>("heart");
  239. creditsBackground = Content.Load<Texture2D>("credits");
  240. hiscoresBackground = Content.Load<Texture2D>("hiscoreBackground");
  241. settingsBackground = Content.Load<Texture2D>("settings");
  242. menuBackground = Content.Load<Texture2D>("menubackground");
  243. gameMenuBackground = Content.Load<Texture2D>("czarnyJakPieklo");
  244. font = Content.Load<SpriteFont>("myFont");
  245. tileset = Content.Load<Texture2D>("tileset_optical");
  246. pauseFont = Content.Load<SpriteFont>("pausefont");
  247. bulletTexture = Content.Load<Texture2D>("bullet");
  248. enemy_texture = Content.Load<Texture2D>("rainbow_optical");
  249. food_texture = Content.Load<Texture2D>("small_food");
  250. pusia = Content.Load<Texture2D>("ponys");
  251. spikes_texture = Content.Load<Texture2D>("spikes");
  252. heart_b = Content.Load<Texture2D>("Wild_At_Heart_by_candyshores");
  253. //gracz
  254. mandy = new player((int)screenWidth, (int)screenHeight);
  255. //level
  256. stages = new List<level>();
  257. stage1 = new level(1, screenWidth, screenHeight);
  258. stages.Add(stage1);
  259. enemyBullets = new List<shoot>();
  260. }
  261. catch (Exception e)
  262. {
  263. this.Exit();
  264. }
  265.  
  266. }
  267. /// <summary>
  268. /// UnloadContent will be called once per game and is the place to unload
  269. /// all content.
  270. /// </summary>
  271. protected override void UnloadContent()
  272. {
  273. // TODO: Unload any non ContentManager content here
  274. }
  275. private void UpdateMenu(GameTime gameTime)//Update menu gry
  276. {
  277. KeyboardState keyboardState1 = Keyboard.GetState();
  278. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  279. if (menuInstance.State != SoundState.Playing && soundEnabled == 0)//dzwiek
  280. {
  281. menuInstance.Play();
  282. }
  283. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  284. if (tocontinue == 0)//czy do menu weszlismy z pauzy- nie
  285. {
  286.  
  287. if (menu.CheckKey(Keys.Down, keyboardState1, oldKeyboardState1))
  288. {
  289. menu.selectedIndex++;
  290. if (menu.selectedIndex == menu.menuItems.Length)
  291. menu.selectedIndex = 0;
  292. }
  293. if (menu.CheckKey(Keys.Up, keyboardState1, oldKeyboardState1))
  294. {
  295. menu.selectedIndex--;
  296. if (menu.selectedIndex < 0)
  297. menu.selectedIndex = menu.menuItems.Length - 1;
  298. }
  299. if (menu.CheckKey(Keys.Enter, keyboardState1, oldKeyboardState1))
  300. {
  301. if (menu.SelectedIndex == 0)
  302. {
  303. mandy = new player((int)screenWidth, (int)screenHeight);
  304. RightScreenCoor = screenWidth;
  305. Camera.Transform = Matrix.Identity;
  306. Camera.UpdateMatrix = false;
  307. Camera.Position = new Vector2(0, 0);
  308. gameState = 1;
  309. stages.Clear();
  310. stage1 = new level(1, screenWidth, screenHeight);
  311. stages.Add(stage1);
  312. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  313. menuInstance.Stop();
  314. }
  315. else if (menu.SelectedIndex == 1)
  316. {
  317. gameState = 2;
  318. // menuInstance.Stop();
  319.  
  320. }
  321. else if (menu.SelectedIndex == 2)
  322. {
  323. gameState = 5;
  324.  
  325. //menuInstance.Stop();
  326.  
  327. }
  328. else if (menu.SelectedIndex == 3)
  329. {
  330. gameState = 3;
  331.  
  332. //menuInstance.Stop();
  333.  
  334. }
  335. else if (menu.SelectedIndex == 4)
  336. {
  337. this.Exit();
  338. }
  339. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  340.  
  341. }
  342. }
  343. else //jednak weszlismy z pauzy
  344. {
  345. if (continueMenu.CheckKey(Keys.Down, keyboardState1, oldKeyboardState1))
  346. {
  347. continueMenu.selectedIndex++;
  348. if (continueMenu.selectedIndex == continueMenu.menuItems.Length)
  349. continueMenu.selectedIndex = 0;
  350. }
  351. if (continueMenu.CheckKey(Keys.Up, keyboardState1, oldKeyboardState1))
  352. {
  353. continueMenu.selectedIndex--;
  354. if (continueMenu.selectedIndex < 0)
  355. continueMenu.selectedIndex = continueMenu.menuItems.Length - 1;
  356. }
  357. if (continueMenu.CheckKey(Keys.Enter, keyboardState1, oldKeyboardState1))
  358. {
  359. if (continueMenu.SelectedIndex == 0)
  360. {
  361. gameState = 1;
  362. menuInstance.Stop();
  363. }
  364. else if (continueMenu.SelectedIndex == 1)
  365. {
  366. mandy = new player((int)screenWidth, (int)screenHeight);
  367. RightScreenCoor = screenWidth;
  368. Camera.Transform = Matrix.Identity;
  369. Camera.UpdateMatrix = false;
  370. Camera.Position = new Vector2(0, 0);
  371. gameState = 1;
  372. score = 0;
  373. stages.Clear();
  374. stage1 = new level(1, screenWidth, screenHeight);
  375. stages.Add(stage1);
  376. bulletsList.Clear();
  377. menuInstance.Stop();
  378. }
  379. else if (continueMenu.SelectedIndex == 2)
  380. {
  381. gameState = 2;
  382.  
  383. }
  384. else if (continueMenu.SelectedIndex == 3)
  385. {
  386. gameState = 5;
  387. }
  388. else if (continueMenu.SelectedIndex == 4)
  389. {
  390. gameState = 3;;
  391. }
  392. else if (continueMenu.SelectedIndex == 5)
  393. {
  394. this.Exit();
  395. }
  396. }
  397.  
  398.  
  399. }
  400. oldKeyboardState1 = keyboardState1;
  401. }
  402. private void UpdateGameMenu(GameTime gameTime)//menu pauzy
  403. {
  404. KeyboardState keyboardState2 = Keyboard.GetState();
  405. if (pauseInstance.State != SoundState.Playing && soundEnabled == 0)
  406. {
  407. pauseInstance.Play();
  408. }
  409. if (gameMenu.CheckKey(Keys.Down, keyboardState2, oldKeyboardState2))
  410. {
  411. gameMenu.selectedIndex++;
  412. if (gameMenu.selectedIndex == gameMenu.menuItems.Length)
  413. gameMenu.selectedIndex = 0;
  414. }
  415. if (gameMenu.CheckKey(Keys.Up, keyboardState2, oldKeyboardState2))
  416. {
  417. gameMenu.selectedIndex--;
  418. if (gameMenu.selectedIndex < 0)
  419. gameMenu.selectedIndex = gameMenu.menuItems.Length - 1;
  420. }
  421. if (gameMenu.CheckKey(Keys.Enter, keyboardState2, oldKeyboardState2))
  422. {
  423. if (gameMenu.SelectedIndex == 0)
  424. {
  425. gameState = 1;
  426. pauseInstance.Stop();
  427. }
  428. else if (gameMenu.SelectedIndex == 1)
  429. {
  430. continueMenu.SelectedIndex = 0;
  431. tocontinue = 1;
  432. gameState = 0;
  433. pauseInstance.Stop();
  434.  
  435. }
  436. else if (gameMenu.SelectedIndex == 2)
  437. {
  438. gameState = 6;
  439. }
  440. else if (gameMenu.SelectedIndex == 3)
  441. {
  442. this.Exit();
  443. }
  444. }
  445.  
  446. oldKeyboardState2 = keyboardState2;
  447. }
  448. private void UpdateHiScores(GameTime gameTime)//menu pauzy
  449. {
  450. KeyboardState keyboardState2 = Keyboard.GetState();
  451. if (hiscoreMenu.CheckKey(Keys.Down, keyboardState2, oldKeyboardState2))
  452. {
  453. hiscoreMenu.SelectedIndex++;
  454. if (hiscoreMenu.selectedIndex == hiscoreMenu.menuItems.Length)
  455. hiscoreMenu.selectedIndex = 0;
  456. }
  457. if (hiscoreMenu.CheckKey(Keys.Up, keyboardState2, oldKeyboardState2))
  458. {
  459. hiscoreMenu.selectedIndex--;
  460. if (hiscoreMenu.selectedIndex < 0)
  461. hiscoreMenu.selectedIndex = hiscoreMenu.menuItems.Length - 1;
  462. }
  463. if (hiscoreMenu.CheckKey(Keys.Enter, keyboardState2, oldKeyboardState2))
  464. {
  465. if (hiscoreMenu.SelectedIndex == 0)
  466. {
  467. gameState = 0;
  468. }
  469. }
  470.  
  471. oldKeyboardState2 = keyboardState2;
  472. }
  473. private void UpdateCredits(GameTime gameTime)//menu pauzy
  474. {
  475. KeyboardState keyboardState2 = Keyboard.GetState();
  476. if (creditsMenu.CheckKey(Keys.Down, keyboardState2, oldKeyboardState2))
  477. {
  478. creditsMenu.SelectedIndex++;
  479. if (creditsMenu.selectedIndex == creditsMenu.menuItems.Length)
  480. creditsMenu.selectedIndex = 0;
  481. }
  482. if (creditsMenu.CheckKey(Keys.Up, keyboardState2, oldKeyboardState2))
  483. {
  484. creditsMenu.selectedIndex--;
  485. if (creditsMenu.selectedIndex < 0)
  486. creditsMenu.selectedIndex = creditsMenu.menuItems.Length - 1;
  487. }
  488. if (creditsMenu.CheckKey(Keys.Enter, keyboardState2, oldKeyboardState2))
  489. {
  490. if (creditsMenu.SelectedIndex == 0)
  491. {
  492. gameState = 0;
  493. }
  494. }
  495.  
  496. oldKeyboardState2 = keyboardState2;
  497. }
  498. private void UpdateSettings(GameTime gameTime)//menu pauzy
  499. {
  500. KeyboardState keyboardState2 = Keyboard.GetState();
  501. if (settingsMenu.CheckKey(Keys.Down, keyboardState2, oldKeyboardState2))
  502. {
  503. settingsMenu.SelectedIndex++;
  504. if (settingsMenu.selectedIndex == settingsMenu.menuItems.Length)
  505. settingsMenu.selectedIndex = 0;
  506. }
  507. if (settingsMenu.CheckKey(Keys.Up, keyboardState2, oldKeyboardState2))
  508. {
  509. settingsMenu.selectedIndex--;
  510. if (settingsMenu.selectedIndex < 0)
  511. settingsMenu.selectedIndex = settingsMenu.menuItems.Length - 1;
  512. }
  513. if (settingsMenu.CheckKey(Keys.Enter, keyboardState2, oldKeyboardState2))
  514. {
  515. if (settingsMenu.SelectedIndex == 0)
  516. {
  517. if (soundEnabled == 0)//on
  518. {
  519. soundEnabled = 1;
  520. menuInstance.Stop();
  521. string[] settingsItems = { "Sound " + onoff[soundEnabled], "Return" };
  522. settingsMenu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), settingsItems);
  523.  
  524. }
  525. else
  526. {
  527. soundEnabled = 0;
  528. menuInstance.Play();
  529. string[] settingsItems = { "Sound " + onoff[soundEnabled], "Return" };
  530. settingsMenu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), settingsItems);
  531.  
  532. }
  533. }
  534. else
  535. {
  536. gameState = 0;
  537. }
  538. }
  539.  
  540. oldKeyboardState2 = keyboardState2;
  541. }
  542. private void UpdateGameSettings(GameTime gameTime)//menu pauzy
  543. {
  544. KeyboardState keyboardState2 = Keyboard.GetState();
  545. if (settingsPauseMenu.CheckKey(Keys.Down, keyboardState2, oldKeyboardState2))
  546. {
  547. settingsPauseMenu.SelectedIndex++;
  548. if (settingsPauseMenu.selectedIndex == settingsPauseMenu.menuItems.Length)
  549. settingsPauseMenu.selectedIndex = 0;
  550. }
  551. if (settingsPauseMenu.CheckKey(Keys.Up, keyboardState2, oldKeyboardState2))
  552. {
  553. settingsPauseMenu.selectedIndex--;
  554. if (settingsPauseMenu.selectedIndex < 0)
  555. settingsPauseMenu.selectedIndex = settingsPauseMenu.menuItems.Length - 1;
  556. }
  557. if (settingsPauseMenu.CheckKey(Keys.Enter, keyboardState2, oldKeyboardState2))
  558. {
  559. if (settingsPauseMenu.SelectedIndex == 0)
  560. {
  561. if (soundEnabled == 0)//on
  562. {
  563. soundEnabled = 1;
  564. pauseInstance.Stop();
  565. string[] pauseSettingsItems = { "Sound " + onoff[soundEnabled], "return" };
  566. settingsPauseMenu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), pauseSettingsItems);
  567. }
  568. else
  569. {
  570. soundEnabled = 0;
  571. pauseInstance.Play();
  572. string[] pauseSettingsItems = { "Sound " + onoff[soundEnabled], "return" };
  573. settingsPauseMenu = new MenuComponent(this, spriteBatch, Content.Load<SpriteFont>("myFont"), pauseSettingsItems);
  574. }
  575. }
  576. else
  577. {
  578. gameState = 4;
  579. }
  580. }
  581.  
  582. oldKeyboardState2 = keyboardState2;
  583. }
  584.  
  585.  
  586.  
  587. private void DrawMandy(GameTime gameTime)
  588. {
  589. Rectangle source;
  590. Rectangle destination;
  591. //animation here
  592. if(mandy.mCurrentState == State.Nothing)
  593. {
  594. //idle
  595. source = new Rectangle(1, 3, 29, 34);
  596. mandy.idle.previous_framechange += (float)gameTime.ElapsedGameTime.TotalSeconds;
  597. if (mandy.idle.previous_framechange > 0.2f)
  598. {
  599. if (gameState != 4 && gameState != 6)
  600. {
  601. mandy.idle.current_frame++;
  602. }
  603. if (mandy.idle.current_frame == mandy.idle.total_frames)
  604. {
  605. mandy.idle.current_frame = 0;
  606. }
  607. //zmiana klatki w obecnej
  608. mandy.idle.previous_framechange = 0f;
  609.  
  610.  
  611. //ustawiam inne animacje na 0
  612.  
  613. }
  614. source = new Rectangle(30 * mandy.idle.current_frame, 3, 30, 34);
  615. }
  616. else if(mandy.mCurrentState == State.Walking)
  617. {
  618. mandy.walk.previous_framechange += (float)gameTime.ElapsedGameTime.TotalSeconds;
  619. //walk animation
  620.  
  621. if (mandy.walk.previous_framechange > 0.2f)
  622. {
  623.  
  624. //zmiana klatki w obecnej
  625. if (gameState != 4 && gameState != 6)
  626. {
  627. mandy.walk.current_frame++;
  628. }
  629.  
  630. mandy.walk.previous_framechange = 0f;
  631. if (mandy.walk.current_frame == mandy.walk.total_frames)
  632. {
  633. mandy.walk.current_frame = 0;
  634. }
  635. }
  636. source = new Rectangle(30 * mandy.walk.current_frame, 39, 29, 36);
  637. }
  638. else if(mandy.mCurrentState == State.Jumping)
  639. {
  640. //just do shit right now
  641. if (mandy.mDirection.Y == 1)
  642. {
  643. //spadanie
  644. source = new Rectangle(1 + 60,78, 29, 35);
  645. }
  646. else
  647. {
  648. source = new Rectangle(1, 78, 29, 35);
  649. //lot w gore
  650. }
  651. }
  652. else
  653. {
  654. source = new Rectangle(1, 3, 29, 34);
  655. }
  656.  
  657. //tu juz ustwilsmy ktora animiacja
  658. //i ktora klatka
  659. Color euzebiusz;
  660. if (mandy.mCurrentState == State.Hurt)
  661. {
  662. euzebiusz = Color.Red;
  663. mandy.mCurrentState = State.Nothing;
  664. }
  665. else
  666. {
  667. euzebiusz = Color.White;
  668. }
  669.  
  670. destination = new Rectangle((int)mandy.position.X, (int)mandy.position.Y, 2 * source.Width, 2 * source.Height);
  671. if (mandy.direction == 1)
  672. {
  673. spriteBatch.Draw(playerTexture, destination, source, euzebiusz);
  674. }
  675. else
  676. {
  677. spriteBatch.Draw(playerTexture, destination, source, euzebiusz, 0, Vector2.Zero, SpriteEffects.FlipHorizontally, 0);
  678. }
  679.  
  680. }
  681.  
  682. private void DrawScenery(GameTime thetime)//rysowanie terenu
  683. {
  684.  
  685. for (int i = 0; i < stages[current_stage-1].ground_data.Count(); i++)
  686. {
  687. Rectangle one_block;
  688. Rectangle source_block;
  689. for (int j = 0; j < stages[current_stage - 1].ground_data[i].number_of_blocks; j++)
  690. {
  691. one_block = new Rectangle((int)stages[current_stage - 1].ground_data[i].position.X + j * stages[current_stage - 1].block_size, (int)stages[current_stage - 1].ground_data[i].position.Y, stages[current_stage - 1].block_size, stages[current_stage - 1].block_size);
  692. if (j == 0)
  693. {
  694. source_block = new Rectangle(0, 0, stages[current_stage - 1].block_size, stages[current_stage - 1].block_size);
  695.  
  696.  
  697. }
  698. else if (j == (stages[current_stage - 1].ground_data[i].number_of_blocks - 1))
  699. {
  700. //right edge texture
  701. source_block = new Rectangle(2 * stages[current_stage - 1].block_size, 0, stages[current_stage - 1].block_size, stages[current_stage - 1].block_size);
  702. }
  703. else
  704. {
  705. source_block = new Rectangle(stages[current_stage - 1].block_size, 0, stages[current_stage - 1].block_size, stages[current_stage - 1].block_size);
  706. //middle texture
  707. }
  708. spriteBatch.Draw(tileset, one_block, source_block, Color.White);
  709. }
  710. }
  711.  
  712. for (int i = 0; i < stages[current_stage-1].food.Count(); i++)
  713. {
  714. Rectangle source;
  715. Rectangle destination;
  716.  
  717. if (stages[current_stage - 1].food[i].type == 1)
  718. {
  719. source = new Rectangle(5, 3, 39, 39);
  720. //pizza
  721. }
  722. else if (stages[current_stage - 1].food[i].type == 2)
  723. {
  724.  
  725. //fries
  726. source = new Rectangle(45, 3, 53, 42);
  727. }
  728. else
  729. {
  730. //burger
  731. source = new Rectangle(7, 44, 44, 52);
  732. }
  733.  
  734. destination = new Rectangle((int)stages[current_stage - 1].food[i].position.X, (int)stages[current_stage - 1].food[i].position.Y - (int)source.Height, (int)source.Width, (int)source.Height);
  735.  
  736. spriteBatch.Draw(food_texture, destination, source, Color.White);
  737. }
  738.  
  739. //aurelisz
  740. for (int i = 0; i < stages[current_stage - 1].spikes_pos.Count(); i++)
  741. {
  742. Rectangle s;
  743. Rectangle d;
  744.  
  745. s = new Rectangle(0, 0, 32, 32);
  746. d = new Rectangle((int)stages[current_stage - 1].spikes_pos[i].position.X, (int)stages[current_stage - 1].spikes_pos[i].position.Y, s.Width, s.Height);
  747.  
  748. stages[current_stage - 1].spikes_pos[i].change_fequency+= (float)thetime.ElapsedGameTime.TotalSeconds;
  749. if (stages[current_stage - 1].spikes_pos[i].change_fequency > 1f)
  750. {
  751. stages[current_stage - 1].spikes_pos[i].change_fequency = 0f;
  752. if (stages[current_stage - 1].spikes_pos[i].active == true)
  753. {
  754. stages[current_stage - 1].spikes_pos[i].active = false;
  755. }
  756. else
  757. {
  758. stages[current_stage - 1].spikes_pos[i].active = true;
  759. }
  760. }
  761.  
  762. if (stages[current_stage - 1].spikes_pos[i].active == true)
  763. {
  764. spriteBatch.Draw(spikes_texture, d, s, Color.White);
  765. }
  766. //aurelisz
  767. }
  768.  
  769. for (int i = 0; i < stages[current_stage - 1].bonus_hearts.Count(); i++)
  770. {
  771. Rectangle s = new Rectangle(2, 4, 35, 30);
  772. Rectangle d = new Rectangle((int)stages[current_stage-1].bonus_hearts[i].position.X, (int)stages[current_stage-1].bonus_hearts[i].position.Y, s.Width, s.Height);
  773. spriteBatch.Draw(heart_b, d, s, Color.White);
  774. }
  775. }
  776.  
  777. private void UpdateEnemies(GameTime thetime)
  778. {
  779. if (gameState != 4 && gameState != 6)
  780. {
  781.  
  782. for (int i = 0; i < stages[current_stage - 1].enemies.Count(); i++)
  783. {
  784.  
  785. stages[current_stage - 1].enemies[i].walk.previous_framechange += (float)thetime.ElapsedGameTime.TotalSeconds;
  786.  
  787. stages[current_stage - 1].enemies[i].Update(thetime, stages[current_stage - 1].enemies[i].speed, stages[current_stage - 1].enemies[i].direction);
  788. if (((int)stages[current_stage - 1].enemies[i].position.X + 110 - stages[current_stage - 1].enemies[i].startX) > stages[current_stage - 1].enemies[i].range)
  789. {
  790. stages[current_stage - 1].enemies[i].direction.X = -1;
  791. }
  792. else if ((int)stages[current_stage - 1].enemies[i].position.X < stages[current_stage - 1].enemies[i].startX)
  793. {
  794. stages[current_stage - 1].enemies[i].direction.X = 1;
  795. }
  796.  
  797. if (stages[current_stage - 1].enemies[i].walk.previous_framechange > 0.2f)
  798. {
  799. stages[current_stage - 1].enemies[i].walk.current_frame++;
  800. stages[current_stage - 1].enemies[i].walk.previous_framechange = 0f;
  801. if (stages[current_stage - 1].enemies[i].walk.current_frame == stages[current_stage - 1].enemies[i].walk.total_frames)
  802. {
  803. stages[current_stage - 1].enemies[i].walk.current_frame = 0;
  804.  
  805. }
  806. }
  807. }
  808. }
  809. }
  810. private void DrawEnemies(GameTime thetime)
  811. {
  812. for (int i = 0; i < stages[current_stage - 1].enemies.Count(); i++)
  813. {
  814.  
  815. Rectangle destination;
  816. Rectangle source;
  817.  
  818. if (stages[current_stage - 1].enemies[i].whoami.Equals(enemies.purple_ponny))
  819. {
  820.  
  821. source = new Rectangle(114 * stages[current_stage - 1].enemies[i].walk.current_frame, 114 * 2 - 5, 115, 112);
  822. destination = new Rectangle((int)stages[current_stage - 1].enemies[i].position.X, (int)stages[current_stage - 1].enemies[i].position.Y, 113, 110);
  823. }
  824. else if (stages[current_stage - 1].enemies[i].whoami.Equals(enemies.blue_ponny))
  825. {
  826. //tutaj rysowanie wrogow
  827. source = new Rectangle(114 * stages[current_stage - 1].enemies[i].walk.current_frame, 115, 115, 112);
  828. destination = new Rectangle((int)stages[current_stage - 1].enemies[i].position.X, (int)stages[current_stage - 1].enemies[i].position.Y, 113, 110);
  829.  
  830. }
  831. else if (stages[current_stage - 1].enemies[i].whoami.Equals(enemies.yellow_ponny))
  832. {
  833. //tutaj rysowanie wrogow
  834. source = new Rectangle(114 * stages[current_stage - 1].enemies[i].walk.current_frame, 0, 115, 112);
  835. destination = new Rectangle((int)stages[current_stage - 1].enemies[i].position.X, (int)stages[current_stage - 1].enemies[i].position.Y, 113, 110);
  836. }
  837. else if (stages[current_stage - 1].enemies[i].whoami.Equals(enemies.shooter_purlpe))
  838. {
  839. source = new Rectangle(140 * stages[current_stage - 1].enemies[i].walk.current_frame, 0, 139, 139);
  840. destination = new Rectangle((int)stages[current_stage - 1].enemies[i].position.X, (int)stages[current_stage - 1].enemies[i].position.Y, 140, 140);
  841. stages[current_stage - 1].enemies[i].lastshoot += (float)thetime.ElapsedGameTime.TotalSeconds;
  842. if (stages[current_stage - 1].enemies[i].lastshoot > 4f)
  843. {
  844. stages[current_stage - 1].enemies[i].lastshoot = 0f;
  845. shoot kasia = new shoot(stages[current_stage - 1].enemies[i].position.X, stages[current_stage - 1].enemies[i].position.Y + 60, stage1.enemies[i].direction.X, true);
  846. enemyBullets.Add(kasia);
  847. }
  848. }
  849. else
  850. {
  851. //jak nie wiadomo ktory to zolty
  852. source = new Rectangle(114 * stages[current_stage - 1].enemies[i].walk.current_frame, 115, 115, 112);
  853. destination = new Rectangle((int)stages[current_stage - 1].enemies[i].position.X, (int)stages[current_stage - 1].enemies[i].position.Y, 113, 110);
  854. }
  855.  
  856. if (stages[current_stage - 1].enemies[i].direction.X > 0)
  857. {
  858. if (stages[current_stage - 1].enemies[i].whoami.Equals(enemies.shooter_purlpe))
  859. {
  860. spriteBatch.Draw(pusia, destination, source, Color.White);
  861. }
  862. else
  863. {
  864. spriteBatch.Draw(enemy_texture, destination, source, Color.White);
  865. }
  866. }
  867. else
  868. {
  869. if (stages[current_stage - 1].enemies[i].whoami.Equals(enemies.shooter_purlpe))
  870. {
  871. spriteBatch.Draw(pusia, destination, source, Color.White, 0, Vector2.Zero, SpriteEffects.FlipHorizontally, 0);
  872. }
  873. else
  874. {
  875. spriteBatch.Draw(enemy_texture, destination, source, Color.White, 0, Vector2.Zero, SpriteEffects.FlipHorizontally, 0);
  876. }
  877.  
  878. }
  879.  
  880. }
  881.  
  882. }
  883. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  884.  
  885. private void DrawText()//rysowanie interface'u
  886. {
  887. if (gameState == 1 || gameState == 3)
  888. {
  889. spriteBatch.DrawString(font, "LEVEL " + current_stage.ToString(), new Vector2(20, 0), Color.Black);
  890. spriteBatch.DrawString(font, "SCORE: " + score.ToString(), new Vector2(20, 31), Color.Black);
  891. spriteBatch.DrawString(pauseFont, "[P]ause", new Vector2(720, 40), Color.Black);
  892. }
  893. }
  894.  
  895. public void DrawMenu(GameTime gameTime)//rysowanie menu
  896. {
  897. if (tocontinue == 0)
  898. {
  899. Rectangle background;
  900. background = new Rectangle(0, 0, screenWidth, screenHeight);
  901. spriteBatch.Begin();
  902. spriteBatch.Draw(menuBackground, background, Color.White);
  903. spriteBatch.End();
  904. Vector2 location = menu.position;
  905. Color tint;
  906. for (int i = 0; i < menu.menuItems.Length; i++)
  907. {
  908. if (i == menu.selectedIndex)
  909. tint = menu.hilite;
  910. else
  911. tint = menu.normal;
  912. spriteBatch.Begin();
  913. spriteBatch.DrawString(menu.spriteFont, menu.menuItems[i], location, tint);
  914. spriteBatch.End();
  915. location.Y += menu.spriteFont.LineSpacing + 5;
  916. }
  917. }
  918. else
  919. {
  920. Rectangle background;
  921. background = new Rectangle(0, 0, screenWidth, screenHeight);
  922. spriteBatch.Begin();
  923. spriteBatch.Draw(menuBackground, background, Color.White);
  924. spriteBatch.End();
  925. Vector2 location = menu.position;
  926. Color tint;
  927. for (int i = 0; i < continueMenu.menuItems.Length; i++)
  928. {
  929. if (i == continueMenu.selectedIndex)
  930. tint = continueMenu.hilite;
  931. else
  932. tint = continueMenu.normal;
  933. spriteBatch.Begin();
  934. spriteBatch.DrawString(continueMenu.spriteFont, continueMenu.menuItems[i], location, tint);
  935. spriteBatch.End();
  936. location.Y += continueMenu.spriteFont.LineSpacing + 5;
  937. }
  938.  
  939.  
  940. }
  941. }
  942. public void DrawGameMenu(GameTime gameTime)//rysowanie pauzy
  943. {
  944. Rectangle background;
  945. background = new Rectangle(0, 0, screenWidth, screenHeight);
  946. spriteBatch.Begin();
  947. spriteBatch.Draw(gameMenuBackground, background, new Color(255,255,255,80));
  948. spriteBatch.End();
  949. Vector2 location = gameMenu.position;
  950. Color tint;
  951. for (int i = 0; i < gameMenu.menuItems.Length; i++)
  952. {
  953. if (i == gameMenu.selectedIndex)
  954. tint = gameMenu.hilite;
  955. else
  956. tint = gameMenu.normal;
  957. spriteBatch.Begin();
  958. spriteBatch.DrawString(gameMenu.spriteFont, gameMenu.menuItems[i], location, tint);
  959. spriteBatch.End();
  960. location.Y += gameMenu.spriteFont.LineSpacing + 5;
  961. }
  962. }
  963. public void DrawHiscores(GameTime gameTime)//rysowanie pauzy
  964. {
  965. Rectangle background;
  966. background = new Rectangle(0, 0, screenWidth, screenHeight);
  967. spriteBatch.Begin();
  968. spriteBatch.Draw(hiscoresBackground, background, Color.White);
  969. spriteBatch.End();
  970. Vector2 location = new Vector2(350,450);
  971. Color tint;
  972. for (int i = 0; i < hiscoreMenu.menuItems.Length; i++)
  973. {
  974. if (i == hiscoreMenu.selectedIndex)
  975. tint = hiscoreMenu.hilite;
  976. else
  977. tint = hiscoreMenu.normal;
  978. spriteBatch.Begin();
  979. spriteBatch.DrawString(menu.spriteFont, hiscoreMenu.menuItems[i], location, tint);
  980. spriteBatch.End();
  981. location.Y += menu.spriteFont.LineSpacing + 5;
  982. }
  983. }
  984. public void DrawSettings(GameTime gameTime)//rysowanie pauzy
  985. {
  986. if (settingsMenu != null)
  987. {
  988. Rectangle background;
  989. background = new Rectangle(0, 0, screenWidth, screenHeight);
  990. spriteBatch.Begin();
  991. spriteBatch.Draw(settingsBackground, background, Color.White);
  992. spriteBatch.End();
  993. Vector2 location = menu.position;
  994. Color tint;
  995. for (int i = 0; i < 2; i++)
  996. {
  997. if (i == settingsMenu.selectedIndex)
  998. tint = settingsMenu.hilite;
  999. else
  1000. tint = settingsMenu.normal;
  1001. spriteBatch.Begin();
  1002. spriteBatch.DrawString(menu.spriteFont, settingsMenu.menuItems[i], location, tint);
  1003. spriteBatch.End();
  1004. location.Y += menu.spriteFont.LineSpacing + 5;
  1005. }
  1006. }
  1007. }
  1008. public void DrawCredits(GameTime gameTime)//rysowanie pauzy
  1009. {
  1010. if (creditsMenu != null)
  1011. {
  1012. Rectangle background;
  1013. background = new Rectangle(0, 0, screenWidth, screenHeight);
  1014. spriteBatch.Begin();
  1015. spriteBatch.Draw(creditsBackground, background, Color.White);
  1016. spriteBatch.End();
  1017. Vector2 location = new Vector2(350, 450);
  1018. Color tint;
  1019. for (int i = 0; i < 1; i++)
  1020. {
  1021. if (i == creditsMenu.selectedIndex)
  1022. tint = creditsMenu.hilite;
  1023. else
  1024. tint = creditsMenu.normal;
  1025. spriteBatch.Begin();
  1026. spriteBatch.DrawString(menu.spriteFont, creditsMenu.menuItems[i], location, tint);
  1027. spriteBatch.End();
  1028. location.Y += menu.spriteFont.LineSpacing + 5;
  1029. }
  1030. }
  1031. }
  1032. public void DrawGamePause(GameTime gameTime)//rysowanie pauzy
  1033. {
  1034. if (settingsPauseMenu != null)
  1035. {
  1036. Rectangle background;
  1037. background = new Rectangle(0, 0, screenWidth, screenHeight);
  1038. spriteBatch.Begin();
  1039. spriteBatch.Draw(gameMenuBackground, background, new Color(255, 255, 255, 80));
  1040. spriteBatch.End();
  1041. Vector2 location = menu.position;
  1042. Color tint;
  1043. for (int i = 0; i < 2; i++)
  1044. {
  1045. if (i == settingsPauseMenu.selectedIndex)
  1046. tint = settingsPauseMenu.hilite;
  1047. else
  1048. tint = settingsPauseMenu.normal;
  1049. spriteBatch.Begin();
  1050. spriteBatch.DrawString(gameMenu.spriteFont, settingsPauseMenu.menuItems[i], location, tint);
  1051. spriteBatch.End();
  1052. location.Y += settingsPauseMenu.spriteFont.LineSpacing + 5;
  1053. }
  1054. }
  1055. }
  1056. /// <summary>
  1057. /// Allows the game to run logic such as updating the world,
  1058. /// checking for collisions, gathering input, and playing audio.
  1059. /// </summary>
  1060. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  1061. protected override void Update(GameTime gameTime)//update
  1062. {
  1063. // Allows the game to exit
  1064. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  1065. this.Exit();
  1066. // TODO: Add your update logic here
  1067. if (gameState == 0)
  1068. {
  1069. UpdateMenu(gameTime);
  1070. }
  1071. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  1072. else if (gameState == 1)
  1073. {
  1074. if (gameInstance.State != SoundState.Playing && soundEnabled == 0)
  1075. {
  1076. gameInstance.Play();
  1077. }
  1078. }
  1079. else if (gameState == 2)
  1080. {
  1081. //tu dodać odczyt z pliku
  1082. //do stringa
  1083. UpdateHiScores(gameTime);
  1084. }
  1085. else if (gameState == 3)
  1086. {
  1087. UpdateCredits(gameTime);
  1088. }
  1089. else if (gameState == 4)
  1090. {
  1091. UpdateGameMenu(gameTime);
  1092. }
  1093. else if (gameState == 5)
  1094. {
  1095. UpdateSettings(gameTime);
  1096. }
  1097. else if (gameState == 6)
  1098. {
  1099. UpdateGameSettings(gameTime);
  1100. }
  1101. UpdateEnemies(gameTime);
  1102. UpdateInput(gameTime);
  1103. if (gameState == 1)
  1104. {
  1105. fire();
  1106. enemyFire();
  1107. }
  1108. if (mandy.position.Y >= screenHeight)
  1109. {
  1110. mandy.mCurrentState = State.Hurt;
  1111. score += 150;
  1112. mandy.hp--;
  1113. }
  1114. if (mandy.hp == 0)
  1115. {
  1116. gameState = 0;
  1117. tocontinue = 0;
  1118. gameInstance.Stop();
  1119. score = 0;
  1120. }
  1121. if (mandy.mCurrentState == State.Hurt)
  1122. {
  1123. mandy.position = new Vector2(20, screenHeight - 90);
  1124. score -= 250;
  1125. RightScreenCoor = screenWidth;
  1126. Camera.Transform = Matrix.Identity;
  1127. Camera.UpdateMatrix = false;
  1128. Camera.Position = new Vector2(0, 0);
  1129. //Camera.Origin = new Vector2(screenWidth / 2, screenHeight / 2);
  1130. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  1131. bulletsList.Clear();
  1132. enemyBullets.Clear();
  1133. mandy.mDirection.Y = 0;
  1134. mandy.mCurrentState = State.Nothing;
  1135. }
  1136. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  1137. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>
  1138. // The time since Update was called last.
  1139. float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
  1140.  
  1141. // TODO: Add your game logic here.
  1142. MyBackground.Update(elapsed * 50); //przesuwa pozycje tla, zwieksz liczbe, aby sunelo szybciej
  1143. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>
  1144. Vector2 aDirection = new Vector2(-1, 0);
  1145.  
  1146. Vector2 aSpeed = new Vector2(160, 0);
  1147.  
  1148. base.Update(gameTime);
  1149. }
  1150.  
  1151. private void ProcessKeyboard(GameTime gameTime)//ogar klawiatury
  1152. {
  1153. if (gameState == 1)
  1154. {
  1155.  
  1156. mandy.Update(gameTime, ref RightScreenCoor, stages[current_stage - 1]);
  1157.  
  1158.  
  1159. KeyboardState keybState = Keyboard.GetState();
  1160. if (keybState.IsKeyDown(Keys.Space) == true && oldKeyboardState3.IsKeyDown(Keys.Space) == false)
  1161. {
  1162. shoot bullet = new shoot(mandy.position.X, mandy.position.Y + 18, mandy.direction,true);
  1163. bulletsList.Add(bullet);
  1164. //bullet.position.X = mandy.position.X;
  1165. //bullet.position.Y = mandy.position.Y + 18;
  1166. //bullet.direction = mandy.direction;
  1167. //bullet.Visible = true;
  1168. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  1169. if (shootInstance.State != SoundState.Playing && soundEnabled == 0)
  1170. {
  1171. shootInstance.Play();
  1172. }
  1173. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  1174. }
  1175. if (keybState.IsKeyDown(Keys.P))
  1176. {
  1177. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  1178. if (gameInstance.State == SoundState.Playing)
  1179. {
  1180. gameInstance.Stop();
  1181. }
  1182. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>-------------
  1183. gameMenu.SelectedIndex = 0;
  1184. gameState = 4;
  1185. }
  1186. oldKeyboardState3 = keybState;
  1187. }
  1188.  
  1189. ////<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>
  1190. }
  1191. public void enemyFire()//strzał
  1192. {
  1193. for (int z = 0; z < enemyBullets.Count; z++)
  1194. {
  1195.  
  1196. //Kolizja z lewej
  1197. if (enemyBullets[z].position.X + 30 >= mandy.position.X && enemyBullets[z].position.X <= mandy.position.X + 50 && enemyBullets[z].position.Y + 18 >= mandy.position.Y && enemyBullets[z].position.Y <= mandy.position.Y + 68)
  1198. {
  1199. mandy.mCurrentState = State.Hurt;
  1200. mandy.hp--;
  1201. break;
  1202. }
  1203.  
  1204. }
  1205. for (int z = 0; z < enemyBullets.Count; z++)
  1206. {
  1207. if (enemyBullets[z].Visible == true)
  1208. {
  1209. if (enemyBullets[z].direction == 1)
  1210. {
  1211. enemyBullets[z].position.X += 15;
  1212. }
  1213. else
  1214. {
  1215. enemyBullets[z].position.X -= 15;
  1216. }
  1217.  
  1218. }
  1219. if (enemyBullets[z].position.X >= RightScreenCoor)
  1220. {
  1221. enemyBullets.RemoveAt(z);
  1222. z--;
  1223. if (z <= -1)
  1224. {
  1225. z = 0;
  1226. }
  1227.  
  1228. }
  1229. else if (enemyBullets[z].position.X <= RightScreenCoor - screenWidth)
  1230. {
  1231. enemyBullets.RemoveAt(z);
  1232. z--;
  1233. if (z <= -1)
  1234. {
  1235. z = 0;
  1236. }
  1237. }
  1238. }
  1239. }
  1240. public void fire()//strzał
  1241. {
  1242. for (int i = 0; i < bulletsList.Count; i++)
  1243. {
  1244. for (int j = 0; j < stages[current_stage - 1].enemies.Count; j++)
  1245. {
  1246. //Kolizja z lewej
  1247. if (bulletsList[i].position.X + 30 >= stages[current_stage - 1].enemies[j].position.X && bulletsList[i].position.X <= stages[current_stage - 1].enemies[j].position.X + 100 && bulletsList[i].position.Y + 18 >= stages[current_stage - 1].enemies[j].position.Y && bulletsList[i].position.Y <= stages[current_stage - 1].enemies[j].position.Y + 100)
  1248. {
  1249. score += 500;
  1250. bulletsList.RemoveAt(i);
  1251. i--;
  1252. if (i <= -1)
  1253. {
  1254. i = 0;
  1255. }
  1256. else if (i >= bulletsList.Count)
  1257. {
  1258. i = bulletsList.Count - 1;
  1259. }
  1260. stages[current_stage - 1].enemies.RemoveAt(j);
  1261. j--;
  1262. if (j <= -1)
  1263. {
  1264. j = 0;
  1265. }
  1266. else if (j >= stages[current_stage - 1].enemies.Count)
  1267. {
  1268. j = stages[current_stage - 1].enemies.Count - 1;
  1269. }
  1270. if (bulletsList.Count == 0)
  1271. {
  1272. break;
  1273. }
  1274.  
  1275. }
  1276.  
  1277.  
  1278.  
  1279. }
  1280. }
  1281. for (int i = 0; i < bulletsList.Count; i++)
  1282. {
  1283. if (bulletsList[i].Visible == true)
  1284. {
  1285. if (bulletsList[i].direction == 1)
  1286. {
  1287. bulletsList[i].position.X += 15;
  1288. }
  1289. else
  1290. {
  1291. bulletsList[i].position.X -= 15;
  1292. }
  1293.  
  1294. }
  1295. if (bulletsList[i].position.X >= RightScreenCoor)
  1296. {
  1297. bulletsList.RemoveAt(i);
  1298. i--;
  1299. if (i <= -1)
  1300. {
  1301. i = 0;
  1302. }
  1303.  
  1304. }
  1305. else if (bulletsList[i].position.X <= RightScreenCoor - screenWidth)
  1306. {
  1307. bulletsList.RemoveAt(i);
  1308. i--;
  1309. if (i <= -1)
  1310. {
  1311. i = 0;
  1312. }
  1313. }
  1314. }
  1315. }
  1316.  
  1317. private void UpdateInput(GameTime gameTime)//nie wiem co to tu wogle robi :P
  1318. {
  1319. ProcessKeyboard(gameTime);
  1320.  
  1321. }
  1322.  
  1323. public void DrawBullet()//rysowanie strzału
  1324. {
  1325. for (int i = 0; i < bulletsList.Count; i++)
  1326. {
  1327. if (bulletsList[i].direction == 1)
  1328. {
  1329. Rectangle bulletR = new Rectangle((int)bulletsList[i].position.X, (int)bulletsList[i].position.Y, bulletTexture.Width, bulletTexture.Height);
  1330. spriteBatch.Draw(bulletTexture, bulletR, Color.White);
  1331. }
  1332. else
  1333. {
  1334. Rectangle bulletR = new Rectangle((int)bulletsList[i].position.X, (int)bulletsList[i].position.Y, bulletTexture.Width, bulletTexture.Height);
  1335. spriteBatch.Draw(bulletTexture, bulletR, null, Color.White, 0, Vector2.Zero, SpriteEffects.FlipHorizontally, 0);
  1336. }
  1337.  
  1338. }
  1339. for (int i = 0; i < enemyBullets.Count; i++)
  1340. {
  1341. if (enemyBullets[i].direction == 1)
  1342. {
  1343. Rectangle bulletR = new Rectangle((int)enemyBullets[i].position.X, (int)enemyBullets[i].position.Y, bulletTexture.Width, bulletTexture.Height);
  1344. spriteBatch.Draw(bulletTexture, bulletR, Color.White);
  1345. }
  1346. else
  1347. {
  1348. Rectangle bulletR = new Rectangle((int)enemyBullets[i].position.X, (int)enemyBullets[i].position.Y, bulletTexture.Width, bulletTexture.Height);
  1349. spriteBatch.Draw(bulletTexture, bulletR, null, Color.White, 0, Vector2.Zero, SpriteEffects.FlipHorizontally, 0);
  1350. }
  1351.  
  1352. }
  1353.  
  1354. }
  1355. /// <summary>
  1356. /// This is called when the game should draw itself.
  1357. /// </summary>
  1358. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  1359. protected override void Draw(GameTime gameTime)//rysowanie
  1360. {
  1361. GraphicsDevice.Clear(Color.CornflowerBlue);
  1362.  
  1363. if (gameState == 0)
  1364. {
  1365. DrawMenu(gameTime);
  1366. }
  1367. else if (gameState == 2)//hiscores
  1368. {
  1369. DrawHiscores(gameTime);
  1370. }
  1371. else if (gameState == 3)//Credits
  1372. {
  1373. DrawCredits(gameTime);
  1374. }
  1375. else if (gameState == 5)//Settings
  1376. {
  1377. DrawSettings(gameTime);
  1378. }
  1379.  
  1380. else
  1381. {
  1382. spriteBatch.Begin();
  1383. MyBackground.Draw(spriteBatch);
  1384. spriteBatch.End();
  1385.  
  1386. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>
  1387. spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Camera.TransformMatrix());
  1388.  
  1389. //<><><><<><><><><><><><><><><><><><><><><><><><><><><><><><><<>><><><><><><><><><><><><><><><><>
  1390. DrawScenery(gameTime);
  1391. DrawBullet();
  1392. DrawEnemies(gameTime);
  1393. DrawMandy(gameTime);
  1394. spriteBatch.End();
  1395. spriteBatch.Begin();
  1396. mandy.drawHP(heartTexture, screenHeight, screenWidth, spriteBatch);
  1397. DrawText();
  1398. spriteBatch.End();
  1399. if (gameState == 4)
  1400. {
  1401. DrawGameMenu(gameTime);
  1402. }
  1403. else if (gameState == 6)
  1404. {
  1405. DrawGamePause(gameTime);
  1406. }
  1407. // TODO: Add your drawing code here
  1408. }
  1409. base.Draw(gameTime);
  1410. }
  1411.  
  1412.  
  1413. }
  1414. }
Advertisement
Add Comment
Please, Sign In to add comment