Abdulg

C++ SDL SHMUP

Mar 9th, 2013
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 66.95 KB | None | 0 0
  1. /*
  2. Not responsible for any brain damage caused by reading this code
  3. Practically finished, will get 100% bug free when I have nothing else to do
  4. Now working on https://github.com/BenAbdul/tripping-octo-dangerzone
  5. */
  6.  
  7. #include "SDL.h"
  8. #include "SDL_image.h"
  9. #include "SDL_ttf.h"
  10. #include "SDL_mixer.h"
  11. #include "SDL_rotozoom.h"
  12. #include <string>
  13. #include <sstream>
  14. #include <time.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <fstream>
  18. #include <vector>
  19.  
  20. const int ScreenWidth = 640;
  21. const int ScreenHeight = 380;
  22. const int ScreenBBP = 32;
  23.  
  24. int PlzWork = 0;
  25. int PlzWork2 = 0;
  26. int PANIC = 0;
  27.  
  28. std::string Name1, Name2, Name3, CName1, CName2, CName3 = "DEADBEEF";
  29. std::string THESCORE;
  30.  
  31. std::stringstream Beat;
  32. std::stringstream Selection;
  33. std::stringstream NameOutputStream;
  34.  
  35. int HScore1, HScore2, HScore3, CHScore1, CHScore2, CHScore3;
  36. int MenuSelection = 1;
  37. int OptionSelection = 1;
  38. int GoToState = 0;
  39. int CauseOfDeath = 0;
  40. int ScoreBeaten = 7;
  41. int Lasers = 1;
  42. int Missiles = 3;
  43. int CurrentSelection = 2;
  44. int LaserTime = 0;
  45. int InvincibilityTime = 0;
  46. int Magnitude = 0;
  47. int Time = 0;
  48. int xShakeOffset = 0;
  49. int yShakeOffset = 0;
  50. int FlashAlpha = 0;
  51.  
  52. double Acceleration = 0.5;
  53. double Proc1, Proc2 = 120;
  54. double Backgroundx = 0;
  55.  
  56. long double PlayerScore = 0;
  57.  
  58. SDL_Event event;
  59.  
  60. std::vector <int> Projectiles;
  61. std::vector <int> Enemies;
  62. std::vector <int> EnemyProjectiles;
  63. std::vector <int> Locks;
  64. std::vector <int> MissileVector;
  65.  
  66. TTF_Font *Font = NULL;
  67. TTF_Font *SmallFont = NULL;
  68.  
  69. SDL_Colour TextColour = {225,225,225};
  70.  
  71. SDL_Surface *Character = NULL;
  72. SDL_Surface *YouTried = NULL;
  73. SDL_Surface *Character2 = NULL;
  74. SDL_Surface *Screen = NULL;
  75. SDL_Surface *BlackScreen = NULL;
  76. SDL_Surface *BlackRectangle = NULL;
  77. SDL_Surface *Message = NULL;
  78. SDL_Surface *Highlight = NULL;
  79. SDL_Surface *MissileSprite = NULL;
  80. SDL_Surface *Message2 = NULL;
  81. SDL_Surface *LaserAmmo = NULL;
  82. SDL_Surface *MissileAmmo = NULL;
  83. SDL_Surface *EnemyShip = NULL;
  84. SDL_Surface *Message3 = NULL;
  85. SDL_Surface *Message4 = NULL;
  86. SDL_Surface *Background = NULL;
  87. SDL_Surface *Projectile = NULL;
  88. SDL_Surface *Crosshair = NULL;
  89. SDL_Surface *AlphaGray = NULL;
  90. SDL_Surface *InvAnimation = NULL;
  91. SDL_Surface *EnemyInvader = NULL;
  92. SDL_Surface *EnemyProjectile = NULL;
  93. SDL_Surface *EnemyWorm = NULL;
  94. SDL_Surface *ScoreBackground = NULL;
  95. SDL_Surface *TitleText = NULL;
  96. SDL_Surface *TitleTextR = NULL;
  97. SDL_Surface *MegaLaser = NULL;
  98. SDL_Surface *MenuBackground = NULL;
  99. SDL_Surface *Burned = NULL;
  100. SDL_Surface *LockSprites = NULL;
  101. SDL_Surface *Score2 = NULL;
  102. SDL_Surface *Explosion = NULL;
  103. SDL_Surface *WeaponsMenu = NULL;
  104. SDL_Surface *InvincibilitySprite = NULL;
  105. SDL_Surface *FinalShip = NULL;
  106. SDL_Surface *RotShip = NULL;
  107. SDL_Surface *WhiteFlash = NULL;
  108. SDL_Surface *ShipMoving1 = NULL;
  109. SDL_Surface *ShipMoving2 = NULL;
  110. SDL_Surface *ShipMoving3 = NULL;
  111. SDL_Surface *ShipIdle = NULL;
  112.  
  113. Mix_Music *MenuMusic = NULL;
  114. Mix_Music *GameMusic = NULL;
  115. Mix_Chunk *ProjectileFired = NULL;
  116. Mix_Chunk *Death1 = NULL;
  117. Mix_Chunk *Death2 = NULL;
  118. Mix_Chunk *Death3 = NULL;
  119. Mix_Chunk *Death4 = NULL;
  120. Mix_Chunk *PlayerDeath = NULL;
  121. Mix_Chunk *Rocket = NULL;
  122.  
  123. bool Quit = false;
  124. bool PlaySound = true;
  125. bool PlayMusic = true;
  126. bool Applied = false;
  127. bool DebugBool = false;
  128. bool GenerationPaused = false;
  129. bool CasualMode = false;
  130. bool Start = false;
  131. bool MusicPlaying = false;
  132. bool EnemyHit = false;
  133. bool HighScoreBeaten = false;
  134. bool LaserFiring = false;
  135. bool Pushed = false;
  136. bool Rival = false;
  137. bool Invincible = false;
  138. bool Shake = false;
  139. bool Flash = false;
  140. bool lrn2program = false;
  141. bool Lazy = false;
  142.  
  143. bool LeftDown,RightDown,UpDown,DownDown = false;
  144.  
  145. SDL_Rect WormFrames [2];
  146. SDL_Rect ProjectileFrames [2];
  147. SDL_Rect ShipFrames [2];
  148. SDL_Rect InvFrames [9];
  149. SDL_Rect AmmoFrames [2];
  150. SDL_Rect LockFrames [4];
  151. SDL_Rect MissileClips [2];
  152. SDL_Rect WMenuClips [3];
  153.  
  154. enum GAMESTATE {INTRO,MAINMENU,SCORES,GAME,OPTIONS};
  155. GAMESTATE STATE = INTRO;
  156.  
  157. SDL_Surface *LoadImage( std::string filename )
  158. {
  159.     SDL_Surface* LoadedImage = NULL;
  160.     SDL_Surface* OptimizedImage = NULL;
  161.         LoadedImage = IMG_Load( filename.c_str() );
  162.     if( LoadedImage != NULL )
  163.     {
  164.         OptimizedImage = SDL_DisplayFormatAlpha( LoadedImage );
  165.         SDL_FreeSurface( LoadedImage );
  166.     }
  167.     return OptimizedImage;
  168. }
  169.  
  170. void ApplySurface( int x, int y, SDL_Surface* Source, SDL_Surface* Destination, SDL_Rect* Clip = NULL )
  171. {
  172.     SDL_Rect offset;
  173.  
  174.     offset.x = x + xShakeOffset;
  175.     offset.y = y + yShakeOffset;
  176.    
  177.     SDL_BlitSurface( Source, Clip, Destination, &offset );
  178. }
  179.  
  180. void LoadScores()
  181. {
  182.     std::ifstream ScoreInput;
  183.     ScoreInput.open("TopLel.dll");
  184.     ScoreInput >> Name1 >> Name2 >> Name3 >> CName1 >> CName2 >> CName3 >> HScore1 >> HScore2 >> HScore3 >> CHScore1 >> CHScore2 >> CHScore3;
  185.     ScoreInput.close();
  186. }
  187.  
  188. bool LoadFiles()
  189. {
  190.     Character = LoadImage("Resources/Images/Ship.png");
  191.     if (Character == NULL) return false;
  192.     InvAnimation = LoadImage("Resources/Images/InvAnimation.png");
  193.     if (InvAnimation == NULL) return false;
  194.     Character2 = LoadImage("Resources/Images/Ship2.png");
  195.     if (Character2 == NULL) return false;
  196.     AlphaGray = LoadImage("Resources/Images/AlphaGray.png");
  197.     if (AlphaGray == NULL) return false;
  198.     BlackScreen = LoadImage("Resources/Images/Black.png");
  199.     if (BlackScreen == NULL) return false;
  200.     YouTried = LoadImage("Resources/Images/YouTried.png");
  201.     if (YouTried == NULL) return false;
  202.     EnemyShip = LoadImage("Resources/Images/EnemyShip.png");
  203.     if (EnemyShip == NULL) return false;
  204.     Explosion = LoadImage("Resources/Images/Explosion.png");
  205.     if (Explosion == NULL) return false;
  206.     ScoreBackground = LoadImage("Resources/Images/Score.png");
  207.     if (ScoreBackground == NULL) return false;
  208.     MegaLaser = LoadImage("Resources/Images/MegaLaser.png");
  209.     if (MegaLaser == NULL) return false;
  210.     InvincibilitySprite = LoadImage("Resources/Images/Blue.png");
  211.     if (InvincibilitySprite == NULL) return false;
  212.     BlackRectangle = LoadImage("Resources/Images/BlackRectangle.png");
  213.     if (BlackRectangle == NULL) return false;
  214.     Highlight = LoadImage("Resources/Images/Highlight.png");
  215.     if (Highlight == NULL) return false;
  216.     Background = LoadImage("Resources/Images/Background.png");
  217.     if (Background == NULL) return false;
  218.     WhiteFlash = IMG_Load("Resources/Images/WhiteFlash.bmp");
  219.     if (WhiteFlash == NULL) return false;
  220.     LaserAmmo = LoadImage("Resources/Images/LaserAmmo.png");
  221.     if (LaserAmmo == NULL) return false;
  222.     MissileSprite = LoadImage("Resources/Images/Missile.png");
  223.     if (MissileSprite == NULL) return false;
  224.     MissileAmmo = LoadImage("Resources/Images/MissileAmmo.png");
  225.     if (MissileAmmo == NULL) return false;
  226.     LockSprites = LoadImage("Resources/Images/Locks.png");
  227.     if (LockSprites == NULL) return false;
  228.     Projectile = LoadImage("Resources/Images/Projectile.png");
  229.     if (Projectile == NULL) return false;
  230.     EnemyInvader = LoadImage("Resources/Images/Invader.png");
  231.     if (EnemyInvader == NULL) return false;
  232.     Burned = LoadImage("Resources/Images/Burned.png");
  233.     if (Burned == NULL) return false;
  234.     ShipMoving1 = LoadImage("Resources/Images/ShipMoving1.png");
  235.     if (ShipMoving1 == NULL) return false;
  236.     ShipMoving2 = LoadImage("Resources/Images/ShipMoving2.png");
  237.     if (ShipMoving2 == NULL) return false;
  238.     ShipMoving3 = LoadImage("Resources/Images/ShipMoving3.png");
  239.     if (ShipMoving3 == NULL) return false;
  240.     ShipIdle = LoadImage("Resources/Images/ShipIdle.png");
  241.     if (ShipIdle == NULL) return false;
  242.     Score2 = LoadImage("Resources/Images/Score2.png");
  243.     if (Score2 == NULL) return false;
  244.     TitleText = LoadImage("Resources/Images/TitleText.png");
  245.     if (TitleText == NULL) return false;
  246.     Crosshair = LoadImage("Resources/Images/Crosshair.png");
  247.     if (Crosshair == NULL) return false;
  248.     MenuBackground = LoadImage("Resources/Images/MenuBackground.png");
  249.     if (MenuBackground == NULL) return false;
  250.     WeaponsMenu = LoadImage("Resources/Images/WeaponsMenu.png");
  251.     if (WeaponsMenu == NULL) return false;
  252.     EnemyProjectile = LoadImage("Resources/Images/EnemyProjectile.png");
  253.     if (EnemyProjectile == NULL) return false;
  254.     EnemyWorm = LoadImage("Resources/Images/Worm.png");
  255.     if (EnemyWorm == NULL) return false;
  256.     MenuMusic = Mix_LoadMUS ("Resources/Sounds/Menu.ogg");
  257.     if (MenuMusic == NULL) return false;
  258.     GameMusic = Mix_LoadMUS ("Resources/Sounds/Game.ogg");
  259.     if (GameMusic == NULL) return false;
  260.     ProjectileFired = Mix_LoadWAV ("Resources/Sounds/ProjectileFired.wav");
  261.     if (ProjectileFired == NULL) return false;
  262.     PlayerDeath = Mix_LoadWAV ("Resources/Sounds/PlayerDeath.wav");
  263.     if (PlayerDeath == NULL) return false;
  264.     Death1 = Mix_LoadWAV ("Resources/Sounds/Death1.wav");
  265.     if (Death1 == NULL) return false;
  266.     Death2 = Mix_LoadWAV ("Resources/Sounds/Death2.wav");
  267.     if (Death2 == NULL) return false;
  268.     Death3 = Mix_LoadWAV ("Resources/Sounds/Death3.wav");
  269.     if (Death3 == NULL) return false;
  270.     Death4 = Mix_LoadWAV ("Resources/Sounds/Death4.wav");
  271.     if (Death4 == NULL) return false;
  272.     Rocket = Mix_LoadWAV ("Resources/Sounds/Rocket.wav");
  273.     if (Rocket == NULL) return false;
  274.     Font = TTF_OpenFont("Resources/Fonts/Arcade.ttf",16);
  275.     if (Font == NULL) return false;
  276.     SmallFont = TTF_OpenFont("Resources/Fonts/Arcade.ttf",9);
  277.     if (SmallFont == NULL) return false;
  278.     LoadScores();
  279. }
  280.  
  281. void CleanUp()
  282. {
  283. }
  284.  
  285. bool Initiate()
  286. {
  287.     if (SDL_Init(SDL_INIT_EVERYTHING) == -1) return false;
  288.     if (TTF_Init() == -1) return false;
  289.     Screen = SDL_SetVideoMode(ScreenWidth,ScreenHeight,ScreenBBP,SDL_SWSURFACE);
  290.     if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) return false;
  291.     SDL_WM_SetCaption("Smash it Scown", NULL);
  292.     SDL_EnableUNICODE(SDL_ENABLE);
  293.     return true;
  294. }
  295.  
  296. void StartShake(int T, int M)
  297. {
  298.     Shake = true;
  299.     Time = T;
  300.     Magnitude = M;
  301. }
  302.  
  303. void StartFlash()
  304. {
  305.     if (Flash == false)
  306.     {
  307.         Flash = true;
  308.         FlashAlpha = 255;
  309.     }
  310. }
  311.  
  312. int GetNumberInput()
  313. {
  314.     SDL_Surface *WorkYouPrick = NULL;
  315.     int NumberToReturn = 0;
  316.     std::stringstream SpareStream;
  317.     SpareStream << NumberToReturn;
  318.     while (Quit == false)
  319.     {
  320.         WorkYouPrick = TTF_RenderText_Solid(Font,SpareStream.str().c_str(),TextColour);
  321.         ApplySurface ((ScreenWidth-BlackRectangle->w)/2,(ScreenHeight-BlackRectangle->h)/2,BlackRectangle,Screen);
  322.         ApplySurface ((ScreenWidth-WorkYouPrick->w)/2,(ScreenHeight-WorkYouPrick->h)/2,WorkYouPrick,Screen);
  323.         SDL_Flip(Screen);
  324.         while(SDL_PollEvent(&event))
  325.         {
  326.             if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) { ApplySurface ((ScreenWidth-BlackRectangle->w)/2,(ScreenHeight-BlackRectangle->h)/2,BlackRectangle,Screen);  return NumberToReturn;}
  327.             if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RIGHT)
  328.             {
  329.                 NumberToReturn++;
  330.                 SpareStream.str("");
  331.                 SpareStream << NumberToReturn;
  332.             }
  333.             if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_LEFT)
  334.             {
  335.                 if (NumberToReturn != 0) NumberToReturn--;
  336.                 SpareStream.str("");
  337.                 SpareStream << NumberToReturn;
  338.             }
  339.             if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_q)
  340.             {
  341.                 if (NumberToReturn - 10 < 0) NumberToReturn = 0;
  342.                 else NumberToReturn = NumberToReturn - 10;
  343.                 SpareStream.str("");
  344.                 SpareStream << NumberToReturn;
  345.             }
  346.             if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_e)
  347.             {
  348.                 NumberToReturn = NumberToReturn + 10;
  349.                 SpareStream.str("");
  350.                 SpareStream << NumberToReturn;
  351.             }
  352.             if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_a)
  353.             {
  354.                 if (NumberToReturn - 100 < 0) NumberToReturn = 0;
  355.                 else NumberToReturn = NumberToReturn -  100;
  356.                 SpareStream.str("");
  357.                 SpareStream << NumberToReturn;
  358.             }
  359.             if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_d)
  360.             {
  361.                 NumberToReturn = NumberToReturn + 100;
  362.                 SpareStream.str("");
  363.                 SpareStream << NumberToReturn;
  364.             }
  365.             if (event.type == SDL_QUIT) Quit = true;
  366.         }
  367.     }
  368. }
  369.  
  370. int RandomNumber(int First, int Second)
  371. {
  372.     return rand () % First + Second;
  373. }
  374.  
  375.  
  376.  
  377. class Player
  378. {
  379. public:
  380.     double x,y;
  381.     int Frame,Frametime;
  382.     int Animation;
  383.     double xVel,yVel;
  384.  
  385.     void Die();
  386.     void RefreshPosition();
  387.     void RenderShip();
  388.  
  389.     Player();
  390. } Ship;
  391.  
  392. Player::Player()
  393. {
  394.     x = 0;
  395.     y = ScreenHeight / 2;
  396.     xVel, yVel = 0;
  397.     Frame = 1;
  398.     Frametime = 0;
  399.     Animation = 2;
  400. }
  401.  
  402. void Player::RenderShip()
  403. {
  404.     if(Invincible == false)
  405.     {
  406.         if (xVel != 0)
  407.         {
  408.             if (Frame > 3)
  409.             {
  410.                 Frame = 1;
  411.             }
  412.             Frametime++;
  413.             if (Frametime > 10)
  414.             {
  415.                 Frame++;
  416.                 Frametime = 0;
  417.             }
  418.  
  419.             switch (Frame)
  420.             {
  421.             case 1:
  422.                 FinalShip = ShipMoving1;
  423.                 break;
  424.             case 2:
  425.                 FinalShip = ShipMoving2;
  426.                 break;
  427.             case 3:
  428.                 FinalShip = ShipMoving3;
  429.                 break;
  430.             }
  431.         }
  432.         else (FinalShip = ShipIdle);
  433.         RotShip = rotozoomSurface(FinalShip,yVel,1,0);
  434.         ApplySurface(x - 14, y, RotShip, Screen);
  435.     }
  436.  
  437.     else
  438.     {
  439.         Frametime++;
  440.  
  441.         if (Frametime > 9)
  442.         {
  443.             Frame++;
  444.             Frametime = 0;
  445.         }
  446.  
  447.         if (Frame > 9) Frame = 1;
  448.  
  449.         ApplySurface(x,y,InvAnimation,Screen,&InvFrames[Frame]);
  450.     }
  451. }
  452.  
  453. class Timer
  454. {
  455.     private:
  456.     int startTicks;
  457.     int pausedTicks;
  458.     bool paused;
  459.     bool started;
  460.  
  461.     public:
  462.     Timer();
  463.     void start();
  464.     void stop();
  465.     void pause();
  466.     void unpause();
  467.     int get_ticks();
  468.     bool is_started();
  469.     bool is_paused();
  470. };
  471.  
  472. Timer::Timer()
  473. {
  474.     startTicks = 0;
  475.     pausedTicks = 0;
  476.     paused = false;
  477.     started = false;
  478. }
  479.  
  480. void Timer::start()
  481. {
  482.     started = true;
  483.     paused = false;
  484.     startTicks = SDL_GetTicks();
  485. }
  486.  
  487. void Timer::stop()
  488. {
  489.     started = false;
  490.     paused = false;
  491. }
  492.  
  493. void Timer::pause()
  494. {
  495.     if( ( started == true ) && ( paused == false ) )
  496.     {
  497.         paused = true;
  498.         pausedTicks = SDL_GetTicks() - startTicks;
  499.     }
  500. }
  501.  
  502. void Timer::unpause()
  503. {
  504.     if( paused == true )
  505.     {
  506.         paused = false;
  507.         startTicks = SDL_GetTicks() - pausedTicks;
  508.         pausedTicks = 0;
  509.     }
  510. }
  511.  
  512. int Timer::get_ticks()
  513. {
  514.     if( started == true )
  515.     {
  516.         if( paused == true )
  517.         {
  518.             return pausedTicks;
  519.         }
  520.         else
  521.         {
  522.             return SDL_GetTicks() - startTicks;
  523.         }
  524.     }
  525.     return 0;
  526. }
  527.  
  528. bool Timer::is_started()
  529. {
  530.     return started;
  531. }
  532.  
  533. bool Timer::is_paused()
  534. {
  535.     return paused;
  536. }
  537.  
  538. void SetClips()
  539. {
  540.     WormFrames[0].x = 0;
  541.     WormFrames[0].y = 0;
  542.     WormFrames[0].w = 50;
  543.     WormFrames[0].h = 50;
  544.  
  545.     WormFrames[1].x = 50;
  546.     WormFrames[1].y = 0;
  547.     WormFrames[1].w = 50;
  548.     WormFrames[1].h = 50;
  549.  
  550.     AmmoFrames[0].x = 0;
  551.     AmmoFrames[0].y = 0;
  552.     AmmoFrames[0].w = 25;
  553.     AmmoFrames[0].h = 25;
  554.  
  555.     AmmoFrames[1].x = 25;
  556.     AmmoFrames[1].y = 0;
  557.     AmmoFrames[1].w = 25;
  558.     AmmoFrames[1].h = 25;
  559.  
  560.     ProjectileFrames[0].x = 0;
  561.     ProjectileFrames[0].y = 0;
  562.     ProjectileFrames[0].w = 30;
  563.     ProjectileFrames[0].h = 10;
  564.  
  565.     ProjectileFrames[1].x = 30;
  566.     ProjectileFrames[1].y = 0;
  567.     ProjectileFrames[1].w = 30;
  568.     ProjectileFrames[1].h = 10;
  569.  
  570.     ShipFrames[0].x = 0;
  571.     ShipFrames[0].y = 0;
  572.     ShipFrames[0].w = 39;
  573.     ShipFrames[0].h = 20;
  574.  
  575.     ShipFrames[1].x = 39;
  576.     ShipFrames[1].y = 0;
  577.     ShipFrames[1].w = 39;
  578.     ShipFrames[1].h = 20;
  579.  
  580.     LockFrames[0].x = 0;
  581.     LockFrames[0].y = 0;
  582.     LockFrames[0].w = 48;
  583.     LockFrames[0].h = 50;
  584.  
  585.     LockFrames[1].x = 49;
  586.     LockFrames[1].y = 0;
  587.     LockFrames[1].w = 48;
  588.     LockFrames[1].h = 50;
  589.  
  590.     LockFrames[2].x = 98;
  591.     LockFrames[2].y = 0;
  592.     LockFrames[2].w = 48;
  593.     LockFrames[2].h = 50;
  594.  
  595.     LockFrames[3].x = 147;
  596.     LockFrames[3].y = 0;
  597.     LockFrames[3].w = 48;
  598.     LockFrames[3].h = 50;
  599.  
  600.     MissileClips[0].x = 0;
  601.     MissileClips[0].y = 0;
  602.     MissileClips[0].w = 38;
  603.     MissileClips[0].h = 17;
  604.  
  605.     MissileClips[1].x = 39;
  606.     MissileClips[1].y = 0;
  607.     MissileClips[1].w = 38;
  608.     MissileClips[1].h = 17;
  609.  
  610.     WMenuClips[0].x = 0;
  611.     WMenuClips[0].y = 0;
  612.     WMenuClips[0].w = 350;
  613.     WMenuClips[0].h = 200;
  614.  
  615.     WMenuClips[1].x = 350;
  616.     WMenuClips[1].y = 0;
  617.     WMenuClips[1].w = 350;
  618.     WMenuClips[1].h = 200;
  619.  
  620.     WMenuClips[2].x = 700;
  621.     WMenuClips[2].y = 0;
  622.     WMenuClips[2].w = 350;
  623.     WMenuClips[2].h = 200;
  624.  
  625.     for (int werk = 0; werk <= 8; werk++)
  626.     {
  627.         InvFrames[werk].x = (36 * werk) + werk;
  628.         InvFrames[werk].y = 0;
  629.         InvFrames[werk].w = 36;
  630.         InvFrames[werk].h = 20;
  631.     }
  632. }
  633.  
  634. void RenderProjectiles()
  635. {
  636.     int PlayerProjectileVectorSize = Projectiles.size();
  637.     if (PlayerProjectileVectorSize >= 5)
  638.     {
  639.         for (int i = 0; i <= PlayerProjectileVectorSize - 1; i+=5)
  640.         {
  641.             if (Projectiles.at(i + 3) == 1)
  642.             {
  643.             int x = Projectiles.at(i);
  644.             int y = Projectiles.at(i + 1);
  645.             ApplySurface(x,y,Projectile,Screen,&ProjectileFrames[Projectiles.at(i + 2)]);
  646.             }
  647.         }
  648.     }
  649.  
  650.     if (EnemyProjectiles.size() >= 5)
  651.     {
  652.         for (int i = 0; i <= EnemyProjectiles.size() - 1; i+=5)
  653.         {
  654.             if (EnemyProjectiles.at(i + 3) == 1)
  655.             {
  656.                 int x = EnemyProjectiles.at(i);
  657.                 int y = EnemyProjectiles.at(i + 1);
  658.                 if (EnemyProjectiles.at(i + 2) < 2) ApplySurface(x,y,EnemyProjectile,Screen,&ProjectileFrames[EnemyProjectiles.at(i + 2)]);
  659.                 else
  660.                 {
  661.                     if (EnemyProjectiles.at(i + 2) == 3) ApplySurface(x,y,EnemyProjectile,Screen,&ProjectileFrames[0]);
  662.                     else ApplySurface(x,y,EnemyProjectile,Screen,&ProjectileFrames[1]);
  663.                 }
  664.             }
  665.         }
  666.     }
  667. }
  668.  
  669. void UpdateProjectiles()
  670. {
  671.     if (Projectiles.size() >= 5)
  672.     {
  673.         for (int i = 0; i <= Projectiles.size() - 5; i+=5)
  674.         {
  675.             Projectiles.at(i) += 15;
  676.             Projectiles.at(i) -= 7;
  677.             ++ Projectiles.at(i + 4);
  678.             if (Projectiles.at(i + 4) > 10)
  679.             {
  680.                 Projectiles.at(i + 4) = 0;
  681.                 ++Projectiles.at(i + 2);
  682.             }
  683.             if (Projectiles.at(i + 2) > 1) Projectiles.at(i + 2) = 0;
  684.         }
  685.     }
  686.  
  687.     if (EnemyProjectiles.size() >= 5)
  688.     {
  689.         for (int i = 0; i <= EnemyProjectiles.size() - 5; i+=5)
  690.         {
  691.             EnemyProjectiles.at(i) -= 7;
  692.             ++ EnemyProjectiles.at(i + 4);
  693.             if (EnemyProjectiles.at(i + 4) > 10)
  694.             {
  695.                 EnemyProjectiles.at(i + 4) = 0;
  696.                 EnemyProjectiles.at(i + 2)++;
  697.             }
  698.             if (EnemyProjectiles.at(i + 2) == 2) EnemyProjectiles.at(i + 2) = 0;
  699.             if (EnemyProjectiles.at(i + 2) == 5)
  700.             {
  701.                 EnemyProjectiles.at(i + 2) = 3;
  702.             }
  703.         }
  704.     }
  705. }
  706.  
  707. bool GenerateChance(int Chance)
  708. {
  709.     int a = rand() % 100 + 1;
  710.     if (a <= Chance) return true;
  711.     else return false;
  712. }
  713.  
  714. void PlayDeathSound()
  715. {
  716.     if (PlaySound == true)
  717.     {
  718.         int WHEELOFFORTUNE = RandomNumber(100,1);
  719.         if (WHEELOFFORTUNE < 25) Mix_PlayChannel( -1, Death1, 0 );
  720.         else if (WHEELOFFORTUNE < 50) Mix_PlayChannel( -1, Death2, 0 );
  721.         else if (WHEELOFFORTUNE < 75) Mix_PlayChannel( -1, Death3, 0 );
  722.         else Mix_PlayChannel( -1, Death4, 0 );
  723.     }
  724. }
  725.  
  726. void UpdateEnemies()
  727. {
  728.     if (Enemies.size() >= 6)
  729.     {
  730.         for (int i = 0;  i <= Enemies.size() - 6; i+=6)
  731.         {
  732.                 if (Enemies.at(i + 4) == 1) //If the enemy is an alien
  733.                 {
  734.                     Enemies.at(i) -= 10; //SPEED
  735.                     int wtf = Enemies.at(i + 3);
  736.                     Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
  737.                     if (Enemies.at(i + 3) >= 20)
  738.                     {
  739.                         Enemies.at(i + 2) ++;
  740.                         Enemies.at(i + 3) = 0;
  741.                     }
  742.                     if (Enemies.at(i + 2) == 3) Enemies.at(i + 2) = 1;
  743.                 }
  744.  
  745.                 if (Enemies.at(i + 4) == 4) //If its an enemy ship
  746.                 {
  747.                     if (Enemies.at(i) > 550) Enemies.at(i) -= 5; //SPEED
  748.                     else
  749.                     {
  750.                         if (Enemies.at(i + 1) > Ship.y + 15)
  751.                         {
  752.                             if (Enemies.at(i + 1) - 1 < Ship.y + 15) Enemies.at(i + 1) = Ship.y + 15;
  753.                             else Enemies.at(i + 1) -= 1;
  754.                         }
  755.                            
  756.                         if (Enemies.at(i + 1) < Ship.y)
  757.                         {
  758.                             if (Enemies.at(i + 1) + 1 > Ship.y + 15) Enemies.at(i + 1) = Ship.y+ 15;
  759.                             else Enemies.at(i + 1) += 1;
  760.                         }
  761.                     }
  762.                     int wtf = Enemies.at(i + 3);
  763.                     Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
  764.                     if (Enemies.at(i + 3) >= 20)
  765.                     {
  766.                         Enemies.at(i + 2) ++;
  767.                         Enemies.at(i + 3) = 0;
  768.                     }
  769.                     if (Enemies.at(i + 2) == 3 && Enemies.at(i + 5) == 1)
  770.                     {
  771.                         Enemies.at(i + 2) = 1;
  772.                         EnemyProjectiles.push_back(Enemies.at(i));
  773.                         EnemyProjectiles.push_back(Enemies.at(i + 1) + 5);
  774.                         EnemyProjectiles.push_back(3);
  775.                         EnemyProjectiles.push_back(1);
  776.                         EnemyProjectiles.push_back(0);
  777.                     }
  778.                 }
  779.  
  780.                 if (Enemies.at(i + 4) == 5) //If its a laser powerup
  781.                 {
  782.                     Enemies.at(i) -= 5; //SPEED
  783.                     int wtf = Enemies.at(i + 3);
  784.                     Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
  785.                     if (Enemies.at(i + 3) >= 20)
  786.                     {
  787.                         Enemies.at(i + 2) ++;
  788.                         Enemies.at(i + 3) = 0;
  789.                     }
  790.                     if (Enemies.at(i + 2) == 3) Enemies.at(i + 2) = 1;
  791.                 }
  792.  
  793.                 if (Enemies.at(i + 4) == 6) //If its a missile powerup
  794.                 {
  795.                     Enemies.at(i) -= 5; //SPEED
  796.                     int wtf = Enemies.at(i + 3);
  797.                     Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
  798.                     if (Enemies.at(i + 3) >= 20)
  799.                     {
  800.                         Enemies.at(i + 2) ++;
  801.                         Enemies.at(i + 3) = 0;
  802.                     }
  803.                     if (Enemies.at(i + 2) == 3) Enemies.at(i + 2) = 1;
  804.                 }
  805.  
  806.                 if (Enemies.at(i + 4) == 7) //If its a invincibility powerup
  807.                 {
  808.                     Enemies.at(i) -= 5; //SPEED
  809.                     int wtf = Enemies.at(i + 3);
  810.                     Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
  811.                     if (Enemies.at(i + 3) >= 20)
  812.                     {
  813.                         Enemies.at(i + 2) ++;
  814.                         Enemies.at(i + 3) = 0;
  815.                     }
  816.                     if (Enemies.at(i + 2) == 3) Enemies.at(i + 2) = 1;
  817.                 }
  818.  
  819.                 if (Enemies.at(i + 4) == 2) //If the enemy is a worm
  820.                 {
  821.                     Enemies.at(i) -= 5; //SPEED
  822.                     int wtf = Enemies.at(i + 3);
  823.                     Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
  824.                     if (Enemies.at(i + 3) >= 10)
  825.                     {
  826.                         Enemies.at(i + 2) ++;
  827.                         Enemies.at(i + 3) = 0;
  828.                     }
  829.                     if (Enemies.at(i + 2) == 3) Enemies.at(i + 2) = 1;
  830.  
  831.                     if (GenerateChance(2) == true && Enemies.at(i + 5) == 1 && Enemies.at(i + 2) == 1)
  832.                     {
  833.                         EnemyProjectiles.push_back(Enemies.at(i));
  834.                         EnemyProjectiles.push_back(Enemies.at(i + 1) + 25);
  835.                         EnemyProjectiles.push_back(0);
  836.                         EnemyProjectiles.push_back(1);
  837.                         EnemyProjectiles.push_back(0);
  838.                     }
  839.                 }
  840.                 if (Enemies.at(i + 4) == 3) //Crosshair
  841.                 {
  842.                     Enemies.at(i) -= 3;
  843.                     if (Enemies.at(i) > Ship.x)
  844.                     {
  845.                         if (Enemies.at(i + 1) > Ship.y + 15)
  846.                         {
  847.                             if (Enemies.at(i + 1) - 1 < Ship.y + 15) Enemies.at(i + 1) = Ship.y + 15;
  848.                             else Enemies.at(i + 1) -= 1;
  849.                         }
  850.                            
  851.                         if (Enemies.at(i + 1) < Ship.y)
  852.                         {
  853.                             if (Enemies.at(i + 1) + 1 > Ship.y + 15) Enemies.at(i + 1) = Ship.y+ 15;
  854.                             else Enemies.at(i + 1) += 1;
  855.                         }
  856.                     }
  857.                 }
  858.         }
  859.     }
  860. }
  861.  
  862. void GenerateEnemy()
  863. {
  864.  
  865.     if(GenerateChance(8) == true) //Crosshair
  866.     {
  867.         Enemies.push_back(640); //x
  868.         Enemies.push_back(Ship.y); //y
  869.         Enemies.push_back(1); //Frame
  870.         Enemies.push_back(0); //Frame time
  871.         Enemies.push_back(3); //Type
  872.         Enemies.push_back(1); //Visible psuedobool
  873.     }
  874.    
  875.     if(GenerateChance(2) == true && Rival == false) //Rival
  876.     {
  877.         Enemies.push_back(640); //x
  878.         Enemies.push_back(Ship.y); //y
  879.         Enemies.push_back(1); //Frame
  880.         Enemies.push_back(0); //Frame time
  881.         Enemies.push_back(4); //Type
  882.         Enemies.push_back(1); //Visible psuedobool
  883.         Rival = true;
  884.     }
  885.  
  886.     Enemies.push_back(640); //x
  887.     Enemies.push_back(RandomNumber(360,-10)); //y
  888.     Enemies.push_back(1); //Frame
  889.     Enemies.push_back(0); //Frame time
  890.     Enemies.push_back(RandomNumber(2,1)); //Type
  891.     Enemies.push_back(1); //Visible psuedobool
  892.    
  893. }
  894.  
  895.  
  896. void RenderEnemies()
  897. {
  898.     if (Enemies.size() >= 6)
  899.     {
  900.         for (int i = 0;  i <= Enemies.size() - 6; i+=6)
  901.         {
  902.             if (Enemies.at(i + 5) == 1) //If the enemy is visible
  903.             {
  904.                 int x = Enemies.at(i);
  905.                 int y = Enemies.at(i + 1);
  906.  
  907.                 SetClips();
  908.  
  909.                 if (Enemies.at(i + 4) == 1) //If the enemy is a Invader
  910.                 {
  911.                     if (Enemies.at(i + 2) == 1)
  912.                     {
  913.                         ApplySurface (x, y, EnemyInvader, Screen, &WormFrames[0]);
  914.                     }
  915.                     else if (Enemies.at(i + 2) == 2)
  916.                     {
  917.                         ApplySurface (x, y, EnemyInvader, Screen, &WormFrames[1]);
  918.                     }
  919.                 }
  920.  
  921.                 if (Enemies.at(i + 4) == 4) //If the enemy is a rival ship
  922.                 {
  923.                     if (Enemies.at(i + 2) == 1)
  924.                     {
  925.                         ApplySurface (x, y, EnemyShip, Screen, &ShipFrames[0]);
  926.                     }
  927.                     else if (Enemies.at(i + 2) == 2)
  928.                     {
  929.                         ApplySurface (x, y, EnemyShip, Screen, &ShipFrames[1]);
  930.                     }
  931.                 }
  932.  
  933.                 if (Enemies.at(i + 4) == 2) //If the enemy is a Worm
  934.                 {
  935.                     if (Enemies.at(i + 2) == 1)
  936.                     {
  937.                         ApplySurface (x, y, EnemyWorm, Screen, &WormFrames[0]);
  938.                     }
  939.                     else if (Enemies.at(i + 2) == 2)
  940.                     {
  941.                         ApplySurface (x, y, EnemyWorm, Screen, &WormFrames[1]);
  942.                     }
  943.                 }
  944.  
  945.                 if (Enemies.at(i + 4) == 5) //If its a laser powerup
  946.                 {
  947.                     if (Enemies.at(i + 2) == 1)
  948.                     {
  949.                         ApplySurface (x, y, LaserAmmo, Screen, &AmmoFrames[0]);
  950.                     }
  951.                     else if (Enemies.at(i + 2) == 2)
  952.                     {
  953.                         ApplySurface (x, y, LaserAmmo, Screen, &AmmoFrames[1]);
  954.                     }
  955.                 }
  956.  
  957.                 if (Enemies.at(i + 4) == 7) //If its a missile powerup
  958.                 {
  959.                     if (Enemies.at(i + 2) == 1)
  960.                     {
  961.                         ApplySurface (x, y, MissileAmmo, Screen, &AmmoFrames[0]);
  962.                     }
  963.                     else if (Enemies.at(i + 2) == 2)
  964.                     {
  965.                         ApplySurface (x, y, MissileAmmo, Screen, &AmmoFrames[1]);
  966.                     }
  967.                 }
  968.  
  969.                 if (Enemies.at(i + 4) == 7) //If its an invincibility powerup
  970.                 {
  971.                     if (Enemies.at(i + 2) == 1)
  972.                     {
  973.                         ApplySurface (x, y, InvincibilitySprite, Screen, &AmmoFrames[0]);
  974.                     }
  975.                     else if (Enemies.at(i + 2) == 2)
  976.                     {
  977.                         ApplySurface (x, y, InvincibilitySprite, Screen, &AmmoFrames[1]);
  978.                     }
  979.                 }
  980.  
  981.                 else if (Enemies.at(i + 4) == 3)
  982.                 {
  983.                     ApplySurface (x, y, Crosshair, Screen);
  984.                     PlzWork2++;
  985.                 }
  986.             }
  987.         }
  988.     }
  989. }
  990.  
  991.  
  992. void ResetGame()
  993. {
  994.     ApplySurface(0,0,BlackScreen,Screen);
  995.     EnemyHit = false;
  996.     HighScoreBeaten = false;
  997.     Backgroundx = 0;
  998.     lrn2program = false;
  999.     LeftDown,RightDown,UpDown,DownDown = false;
  1000.     Rival = false;
  1001.     Proc1 = 50;
  1002.     Proc2 = 50;
  1003.     Lasers = 1;
  1004.     Missiles = 3;
  1005.     CurrentSelection = 2;
  1006.     LaserFiring = false;
  1007.     LaserTime = 0;
  1008.     if (Enemies.size() > 0) Enemies.erase(Enemies.begin(),Enemies.end());
  1009.     if (Projectiles.size() > 0) Projectiles.erase(Projectiles.begin(),Projectiles.end());
  1010.     if (EnemyProjectiles.size() > 0) EnemyProjectiles.erase(EnemyProjectiles.begin(),EnemyProjectiles.end());
  1011.     if (Locks.size() > 0) Locks.erase(Locks.begin(),Locks.end());
  1012.     if (MissileVector.size() > 0) MissileVector.erase(MissileVector.begin(),MissileVector.end());
  1013.     Ship.x = 0;
  1014.     Ship.y = ScreenHeight / 2;
  1015.     Ship.xVel = 0;
  1016.     Ship.yVel = 0;
  1017.     PlayerScore = 0;
  1018.     Start = false;
  1019.    
  1020. }
  1021.  
  1022. void SortScores()
  1023. {
  1024.     Beat.str("");
  1025.     HighScoreBeaten = true;
  1026.     if (CasualMode == false)
  1027.     {
  1028.         if (PlayerScore > HScore1)
  1029.         {
  1030.             HScore3 = HScore2;
  1031.             HScore2 = HScore1;
  1032.             HScore1 = PlayerScore;
  1033.             Beat << "You beat the high score!";
  1034.             ScoreBeaten = 1;
  1035.         }
  1036.         else if (PlayerScore > HScore2)
  1037.         {
  1038.             HScore3 = HScore2;
  1039.             HScore2 = PlayerScore;
  1040.             Beat << "2nd. Meh.";
  1041.             ScoreBeaten = 2;
  1042.         }
  1043.         else if (PlayerScore > HScore3)
  1044.         {
  1045.             HScore3 = PlayerScore;
  1046.             Beat << "Just made it. Try harder next time.";
  1047.             ScoreBeaten = 3;
  1048.         }
  1049.         else
  1050.         {
  1051.             Beat << "You suck.";
  1052.             ScoreBeaten = 0;
  1053.         }
  1054.  
  1055.     }
  1056.  
  1057.     else
  1058.     {
  1059.         if (PlayerScore > CHScore1)
  1060.         {
  1061.             CHScore3 = CHScore2;
  1062.             CHScore2 = CHScore1;
  1063.             CHScore1 = PlayerScore;
  1064.             Beat << "1st! Now try Normal mode!";
  1065.             ScoreBeaten = 4;
  1066.         }
  1067.         else if (PlayerScore > CHScore2)
  1068.         {
  1069.             CHScore3 = CHScore2;
  1070.             CHScore2 = PlayerScore;
  1071.             Beat << "2nd. You can do better.";
  1072.             ScoreBeaten = 5;
  1073.         }
  1074.         else if (PlayerScore > HScore3)
  1075.         {
  1076.             CHScore3 = PlayerScore;
  1077.             Beat << "3rd. Git gud scrub";
  1078.             ScoreBeaten = 6;
  1079.         }
  1080.         else
  1081.         {
  1082.             Beat << "HAHAHAHAHAHA OH MAN WHAT WAS THAT";
  1083.             ScoreBeaten = 0;
  1084.         }
  1085.     }
  1086. }
  1087.  
  1088. void GetNameInput() //Ascii charactars from A-Z is 65-90
  1089. {
  1090.     int Highlighted = 1;
  1091.     char One = 65;
  1092.     char Two = 65;
  1093.     char Three = 65;
  1094.     bool EnterPressed = false;
  1095.     while (EnterPressed == false)
  1096.     {
  1097.         ApplySurface(0,0,BlackScreen,Screen);
  1098.         ApplySurface(0,(ScreenHeight - YouTried->h)/2,YouTried,Screen);
  1099.         NameOutputStream.str("");
  1100.         NameOutputStream << One << " " << Two << " " << Three;
  1101.         Message = TTF_RenderText_Solid(Font,NameOutputStream.str().c_str(), TextColour);
  1102.         ApplySurface(270,((ScreenHeight - YouTried->h)/2) + 97,Message,Screen);
  1103.         SDL_Flip(Screen);
  1104.         while (SDL_PollEvent(&event))
  1105.         {
  1106.             if(event.type == SDL_QUIT)
  1107.             {
  1108.                 Quit = true;
  1109.                 EnterPressed = true;
  1110.                 STATE = MAINMENU;
  1111.             }
  1112.  
  1113.             if (event.type == SDL_KEYDOWN)
  1114.             {
  1115.                 if (event.key.keysym.sym == SDLK_RETURN)
  1116.                 {
  1117.                     EnterPressed = true;
  1118.                     NameOutputStream.str("");
  1119.                     NameOutputStream << One << Two << Three;
  1120.                 }
  1121.  
  1122.                
  1123.                 if (event.key.keysym.sym == SDLK_RIGHT) Highlighted++;
  1124.                 if (event.key.keysym.sym == SDLK_LEFT) Highlighted--;
  1125.                 if (Highlighted < 1) Highlighted = 3;
  1126.                 else if (Highlighted > 3) Highlighted = 1;
  1127.  
  1128.                 if (event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_DOWN)
  1129.                 {
  1130.                     switch(Highlighted)
  1131.                     {
  1132.                     case 1:
  1133.  
  1134.                         if (event.key.keysym.sym == SDLK_UP) (int)One++;
  1135.                         else (int)One--;
  1136.                         if ((int)One < 65) One = 90;
  1137.                         else if ((int)One > 90) One = 65;
  1138.                         break;
  1139.  
  1140.                     case 2:
  1141.                        
  1142.                         if (event.key.keysym.sym == SDLK_UP) (int)Two++;
  1143.                         else (int)Two--;
  1144.                         if ((int)Two < 65) Two = 90;
  1145.                         else if ((int)Two > 90) Two = 65;
  1146.                         break;
  1147.  
  1148.                     case 3:
  1149.                        
  1150.                         if (event.key.keysym.sym == SDLK_UP) (int)Three++;
  1151.                         else (int)Three--;
  1152.                         if ((int)Three < 65) Three = 90;
  1153.                         else if ((int)Three > 90) Three = 65;
  1154.                         break;
  1155.  
  1156.                     }
  1157.                 }
  1158.             }
  1159.         }
  1160.     }
  1161. } // 10/10 code
  1162.  
  1163. void Player::Die()
  1164. {
  1165.     if (DebugBool == false && Invincible == false)
  1166.     {
  1167.  
  1168.     Ship.yVel = -20;
  1169.     Ship.xVel = 7;
  1170.     Timer JUMP;
  1171.     for (int p2w = 0; p2w < 150; p2w++)
  1172.     {
  1173.         JUMP.start();
  1174.         Ship.yVel += 2;
  1175.  
  1176.         Backgroundx -= 0.1;
  1177.         if (Backgroundx <= -2000 + 640) Backgroundx = 0;
  1178.         ApplySurface(Backgroundx,0,Background,Screen);
  1179.         ApplySurface(Ship.x,Ship.y,Burned,Screen);
  1180.         Ship.RefreshPosition();
  1181.         UpdateProjectiles();
  1182.         UpdateEnemies();
  1183.         RenderEnemies();
  1184.         RenderProjectiles();
  1185.         ApplySurface(0,0,ScoreBackground,Screen);
  1186.         if (EnemyHit == false) Message = TTF_RenderText_Solid(Font,"0",TextColour);
  1187.         else
  1188.         {
  1189.             THESCORE = std::to_string(PlayerScore);
  1190.             Message = TTF_RenderText_Solid(Font,THESCORE.c_str(),TextColour);
  1191.         }
  1192.         ApplySurface(25,355, Message, Screen);
  1193.        
  1194.         Selection.str("");
  1195.         if (CurrentSelection == 0) Selection << "BFG      " << Lasers;
  1196.         else if (CurrentSelection == 1) Selection << "RPG      " << Missiles;
  1197.         else if (CurrentSelection == 2) Selection << "LZR";
  1198.         Message = TTF_RenderText_Solid(Font,Selection.str().c_str(),TextColour);
  1199.         ApplySurface(ScreenWidth - 10 - (Message->w + 10),355,Message,Screen);
  1200.         SDL_Flip(Screen);
  1201.  
  1202.         while(SDL_PollEvent(&event))
  1203.         {
  1204.             if (event.type == SDL_QUIT)
  1205.             {
  1206.                 Quit = true;
  1207.                 STATE = MAINMENU;
  1208.             }
  1209.         }
  1210.  
  1211.         if( JUMP.get_ticks() < 1000 / 60 )
  1212.         {
  1213.             SDL_Delay( ( 1000 / 60 ) - JUMP.get_ticks() );
  1214.         }
  1215.     }
  1216.  
  1217.     if (PlaySound == true) Mix_PlayChannel( -1, PlayerDeath, 0 );
  1218.     std::stringstream WhatKilledMe;
  1219.     WhatKilledMe.str("");
  1220.     WhatKilledMe << "You were killed by ";
  1221.     switch(CauseOfDeath)
  1222.     {
  1223.     case 1:
  1224.         WhatKilledMe << "a space invader!";
  1225.         break;
  1226.     case 2:
  1227.         WhatKilledMe << "a space worm!";
  1228.         break;
  1229.     case 3:
  1230.         WhatKilledMe << "the lock on laser!";
  1231.         break;
  1232.     case 4:
  1233.         WhatKilledMe << "another ship!";
  1234.         break;
  1235.     }
  1236.     Message = TTF_RenderText_Solid(Font,WhatKilledMe.str().c_str(),TextColour);
  1237.     ApplySurface((ScreenWidth - Message->w) / 2, ((ScreenHeight - Message->h) / 2) - 30, Message, Screen);
  1238.     SortScores();
  1239.     std::stringstream Wat;
  1240.     Wat.str("");
  1241.     Wat << "Your score was " << PlayerScore << "!";
  1242.     Message = TTF_RenderText_Solid(Font,Wat.str().c_str(),TextColour);
  1243.     ApplySurface((ScreenWidth - Message->w) / 2, (ScreenHeight - Message->h) / 2, Message, Screen);
  1244.     SDL_FreeSurface(Message);
  1245.     Message = TTF_RenderText_Solid(Font,Beat.str().c_str(),TextColour);
  1246.     ApplySurface((ScreenWidth - Message->w) / 2, ((ScreenHeight - Message->h) / 2) + 30, Message, Screen);
  1247.     SDL_Flip(Screen);
  1248.     if (ScoreBeaten > 0)
  1249.     {
  1250.         SDL_Delay(3000);
  1251.         GetNameInput();
  1252.         if (CasualMode == false)
  1253.         {
  1254.             switch (ScoreBeaten)
  1255.             {
  1256.             case 1:
  1257.                 Name3 = Name2;
  1258.                 Name2 = Name1;
  1259.                 Name1 = NameOutputStream.str();
  1260.                 break;
  1261.             case 2:
  1262.                 Name3 = Name2;
  1263.                 Name2 = NameOutputStream.str();
  1264.                 break;
  1265.             case 3:
  1266.                 Name3 = NameOutputStream.str();
  1267.                 break;
  1268.             }
  1269.         }
  1270.         else
  1271.         {
  1272.             switch (ScoreBeaten)
  1273.             {
  1274.             case 4:
  1275.                 CName3 = CName2;
  1276.                 CName2 = CName1;
  1277.                 CName1 = NameOutputStream.str();
  1278.                 break;
  1279.             case 5:
  1280.                 CName3 = CName2;
  1281.                 CName2 = NameOutputStream.str();
  1282.                 break;
  1283.             case 6:
  1284.                 CName3 = NameOutputStream.str();
  1285.                 break;
  1286.             }
  1287.         }
  1288.     }
  1289.     std::ofstream SaveScores;
  1290.     SaveScores.open("TopLel.dll");
  1291.     SaveScores << Name1 << std::endl << Name2 << std::endl << Name3 << std::endl << CName1 << std::endl << CName2 << std::endl << CName3
  1292.                << std::endl << HScore1 << std::endl << HScore2 << std::endl << HScore3  << std::endl << CHScore1 << std::endl << CHScore2
  1293.                 << std::endl << CHScore3;
  1294.     SaveScores.close();
  1295.     SDL_Flip(Screen);
  1296.     while (lrn2program == false)
  1297.     {
  1298.         while (SDL_PollEvent(&event))
  1299.         {
  1300.             if (event.type == SDL_QUIT) Quit = true;
  1301.             if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) lrn2program = true;
  1302.         }
  1303.     }
  1304.     STATE = MAINMENU;
  1305.     Lazy = true;
  1306. }
  1307. }
  1308.  
  1309.  
  1310. void Player::RefreshPosition()
  1311. {
  1312.     x = x + xVel;
  1313.     y = y + yVel;
  1314. }
  1315.  
  1316. void CheckEnemyProjectileCollisions()
  1317. {
  1318.     if (EnemyProjectiles.size() >= 2)
  1319.     {
  1320.         for (int P = 0; P < EnemyProjectiles.size(); P+=5)
  1321.         {
  1322.             int PLeft = EnemyProjectiles.at(P);
  1323.             int PTop = EnemyProjectiles.at(P + 1);
  1324.             int PBottom = EnemyProjectiles.at(P + 1) + 10;
  1325.             if (PLeft >= Ship.x && PLeft <= Ship.x + 39)
  1326.             {
  1327.                 if (PTop >= Ship.y && PTop <= Ship.y + 20)
  1328.                 {
  1329.                     if (EnemyProjectiles.at(P + 2) < 2) CauseOfDeath = 2;
  1330.                     else CauseOfDeath = 4;
  1331.                     Ship.Die();
  1332.                    
  1333.                 }
  1334.                 else if (PBottom >= Ship.y && PBottom <= Ship.y + 20)
  1335.                 {
  1336.                     if (EnemyProjectiles.at(P + 2) < 2) CauseOfDeath = 2;
  1337.                     else CauseOfDeath = 4;
  1338.                     Ship.Die();
  1339.                    
  1340.                 }
  1341.             }
  1342.         }
  1343.     }
  1344. }
  1345.  
  1346. void UpdateLocks()
  1347. {
  1348.     if (Locks.size() >= 4)
  1349.     {
  1350.         for (int l = 0; l <= Locks.size() - 4; l += 4)
  1351.         {
  1352.             if (Locks.at(l + 3) == 0) continue;
  1353.             Locks.at(l + 2)++;
  1354.             if (Locks.at(l + 2) > 60)
  1355.             {
  1356.                 Locks.at(l + 3) = 0;
  1357.                 int CLeft = Locks.at(l);
  1358.                 int CRight = CLeft + 50;
  1359.                 int CTop = Locks.at(l + 1);
  1360.                 int CBottom = CTop + 50;
  1361.  
  1362.                 int PLeft = Ship.x;
  1363.                 int PRight = PLeft + Character->w;
  1364.                 int PTop = Ship.y;
  1365.                 int PBottom = PTop + 50;
  1366.  
  1367.                 bool LockOn = false;
  1368.  
  1369.                 if (PRight >= CLeft && PRight <= CRight)
  1370.                 {
  1371.                     if (PTop <= CBottom && PTop >= CTop)
  1372.                     {
  1373.                         CauseOfDeath = 3;
  1374.                         Ship.Die();
  1375.                        
  1376.                     }
  1377.                     else if (PBottom <= CBottom && PBottom >= CTop)
  1378.                     {
  1379.                         CauseOfDeath = 3;
  1380.                         Ship.Die();
  1381.                     }
  1382.                 }
  1383.  
  1384.                 else if (PLeft >= CLeft && PLeft <= CRight)
  1385.                 {
  1386.                     if (PTop <= CBottom && PTop >= CTop)
  1387.                     {
  1388.                         CauseOfDeath = 3;
  1389.                         Ship.Die();
  1390.                     }
  1391.                     if (PBottom <= CBottom && PBottom >= CTop)
  1392.                     {
  1393.                         CauseOfDeath = 3;
  1394.                         Ship.Die();
  1395.                     }
  1396.                 }
  1397.  
  1398.             }
  1399.             if (Locks.at(l + 2) < 15) ApplySurface(Locks.at(l), Locks.at(l + 1), LockSprites, Screen, &LockFrames[0]);
  1400.             else if (Locks.at(l + 2) < 30) ApplySurface(Locks.at(l), Locks.at(l + 1), LockSprites, Screen, &LockFrames[1]);
  1401.             else if (Locks.at(l + 2) < 45) ApplySurface(Locks.at(l), Locks.at(l + 1), LockSprites, Screen, &LockFrames[2]);
  1402.             else ApplySurface(Locks.at(l), Locks.at(l + 1), LockSprites, Screen, &LockFrames[3]);
  1403.         }
  1404.     }
  1405. }
  1406.  
  1407. void WeaponsMenuFunction()
  1408. {
  1409.     std::stringstream WMenu;
  1410.     for (int y = -200; y <= 0; y += 5)
  1411.     {
  1412.         ApplySurface(Backgroundx,0,Background,Screen);
  1413.         RenderEnemies();
  1414.         RenderProjectiles();
  1415.         if (Ship.xVel + Ship.yVel != 0) ApplySurface(Ship.x - 14, Ship.y, ShipMoving2,Screen);
  1416.         else ApplySurface(Ship.x - 14, Ship.y, ShipIdle,Screen);
  1417.         ApplySurface(0,0,Score2,Screen);
  1418.         ApplySurface(0,0,AlphaGray,Screen);
  1419.         ApplySurface((ScreenWidth - 350) / 2,y, WeaponsMenu, Screen, &WMenuClips[CurrentSelection]);
  1420.         WMenu.str("");
  1421.         WMenu << Lasers;
  1422.         Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
  1423.         ApplySurface(((ScreenWidth - 350) / 2) + 260, y + 47, Message, Screen);
  1424.         WMenu.str("");
  1425.         WMenu << Missiles;
  1426.         Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
  1427.         ApplySurface(((ScreenWidth - 350) / 2) + 260, y + 84, Message, Screen);
  1428.         if (EnemyHit == false) Message = TTF_RenderText_Solid(Font,"0",TextColour);
  1429.         else
  1430.         {
  1431.             THESCORE = std::to_string(PlayerScore);
  1432.             Message = TTF_RenderText_Solid(Font,THESCORE.c_str(),TextColour);
  1433.         }
  1434.         ApplySurface(25,355, Message, Screen);
  1435.        
  1436.         Selection.str("");
  1437.         if (CurrentSelection == 0) Selection << "BFG      " << Lasers;
  1438.         else if (CurrentSelection == 1) Selection << "RPG      " << Missiles;
  1439.         else if (CurrentSelection == 2) Selection << "LZR";
  1440.         Message = TTF_RenderText_Solid(Font,Selection.str().c_str(),TextColour);
  1441.         ApplySurface(ScreenWidth - 10 - (Message->w + 10),355,Message,Screen);
  1442.         SDL_Flip(Screen);
  1443.         SDL_Delay(10);
  1444.     }
  1445.     bool AWAY = false;
  1446.     while(AWAY == false)
  1447.     {
  1448.         SDL_Flip(Screen);
  1449.         if (CurrentSelection < 0) CurrentSelection = 2;
  1450.         if (CurrentSelection > 2) CurrentSelection = 0;
  1451.         ApplySurface(Backgroundx,0,Background,Screen);
  1452.         RenderEnemies();
  1453.         RenderProjectiles();
  1454.         if (Ship.xVel + Ship.yVel != 0) ApplySurface(Ship.x - 14, Ship.y, ShipMoving2,Screen);
  1455.         else ApplySurface(Ship.x - 14, Ship.y, ShipIdle,Screen);
  1456.         ApplySurface(0,0,Score2,Screen);
  1457.         ApplySurface(0,0,AlphaGray,Screen);
  1458.         ApplySurface((ScreenWidth - 350) / 2,0, WeaponsMenu, Screen, &WMenuClips[CurrentSelection]);
  1459.         WMenu.str("");
  1460.         WMenu << Lasers;
  1461.         Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
  1462.         ApplySurface(((ScreenWidth - 350) / 2) + 260, 47, Message, Screen);
  1463.         WMenu.str("");
  1464.         WMenu << Missiles;
  1465.         Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
  1466.         ApplySurface(((ScreenWidth - 350) / 2) + 260, 84, Message, Screen);
  1467.         if (EnemyHit == false) Message = TTF_RenderText_Solid(Font,"0",TextColour);
  1468.         else
  1469.         {
  1470.             THESCORE = std::to_string(PlayerScore);
  1471.             Message = TTF_RenderText_Solid(Font,THESCORE.c_str(),TextColour);
  1472.         }
  1473.         ApplySurface(25,355, Message, Screen);
  1474.        
  1475.         Selection.str("");
  1476.         if (CurrentSelection == 0) Selection << "BFG      " << Lasers;
  1477.         else if (CurrentSelection == 1) Selection << "RPG      " << Missiles;
  1478.         else if (CurrentSelection == 2) Selection << "LZR";
  1479.         Message = TTF_RenderText_Solid(Font,Selection.str().c_str(),TextColour);
  1480.         ApplySurface(ScreenWidth - 10 - (Message->w + 10),355,Message,Screen);
  1481.         while(SDL_PollEvent(&event))
  1482.         {
  1483.             if(event.type == SDL_QUIT)
  1484.             {
  1485.                 Quit = true;
  1486.                 STATE = MAINMENU;
  1487.                 return;
  1488.             }
  1489.             if (event.type == SDL_KEYDOWN)
  1490.             {
  1491.                 if (event.key.keysym.sym == SDLK_UP) CurrentSelection--;
  1492.                 if (event.key.keysym.sym == SDLK_DOWN) CurrentSelection++;
  1493.                 if (event.key.keysym.sym == SDLK_SPACE) AWAY = true;
  1494.             }
  1495.         }
  1496.     }
  1497.     for (int y = 0; y >= -200; y -= 5)
  1498.     {
  1499.         ApplySurface(Backgroundx,0,Background,Screen);
  1500.         RenderEnemies();
  1501.         RenderProjectiles();
  1502.         if (Ship.xVel + Ship.yVel != 0) ApplySurface(Ship.x - 14, Ship.y, ShipMoving2,Screen);
  1503.         else ApplySurface(Ship.x - 14, Ship.y, ShipIdle,Screen);
  1504.         ApplySurface(0,0,Score2,Screen);
  1505.         ApplySurface(0,0,AlphaGray,Screen);
  1506.         ApplySurface((ScreenWidth - 350) / 2,y, WeaponsMenu, Screen, &WMenuClips[CurrentSelection]);
  1507.         WMenu.str("");
  1508.         WMenu << Lasers;
  1509.         Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
  1510.         ApplySurface(((ScreenWidth - 350) / 2) + 260, y + 47, Message, Screen);
  1511.         WMenu.str("");
  1512.         WMenu << Missiles;
  1513.         Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
  1514.         ApplySurface(((ScreenWidth - 350) / 2) + 260, y + 84, Message, Screen);
  1515.         if (EnemyHit == false) Message = TTF_RenderText_Solid(Font,"0",TextColour);
  1516.         else
  1517.         {
  1518.             THESCORE = std::to_string(PlayerScore);
  1519.             Message = TTF_RenderText_Solid(Font,THESCORE.c_str(),TextColour);
  1520.         }
  1521.         ApplySurface(25,355, Message, Screen);
  1522.        
  1523.         Selection.str("");
  1524.         if (CurrentSelection == 0) Selection << "BFG      " << Lasers;
  1525.         else if (CurrentSelection == 1) Selection << "RPG      " << Missiles;
  1526.         else if (CurrentSelection == 2) Selection << "LZR";
  1527.         Message = TTF_RenderText_Solid(Font,Selection.str().c_str(),TextColour);
  1528.         ApplySurface(ScreenWidth - 10 - (Message->w + 10),355,Message,Screen);
  1529.         SDL_Flip(Screen);
  1530.         SDL_Delay(10);
  1531.     }
  1532. }
  1533.  
  1534. void CheckProjectileCollisions()
  1535. {
  1536.     if (Projectiles.size() >= 2 && Enemies.size() > 2) // If there are enemies and projectiles
  1537.     {
  1538.         for (int i = 0; i < Projectiles.size(); i += 5) //Nesting to the extreme m8
  1539.         {
  1540.             if (Projectiles.at(i + 3) == 1) //If projectile is visible
  1541.             {
  1542.                 int PRight = Projectiles.at(i) + 30;
  1543.                 int PTop = Projectiles.at(i + 1);
  1544.                 int PBottom = Projectiles.at(i + 1) + 10;
  1545.                 for (int e = 0; e < Enemies.size();  e +=6)
  1546.                 {
  1547.                     if (Enemies.at(e + 5) == 0) continue; // If the enemy is not visible
  1548.                     if (Enemies.at(e + 4) == 3) continue; // If the enemy is a fukken crosshair
  1549.                     if (Enemies.at(e + 4) >= 5) continue; // If the enemy is a fukken powerup or whatever
  1550.                     int ELeft = Enemies.at(e);
  1551.                     int ERight = Enemies.at(e) + 50;
  1552.                     int ETop = Enemies.at(e + 1);
  1553.                     int EBottom;
  1554.                     if (Enemies.at(e + 4) != 4) EBottom = Enemies.at(e + 1) + 50; //If its not a rival
  1555.                     else EBottom = Enemies.at(e + 1) + 20;
  1556.                     if (PRight >= ELeft && PRight <= ERight)
  1557.                     {
  1558.                         if (PBottom >= ETop && PBottom<= EBottom)
  1559.                         {
  1560.                             Projectiles.at(i + 3) = 0;
  1561.                             Enemies.at(e + 5) = 0;
  1562.                             EnemyHit = true;
  1563.  
  1564.                             if (Enemies.at(e + 4) == 1) // If enemy is a space invaders alien
  1565.                             {
  1566.                                 PlayerScore += 100;
  1567.                                 PlayDeathSound();
  1568.                                 if(GenerateChance(2) == true) // Laser Powerup
  1569.                                 {
  1570.                                     Enemies.push_back(Enemies.at(e) + 12);
  1571.                                     Enemies.push_back(Enemies.at(e + 1) + 12);
  1572.                                     Enemies.push_back(1);
  1573.                                     Enemies.push_back(0);
  1574.                                     Enemies.push_back(5);
  1575.                                     Enemies.push_back(1);
  1576.                                 }
  1577.                             }
  1578.  
  1579.                             if (Enemies.at(e + 4) == 4)
  1580.                             {
  1581.                                 Enemies.push_back(Enemies.at(e) + 12);
  1582.                                 Enemies.push_back(Enemies.at(e + 1) + 12);
  1583.                                 Enemies.push_back(1);
  1584.                                 Enemies.push_back(0);
  1585.                                 Enemies.push_back(7);
  1586.                                 Enemies.push_back(1);
  1587.                                 Rival = false;
  1588.                             }
  1589.                             if (Enemies.at(e + 4) == 2) // If enemy is a worm
  1590.                             {
  1591.                                 PlayerScore += 150;
  1592.                                 PlayDeathSound();
  1593.                                 if(GenerateChance(50) == true) // Missile Powerup
  1594.                                 {
  1595.                                     PANIC++;
  1596.                                     Enemies.push_back(Enemies.at(e) + 12);
  1597.                                     Enemies.push_back(Enemies.at(e + 1) + 12);
  1598.                                     Enemies.push_back(1);
  1599.                                     Enemies.push_back(0);
  1600.                                     Enemies.push_back(6);
  1601.                                     Enemies.push_back(1);
  1602.                                 }
  1603.                             }
  1604.                         }
  1605.  
  1606.                         else if (PTop >= ETop && PTop <= EBottom)
  1607.                         {
  1608.                             Projectiles.at(i + 3) = 0;
  1609.                             Enemies.at(e + 5) = 0;
  1610.                             EnemyHit = true;
  1611.  
  1612.                             if (Enemies.at(e + 4) == 1) // If enemy is a space invaders alien
  1613.                             {
  1614.                                 PlayerScore += 100;
  1615.                                 PlayDeathSound;
  1616.                             }
  1617.  
  1618.                             if (Enemies.at(e + 4) == 2) // If enemy is a worm
  1619.                             {
  1620.                                 PlayerScore += 150;
  1621.                                 PlayDeathSound();
  1622.                             }
  1623.                         }
  1624.                     }
  1625.                 }
  1626.             }
  1627.         }
  1628.     }
  1629. } //You know you have good code when this happens
  1630.  
  1631. int CrosshairCollisionsDetected = 0;
  1632.  
  1633. void CheckPlayerCollisions()
  1634. {
  1635.     bool CollisionDetected = false;
  1636.     if (Enemies.size() > 4)
  1637.     {
  1638.         for (int e = 0; e < Enemies.size(); e += 6)
  1639.         {
  1640.             if (Enemies.at(e + 5) == 0) continue;
  1641.             CollisionDetected = false;
  1642.             int ELeft = Enemies.at(e);
  1643.             int ERight = Enemies.at(e) + 50;
  1644.             int ETop = Enemies.at(e + 1);
  1645.             int EBottom = Enemies.at(e + 1) + 50;
  1646.             int PRight = Ship.x + 39;
  1647.             int PTop = Ship.y;
  1648.             int PBottom = Ship.y + 20;
  1649.             if (PRight >= ELeft && PRight <= ERight)
  1650.             {
  1651.                 if (PTop <= EBottom && PTop >= ETop) CollisionDetected = true;
  1652.                 if (PBottom <= EBottom && PBottom >= ETop) CollisionDetected = true;
  1653.             }
  1654.  
  1655.             if (CollisionDetected == true)
  1656.             {
  1657.                 if (Enemies.at(e + 4) == 1 )
  1658.                 {
  1659.                     CauseOfDeath = 1;
  1660.                     Ship.Die();
  1661.                    
  1662.                 }
  1663.                 else if (Enemies.at(e + 4) == 2)
  1664.                 {
  1665.                     CauseOfDeath = 2;
  1666.                     Ship.Die();
  1667.                    
  1668.                 }
  1669.                 else if (Enemies.at(e + 4) == 3)// If its a crosshair
  1670.                 {
  1671.                     Locks.push_back(Enemies.at(e) - 10);
  1672.                     Locks.push_back(Enemies.at(e + 1));
  1673.                     Locks.push_back(0);
  1674.                     Locks.push_back(1);
  1675.                    
  1676.                     Enemies.at(e + 5) = 0;
  1677.                 }
  1678.                 else if (Enemies.at(e + 4) == 4)
  1679.                 {
  1680.                     Ship.Die();
  1681.                     CauseOfDeath = 4;
  1682.                 }
  1683.                 else if (Enemies.at(e + 4) == 5)
  1684.                 {
  1685.                     Lasers++; //Laser ammo
  1686.                     Enemies.at(e + 5) = 0;
  1687.                 }
  1688.  
  1689.                 else if (Enemies.at(e + 4) == 6)
  1690.                 {
  1691.                     Missiles+=3; //Missile ammo
  1692.                     Enemies.at(e + 5) = 0;
  1693.                 }
  1694.  
  1695.                 else if (Enemies.at(e + 4) == 7)
  1696.                 {
  1697.                     Invincible = true;
  1698.                     InvincibilityTime = 600;
  1699.                     Enemies.at(e + 5) = 0;
  1700.                 }
  1701.             }
  1702.         }
  1703.     }
  1704. } //Agen lmoa
  1705.  
  1706. void DoMissiles() //Got lazy
  1707. {
  1708.     if(MissileVector.size() == 0) return;
  1709.     std::stringstream MissileDebug;
  1710.     bool FukkenShit = false;
  1711.     for (int i = 0; i < MissileVector.size() - 2; i += 6)
  1712.     {
  1713.         if (MissileVector.at(i + 5) == 0) continue;
  1714.         if (MissileVector.at(i + 2) == 0)
  1715.         {
  1716.             MissileVector.at(i + 1) += 3;
  1717.             MissileVector.at(i + 4) ++;
  1718.             if (MissileVector.at(i + 4) > 20)
  1719.             {
  1720.                 if (PlaySound == true) Mix_PlayChannel( -1, Rocket, 0 );
  1721.                 StartShake(50,10);
  1722.                 MissileVector.at(i + 2) = 1;
  1723.                 MissileVector.at(i + 4) = 0;
  1724.             }
  1725.         }
  1726.  
  1727.         else
  1728.         {
  1729.             MissileVector.at(i) += 10;
  1730.             MissileVector.at(i + 4) ++;
  1731.             if (MissileVector.at(i + 4) > 20) MissileVector.at(i + 3)++;
  1732.             if (MissileVector.at(i + 3) > 1) MissileVector.at(i + 3) = 0;
  1733.             int PRight = MissileVector.at(i) + 38;
  1734.             int PTop = MissileVector.at(i + 1);
  1735.             int PBottom = MissileVector.at(i + 1) + 10;
  1736.             for (int e = 0; e < Enemies.size();  e +=6)
  1737.             {
  1738.                 if (Enemies.at(e + 5) == 0) continue; // If the enemy is not visible
  1739.                 if (Enemies.at(e + 4) == 3) continue; // If the enemy is a fukken crosshair
  1740.                 if (Enemies.at(e + 4) >= 5) continue; // If the enemy is a fukken powerup or whatever
  1741.                 if (Enemies.at(e) < 0) continue;
  1742.                 int ELeft = Enemies.at(e);
  1743.                 int ERight = Enemies.at(e) + 50;
  1744.                 int ETop = Enemies.at(e + 1);
  1745.                 int EBottom;
  1746.                 if (Enemies.at(e + 4) != 4) EBottom = Enemies.at(e + 1) + 50; //If its not a rival
  1747.                 else EBottom = Enemies.at(e + 1) + 20;
  1748.                 if (PRight >= ELeft && PRight <= ERight)
  1749.                 {
  1750.                     if (PBottom >= ETop && PBottom<= EBottom)
  1751.                     {
  1752.                         StartFlash();
  1753.                         for (int et = 0; et < Enemies.size();  et +=6)
  1754.                         {
  1755.                         if (Enemies.at(et + 5) == 0) continue;
  1756.                         if (Enemies.at(et) < 0) continue;
  1757.                         int MaxXRange = MissileVector.at(i) + 100;
  1758.                         int MinXRange = MissileVector.at(i) - 100;
  1759.                         int MaxYRange = MissileVector.at(i + 1) + 100;
  1760.                         int MinYRange = MissileVector.at(i + 1) - 100;
  1761.  
  1762.                         int EtLeft = Enemies.at(et);
  1763.                         int EtTop = Enemies.at(et + 1);
  1764.                         if (EtTop == ETop) continue;
  1765.                         bool a = false;
  1766.                         bool b = false;
  1767.                         bool c = false;
  1768.                         bool d = false;
  1769.  
  1770.                         if (EtLeft < MaxXRange) a = true;
  1771.                         if (EtLeft > MinXRange) b = true;
  1772.                         if (EtTop < MaxYRange) c = true;
  1773.                         if (EtLeft > MinXRange) d = true;
  1774.  
  1775.                         if (a == true && b == true && c == true && d == true)
  1776.                         {
  1777.                             Enemies.at(et + 5) = 0;
  1778.                             switch(Enemies.at(et + 4))
  1779.                             {
  1780.                             case 1: PlayerScore += 100;
  1781.                                     break;
  1782.                             case 2: PlayerScore += 150;
  1783.                                     break;
  1784.                             case 4: PlayerScore += 250;
  1785.                                     break;
  1786.                             }
  1787.                         }
  1788.  
  1789.                         }
  1790.                         MissileVector.at(i + 5) = 0;
  1791.                         Enemies.at(e + 5) = 0;
  1792.                     }
  1793.            
  1794.                 else if (PTop >= ETop && PTop <= EBottom)
  1795.                 {
  1796.                     StartFlash();
  1797.                     for (int et = 0; et < Enemies.size();  et +=6)
  1798.                     {
  1799.                         if (Enemies.at(et + 5) == 0) continue;
  1800.                         if (Enemies.at(et) < 0) continue;
  1801.                         int MaxXRange = MissileVector.at(i) + 100;
  1802.                         int MinXRange = MissileVector.at(i) - 100;
  1803.                         int MaxYRange = MissileVector.at(i + 1) + 100;
  1804.                         int MinYRange = MissileVector.at(i + 1) - 100;
  1805.  
  1806.                         int EtLeft = Enemies.at(et);
  1807.                         int EtTop = Enemies.at(et + 1);
  1808.  
  1809.                         if (EtTop == ETop) continue;
  1810.  
  1811.                         bool a = false;
  1812.                         bool b = false;
  1813.                         bool c = false;
  1814.                         bool d = false;
  1815.  
  1816.                         if (EtLeft < MaxXRange) a = true;
  1817.                         if (EtLeft > MinXRange) b = true;
  1818.                         if (EtTop < MaxYRange) c = true;
  1819.                         if (EtLeft > MinXRange) d = true;
  1820.  
  1821.                         if (a == true && b == true && c == true && d == true)
  1822.                         {
  1823.                             Enemies.at(et + 5) = 0;
  1824.                             switch(Enemies.at(et + 4))
  1825.                             {
  1826.                             case 1: PlayerScore += 100;
  1827.                                     break;
  1828.                             case 2: PlayerScore += 150;
  1829.                                     break;
  1830.                             case 4: PlayerScore += 250;
  1831.                                     break;
  1832.                             }
  1833.  
  1834.                         }
  1835.                     }
  1836.                     MissileVector.at(i + 5) = 0;
  1837.                     Enemies.at(e + 5) = 0;
  1838.                 }
  1839.             }
  1840.         }
  1841.        
  1842.     }
  1843.         ApplySurface(MissileVector.at(i),MissileVector.at(i + 1),MissileSprite,Screen,&MissileClips[MissileVector.at(i + 3)]);
  1844. }
  1845. }
  1846.        
  1847.  
  1848.  
  1849.  
  1850. int Intro()
  1851. {
  1852.     int BGI = 0;
  1853.     int Timings[28] = {0,1000,200,1000,100,700,200,300,300,1000,100,100,100,100,2000,100,100,100,100,100,100,2000,100,100,100,100,100,2000};
  1854.     Timer IntroTiming;
  1855.     SDL_Surface *Intro1, *Intro2, *Intro3, *Intro4, *Intro5 = NULL;
  1856.     Intro1 = LoadImage("Resources/Images/Intro1.png");
  1857.     Intro2 = LoadImage("Resources/Images/Intro2.png");
  1858.     Intro3 = LoadImage("Resources/Images/Intro3.png");
  1859.     Intro4 = LoadImage("Resources/Images/Intro4.png");
  1860.     Intro5 = LoadImage("Resources/Images/Intro5.png");
  1861.  
  1862.     if (Intro1 == NULL || Intro2 == NULL || Intro3 == NULL || Intro4 == NULL || Intro5 == NULL) return -1;
  1863.     for (int Frame = 1; Frame <= 27; Frame++)
  1864.     {
  1865.         IntroTiming.start();
  1866.  
  1867.         while (SDL_PollEvent(&event))
  1868.         {
  1869.             if (event.type == SDL_QUIT)
  1870.             {
  1871.                 Quit = true;
  1872.                 return 1;
  1873.             }
  1874.  
  1875.             if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN)
  1876.             {
  1877.                 STATE = MAINMENU;
  1878.                 return 1;
  1879.             }
  1880.         }
  1881.  
  1882.         if (Frame == 6 || Frame == 11 || Frame == 16 || Frame == 21) BGI = 0;
  1883.  
  1884.         if (Frame < 6) ApplySurface(BGI,0,Intro1,Screen);
  1885.         else if (Frame < 11) ApplySurface(BGI,0,Intro2,Screen);
  1886.         else if (Frame < 16) ApplySurface(BGI,0,Intro3,Screen);
  1887.         else if (Frame < 21) ApplySurface(BGI,0,Intro4,Screen);
  1888.         else ApplySurface(BGI,0,Intro5,Screen);
  1889.  
  1890.         SDL_Flip(Screen);
  1891.         BGI -= 639;
  1892.         SDL_Delay(Timings[Frame] - IntroTiming.get_ticks());
  1893.     }
  1894.     SDL_FreeSurface(Intro1);
  1895.     SDL_FreeSurface(Intro2);
  1896.     SDL_FreeSurface(Intro3);
  1897.     SDL_FreeSurface(Intro4);
  1898.     SDL_FreeSurface(Intro5);
  1899.     STATE = MAINMENU;
  1900.     return 0;
  1901. }
  1902.  
  1903. int Menu()
  1904. {
  1905.     double Rotation = 0;
  1906.     double Zoom = 1.8;
  1907.     bool RPositiveIncrement = true;
  1908.     bool ZPositiveIncrement = true;
  1909.     double MBackgroundx = 0;
  1910.     while (Quit == false && STATE == MAINMENU)
  1911.     {
  1912.     MBackgroundx -=0.25;
  1913.     if (MBackgroundx <= -2000 + 640) MBackgroundx = 0;
  1914.     ApplySurface(MBackgroundx,0,MenuBackground,Screen);
  1915.  
  1916.     if (MenuSelection > 3) MenuSelection = 1;
  1917.     if (MenuSelection < 1) MenuSelection = 3;
  1918.  
  1919.     if (Rotation > 3)
  1920.     {
  1921.         RPositiveIncrement = false;
  1922.         Rotation = 3;
  1923.     }
  1924.     else if (Rotation < - 3)
  1925.     {
  1926.         RPositiveIncrement = true;
  1927.         Rotation = -3;
  1928.     }
  1929.     if (RPositiveIncrement == true) Rotation += 0.005;
  1930.     else Rotation -= 0.005;
  1931.  
  1932.     if (Zoom > 2)
  1933.     {
  1934.         ZPositiveIncrement = false;
  1935.         Zoom = 2;
  1936.     }
  1937.     else if (Zoom < 1.75)
  1938.     {
  1939.         ZPositiveIncrement = true;
  1940.         Zoom = 1.75;
  1941.     }
  1942.     if (ZPositiveIncrement == true) Zoom += 0.0001;
  1943.     else Zoom -= 0.0001;
  1944.     SDL_FreeSurface(TitleTextR);
  1945.     TitleTextR = rotozoomSurface (TitleText, Rotation, Zoom, 0);
  1946.     ApplySurface((ScreenWidth - TitleTextR->w) / 2, ((ScreenHeight - TitleTextR->h) / 2) - 40, TitleTextR, Screen);
  1947.  
  1948.     if (MusicPlaying == false && PlayMusic == true)
  1949.     {
  1950.         Mix_PlayMusic(MenuMusic,-1);
  1951.         MusicPlaying = true;
  1952.     }
  1953.     Message = TTF_RenderText_Solid(Font,"New game",TextColour);
  1954.     ApplySurface(65,300, Message, Screen);
  1955.     Message2 = TTF_RenderText_Solid(Font,"High Scores",TextColour);
  1956.     ApplySurface(Message->w + 115, 300, Message2, Screen);
  1957.     Message3 = TTF_RenderText_Solid(Font,"Options",TextColour);
  1958.     ApplySurface(Message->w + Message2->w + 165, 300, Message3, Screen);
  1959.     switch(MenuSelection)
  1960.     {
  1961.         case 1:
  1962.             ApplySurface(20, 300, Character, Screen, &ShipFrames[0]);
  1963.             break;
  1964.         case 2:
  1965.             ApplySurface(Message->w + 70, 300, Character, Screen,&ShipFrames[0]);
  1966.             break;
  1967.         case 3:
  1968.             ApplySurface(Message->w + Message2->w + 120, 300, Character, Screen,&ShipFrames[0]);
  1969.             break;
  1970.     }
  1971.     SDL_Flip(Screen);
  1972.         while (SDL_PollEvent(&event))
  1973.         {
  1974.             if (event.type == SDL_QUIT) Quit = true;
  1975.  
  1976.             if (event.type == SDL_KEYDOWN)
  1977.             {
  1978.                 if (event.key.keysym.sym == SDLK_LEFT) --MenuSelection;
  1979.                 if (event.key.keysym.sym == SDLK_RIGHT) ++MenuSelection;
  1980.  
  1981.                 if (event.key.keysym.sym == SDLK_RETURN)
  1982.                 {
  1983.                     if (MenuSelection == 1)
  1984.                     {
  1985.                         MusicPlaying = false;
  1986.                         ResetGame();
  1987.                         int x = 20;
  1988.                         ApplySurface(0,0,BlackScreen,Screen);
  1989.                         for (int Why = 0; Why < 140; Why++)
  1990.                         {
  1991.                             MBackgroundx -= 3;
  1992.                             if (MBackgroundx <= -2000 + 640) MBackgroundx = 0;
  1993.                             ApplySurface(MBackgroundx,0,MenuBackground,Screen);
  1994.                            
  1995.                             x = x + 5;
  1996.                             ApplySurface(x, 300, Character, Screen, &ShipFrames[0]);
  1997.                             SDL_Flip(Screen);
  1998.                             SDL_Delay(10);
  1999.                         }
  2000.                         Mix_HaltMusic();
  2001.                     }
  2002.                     return MenuSelection;
  2003.                 }
  2004.             }
  2005.         }
  2006.     }
  2007. }
  2008.  
  2009. void Scores()
  2010. {
  2011.     bool Normal = true;
  2012.     std::stringstream ImNotSure;
  2013.     while (Quit == false && STATE == SCORES)
  2014.     {
  2015.         ApplySurface(0,0,BlackScreen,Screen);
  2016.         if (Normal == true) Message = TTF_RenderText_Solid(Font,"< Normal Mode >",TextColour);
  2017.         else Message = TTF_RenderText_Solid(Font,"< Casual Mode >",TextColour);
  2018.         ApplySurface((ScreenWidth - Message->w) / 2, 15, Message, Screen);
  2019.  
  2020.         if (Normal == true)
  2021.         {
  2022.             Message = TTF_RenderText_Solid(Font,Name1.c_str(),TextColour);
  2023.             ApplySurface((ScreenWidth - Message->w) / 2, 90, Message, Screen);
  2024.             ImNotSure << "With " << HScore1;
  2025.             Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
  2026.             ApplySurface((ScreenWidth - Message->w) / 2, 115, Message, Screen);
  2027.             ImNotSure.str("");
  2028.  
  2029.             Message = TTF_RenderText_Solid(Font,Name2.c_str(),TextColour);
  2030.             ApplySurface((ScreenWidth - Message->w) / 2, 150, Message, Screen);
  2031.             ImNotSure << "With " << HScore2;
  2032.             Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
  2033.             ApplySurface((ScreenWidth - Message->w) / 2, 175, Message, Screen);
  2034.             ImNotSure.str("");
  2035.  
  2036.             Message = TTF_RenderText_Solid(Font,Name3.c_str(),TextColour);
  2037.             ApplySurface((ScreenWidth - Message->w) / 2, 210, Message, Screen);
  2038.             ImNotSure << "With " << HScore3;
  2039.             Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
  2040.             ApplySurface((ScreenWidth - Message->w) / 2, 235, Message, Screen);
  2041.             ImNotSure.str("");
  2042.         }
  2043.  
  2044.         else
  2045.         {
  2046.             Message = TTF_RenderText_Solid(Font,CName1.c_str(),TextColour);
  2047.             ApplySurface((ScreenWidth - Message->w) / 2, 90, Message, Screen);
  2048.             ImNotSure << "With " << CHScore1;
  2049.             Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
  2050.             ApplySurface((ScreenWidth - Message->w) / 2, 115, Message, Screen);
  2051.             ImNotSure.str("");
  2052.  
  2053.             Message = TTF_RenderText_Solid(Font,CName2.c_str(),TextColour);
  2054.             ApplySurface((ScreenWidth - Message->w) / 2, 150, Message, Screen);
  2055.             ImNotSure << "With " << CHScore2;
  2056.             Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
  2057.             ApplySurface((ScreenWidth - Message->w) / 2, 175, Message, Screen);
  2058.             ImNotSure.str("");
  2059.  
  2060.             Message = TTF_RenderText_Solid(Font,CName3.c_str(),TextColour);
  2061.             ApplySurface((ScreenWidth - Message->w) / 2, 210, Message, Screen);
  2062.             ImNotSure << "With " << CHScore3;
  2063.             Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
  2064.             ApplySurface((ScreenWidth - Message->w) / 2, 235, Message, Screen);
  2065.             ImNotSure.str("");
  2066.         }
  2067.         SDL_Flip(Screen);
  2068.         while (SDL_PollEvent(&event))
  2069.         {
  2070.             if (event.type == SDL_QUIT) Quit = true;
  2071.             if (event.type == SDL_KEYDOWN)
  2072.             {
  2073.                 if (event.key.keysym.sym == SDLK_ESCAPE) STATE = MAINMENU;
  2074.                 if (event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_RIGHT) Normal = !Normal;
  2075.             }
  2076.         }
  2077.     }
  2078. }
  2079.  
  2080. void Game()
  2081.  
  2082. {
  2083.     srand (time (NULL));
  2084.     ResetGame();
  2085.     Timer FPS;
  2086.     Timer Shot;
  2087.     Timer EnemyPause;
  2088.     Timer EnemyNotPause;
  2089.     PlayerScore = 0;
  2090.     std::stringstream DebugStream;
  2091.     bool CreateEnemies = true;
  2092.     int Random, Random4;
  2093.     int Random2,Random3;
  2094.     if (PlayMusic == true) Mix_PlayMusic(GameMusic,-1);
  2095.     while (Quit == false && STATE == GAME)
  2096.     {
  2097.         FPS.start();
  2098.  
  2099.         Backgroundx -=0.1;
  2100.         if (Backgroundx <= -2000 + 640) Backgroundx = 0;
  2101.  
  2102.  
  2103.         if (Shake == true)
  2104.         {
  2105.             xShakeOffset = RandomNumber(Magnitude , ((Magnitude * -1) / 2));
  2106.             yShakeOffset = RandomNumber(Magnitude , ((Magnitude * -1) / 2));
  2107.             Time--;
  2108.             if (Time == 0)
  2109.             {
  2110.                 Shake = false;
  2111.                 xShakeOffset = 0;
  2112.                 yShakeOffset = 0;
  2113.             }
  2114.         }
  2115.  
  2116.         Uint8 *Keystates = SDL_GetKeyState( NULL );
  2117.         int Duration = RandomNumber(15000,9000);
  2118.         int Break = RandomNumber(1750,0);
  2119.         int Time = SDL_GetTicks();
  2120.         Random4 = RandomNumber(25,1);
  2121.  
  2122.         if (Invincible == true)
  2123.         {
  2124.             InvincibilityTime --;
  2125.             if (InvincibilityTime == 0) Invincible = false;
  2126.             std::stringstream Idek;
  2127.             Idek.str("");
  2128.             Idek << InvincibilityTime;
  2129.             Message = TTF_RenderText_Solid(Font,Idek.str().c_str(),TextColour);
  2130.             ApplySurface((ScreenWidth - Message->w)/2, 20, Message, Screen);
  2131.         }
  2132.         if (CasualMode == false)
  2133.         {
  2134.             if (Proc1 < 600) Proc1+=1;
  2135.             Random2 = RandomNumber(25000,1);
  2136.             Random3 = RandomNumber(4000,1);
  2137.  
  2138.             if (Random2 <= Proc1 && CreateEnemies == true)
  2139.             {
  2140.                 GenerateEnemy();
  2141.             }
  2142.         }
  2143.  
  2144.         else
  2145.         {
  2146.             if (Proc2 < 450) Proc2+=0.5;
  2147.             Random2 = RandomNumber(30000,1);
  2148.             Random3 = RandomNumber(3500,1);
  2149.  
  2150.             if (Random2 <= Proc2 && CreateEnemies == true)
  2151.             {
  2152.                 GenerateEnemy();
  2153.             }
  2154.         }
  2155.         if (Random3 <= 50 && CreateEnemies == true && EnemyHit == true && EnemyNotPause.get_ticks() > 5000)
  2156.         {
  2157.             CreateEnemies = false;
  2158.             EnemyPause.start();
  2159.         }
  2160.         if (CreateEnemies == false && EnemyPause.get_ticks() > 5000)
  2161.         {
  2162.             Enemies.erase(Enemies.begin(),Enemies.end());
  2163.             CreateEnemies = true;
  2164.             EnemyNotPause.start();
  2165.         }
  2166.  
  2167.         if (Ship.x > ScreenWidth - (Character->w ))
  2168.         {
  2169.             Ship.x = ScreenWidth - (Character->w );
  2170.         }
  2171.  
  2172.         if (Ship.x < 0)
  2173.         {
  2174.             Ship.x = 0;
  2175.         }
  2176.  
  2177.         if (Ship.y > ScreenHeight - Character->h)
  2178.         {
  2179.             Ship.y = ScreenHeight - Character->h;
  2180.         }
  2181.  
  2182.         if (Ship.y < 0)
  2183.         {
  2184.             Ship.y = 0;
  2185.         }
  2186.  
  2187.         if (Start == false) Ship.x += 10;
  2188.         if (Start == false && Ship.x > 100)
  2189.         {
  2190.             Start = true;
  2191.         }
  2192.  
  2193.         if (Keystates[SDLK_UP])
  2194.         {
  2195.             if (Ship.yVel - Acceleration < -10) Ship.yVel = -10;
  2196.             else Ship.yVel -= Acceleration;
  2197.         }
  2198.         if (Keystates[SDLK_DOWN])
  2199.         {
  2200.             if (Ship.yVel + Acceleration > 10) Ship.yVel = 10;
  2201.             else Ship.yVel += Acceleration;
  2202.         }
  2203.         if (Keystates[SDLK_RIGHT])
  2204.         {
  2205.             if (Ship.xVel + Acceleration > 10) Ship.xVel = 10;
  2206.             else Ship.xVel += Acceleration;
  2207.         }
  2208.         if (Keystates[SDLK_LEFT])
  2209.         {
  2210.             if (Ship.xVel - Acceleration < -10) Ship.xVel = -10;
  2211.             else Ship.xVel -= Acceleration;
  2212.         }
  2213.         if (Keystates[SDLK_UP] != 1 && Keystates[SDLK_DOWN] != 1)
  2214.         {
  2215.             if (Ship.yVel < 0)
  2216.             {
  2217.                 if (Ship.yVel + 0.5 > 0) Ship.yVel = 0;
  2218.                 else Ship.yVel += 0.5;
  2219.             }
  2220.  
  2221.             if (Ship.yVel > 0)
  2222.             {
  2223.                 if (Ship.yVel - 0.5 < 0) Ship.yVel = 0;
  2224.                 else Ship.yVel -= 0.5;
  2225.             }
  2226.         }
  2227.         if (Keystates[SDLK_LEFT] != 1 && Keystates[SDLK_RIGHT] != 1)
  2228.         {
  2229.             if (Ship.xVel < 0)
  2230.             {
  2231.                 if (Ship.xVel + 0.5 > 0) Ship.xVel = 0;
  2232.                 else Ship.xVel += 0.5;
  2233.             }
  2234.  
  2235.             if (Ship.xVel > 0)
  2236.             {
  2237.                 if (Ship.xVel - 0.5 < 0) Ship.xVel = 0;
  2238.                 else Ship.xVel -= 0.5;
  2239.             }
  2240.         }
  2241.         Ship.RefreshPosition();
  2242.         ApplySurface(0,0,BlackScreen,Screen);
  2243.         ApplySurface(Backgroundx,0,Background,Screen);
  2244.         Ship.RenderShip();
  2245.         UpdateProjectiles();
  2246.         RenderProjectiles(); //scown nwocs
  2247.         UpdateEnemies();
  2248.         RenderEnemies();
  2249.         DoMissiles();
  2250.         CheckProjectileCollisions();
  2251.         CheckPlayerCollisions();
  2252.         CheckEnemyProjectileCollisions();
  2253.         UpdateLocks();
  2254.  
  2255.         if (Invincible == true)
  2256.         {
  2257.             std::stringstream Idek;
  2258.             Idek.str("");
  2259.             Idek << InvincibilityTime / 10;
  2260.             Message = TTF_RenderText_Solid(Font,Idek.str().c_str(),TextColour);
  2261.             ApplySurface((ScreenWidth - Message->w)/2, 40, Message, Screen);
  2262.         }
  2263.  
  2264.         if (LaserFiring == true)
  2265.         {
  2266.             LaserTime++;
  2267.             if (LaserTime >= 60)
  2268.             {
  2269.                 if (Pushed == false)
  2270.                 {
  2271.                     Ship.xVel = - 10;
  2272.                     StartShake(60,40);
  2273.                     Pushed = true;
  2274.                 }
  2275.                 ApplySurface(Ship.x + (Character->w / 2), Ship.y - (Character->h / 2), MegaLaser, Screen);
  2276.                 if (Enemies.size() > 1)
  2277.                 {
  2278.                     for(int e = 0; e < Enemies.size() - 3;  e+= 6) //Checking Enemies
  2279.                     {
  2280.                         if(Enemies.at(e + 4) == 3) continue; //If its a crosshair
  2281.                         if(Enemies.at(e + 5) == 0) continue;
  2282.                         if(Enemies.at(e + 1) < Ship.y + 45 && Enemies.at(e + 1) > Ship.y - 45)
  2283.                         {
  2284.                             Enemies.at(e + 5) = 0;
  2285.                             switch(Enemies.at(e + 4))
  2286.                             {
  2287.                             case 1: PlayerScore += 100;
  2288.                                     break;
  2289.                             case 2: PlayerScore += 150;
  2290.                                     break;
  2291.                             case 4: PlayerScore += 250;
  2292.                                     break;
  2293.                             }
  2294.                         }
  2295.                     }
  2296.                 }
  2297.  
  2298.                 if (EnemyProjectiles.size() > 1)
  2299.                 {
  2300.                     for(int e = 0; e < EnemyProjectiles.size() - 3;  e+= 5) //Checking Projectiles
  2301.                     {
  2302.                         if(EnemyProjectiles.at(e + 1) < Ship.y + 45 && EnemyProjectiles.at(e + 1) > Ship.y - 45) EnemyProjectiles.at(e + 3) = 0;
  2303.                     }
  2304.                 }
  2305.                 if (LaserTime > 90)
  2306.                 {
  2307.                     LaserFiring = false;
  2308.                     LaserTime = 0;
  2309.                     Pushed = false;
  2310.                 }
  2311.             }
  2312.         }
  2313.  
  2314.         ApplySurface(0, 0, ScoreBackground, Screen);
  2315.         if (EnemyHit == false) Message = TTF_RenderText_Solid(Font,"0",TextColour);
  2316.         else
  2317.         {
  2318.             THESCORE = std::to_string(PlayerScore);
  2319.             Message = TTF_RenderText_Solid(Font,THESCORE.c_str(),TextColour);
  2320.         }
  2321.         ApplySurface(25,355, Message, Screen);
  2322.        
  2323.         Selection.str("");
  2324.         if (CurrentSelection == 0) Selection << "BFG      " << Lasers;
  2325.         else if (CurrentSelection == 1) Selection << "RPG      " << Missiles;
  2326.         else if (CurrentSelection == 2) Selection << "LZR";
  2327.         Message = TTF_RenderText_Solid(Font,Selection.str().c_str(),TextColour);
  2328.         ApplySurface(ScreenWidth - 10 - (Message->w + 10),355,Message,Screen);
  2329.  
  2330.         if (Flash == true)
  2331.         {
  2332.             FlashAlpha -= 5;
  2333.             SDL_SetAlpha(WhiteFlash, SDL_SRCALPHA, FlashAlpha);
  2334.             ApplySurface(0,0,WhiteFlash,Screen);
  2335.             if (FlashAlpha < 0) Flash = false;
  2336.         }
  2337.  
  2338.         if (DebugBool == true)
  2339.         {
  2340.             DebugStream.str("");
  2341.             DebugStream << "Ship x: " << Ship.x << " Ship y: " << Ship.y << " LaserAmmos generated: " << PANIC;
  2342.             Message = TTF_RenderText_Solid(SmallFont,DebugStream.str().c_str(),TextColour);
  2343.             ApplySurface(0,0,Message,Screen);
  2344.         }
  2345.         SDL_Flip(Screen);
  2346.         if (Shot.get_ticks() > 2000)
  2347.         {
  2348.             Projectiles.erase(Projectiles.begin(),Projectiles.end());
  2349.             MissileVector.erase(MissileVector.begin(),MissileVector.end());
  2350.         }
  2351.         while (SDL_PollEvent(&event))
  2352.         {
  2353.             if (event.type == SDL_QUIT) Quit = true;
  2354.             if (event.type == SDL_KEYDOWN)
  2355.             {
  2356.                 if (event.key.keysym.sym == SDLK_x)
  2357.                 {
  2358.                     if(CurrentSelection == 0)
  2359.                     {
  2360.                         if(Lasers > 0 && LaserFiring == false)
  2361.                         {
  2362.                             if (Lasers = 1) CurrentSelection = 2;
  2363.                             LaserFiring = true;
  2364.                             Lasers--;
  2365.                         }
  2366.                     }
  2367.  
  2368.                     else if(CurrentSelection == 1)
  2369.                     {
  2370.                         if (Missiles > 0)
  2371.                         {
  2372.                             if (Missiles == 1) CurrentSelection = 2;
  2373.                             Missiles--;
  2374.                             StartShake(10,4);
  2375.                             if (PlaySound == true) Mix_PlayChannel( -1, ProjectileFired, 0 );
  2376.                             MissileVector.push_back(Ship.x);
  2377.                             MissileVector.push_back(Ship.y + 10);
  2378.                             MissileVector.push_back(0);
  2379.                             MissileVector.push_back(0);
  2380.                             MissileVector.push_back(0);
  2381.                             MissileVector.push_back(1);
  2382.                             Shot.start();
  2383.                         }
  2384.  
  2385.                     }
  2386.  
  2387.                     else if(CurrentSelection == 2)
  2388.                     {
  2389.                         if (PlaySound == true) Mix_PlayChannel( -1, ProjectileFired, 0 );
  2390.                         StartShake(10,4);
  2391.                         Projectiles.push_back(Ship.x);
  2392.                         Projectiles.push_back(Ship.y + 10);
  2393.                         Projectiles.push_back(0);
  2394.                         Projectiles.push_back(1);
  2395.                         Projectiles.push_back(0);
  2396.                         Shot.start();
  2397.                     }
  2398.                 }
  2399.  
  2400.                 if (event.key.keysym.sym == SDLK_SPACE)
  2401.                 {
  2402.                     WeaponsMenuFunction();
  2403.                 }
  2404.                 if (event.key.keysym.sym == SDLK_ESCAPE)
  2405.                 {
  2406.                     STATE = MAINMENU;
  2407.                 }
  2408.                 if (event.key.keysym.sym == SDLK_e)
  2409.                 {
  2410.                     StartShake(60,20);
  2411.                 }
  2412.  
  2413.                 if (event.key.keysym.sym == SDLK_TAB)
  2414.                 {
  2415.                     if (Name1 == "SKY") DebugBool = !DebugBool;
  2416.                 }
  2417.             }
  2418.         }
  2419.         if( FPS.get_ticks() < 1000 / 60 )
  2420.         {
  2421.             SDL_Delay( ( 1000 / 60 ) - FPS.get_ticks() );
  2422.         }
  2423.     }
  2424. }
  2425.  
  2426. void Options()
  2427. {
  2428.     MusicPlaying = false;
  2429.     while (Quit == false && STATE == OPTIONS)
  2430.     {
  2431.         if (PlayMusic == false) Mix_HaltMusic();
  2432.         if (OptionSelection < 1) OptionSelection = 3;
  2433.         if (OptionSelection > 3) OptionSelection = 1;
  2434.         ApplySurface(0,0,BlackScreen,Screen);
  2435.         std::stringstream Difficulty;
  2436.         Difficulty.str("");
  2437.         Difficulty << "Difficulty: ";
  2438.         if (CasualMode == true) Difficulty << "Casual babby mode";
  2439.         else Difficulty << "Normal mode";
  2440.         Message = TTF_RenderText_Solid(Font,Difficulty.str().c_str(),TextColour);
  2441.         ApplySurface((ScreenWidth - Message->w) / 2, ((ScreenHeight - Message->h) / 2) - 30, Message, Screen);
  2442.         Difficulty.str("");
  2443.         Difficulty << "Music: ";
  2444.         if (PlayMusic == true) Difficulty << "On";
  2445.         else Difficulty << "Off";
  2446.         Message2 = TTF_RenderText_Solid(Font,Difficulty.str().c_str(),TextColour);
  2447.         ApplySurface((ScreenWidth - Message2->w) / 2, (ScreenHeight - Message2->h) / 2, Message2, Screen);
  2448.         Difficulty.str("");
  2449.         Difficulty << "Sounds: ";
  2450.         if (PlaySound == true) Difficulty << "On";
  2451.         else Difficulty << "Off";
  2452.         Message3 = TTF_RenderText_Solid(Font,Difficulty.str().c_str(),TextColour);
  2453.         ApplySurface((ScreenWidth - Message3->w) / 2, ((ScreenHeight - Message3->h) / 2) + 30, Message3, Screen);
  2454.         switch(OptionSelection)
  2455.         {
  2456.         case 1:
  2457.             ApplySurface((ScreenWidth - Message->w) / 2 - 40, (ScreenHeight - Message->h) / 2 - 30, Character, Screen,&ShipFrames[0]);
  2458.             break;
  2459.         case 2:
  2460.             ApplySurface((ScreenWidth - Message2->w) / 2 - (Message2->w /2) + 30, (ScreenHeight - Message2->h) / 2, Character, Screen,&ShipFrames[0]);
  2461.             break;
  2462.         case 3:
  2463.             ApplySurface((ScreenWidth - Message3->w) / 2 - (Message3->w /2) + 40, (ScreenHeight - Message3->h) / 2 + 30, Character, Screen,&ShipFrames[0]);
  2464.             break;
  2465.         }
  2466.         SDL_Flip(Screen);
  2467.         while (SDL_PollEvent(&event))
  2468.         {
  2469.             if (event.type == SDL_QUIT) Quit = true;
  2470.             if (event.type == SDL_KEYDOWN)
  2471.             {
  2472.                 if (event.key.keysym.sym == SDLK_UP) --OptionSelection;
  2473.                 if (event.key.keysym.sym == SDLK_DOWN) ++OptionSelection;
  2474.                
  2475.                 if (event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_RIGHT)
  2476.                 {
  2477.                     if (OptionSelection == 1) CasualMode = !CasualMode;
  2478.                     else if (OptionSelection == 2) PlayMusic = !PlayMusic;
  2479.                     else PlaySound = !PlaySound;
  2480.                 }
  2481.                 if (event.key.keysym.sym == SDLK_RETURN) STATE = MAINMENU;
  2482.             }
  2483.         }
  2484.     }
  2485. }
  2486.  
  2487. int main (int argc, char* argv [])
  2488. {
  2489.     /*Initiating and loading files*/
  2490.     if (Initiate() == false) return -1;
  2491.     if (LoadFiles() == false) return -1;
  2492.     SetClips();
  2493.     while (Quit == false)
  2494.     {
  2495.         switch (STATE)
  2496.         {
  2497.         case INTRO:
  2498.             if (Intro() == -1) return -1;
  2499.             break;
  2500.         case MAINMENU:
  2501.             if (Lazy == true)
  2502.             {
  2503.                 Lazy = false;
  2504.                 STATE = GAME;
  2505.             }
  2506.             else
  2507.             {
  2508.                 GoToState = Menu();
  2509.                 switch (GoToState)
  2510.                 {
  2511.                     case 1: STATE = GAME; break;
  2512.                     case 2: STATE = SCORES; break;
  2513.                     case 3: STATE = OPTIONS; break;
  2514.                 }
  2515.             }
  2516.             break;
  2517.         case SCORES:
  2518.             Scores();
  2519.             break;
  2520.         case GAME:
  2521.             Game();
  2522.             break;
  2523.         case OPTIONS:
  2524.             Options();
  2525.             break;
  2526.         }
  2527.     }
  2528.     CleanUp();
  2529.     return 0;
  2530. }
Advertisement
Add Comment
Please, Sign In to add comment