Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Not responsible for any brain damage caused by reading this code
- Practically finished, will get 100% bug free when I have nothing else to do
- Now working on https://github.com/BenAbdul/tripping-octo-dangerzone
- */
- #include "SDL.h"
- #include "SDL_image.h"
- #include "SDL_ttf.h"
- #include "SDL_mixer.h"
- #include "SDL_rotozoom.h"
- #include <string>
- #include <sstream>
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fstream>
- #include <vector>
- const int ScreenWidth = 640;
- const int ScreenHeight = 380;
- const int ScreenBBP = 32;
- int PlzWork = 0;
- int PlzWork2 = 0;
- int PANIC = 0;
- std::string Name1, Name2, Name3, CName1, CName2, CName3 = "DEADBEEF";
- std::string THESCORE;
- std::stringstream Beat;
- std::stringstream Selection;
- std::stringstream NameOutputStream;
- int HScore1, HScore2, HScore3, CHScore1, CHScore2, CHScore3;
- int MenuSelection = 1;
- int OptionSelection = 1;
- int GoToState = 0;
- int CauseOfDeath = 0;
- int ScoreBeaten = 7;
- int Lasers = 1;
- int Missiles = 3;
- int CurrentSelection = 2;
- int LaserTime = 0;
- int InvincibilityTime = 0;
- int Magnitude = 0;
- int Time = 0;
- int xShakeOffset = 0;
- int yShakeOffset = 0;
- int FlashAlpha = 0;
- double Acceleration = 0.5;
- double Proc1, Proc2 = 120;
- double Backgroundx = 0;
- long double PlayerScore = 0;
- SDL_Event event;
- std::vector <int> Projectiles;
- std::vector <int> Enemies;
- std::vector <int> EnemyProjectiles;
- std::vector <int> Locks;
- std::vector <int> MissileVector;
- TTF_Font *Font = NULL;
- TTF_Font *SmallFont = NULL;
- SDL_Colour TextColour = {225,225,225};
- SDL_Surface *Character = NULL;
- SDL_Surface *YouTried = NULL;
- SDL_Surface *Character2 = NULL;
- SDL_Surface *Screen = NULL;
- SDL_Surface *BlackScreen = NULL;
- SDL_Surface *BlackRectangle = NULL;
- SDL_Surface *Message = NULL;
- SDL_Surface *Highlight = NULL;
- SDL_Surface *MissileSprite = NULL;
- SDL_Surface *Message2 = NULL;
- SDL_Surface *LaserAmmo = NULL;
- SDL_Surface *MissileAmmo = NULL;
- SDL_Surface *EnemyShip = NULL;
- SDL_Surface *Message3 = NULL;
- SDL_Surface *Message4 = NULL;
- SDL_Surface *Background = NULL;
- SDL_Surface *Projectile = NULL;
- SDL_Surface *Crosshair = NULL;
- SDL_Surface *AlphaGray = NULL;
- SDL_Surface *InvAnimation = NULL;
- SDL_Surface *EnemyInvader = NULL;
- SDL_Surface *EnemyProjectile = NULL;
- SDL_Surface *EnemyWorm = NULL;
- SDL_Surface *ScoreBackground = NULL;
- SDL_Surface *TitleText = NULL;
- SDL_Surface *TitleTextR = NULL;
- SDL_Surface *MegaLaser = NULL;
- SDL_Surface *MenuBackground = NULL;
- SDL_Surface *Burned = NULL;
- SDL_Surface *LockSprites = NULL;
- SDL_Surface *Score2 = NULL;
- SDL_Surface *Explosion = NULL;
- SDL_Surface *WeaponsMenu = NULL;
- SDL_Surface *InvincibilitySprite = NULL;
- SDL_Surface *FinalShip = NULL;
- SDL_Surface *RotShip = NULL;
- SDL_Surface *WhiteFlash = NULL;
- SDL_Surface *ShipMoving1 = NULL;
- SDL_Surface *ShipMoving2 = NULL;
- SDL_Surface *ShipMoving3 = NULL;
- SDL_Surface *ShipIdle = NULL;
- Mix_Music *MenuMusic = NULL;
- Mix_Music *GameMusic = NULL;
- Mix_Chunk *ProjectileFired = NULL;
- Mix_Chunk *Death1 = NULL;
- Mix_Chunk *Death2 = NULL;
- Mix_Chunk *Death3 = NULL;
- Mix_Chunk *Death4 = NULL;
- Mix_Chunk *PlayerDeath = NULL;
- Mix_Chunk *Rocket = NULL;
- bool Quit = false;
- bool PlaySound = true;
- bool PlayMusic = true;
- bool Applied = false;
- bool DebugBool = false;
- bool GenerationPaused = false;
- bool CasualMode = false;
- bool Start = false;
- bool MusicPlaying = false;
- bool EnemyHit = false;
- bool HighScoreBeaten = false;
- bool LaserFiring = false;
- bool Pushed = false;
- bool Rival = false;
- bool Invincible = false;
- bool Shake = false;
- bool Flash = false;
- bool lrn2program = false;
- bool Lazy = false;
- bool LeftDown,RightDown,UpDown,DownDown = false;
- SDL_Rect WormFrames [2];
- SDL_Rect ProjectileFrames [2];
- SDL_Rect ShipFrames [2];
- SDL_Rect InvFrames [9];
- SDL_Rect AmmoFrames [2];
- SDL_Rect LockFrames [4];
- SDL_Rect MissileClips [2];
- SDL_Rect WMenuClips [3];
- enum GAMESTATE {INTRO,MAINMENU,SCORES,GAME,OPTIONS};
- GAMESTATE STATE = INTRO;
- SDL_Surface *LoadImage( std::string filename )
- {
- SDL_Surface* LoadedImage = NULL;
- SDL_Surface* OptimizedImage = NULL;
- LoadedImage = IMG_Load( filename.c_str() );
- if( LoadedImage != NULL )
- {
- OptimizedImage = SDL_DisplayFormatAlpha( LoadedImage );
- SDL_FreeSurface( LoadedImage );
- }
- return OptimizedImage;
- }
- void ApplySurface( int x, int y, SDL_Surface* Source, SDL_Surface* Destination, SDL_Rect* Clip = NULL )
- {
- SDL_Rect offset;
- offset.x = x + xShakeOffset;
- offset.y = y + yShakeOffset;
- SDL_BlitSurface( Source, Clip, Destination, &offset );
- }
- void LoadScores()
- {
- std::ifstream ScoreInput;
- ScoreInput.open("TopLel.dll");
- ScoreInput >> Name1 >> Name2 >> Name3 >> CName1 >> CName2 >> CName3 >> HScore1 >> HScore2 >> HScore3 >> CHScore1 >> CHScore2 >> CHScore3;
- ScoreInput.close();
- }
- bool LoadFiles()
- {
- Character = LoadImage("Resources/Images/Ship.png");
- if (Character == NULL) return false;
- InvAnimation = LoadImage("Resources/Images/InvAnimation.png");
- if (InvAnimation == NULL) return false;
- Character2 = LoadImage("Resources/Images/Ship2.png");
- if (Character2 == NULL) return false;
- AlphaGray = LoadImage("Resources/Images/AlphaGray.png");
- if (AlphaGray == NULL) return false;
- BlackScreen = LoadImage("Resources/Images/Black.png");
- if (BlackScreen == NULL) return false;
- YouTried = LoadImage("Resources/Images/YouTried.png");
- if (YouTried == NULL) return false;
- EnemyShip = LoadImage("Resources/Images/EnemyShip.png");
- if (EnemyShip == NULL) return false;
- Explosion = LoadImage("Resources/Images/Explosion.png");
- if (Explosion == NULL) return false;
- ScoreBackground = LoadImage("Resources/Images/Score.png");
- if (ScoreBackground == NULL) return false;
- MegaLaser = LoadImage("Resources/Images/MegaLaser.png");
- if (MegaLaser == NULL) return false;
- InvincibilitySprite = LoadImage("Resources/Images/Blue.png");
- if (InvincibilitySprite == NULL) return false;
- BlackRectangle = LoadImage("Resources/Images/BlackRectangle.png");
- if (BlackRectangle == NULL) return false;
- Highlight = LoadImage("Resources/Images/Highlight.png");
- if (Highlight == NULL) return false;
- Background = LoadImage("Resources/Images/Background.png");
- if (Background == NULL) return false;
- WhiteFlash = IMG_Load("Resources/Images/WhiteFlash.bmp");
- if (WhiteFlash == NULL) return false;
- LaserAmmo = LoadImage("Resources/Images/LaserAmmo.png");
- if (LaserAmmo == NULL) return false;
- MissileSprite = LoadImage("Resources/Images/Missile.png");
- if (MissileSprite == NULL) return false;
- MissileAmmo = LoadImage("Resources/Images/MissileAmmo.png");
- if (MissileAmmo == NULL) return false;
- LockSprites = LoadImage("Resources/Images/Locks.png");
- if (LockSprites == NULL) return false;
- Projectile = LoadImage("Resources/Images/Projectile.png");
- if (Projectile == NULL) return false;
- EnemyInvader = LoadImage("Resources/Images/Invader.png");
- if (EnemyInvader == NULL) return false;
- Burned = LoadImage("Resources/Images/Burned.png");
- if (Burned == NULL) return false;
- ShipMoving1 = LoadImage("Resources/Images/ShipMoving1.png");
- if (ShipMoving1 == NULL) return false;
- ShipMoving2 = LoadImage("Resources/Images/ShipMoving2.png");
- if (ShipMoving2 == NULL) return false;
- ShipMoving3 = LoadImage("Resources/Images/ShipMoving3.png");
- if (ShipMoving3 == NULL) return false;
- ShipIdle = LoadImage("Resources/Images/ShipIdle.png");
- if (ShipIdle == NULL) return false;
- Score2 = LoadImage("Resources/Images/Score2.png");
- if (Score2 == NULL) return false;
- TitleText = LoadImage("Resources/Images/TitleText.png");
- if (TitleText == NULL) return false;
- Crosshair = LoadImage("Resources/Images/Crosshair.png");
- if (Crosshair == NULL) return false;
- MenuBackground = LoadImage("Resources/Images/MenuBackground.png");
- if (MenuBackground == NULL) return false;
- WeaponsMenu = LoadImage("Resources/Images/WeaponsMenu.png");
- if (WeaponsMenu == NULL) return false;
- EnemyProjectile = LoadImage("Resources/Images/EnemyProjectile.png");
- if (EnemyProjectile == NULL) return false;
- EnemyWorm = LoadImage("Resources/Images/Worm.png");
- if (EnemyWorm == NULL) return false;
- MenuMusic = Mix_LoadMUS ("Resources/Sounds/Menu.ogg");
- if (MenuMusic == NULL) return false;
- GameMusic = Mix_LoadMUS ("Resources/Sounds/Game.ogg");
- if (GameMusic == NULL) return false;
- ProjectileFired = Mix_LoadWAV ("Resources/Sounds/ProjectileFired.wav");
- if (ProjectileFired == NULL) return false;
- PlayerDeath = Mix_LoadWAV ("Resources/Sounds/PlayerDeath.wav");
- if (PlayerDeath == NULL) return false;
- Death1 = Mix_LoadWAV ("Resources/Sounds/Death1.wav");
- if (Death1 == NULL) return false;
- Death2 = Mix_LoadWAV ("Resources/Sounds/Death2.wav");
- if (Death2 == NULL) return false;
- Death3 = Mix_LoadWAV ("Resources/Sounds/Death3.wav");
- if (Death3 == NULL) return false;
- Death4 = Mix_LoadWAV ("Resources/Sounds/Death4.wav");
- if (Death4 == NULL) return false;
- Rocket = Mix_LoadWAV ("Resources/Sounds/Rocket.wav");
- if (Rocket == NULL) return false;
- Font = TTF_OpenFont("Resources/Fonts/Arcade.ttf",16);
- if (Font == NULL) return false;
- SmallFont = TTF_OpenFont("Resources/Fonts/Arcade.ttf",9);
- if (SmallFont == NULL) return false;
- LoadScores();
- }
- void CleanUp()
- {
- }
- bool Initiate()
- {
- if (SDL_Init(SDL_INIT_EVERYTHING) == -1) return false;
- if (TTF_Init() == -1) return false;
- Screen = SDL_SetVideoMode(ScreenWidth,ScreenHeight,ScreenBBP,SDL_SWSURFACE);
- if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 ) return false;
- SDL_WM_SetCaption("Smash it Scown", NULL);
- SDL_EnableUNICODE(SDL_ENABLE);
- return true;
- }
- void StartShake(int T, int M)
- {
- Shake = true;
- Time = T;
- Magnitude = M;
- }
- void StartFlash()
- {
- if (Flash == false)
- {
- Flash = true;
- FlashAlpha = 255;
- }
- }
- int GetNumberInput()
- {
- SDL_Surface *WorkYouPrick = NULL;
- int NumberToReturn = 0;
- std::stringstream SpareStream;
- SpareStream << NumberToReturn;
- while (Quit == false)
- {
- WorkYouPrick = TTF_RenderText_Solid(Font,SpareStream.str().c_str(),TextColour);
- ApplySurface ((ScreenWidth-BlackRectangle->w)/2,(ScreenHeight-BlackRectangle->h)/2,BlackRectangle,Screen);
- ApplySurface ((ScreenWidth-WorkYouPrick->w)/2,(ScreenHeight-WorkYouPrick->h)/2,WorkYouPrick,Screen);
- SDL_Flip(Screen);
- while(SDL_PollEvent(&event))
- {
- if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) { ApplySurface ((ScreenWidth-BlackRectangle->w)/2,(ScreenHeight-BlackRectangle->h)/2,BlackRectangle,Screen); return NumberToReturn;}
- if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RIGHT)
- {
- NumberToReturn++;
- SpareStream.str("");
- SpareStream << NumberToReturn;
- }
- if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_LEFT)
- {
- if (NumberToReturn != 0) NumberToReturn--;
- SpareStream.str("");
- SpareStream << NumberToReturn;
- }
- if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_q)
- {
- if (NumberToReturn - 10 < 0) NumberToReturn = 0;
- else NumberToReturn = NumberToReturn - 10;
- SpareStream.str("");
- SpareStream << NumberToReturn;
- }
- if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_e)
- {
- NumberToReturn = NumberToReturn + 10;
- SpareStream.str("");
- SpareStream << NumberToReturn;
- }
- if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_a)
- {
- if (NumberToReturn - 100 < 0) NumberToReturn = 0;
- else NumberToReturn = NumberToReturn - 100;
- SpareStream.str("");
- SpareStream << NumberToReturn;
- }
- if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_d)
- {
- NumberToReturn = NumberToReturn + 100;
- SpareStream.str("");
- SpareStream << NumberToReturn;
- }
- if (event.type == SDL_QUIT) Quit = true;
- }
- }
- }
- int RandomNumber(int First, int Second)
- {
- return rand () % First + Second;
- }
- class Player
- {
- public:
- double x,y;
- int Frame,Frametime;
- int Animation;
- double xVel,yVel;
- void Die();
- void RefreshPosition();
- void RenderShip();
- Player();
- } Ship;
- Player::Player()
- {
- x = 0;
- y = ScreenHeight / 2;
- xVel, yVel = 0;
- Frame = 1;
- Frametime = 0;
- Animation = 2;
- }
- void Player::RenderShip()
- {
- if(Invincible == false)
- {
- if (xVel != 0)
- {
- if (Frame > 3)
- {
- Frame = 1;
- }
- Frametime++;
- if (Frametime > 10)
- {
- Frame++;
- Frametime = 0;
- }
- switch (Frame)
- {
- case 1:
- FinalShip = ShipMoving1;
- break;
- case 2:
- FinalShip = ShipMoving2;
- break;
- case 3:
- FinalShip = ShipMoving3;
- break;
- }
- }
- else (FinalShip = ShipIdle);
- RotShip = rotozoomSurface(FinalShip,yVel,1,0);
- ApplySurface(x - 14, y, RotShip, Screen);
- }
- else
- {
- Frametime++;
- if (Frametime > 9)
- {
- Frame++;
- Frametime = 0;
- }
- if (Frame > 9) Frame = 1;
- ApplySurface(x,y,InvAnimation,Screen,&InvFrames[Frame]);
- }
- }
- class Timer
- {
- private:
- int startTicks;
- int pausedTicks;
- bool paused;
- bool started;
- public:
- Timer();
- void start();
- void stop();
- void pause();
- void unpause();
- int get_ticks();
- bool is_started();
- bool is_paused();
- };
- Timer::Timer()
- {
- startTicks = 0;
- pausedTicks = 0;
- paused = false;
- started = false;
- }
- void Timer::start()
- {
- started = true;
- paused = false;
- startTicks = SDL_GetTicks();
- }
- void Timer::stop()
- {
- started = false;
- paused = false;
- }
- void Timer::pause()
- {
- if( ( started == true ) && ( paused == false ) )
- {
- paused = true;
- pausedTicks = SDL_GetTicks() - startTicks;
- }
- }
- void Timer::unpause()
- {
- if( paused == true )
- {
- paused = false;
- startTicks = SDL_GetTicks() - pausedTicks;
- pausedTicks = 0;
- }
- }
- int Timer::get_ticks()
- {
- if( started == true )
- {
- if( paused == true )
- {
- return pausedTicks;
- }
- else
- {
- return SDL_GetTicks() - startTicks;
- }
- }
- return 0;
- }
- bool Timer::is_started()
- {
- return started;
- }
- bool Timer::is_paused()
- {
- return paused;
- }
- void SetClips()
- {
- WormFrames[0].x = 0;
- WormFrames[0].y = 0;
- WormFrames[0].w = 50;
- WormFrames[0].h = 50;
- WormFrames[1].x = 50;
- WormFrames[1].y = 0;
- WormFrames[1].w = 50;
- WormFrames[1].h = 50;
- AmmoFrames[0].x = 0;
- AmmoFrames[0].y = 0;
- AmmoFrames[0].w = 25;
- AmmoFrames[0].h = 25;
- AmmoFrames[1].x = 25;
- AmmoFrames[1].y = 0;
- AmmoFrames[1].w = 25;
- AmmoFrames[1].h = 25;
- ProjectileFrames[0].x = 0;
- ProjectileFrames[0].y = 0;
- ProjectileFrames[0].w = 30;
- ProjectileFrames[0].h = 10;
- ProjectileFrames[1].x = 30;
- ProjectileFrames[1].y = 0;
- ProjectileFrames[1].w = 30;
- ProjectileFrames[1].h = 10;
- ShipFrames[0].x = 0;
- ShipFrames[0].y = 0;
- ShipFrames[0].w = 39;
- ShipFrames[0].h = 20;
- ShipFrames[1].x = 39;
- ShipFrames[1].y = 0;
- ShipFrames[1].w = 39;
- ShipFrames[1].h = 20;
- LockFrames[0].x = 0;
- LockFrames[0].y = 0;
- LockFrames[0].w = 48;
- LockFrames[0].h = 50;
- LockFrames[1].x = 49;
- LockFrames[1].y = 0;
- LockFrames[1].w = 48;
- LockFrames[1].h = 50;
- LockFrames[2].x = 98;
- LockFrames[2].y = 0;
- LockFrames[2].w = 48;
- LockFrames[2].h = 50;
- LockFrames[3].x = 147;
- LockFrames[3].y = 0;
- LockFrames[3].w = 48;
- LockFrames[3].h = 50;
- MissileClips[0].x = 0;
- MissileClips[0].y = 0;
- MissileClips[0].w = 38;
- MissileClips[0].h = 17;
- MissileClips[1].x = 39;
- MissileClips[1].y = 0;
- MissileClips[1].w = 38;
- MissileClips[1].h = 17;
- WMenuClips[0].x = 0;
- WMenuClips[0].y = 0;
- WMenuClips[0].w = 350;
- WMenuClips[0].h = 200;
- WMenuClips[1].x = 350;
- WMenuClips[1].y = 0;
- WMenuClips[1].w = 350;
- WMenuClips[1].h = 200;
- WMenuClips[2].x = 700;
- WMenuClips[2].y = 0;
- WMenuClips[2].w = 350;
- WMenuClips[2].h = 200;
- for (int werk = 0; werk <= 8; werk++)
- {
- InvFrames[werk].x = (36 * werk) + werk;
- InvFrames[werk].y = 0;
- InvFrames[werk].w = 36;
- InvFrames[werk].h = 20;
- }
- }
- void RenderProjectiles()
- {
- int PlayerProjectileVectorSize = Projectiles.size();
- if (PlayerProjectileVectorSize >= 5)
- {
- for (int i = 0; i <= PlayerProjectileVectorSize - 1; i+=5)
- {
- if (Projectiles.at(i + 3) == 1)
- {
- int x = Projectiles.at(i);
- int y = Projectiles.at(i + 1);
- ApplySurface(x,y,Projectile,Screen,&ProjectileFrames[Projectiles.at(i + 2)]);
- }
- }
- }
- if (EnemyProjectiles.size() >= 5)
- {
- for (int i = 0; i <= EnemyProjectiles.size() - 1; i+=5)
- {
- if (EnemyProjectiles.at(i + 3) == 1)
- {
- int x = EnemyProjectiles.at(i);
- int y = EnemyProjectiles.at(i + 1);
- if (EnemyProjectiles.at(i + 2) < 2) ApplySurface(x,y,EnemyProjectile,Screen,&ProjectileFrames[EnemyProjectiles.at(i + 2)]);
- else
- {
- if (EnemyProjectiles.at(i + 2) == 3) ApplySurface(x,y,EnemyProjectile,Screen,&ProjectileFrames[0]);
- else ApplySurface(x,y,EnemyProjectile,Screen,&ProjectileFrames[1]);
- }
- }
- }
- }
- }
- void UpdateProjectiles()
- {
- if (Projectiles.size() >= 5)
- {
- for (int i = 0; i <= Projectiles.size() - 5; i+=5)
- {
- Projectiles.at(i) += 15;
- Projectiles.at(i) -= 7;
- ++ Projectiles.at(i + 4);
- if (Projectiles.at(i + 4) > 10)
- {
- Projectiles.at(i + 4) = 0;
- ++Projectiles.at(i + 2);
- }
- if (Projectiles.at(i + 2) > 1) Projectiles.at(i + 2) = 0;
- }
- }
- if (EnemyProjectiles.size() >= 5)
- {
- for (int i = 0; i <= EnemyProjectiles.size() - 5; i+=5)
- {
- EnemyProjectiles.at(i) -= 7;
- ++ EnemyProjectiles.at(i + 4);
- if (EnemyProjectiles.at(i + 4) > 10)
- {
- EnemyProjectiles.at(i + 4) = 0;
- EnemyProjectiles.at(i + 2)++;
- }
- if (EnemyProjectiles.at(i + 2) == 2) EnemyProjectiles.at(i + 2) = 0;
- if (EnemyProjectiles.at(i + 2) == 5)
- {
- EnemyProjectiles.at(i + 2) = 3;
- }
- }
- }
- }
- bool GenerateChance(int Chance)
- {
- int a = rand() % 100 + 1;
- if (a <= Chance) return true;
- else return false;
- }
- void PlayDeathSound()
- {
- if (PlaySound == true)
- {
- int WHEELOFFORTUNE = RandomNumber(100,1);
- if (WHEELOFFORTUNE < 25) Mix_PlayChannel( -1, Death1, 0 );
- else if (WHEELOFFORTUNE < 50) Mix_PlayChannel( -1, Death2, 0 );
- else if (WHEELOFFORTUNE < 75) Mix_PlayChannel( -1, Death3, 0 );
- else Mix_PlayChannel( -1, Death4, 0 );
- }
- }
- void UpdateEnemies()
- {
- if (Enemies.size() >= 6)
- {
- for (int i = 0; i <= Enemies.size() - 6; i+=6)
- {
- if (Enemies.at(i + 4) == 1) //If the enemy is an alien
- {
- Enemies.at(i) -= 10; //SPEED
- int wtf = Enemies.at(i + 3);
- Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
- if (Enemies.at(i + 3) >= 20)
- {
- Enemies.at(i + 2) ++;
- Enemies.at(i + 3) = 0;
- }
- if (Enemies.at(i + 2) == 3) Enemies.at(i + 2) = 1;
- }
- if (Enemies.at(i + 4) == 4) //If its an enemy ship
- {
- if (Enemies.at(i) > 550) Enemies.at(i) -= 5; //SPEED
- else
- {
- if (Enemies.at(i + 1) > Ship.y + 15)
- {
- if (Enemies.at(i + 1) - 1 < Ship.y + 15) Enemies.at(i + 1) = Ship.y + 15;
- else Enemies.at(i + 1) -= 1;
- }
- if (Enemies.at(i + 1) < Ship.y)
- {
- if (Enemies.at(i + 1) + 1 > Ship.y + 15) Enemies.at(i + 1) = Ship.y+ 15;
- else Enemies.at(i + 1) += 1;
- }
- }
- int wtf = Enemies.at(i + 3);
- Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
- if (Enemies.at(i + 3) >= 20)
- {
- Enemies.at(i + 2) ++;
- Enemies.at(i + 3) = 0;
- }
- if (Enemies.at(i + 2) == 3 && Enemies.at(i + 5) == 1)
- {
- Enemies.at(i + 2) = 1;
- EnemyProjectiles.push_back(Enemies.at(i));
- EnemyProjectiles.push_back(Enemies.at(i + 1) + 5);
- EnemyProjectiles.push_back(3);
- EnemyProjectiles.push_back(1);
- EnemyProjectiles.push_back(0);
- }
- }
- if (Enemies.at(i + 4) == 5) //If its a laser powerup
- {
- Enemies.at(i) -= 5; //SPEED
- int wtf = Enemies.at(i + 3);
- Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
- if (Enemies.at(i + 3) >= 20)
- {
- Enemies.at(i + 2) ++;
- Enemies.at(i + 3) = 0;
- }
- if (Enemies.at(i + 2) == 3) Enemies.at(i + 2) = 1;
- }
- if (Enemies.at(i + 4) == 6) //If its a missile powerup
- {
- Enemies.at(i) -= 5; //SPEED
- int wtf = Enemies.at(i + 3);
- Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
- if (Enemies.at(i + 3) >= 20)
- {
- Enemies.at(i + 2) ++;
- Enemies.at(i + 3) = 0;
- }
- if (Enemies.at(i + 2) == 3) Enemies.at(i + 2) = 1;
- }
- if (Enemies.at(i + 4) == 7) //If its a invincibility powerup
- {
- Enemies.at(i) -= 5; //SPEED
- int wtf = Enemies.at(i + 3);
- Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
- if (Enemies.at(i + 3) >= 20)
- {
- Enemies.at(i + 2) ++;
- Enemies.at(i + 3) = 0;
- }
- if (Enemies.at(i + 2) == 3) Enemies.at(i + 2) = 1;
- }
- if (Enemies.at(i + 4) == 2) //If the enemy is a worm
- {
- Enemies.at(i) -= 5; //SPEED
- int wtf = Enemies.at(i + 3);
- Enemies.at(i + 3) = wtf + 1; // ADVANCE FRAMETIME
- if (Enemies.at(i + 3) >= 10)
- {
- Enemies.at(i + 2) ++;
- Enemies.at(i + 3) = 0;
- }
- if (Enemies.at(i + 2) == 3) Enemies.at(i + 2) = 1;
- if (GenerateChance(2) == true && Enemies.at(i + 5) == 1 && Enemies.at(i + 2) == 1)
- {
- EnemyProjectiles.push_back(Enemies.at(i));
- EnemyProjectiles.push_back(Enemies.at(i + 1) + 25);
- EnemyProjectiles.push_back(0);
- EnemyProjectiles.push_back(1);
- EnemyProjectiles.push_back(0);
- }
- }
- if (Enemies.at(i + 4) == 3) //Crosshair
- {
- Enemies.at(i) -= 3;
- if (Enemies.at(i) > Ship.x)
- {
- if (Enemies.at(i + 1) > Ship.y + 15)
- {
- if (Enemies.at(i + 1) - 1 < Ship.y + 15) Enemies.at(i + 1) = Ship.y + 15;
- else Enemies.at(i + 1) -= 1;
- }
- if (Enemies.at(i + 1) < Ship.y)
- {
- if (Enemies.at(i + 1) + 1 > Ship.y + 15) Enemies.at(i + 1) = Ship.y+ 15;
- else Enemies.at(i + 1) += 1;
- }
- }
- }
- }
- }
- }
- void GenerateEnemy()
- {
- if(GenerateChance(8) == true) //Crosshair
- {
- Enemies.push_back(640); //x
- Enemies.push_back(Ship.y); //y
- Enemies.push_back(1); //Frame
- Enemies.push_back(0); //Frame time
- Enemies.push_back(3); //Type
- Enemies.push_back(1); //Visible psuedobool
- }
- if(GenerateChance(2) == true && Rival == false) //Rival
- {
- Enemies.push_back(640); //x
- Enemies.push_back(Ship.y); //y
- Enemies.push_back(1); //Frame
- Enemies.push_back(0); //Frame time
- Enemies.push_back(4); //Type
- Enemies.push_back(1); //Visible psuedobool
- Rival = true;
- }
- Enemies.push_back(640); //x
- Enemies.push_back(RandomNumber(360,-10)); //y
- Enemies.push_back(1); //Frame
- Enemies.push_back(0); //Frame time
- Enemies.push_back(RandomNumber(2,1)); //Type
- Enemies.push_back(1); //Visible psuedobool
- }
- void RenderEnemies()
- {
- if (Enemies.size() >= 6)
- {
- for (int i = 0; i <= Enemies.size() - 6; i+=6)
- {
- if (Enemies.at(i + 5) == 1) //If the enemy is visible
- {
- int x = Enemies.at(i);
- int y = Enemies.at(i + 1);
- SetClips();
- if (Enemies.at(i + 4) == 1) //If the enemy is a Invader
- {
- if (Enemies.at(i + 2) == 1)
- {
- ApplySurface (x, y, EnemyInvader, Screen, &WormFrames[0]);
- }
- else if (Enemies.at(i + 2) == 2)
- {
- ApplySurface (x, y, EnemyInvader, Screen, &WormFrames[1]);
- }
- }
- if (Enemies.at(i + 4) == 4) //If the enemy is a rival ship
- {
- if (Enemies.at(i + 2) == 1)
- {
- ApplySurface (x, y, EnemyShip, Screen, &ShipFrames[0]);
- }
- else if (Enemies.at(i + 2) == 2)
- {
- ApplySurface (x, y, EnemyShip, Screen, &ShipFrames[1]);
- }
- }
- if (Enemies.at(i + 4) == 2) //If the enemy is a Worm
- {
- if (Enemies.at(i + 2) == 1)
- {
- ApplySurface (x, y, EnemyWorm, Screen, &WormFrames[0]);
- }
- else if (Enemies.at(i + 2) == 2)
- {
- ApplySurface (x, y, EnemyWorm, Screen, &WormFrames[1]);
- }
- }
- if (Enemies.at(i + 4) == 5) //If its a laser powerup
- {
- if (Enemies.at(i + 2) == 1)
- {
- ApplySurface (x, y, LaserAmmo, Screen, &AmmoFrames[0]);
- }
- else if (Enemies.at(i + 2) == 2)
- {
- ApplySurface (x, y, LaserAmmo, Screen, &AmmoFrames[1]);
- }
- }
- if (Enemies.at(i + 4) == 7) //If its a missile powerup
- {
- if (Enemies.at(i + 2) == 1)
- {
- ApplySurface (x, y, MissileAmmo, Screen, &AmmoFrames[0]);
- }
- else if (Enemies.at(i + 2) == 2)
- {
- ApplySurface (x, y, MissileAmmo, Screen, &AmmoFrames[1]);
- }
- }
- if (Enemies.at(i + 4) == 7) //If its an invincibility powerup
- {
- if (Enemies.at(i + 2) == 1)
- {
- ApplySurface (x, y, InvincibilitySprite, Screen, &AmmoFrames[0]);
- }
- else if (Enemies.at(i + 2) == 2)
- {
- ApplySurface (x, y, InvincibilitySprite, Screen, &AmmoFrames[1]);
- }
- }
- else if (Enemies.at(i + 4) == 3)
- {
- ApplySurface (x, y, Crosshair, Screen);
- PlzWork2++;
- }
- }
- }
- }
- }
- void ResetGame()
- {
- ApplySurface(0,0,BlackScreen,Screen);
- EnemyHit = false;
- HighScoreBeaten = false;
- Backgroundx = 0;
- lrn2program = false;
- LeftDown,RightDown,UpDown,DownDown = false;
- Rival = false;
- Proc1 = 50;
- Proc2 = 50;
- Lasers = 1;
- Missiles = 3;
- CurrentSelection = 2;
- LaserFiring = false;
- LaserTime = 0;
- if (Enemies.size() > 0) Enemies.erase(Enemies.begin(),Enemies.end());
- if (Projectiles.size() > 0) Projectiles.erase(Projectiles.begin(),Projectiles.end());
- if (EnemyProjectiles.size() > 0) EnemyProjectiles.erase(EnemyProjectiles.begin(),EnemyProjectiles.end());
- if (Locks.size() > 0) Locks.erase(Locks.begin(),Locks.end());
- if (MissileVector.size() > 0) MissileVector.erase(MissileVector.begin(),MissileVector.end());
- Ship.x = 0;
- Ship.y = ScreenHeight / 2;
- Ship.xVel = 0;
- Ship.yVel = 0;
- PlayerScore = 0;
- Start = false;
- }
- void SortScores()
- {
- Beat.str("");
- HighScoreBeaten = true;
- if (CasualMode == false)
- {
- if (PlayerScore > HScore1)
- {
- HScore3 = HScore2;
- HScore2 = HScore1;
- HScore1 = PlayerScore;
- Beat << "You beat the high score!";
- ScoreBeaten = 1;
- }
- else if (PlayerScore > HScore2)
- {
- HScore3 = HScore2;
- HScore2 = PlayerScore;
- Beat << "2nd. Meh.";
- ScoreBeaten = 2;
- }
- else if (PlayerScore > HScore3)
- {
- HScore3 = PlayerScore;
- Beat << "Just made it. Try harder next time.";
- ScoreBeaten = 3;
- }
- else
- {
- Beat << "You suck.";
- ScoreBeaten = 0;
- }
- }
- else
- {
- if (PlayerScore > CHScore1)
- {
- CHScore3 = CHScore2;
- CHScore2 = CHScore1;
- CHScore1 = PlayerScore;
- Beat << "1st! Now try Normal mode!";
- ScoreBeaten = 4;
- }
- else if (PlayerScore > CHScore2)
- {
- CHScore3 = CHScore2;
- CHScore2 = PlayerScore;
- Beat << "2nd. You can do better.";
- ScoreBeaten = 5;
- }
- else if (PlayerScore > HScore3)
- {
- CHScore3 = PlayerScore;
- Beat << "3rd. Git gud scrub";
- ScoreBeaten = 6;
- }
- else
- {
- Beat << "HAHAHAHAHAHA OH MAN WHAT WAS THAT";
- ScoreBeaten = 0;
- }
- }
- }
- void GetNameInput() //Ascii charactars from A-Z is 65-90
- {
- int Highlighted = 1;
- char One = 65;
- char Two = 65;
- char Three = 65;
- bool EnterPressed = false;
- while (EnterPressed == false)
- {
- ApplySurface(0,0,BlackScreen,Screen);
- ApplySurface(0,(ScreenHeight - YouTried->h)/2,YouTried,Screen);
- NameOutputStream.str("");
- NameOutputStream << One << " " << Two << " " << Three;
- Message = TTF_RenderText_Solid(Font,NameOutputStream.str().c_str(), TextColour);
- ApplySurface(270,((ScreenHeight - YouTried->h)/2) + 97,Message,Screen);
- SDL_Flip(Screen);
- while (SDL_PollEvent(&event))
- {
- if(event.type == SDL_QUIT)
- {
- Quit = true;
- EnterPressed = true;
- STATE = MAINMENU;
- }
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym == SDLK_RETURN)
- {
- EnterPressed = true;
- NameOutputStream.str("");
- NameOutputStream << One << Two << Three;
- }
- if (event.key.keysym.sym == SDLK_RIGHT) Highlighted++;
- if (event.key.keysym.sym == SDLK_LEFT) Highlighted--;
- if (Highlighted < 1) Highlighted = 3;
- else if (Highlighted > 3) Highlighted = 1;
- if (event.key.keysym.sym == SDLK_UP || event.key.keysym.sym == SDLK_DOWN)
- {
- switch(Highlighted)
- {
- case 1:
- if (event.key.keysym.sym == SDLK_UP) (int)One++;
- else (int)One--;
- if ((int)One < 65) One = 90;
- else if ((int)One > 90) One = 65;
- break;
- case 2:
- if (event.key.keysym.sym == SDLK_UP) (int)Two++;
- else (int)Two--;
- if ((int)Two < 65) Two = 90;
- else if ((int)Two > 90) Two = 65;
- break;
- case 3:
- if (event.key.keysym.sym == SDLK_UP) (int)Three++;
- else (int)Three--;
- if ((int)Three < 65) Three = 90;
- else if ((int)Three > 90) Three = 65;
- break;
- }
- }
- }
- }
- }
- } // 10/10 code
- void Player::Die()
- {
- if (DebugBool == false && Invincible == false)
- {
- Ship.yVel = -20;
- Ship.xVel = 7;
- Timer JUMP;
- for (int p2w = 0; p2w < 150; p2w++)
- {
- JUMP.start();
- Ship.yVel += 2;
- Backgroundx -= 0.1;
- if (Backgroundx <= -2000 + 640) Backgroundx = 0;
- ApplySurface(Backgroundx,0,Background,Screen);
- ApplySurface(Ship.x,Ship.y,Burned,Screen);
- Ship.RefreshPosition();
- UpdateProjectiles();
- UpdateEnemies();
- RenderEnemies();
- RenderProjectiles();
- ApplySurface(0,0,ScoreBackground,Screen);
- if (EnemyHit == false) Message = TTF_RenderText_Solid(Font,"0",TextColour);
- else
- {
- THESCORE = std::to_string(PlayerScore);
- Message = TTF_RenderText_Solid(Font,THESCORE.c_str(),TextColour);
- }
- ApplySurface(25,355, Message, Screen);
- Selection.str("");
- if (CurrentSelection == 0) Selection << "BFG " << Lasers;
- else if (CurrentSelection == 1) Selection << "RPG " << Missiles;
- else if (CurrentSelection == 2) Selection << "LZR";
- Message = TTF_RenderText_Solid(Font,Selection.str().c_str(),TextColour);
- ApplySurface(ScreenWidth - 10 - (Message->w + 10),355,Message,Screen);
- SDL_Flip(Screen);
- while(SDL_PollEvent(&event))
- {
- if (event.type == SDL_QUIT)
- {
- Quit = true;
- STATE = MAINMENU;
- }
- }
- if( JUMP.get_ticks() < 1000 / 60 )
- {
- SDL_Delay( ( 1000 / 60 ) - JUMP.get_ticks() );
- }
- }
- if (PlaySound == true) Mix_PlayChannel( -1, PlayerDeath, 0 );
- std::stringstream WhatKilledMe;
- WhatKilledMe.str("");
- WhatKilledMe << "You were killed by ";
- switch(CauseOfDeath)
- {
- case 1:
- WhatKilledMe << "a space invader!";
- break;
- case 2:
- WhatKilledMe << "a space worm!";
- break;
- case 3:
- WhatKilledMe << "the lock on laser!";
- break;
- case 4:
- WhatKilledMe << "another ship!";
- break;
- }
- Message = TTF_RenderText_Solid(Font,WhatKilledMe.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, ((ScreenHeight - Message->h) / 2) - 30, Message, Screen);
- SortScores();
- std::stringstream Wat;
- Wat.str("");
- Wat << "Your score was " << PlayerScore << "!";
- Message = TTF_RenderText_Solid(Font,Wat.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, (ScreenHeight - Message->h) / 2, Message, Screen);
- SDL_FreeSurface(Message);
- Message = TTF_RenderText_Solid(Font,Beat.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, ((ScreenHeight - Message->h) / 2) + 30, Message, Screen);
- SDL_Flip(Screen);
- if (ScoreBeaten > 0)
- {
- SDL_Delay(3000);
- GetNameInput();
- if (CasualMode == false)
- {
- switch (ScoreBeaten)
- {
- case 1:
- Name3 = Name2;
- Name2 = Name1;
- Name1 = NameOutputStream.str();
- break;
- case 2:
- Name3 = Name2;
- Name2 = NameOutputStream.str();
- break;
- case 3:
- Name3 = NameOutputStream.str();
- break;
- }
- }
- else
- {
- switch (ScoreBeaten)
- {
- case 4:
- CName3 = CName2;
- CName2 = CName1;
- CName1 = NameOutputStream.str();
- break;
- case 5:
- CName3 = CName2;
- CName2 = NameOutputStream.str();
- break;
- case 6:
- CName3 = NameOutputStream.str();
- break;
- }
- }
- }
- std::ofstream SaveScores;
- SaveScores.open("TopLel.dll");
- SaveScores << Name1 << std::endl << Name2 << std::endl << Name3 << std::endl << CName1 << std::endl << CName2 << std::endl << CName3
- << std::endl << HScore1 << std::endl << HScore2 << std::endl << HScore3 << std::endl << CHScore1 << std::endl << CHScore2
- << std::endl << CHScore3;
- SaveScores.close();
- SDL_Flip(Screen);
- while (lrn2program == false)
- {
- while (SDL_PollEvent(&event))
- {
- if (event.type == SDL_QUIT) Quit = true;
- if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) lrn2program = true;
- }
- }
- STATE = MAINMENU;
- Lazy = true;
- }
- }
- void Player::RefreshPosition()
- {
- x = x + xVel;
- y = y + yVel;
- }
- void CheckEnemyProjectileCollisions()
- {
- if (EnemyProjectiles.size() >= 2)
- {
- for (int P = 0; P < EnemyProjectiles.size(); P+=5)
- {
- int PLeft = EnemyProjectiles.at(P);
- int PTop = EnemyProjectiles.at(P + 1);
- int PBottom = EnemyProjectiles.at(P + 1) + 10;
- if (PLeft >= Ship.x && PLeft <= Ship.x + 39)
- {
- if (PTop >= Ship.y && PTop <= Ship.y + 20)
- {
- if (EnemyProjectiles.at(P + 2) < 2) CauseOfDeath = 2;
- else CauseOfDeath = 4;
- Ship.Die();
- }
- else if (PBottom >= Ship.y && PBottom <= Ship.y + 20)
- {
- if (EnemyProjectiles.at(P + 2) < 2) CauseOfDeath = 2;
- else CauseOfDeath = 4;
- Ship.Die();
- }
- }
- }
- }
- }
- void UpdateLocks()
- {
- if (Locks.size() >= 4)
- {
- for (int l = 0; l <= Locks.size() - 4; l += 4)
- {
- if (Locks.at(l + 3) == 0) continue;
- Locks.at(l + 2)++;
- if (Locks.at(l + 2) > 60)
- {
- Locks.at(l + 3) = 0;
- int CLeft = Locks.at(l);
- int CRight = CLeft + 50;
- int CTop = Locks.at(l + 1);
- int CBottom = CTop + 50;
- int PLeft = Ship.x;
- int PRight = PLeft + Character->w;
- int PTop = Ship.y;
- int PBottom = PTop + 50;
- bool LockOn = false;
- if (PRight >= CLeft && PRight <= CRight)
- {
- if (PTop <= CBottom && PTop >= CTop)
- {
- CauseOfDeath = 3;
- Ship.Die();
- }
- else if (PBottom <= CBottom && PBottom >= CTop)
- {
- CauseOfDeath = 3;
- Ship.Die();
- }
- }
- else if (PLeft >= CLeft && PLeft <= CRight)
- {
- if (PTop <= CBottom && PTop >= CTop)
- {
- CauseOfDeath = 3;
- Ship.Die();
- }
- if (PBottom <= CBottom && PBottom >= CTop)
- {
- CauseOfDeath = 3;
- Ship.Die();
- }
- }
- }
- if (Locks.at(l + 2) < 15) ApplySurface(Locks.at(l), Locks.at(l + 1), LockSprites, Screen, &LockFrames[0]);
- else if (Locks.at(l + 2) < 30) ApplySurface(Locks.at(l), Locks.at(l + 1), LockSprites, Screen, &LockFrames[1]);
- else if (Locks.at(l + 2) < 45) ApplySurface(Locks.at(l), Locks.at(l + 1), LockSprites, Screen, &LockFrames[2]);
- else ApplySurface(Locks.at(l), Locks.at(l + 1), LockSprites, Screen, &LockFrames[3]);
- }
- }
- }
- void WeaponsMenuFunction()
- {
- std::stringstream WMenu;
- for (int y = -200; y <= 0; y += 5)
- {
- ApplySurface(Backgroundx,0,Background,Screen);
- RenderEnemies();
- RenderProjectiles();
- if (Ship.xVel + Ship.yVel != 0) ApplySurface(Ship.x - 14, Ship.y, ShipMoving2,Screen);
- else ApplySurface(Ship.x - 14, Ship.y, ShipIdle,Screen);
- ApplySurface(0,0,Score2,Screen);
- ApplySurface(0,0,AlphaGray,Screen);
- ApplySurface((ScreenWidth - 350) / 2,y, WeaponsMenu, Screen, &WMenuClips[CurrentSelection]);
- WMenu.str("");
- WMenu << Lasers;
- Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
- ApplySurface(((ScreenWidth - 350) / 2) + 260, y + 47, Message, Screen);
- WMenu.str("");
- WMenu << Missiles;
- Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
- ApplySurface(((ScreenWidth - 350) / 2) + 260, y + 84, Message, Screen);
- if (EnemyHit == false) Message = TTF_RenderText_Solid(Font,"0",TextColour);
- else
- {
- THESCORE = std::to_string(PlayerScore);
- Message = TTF_RenderText_Solid(Font,THESCORE.c_str(),TextColour);
- }
- ApplySurface(25,355, Message, Screen);
- Selection.str("");
- if (CurrentSelection == 0) Selection << "BFG " << Lasers;
- else if (CurrentSelection == 1) Selection << "RPG " << Missiles;
- else if (CurrentSelection == 2) Selection << "LZR";
- Message = TTF_RenderText_Solid(Font,Selection.str().c_str(),TextColour);
- ApplySurface(ScreenWidth - 10 - (Message->w + 10),355,Message,Screen);
- SDL_Flip(Screen);
- SDL_Delay(10);
- }
- bool AWAY = false;
- while(AWAY == false)
- {
- SDL_Flip(Screen);
- if (CurrentSelection < 0) CurrentSelection = 2;
- if (CurrentSelection > 2) CurrentSelection = 0;
- ApplySurface(Backgroundx,0,Background,Screen);
- RenderEnemies();
- RenderProjectiles();
- if (Ship.xVel + Ship.yVel != 0) ApplySurface(Ship.x - 14, Ship.y, ShipMoving2,Screen);
- else ApplySurface(Ship.x - 14, Ship.y, ShipIdle,Screen);
- ApplySurface(0,0,Score2,Screen);
- ApplySurface(0,0,AlphaGray,Screen);
- ApplySurface((ScreenWidth - 350) / 2,0, WeaponsMenu, Screen, &WMenuClips[CurrentSelection]);
- WMenu.str("");
- WMenu << Lasers;
- Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
- ApplySurface(((ScreenWidth - 350) / 2) + 260, 47, Message, Screen);
- WMenu.str("");
- WMenu << Missiles;
- Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
- ApplySurface(((ScreenWidth - 350) / 2) + 260, 84, Message, Screen);
- if (EnemyHit == false) Message = TTF_RenderText_Solid(Font,"0",TextColour);
- else
- {
- THESCORE = std::to_string(PlayerScore);
- Message = TTF_RenderText_Solid(Font,THESCORE.c_str(),TextColour);
- }
- ApplySurface(25,355, Message, Screen);
- Selection.str("");
- if (CurrentSelection == 0) Selection << "BFG " << Lasers;
- else if (CurrentSelection == 1) Selection << "RPG " << Missiles;
- else if (CurrentSelection == 2) Selection << "LZR";
- Message = TTF_RenderText_Solid(Font,Selection.str().c_str(),TextColour);
- ApplySurface(ScreenWidth - 10 - (Message->w + 10),355,Message,Screen);
- while(SDL_PollEvent(&event))
- {
- if(event.type == SDL_QUIT)
- {
- Quit = true;
- STATE = MAINMENU;
- return;
- }
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym == SDLK_UP) CurrentSelection--;
- if (event.key.keysym.sym == SDLK_DOWN) CurrentSelection++;
- if (event.key.keysym.sym == SDLK_SPACE) AWAY = true;
- }
- }
- }
- for (int y = 0; y >= -200; y -= 5)
- {
- ApplySurface(Backgroundx,0,Background,Screen);
- RenderEnemies();
- RenderProjectiles();
- if (Ship.xVel + Ship.yVel != 0) ApplySurface(Ship.x - 14, Ship.y, ShipMoving2,Screen);
- else ApplySurface(Ship.x - 14, Ship.y, ShipIdle,Screen);
- ApplySurface(0,0,Score2,Screen);
- ApplySurface(0,0,AlphaGray,Screen);
- ApplySurface((ScreenWidth - 350) / 2,y, WeaponsMenu, Screen, &WMenuClips[CurrentSelection]);
- WMenu.str("");
- WMenu << Lasers;
- Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
- ApplySurface(((ScreenWidth - 350) / 2) + 260, y + 47, Message, Screen);
- WMenu.str("");
- WMenu << Missiles;
- Message = TTF_RenderText_Solid(Font,WMenu.str().c_str(),TextColour);
- ApplySurface(((ScreenWidth - 350) / 2) + 260, y + 84, Message, Screen);
- if (EnemyHit == false) Message = TTF_RenderText_Solid(Font,"0",TextColour);
- else
- {
- THESCORE = std::to_string(PlayerScore);
- Message = TTF_RenderText_Solid(Font,THESCORE.c_str(),TextColour);
- }
- ApplySurface(25,355, Message, Screen);
- Selection.str("");
- if (CurrentSelection == 0) Selection << "BFG " << Lasers;
- else if (CurrentSelection == 1) Selection << "RPG " << Missiles;
- else if (CurrentSelection == 2) Selection << "LZR";
- Message = TTF_RenderText_Solid(Font,Selection.str().c_str(),TextColour);
- ApplySurface(ScreenWidth - 10 - (Message->w + 10),355,Message,Screen);
- SDL_Flip(Screen);
- SDL_Delay(10);
- }
- }
- void CheckProjectileCollisions()
- {
- if (Projectiles.size() >= 2 && Enemies.size() > 2) // If there are enemies and projectiles
- {
- for (int i = 0; i < Projectiles.size(); i += 5) //Nesting to the extreme m8
- {
- if (Projectiles.at(i + 3) == 1) //If projectile is visible
- {
- int PRight = Projectiles.at(i) + 30;
- int PTop = Projectiles.at(i + 1);
- int PBottom = Projectiles.at(i + 1) + 10;
- for (int e = 0; e < Enemies.size(); e +=6)
- {
- if (Enemies.at(e + 5) == 0) continue; // If the enemy is not visible
- if (Enemies.at(e + 4) == 3) continue; // If the enemy is a fukken crosshair
- if (Enemies.at(e + 4) >= 5) continue; // If the enemy is a fukken powerup or whatever
- int ELeft = Enemies.at(e);
- int ERight = Enemies.at(e) + 50;
- int ETop = Enemies.at(e + 1);
- int EBottom;
- if (Enemies.at(e + 4) != 4) EBottom = Enemies.at(e + 1) + 50; //If its not a rival
- else EBottom = Enemies.at(e + 1) + 20;
- if (PRight >= ELeft && PRight <= ERight)
- {
- if (PBottom >= ETop && PBottom<= EBottom)
- {
- Projectiles.at(i + 3) = 0;
- Enemies.at(e + 5) = 0;
- EnemyHit = true;
- if (Enemies.at(e + 4) == 1) // If enemy is a space invaders alien
- {
- PlayerScore += 100;
- PlayDeathSound();
- if(GenerateChance(2) == true) // Laser Powerup
- {
- Enemies.push_back(Enemies.at(e) + 12);
- Enemies.push_back(Enemies.at(e + 1) + 12);
- Enemies.push_back(1);
- Enemies.push_back(0);
- Enemies.push_back(5);
- Enemies.push_back(1);
- }
- }
- if (Enemies.at(e + 4) == 4)
- {
- Enemies.push_back(Enemies.at(e) + 12);
- Enemies.push_back(Enemies.at(e + 1) + 12);
- Enemies.push_back(1);
- Enemies.push_back(0);
- Enemies.push_back(7);
- Enemies.push_back(1);
- Rival = false;
- }
- if (Enemies.at(e + 4) == 2) // If enemy is a worm
- {
- PlayerScore += 150;
- PlayDeathSound();
- if(GenerateChance(50) == true) // Missile Powerup
- {
- PANIC++;
- Enemies.push_back(Enemies.at(e) + 12);
- Enemies.push_back(Enemies.at(e + 1) + 12);
- Enemies.push_back(1);
- Enemies.push_back(0);
- Enemies.push_back(6);
- Enemies.push_back(1);
- }
- }
- }
- else if (PTop >= ETop && PTop <= EBottom)
- {
- Projectiles.at(i + 3) = 0;
- Enemies.at(e + 5) = 0;
- EnemyHit = true;
- if (Enemies.at(e + 4) == 1) // If enemy is a space invaders alien
- {
- PlayerScore += 100;
- PlayDeathSound;
- }
- if (Enemies.at(e + 4) == 2) // If enemy is a worm
- {
- PlayerScore += 150;
- PlayDeathSound();
- }
- }
- }
- }
- }
- }
- }
- } //You know you have good code when this happens
- int CrosshairCollisionsDetected = 0;
- void CheckPlayerCollisions()
- {
- bool CollisionDetected = false;
- if (Enemies.size() > 4)
- {
- for (int e = 0; e < Enemies.size(); e += 6)
- {
- if (Enemies.at(e + 5) == 0) continue;
- CollisionDetected = false;
- int ELeft = Enemies.at(e);
- int ERight = Enemies.at(e) + 50;
- int ETop = Enemies.at(e + 1);
- int EBottom = Enemies.at(e + 1) + 50;
- int PRight = Ship.x + 39;
- int PTop = Ship.y;
- int PBottom = Ship.y + 20;
- if (PRight >= ELeft && PRight <= ERight)
- {
- if (PTop <= EBottom && PTop >= ETop) CollisionDetected = true;
- if (PBottom <= EBottom && PBottom >= ETop) CollisionDetected = true;
- }
- if (CollisionDetected == true)
- {
- if (Enemies.at(e + 4) == 1 )
- {
- CauseOfDeath = 1;
- Ship.Die();
- }
- else if (Enemies.at(e + 4) == 2)
- {
- CauseOfDeath = 2;
- Ship.Die();
- }
- else if (Enemies.at(e + 4) == 3)// If its a crosshair
- {
- Locks.push_back(Enemies.at(e) - 10);
- Locks.push_back(Enemies.at(e + 1));
- Locks.push_back(0);
- Locks.push_back(1);
- Enemies.at(e + 5) = 0;
- }
- else if (Enemies.at(e + 4) == 4)
- {
- Ship.Die();
- CauseOfDeath = 4;
- }
- else if (Enemies.at(e + 4) == 5)
- {
- Lasers++; //Laser ammo
- Enemies.at(e + 5) = 0;
- }
- else if (Enemies.at(e + 4) == 6)
- {
- Missiles+=3; //Missile ammo
- Enemies.at(e + 5) = 0;
- }
- else if (Enemies.at(e + 4) == 7)
- {
- Invincible = true;
- InvincibilityTime = 600;
- Enemies.at(e + 5) = 0;
- }
- }
- }
- }
- } //Agen lmoa
- void DoMissiles() //Got lazy
- {
- if(MissileVector.size() == 0) return;
- std::stringstream MissileDebug;
- bool FukkenShit = false;
- for (int i = 0; i < MissileVector.size() - 2; i += 6)
- {
- if (MissileVector.at(i + 5) == 0) continue;
- if (MissileVector.at(i + 2) == 0)
- {
- MissileVector.at(i + 1) += 3;
- MissileVector.at(i + 4) ++;
- if (MissileVector.at(i + 4) > 20)
- {
- if (PlaySound == true) Mix_PlayChannel( -1, Rocket, 0 );
- StartShake(50,10);
- MissileVector.at(i + 2) = 1;
- MissileVector.at(i + 4) = 0;
- }
- }
- else
- {
- MissileVector.at(i) += 10;
- MissileVector.at(i + 4) ++;
- if (MissileVector.at(i + 4) > 20) MissileVector.at(i + 3)++;
- if (MissileVector.at(i + 3) > 1) MissileVector.at(i + 3) = 0;
- int PRight = MissileVector.at(i) + 38;
- int PTop = MissileVector.at(i + 1);
- int PBottom = MissileVector.at(i + 1) + 10;
- for (int e = 0; e < Enemies.size(); e +=6)
- {
- if (Enemies.at(e + 5) == 0) continue; // If the enemy is not visible
- if (Enemies.at(e + 4) == 3) continue; // If the enemy is a fukken crosshair
- if (Enemies.at(e + 4) >= 5) continue; // If the enemy is a fukken powerup or whatever
- if (Enemies.at(e) < 0) continue;
- int ELeft = Enemies.at(e);
- int ERight = Enemies.at(e) + 50;
- int ETop = Enemies.at(e + 1);
- int EBottom;
- if (Enemies.at(e + 4) != 4) EBottom = Enemies.at(e + 1) + 50; //If its not a rival
- else EBottom = Enemies.at(e + 1) + 20;
- if (PRight >= ELeft && PRight <= ERight)
- {
- if (PBottom >= ETop && PBottom<= EBottom)
- {
- StartFlash();
- for (int et = 0; et < Enemies.size(); et +=6)
- {
- if (Enemies.at(et + 5) == 0) continue;
- if (Enemies.at(et) < 0) continue;
- int MaxXRange = MissileVector.at(i) + 100;
- int MinXRange = MissileVector.at(i) - 100;
- int MaxYRange = MissileVector.at(i + 1) + 100;
- int MinYRange = MissileVector.at(i + 1) - 100;
- int EtLeft = Enemies.at(et);
- int EtTop = Enemies.at(et + 1);
- if (EtTop == ETop) continue;
- bool a = false;
- bool b = false;
- bool c = false;
- bool d = false;
- if (EtLeft < MaxXRange) a = true;
- if (EtLeft > MinXRange) b = true;
- if (EtTop < MaxYRange) c = true;
- if (EtLeft > MinXRange) d = true;
- if (a == true && b == true && c == true && d == true)
- {
- Enemies.at(et + 5) = 0;
- switch(Enemies.at(et + 4))
- {
- case 1: PlayerScore += 100;
- break;
- case 2: PlayerScore += 150;
- break;
- case 4: PlayerScore += 250;
- break;
- }
- }
- }
- MissileVector.at(i + 5) = 0;
- Enemies.at(e + 5) = 0;
- }
- else if (PTop >= ETop && PTop <= EBottom)
- {
- StartFlash();
- for (int et = 0; et < Enemies.size(); et +=6)
- {
- if (Enemies.at(et + 5) == 0) continue;
- if (Enemies.at(et) < 0) continue;
- int MaxXRange = MissileVector.at(i) + 100;
- int MinXRange = MissileVector.at(i) - 100;
- int MaxYRange = MissileVector.at(i + 1) + 100;
- int MinYRange = MissileVector.at(i + 1) - 100;
- int EtLeft = Enemies.at(et);
- int EtTop = Enemies.at(et + 1);
- if (EtTop == ETop) continue;
- bool a = false;
- bool b = false;
- bool c = false;
- bool d = false;
- if (EtLeft < MaxXRange) a = true;
- if (EtLeft > MinXRange) b = true;
- if (EtTop < MaxYRange) c = true;
- if (EtLeft > MinXRange) d = true;
- if (a == true && b == true && c == true && d == true)
- {
- Enemies.at(et + 5) = 0;
- switch(Enemies.at(et + 4))
- {
- case 1: PlayerScore += 100;
- break;
- case 2: PlayerScore += 150;
- break;
- case 4: PlayerScore += 250;
- break;
- }
- }
- }
- MissileVector.at(i + 5) = 0;
- Enemies.at(e + 5) = 0;
- }
- }
- }
- }
- ApplySurface(MissileVector.at(i),MissileVector.at(i + 1),MissileSprite,Screen,&MissileClips[MissileVector.at(i + 3)]);
- }
- }
- int Intro()
- {
- int BGI = 0;
- 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};
- Timer IntroTiming;
- SDL_Surface *Intro1, *Intro2, *Intro3, *Intro4, *Intro5 = NULL;
- Intro1 = LoadImage("Resources/Images/Intro1.png");
- Intro2 = LoadImage("Resources/Images/Intro2.png");
- Intro3 = LoadImage("Resources/Images/Intro3.png");
- Intro4 = LoadImage("Resources/Images/Intro4.png");
- Intro5 = LoadImage("Resources/Images/Intro5.png");
- if (Intro1 == NULL || Intro2 == NULL || Intro3 == NULL || Intro4 == NULL || Intro5 == NULL) return -1;
- for (int Frame = 1; Frame <= 27; Frame++)
- {
- IntroTiming.start();
- while (SDL_PollEvent(&event))
- {
- if (event.type == SDL_QUIT)
- {
- Quit = true;
- return 1;
- }
- if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN)
- {
- STATE = MAINMENU;
- return 1;
- }
- }
- if (Frame == 6 || Frame == 11 || Frame == 16 || Frame == 21) BGI = 0;
- if (Frame < 6) ApplySurface(BGI,0,Intro1,Screen);
- else if (Frame < 11) ApplySurface(BGI,0,Intro2,Screen);
- else if (Frame < 16) ApplySurface(BGI,0,Intro3,Screen);
- else if (Frame < 21) ApplySurface(BGI,0,Intro4,Screen);
- else ApplySurface(BGI,0,Intro5,Screen);
- SDL_Flip(Screen);
- BGI -= 639;
- SDL_Delay(Timings[Frame] - IntroTiming.get_ticks());
- }
- SDL_FreeSurface(Intro1);
- SDL_FreeSurface(Intro2);
- SDL_FreeSurface(Intro3);
- SDL_FreeSurface(Intro4);
- SDL_FreeSurface(Intro5);
- STATE = MAINMENU;
- return 0;
- }
- int Menu()
- {
- double Rotation = 0;
- double Zoom = 1.8;
- bool RPositiveIncrement = true;
- bool ZPositiveIncrement = true;
- double MBackgroundx = 0;
- while (Quit == false && STATE == MAINMENU)
- {
- MBackgroundx -=0.25;
- if (MBackgroundx <= -2000 + 640) MBackgroundx = 0;
- ApplySurface(MBackgroundx,0,MenuBackground,Screen);
- if (MenuSelection > 3) MenuSelection = 1;
- if (MenuSelection < 1) MenuSelection = 3;
- if (Rotation > 3)
- {
- RPositiveIncrement = false;
- Rotation = 3;
- }
- else if (Rotation < - 3)
- {
- RPositiveIncrement = true;
- Rotation = -3;
- }
- if (RPositiveIncrement == true) Rotation += 0.005;
- else Rotation -= 0.005;
- if (Zoom > 2)
- {
- ZPositiveIncrement = false;
- Zoom = 2;
- }
- else if (Zoom < 1.75)
- {
- ZPositiveIncrement = true;
- Zoom = 1.75;
- }
- if (ZPositiveIncrement == true) Zoom += 0.0001;
- else Zoom -= 0.0001;
- SDL_FreeSurface(TitleTextR);
- TitleTextR = rotozoomSurface (TitleText, Rotation, Zoom, 0);
- ApplySurface((ScreenWidth - TitleTextR->w) / 2, ((ScreenHeight - TitleTextR->h) / 2) - 40, TitleTextR, Screen);
- if (MusicPlaying == false && PlayMusic == true)
- {
- Mix_PlayMusic(MenuMusic,-1);
- MusicPlaying = true;
- }
- Message = TTF_RenderText_Solid(Font,"New game",TextColour);
- ApplySurface(65,300, Message, Screen);
- Message2 = TTF_RenderText_Solid(Font,"High Scores",TextColour);
- ApplySurface(Message->w + 115, 300, Message2, Screen);
- Message3 = TTF_RenderText_Solid(Font,"Options",TextColour);
- ApplySurface(Message->w + Message2->w + 165, 300, Message3, Screen);
- switch(MenuSelection)
- {
- case 1:
- ApplySurface(20, 300, Character, Screen, &ShipFrames[0]);
- break;
- case 2:
- ApplySurface(Message->w + 70, 300, Character, Screen,&ShipFrames[0]);
- break;
- case 3:
- ApplySurface(Message->w + Message2->w + 120, 300, Character, Screen,&ShipFrames[0]);
- break;
- }
- SDL_Flip(Screen);
- while (SDL_PollEvent(&event))
- {
- if (event.type == SDL_QUIT) Quit = true;
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym == SDLK_LEFT) --MenuSelection;
- if (event.key.keysym.sym == SDLK_RIGHT) ++MenuSelection;
- if (event.key.keysym.sym == SDLK_RETURN)
- {
- if (MenuSelection == 1)
- {
- MusicPlaying = false;
- ResetGame();
- int x = 20;
- ApplySurface(0,0,BlackScreen,Screen);
- for (int Why = 0; Why < 140; Why++)
- {
- MBackgroundx -= 3;
- if (MBackgroundx <= -2000 + 640) MBackgroundx = 0;
- ApplySurface(MBackgroundx,0,MenuBackground,Screen);
- x = x + 5;
- ApplySurface(x, 300, Character, Screen, &ShipFrames[0]);
- SDL_Flip(Screen);
- SDL_Delay(10);
- }
- Mix_HaltMusic();
- }
- return MenuSelection;
- }
- }
- }
- }
- }
- void Scores()
- {
- bool Normal = true;
- std::stringstream ImNotSure;
- while (Quit == false && STATE == SCORES)
- {
- ApplySurface(0,0,BlackScreen,Screen);
- if (Normal == true) Message = TTF_RenderText_Solid(Font,"< Normal Mode >",TextColour);
- else Message = TTF_RenderText_Solid(Font,"< Casual Mode >",TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 15, Message, Screen);
- if (Normal == true)
- {
- Message = TTF_RenderText_Solid(Font,Name1.c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 90, Message, Screen);
- ImNotSure << "With " << HScore1;
- Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 115, Message, Screen);
- ImNotSure.str("");
- Message = TTF_RenderText_Solid(Font,Name2.c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 150, Message, Screen);
- ImNotSure << "With " << HScore2;
- Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 175, Message, Screen);
- ImNotSure.str("");
- Message = TTF_RenderText_Solid(Font,Name3.c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 210, Message, Screen);
- ImNotSure << "With " << HScore3;
- Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 235, Message, Screen);
- ImNotSure.str("");
- }
- else
- {
- Message = TTF_RenderText_Solid(Font,CName1.c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 90, Message, Screen);
- ImNotSure << "With " << CHScore1;
- Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 115, Message, Screen);
- ImNotSure.str("");
- Message = TTF_RenderText_Solid(Font,CName2.c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 150, Message, Screen);
- ImNotSure << "With " << CHScore2;
- Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 175, Message, Screen);
- ImNotSure.str("");
- Message = TTF_RenderText_Solid(Font,CName3.c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 210, Message, Screen);
- ImNotSure << "With " << CHScore3;
- Message = TTF_RenderText_Solid(Font,ImNotSure.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, 235, Message, Screen);
- ImNotSure.str("");
- }
- SDL_Flip(Screen);
- while (SDL_PollEvent(&event))
- {
- if (event.type == SDL_QUIT) Quit = true;
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym == SDLK_ESCAPE) STATE = MAINMENU;
- if (event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_RIGHT) Normal = !Normal;
- }
- }
- }
- }
- void Game()
- {
- srand (time (NULL));
- ResetGame();
- Timer FPS;
- Timer Shot;
- Timer EnemyPause;
- Timer EnemyNotPause;
- PlayerScore = 0;
- std::stringstream DebugStream;
- bool CreateEnemies = true;
- int Random, Random4;
- int Random2,Random3;
- if (PlayMusic == true) Mix_PlayMusic(GameMusic,-1);
- while (Quit == false && STATE == GAME)
- {
- FPS.start();
- Backgroundx -=0.1;
- if (Backgroundx <= -2000 + 640) Backgroundx = 0;
- if (Shake == true)
- {
- xShakeOffset = RandomNumber(Magnitude , ((Magnitude * -1) / 2));
- yShakeOffset = RandomNumber(Magnitude , ((Magnitude * -1) / 2));
- Time--;
- if (Time == 0)
- {
- Shake = false;
- xShakeOffset = 0;
- yShakeOffset = 0;
- }
- }
- Uint8 *Keystates = SDL_GetKeyState( NULL );
- int Duration = RandomNumber(15000,9000);
- int Break = RandomNumber(1750,0);
- int Time = SDL_GetTicks();
- Random4 = RandomNumber(25,1);
- if (Invincible == true)
- {
- InvincibilityTime --;
- if (InvincibilityTime == 0) Invincible = false;
- std::stringstream Idek;
- Idek.str("");
- Idek << InvincibilityTime;
- Message = TTF_RenderText_Solid(Font,Idek.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w)/2, 20, Message, Screen);
- }
- if (CasualMode == false)
- {
- if (Proc1 < 600) Proc1+=1;
- Random2 = RandomNumber(25000,1);
- Random3 = RandomNumber(4000,1);
- if (Random2 <= Proc1 && CreateEnemies == true)
- {
- GenerateEnemy();
- }
- }
- else
- {
- if (Proc2 < 450) Proc2+=0.5;
- Random2 = RandomNumber(30000,1);
- Random3 = RandomNumber(3500,1);
- if (Random2 <= Proc2 && CreateEnemies == true)
- {
- GenerateEnemy();
- }
- }
- if (Random3 <= 50 && CreateEnemies == true && EnemyHit == true && EnemyNotPause.get_ticks() > 5000)
- {
- CreateEnemies = false;
- EnemyPause.start();
- }
- if (CreateEnemies == false && EnemyPause.get_ticks() > 5000)
- {
- Enemies.erase(Enemies.begin(),Enemies.end());
- CreateEnemies = true;
- EnemyNotPause.start();
- }
- if (Ship.x > ScreenWidth - (Character->w ))
- {
- Ship.x = ScreenWidth - (Character->w );
- }
- if (Ship.x < 0)
- {
- Ship.x = 0;
- }
- if (Ship.y > ScreenHeight - Character->h)
- {
- Ship.y = ScreenHeight - Character->h;
- }
- if (Ship.y < 0)
- {
- Ship.y = 0;
- }
- if (Start == false) Ship.x += 10;
- if (Start == false && Ship.x > 100)
- {
- Start = true;
- }
- if (Keystates[SDLK_UP])
- {
- if (Ship.yVel - Acceleration < -10) Ship.yVel = -10;
- else Ship.yVel -= Acceleration;
- }
- if (Keystates[SDLK_DOWN])
- {
- if (Ship.yVel + Acceleration > 10) Ship.yVel = 10;
- else Ship.yVel += Acceleration;
- }
- if (Keystates[SDLK_RIGHT])
- {
- if (Ship.xVel + Acceleration > 10) Ship.xVel = 10;
- else Ship.xVel += Acceleration;
- }
- if (Keystates[SDLK_LEFT])
- {
- if (Ship.xVel - Acceleration < -10) Ship.xVel = -10;
- else Ship.xVel -= Acceleration;
- }
- if (Keystates[SDLK_UP] != 1 && Keystates[SDLK_DOWN] != 1)
- {
- if (Ship.yVel < 0)
- {
- if (Ship.yVel + 0.5 > 0) Ship.yVel = 0;
- else Ship.yVel += 0.5;
- }
- if (Ship.yVel > 0)
- {
- if (Ship.yVel - 0.5 < 0) Ship.yVel = 0;
- else Ship.yVel -= 0.5;
- }
- }
- if (Keystates[SDLK_LEFT] != 1 && Keystates[SDLK_RIGHT] != 1)
- {
- if (Ship.xVel < 0)
- {
- if (Ship.xVel + 0.5 > 0) Ship.xVel = 0;
- else Ship.xVel += 0.5;
- }
- if (Ship.xVel > 0)
- {
- if (Ship.xVel - 0.5 < 0) Ship.xVel = 0;
- else Ship.xVel -= 0.5;
- }
- }
- Ship.RefreshPosition();
- ApplySurface(0,0,BlackScreen,Screen);
- ApplySurface(Backgroundx,0,Background,Screen);
- Ship.RenderShip();
- UpdateProjectiles();
- RenderProjectiles(); //scown nwocs
- UpdateEnemies();
- RenderEnemies();
- DoMissiles();
- CheckProjectileCollisions();
- CheckPlayerCollisions();
- CheckEnemyProjectileCollisions();
- UpdateLocks();
- if (Invincible == true)
- {
- std::stringstream Idek;
- Idek.str("");
- Idek << InvincibilityTime / 10;
- Message = TTF_RenderText_Solid(Font,Idek.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w)/2, 40, Message, Screen);
- }
- if (LaserFiring == true)
- {
- LaserTime++;
- if (LaserTime >= 60)
- {
- if (Pushed == false)
- {
- Ship.xVel = - 10;
- StartShake(60,40);
- Pushed = true;
- }
- ApplySurface(Ship.x + (Character->w / 2), Ship.y - (Character->h / 2), MegaLaser, Screen);
- if (Enemies.size() > 1)
- {
- for(int e = 0; e < Enemies.size() - 3; e+= 6) //Checking Enemies
- {
- if(Enemies.at(e + 4) == 3) continue; //If its a crosshair
- if(Enemies.at(e + 5) == 0) continue;
- if(Enemies.at(e + 1) < Ship.y + 45 && Enemies.at(e + 1) > Ship.y - 45)
- {
- Enemies.at(e + 5) = 0;
- switch(Enemies.at(e + 4))
- {
- case 1: PlayerScore += 100;
- break;
- case 2: PlayerScore += 150;
- break;
- case 4: PlayerScore += 250;
- break;
- }
- }
- }
- }
- if (EnemyProjectiles.size() > 1)
- {
- for(int e = 0; e < EnemyProjectiles.size() - 3; e+= 5) //Checking Projectiles
- {
- if(EnemyProjectiles.at(e + 1) < Ship.y + 45 && EnemyProjectiles.at(e + 1) > Ship.y - 45) EnemyProjectiles.at(e + 3) = 0;
- }
- }
- if (LaserTime > 90)
- {
- LaserFiring = false;
- LaserTime = 0;
- Pushed = false;
- }
- }
- }
- ApplySurface(0, 0, ScoreBackground, Screen);
- if (EnemyHit == false) Message = TTF_RenderText_Solid(Font,"0",TextColour);
- else
- {
- THESCORE = std::to_string(PlayerScore);
- Message = TTF_RenderText_Solid(Font,THESCORE.c_str(),TextColour);
- }
- ApplySurface(25,355, Message, Screen);
- Selection.str("");
- if (CurrentSelection == 0) Selection << "BFG " << Lasers;
- else if (CurrentSelection == 1) Selection << "RPG " << Missiles;
- else if (CurrentSelection == 2) Selection << "LZR";
- Message = TTF_RenderText_Solid(Font,Selection.str().c_str(),TextColour);
- ApplySurface(ScreenWidth - 10 - (Message->w + 10),355,Message,Screen);
- if (Flash == true)
- {
- FlashAlpha -= 5;
- SDL_SetAlpha(WhiteFlash, SDL_SRCALPHA, FlashAlpha);
- ApplySurface(0,0,WhiteFlash,Screen);
- if (FlashAlpha < 0) Flash = false;
- }
- if (DebugBool == true)
- {
- DebugStream.str("");
- DebugStream << "Ship x: " << Ship.x << " Ship y: " << Ship.y << " LaserAmmos generated: " << PANIC;
- Message = TTF_RenderText_Solid(SmallFont,DebugStream.str().c_str(),TextColour);
- ApplySurface(0,0,Message,Screen);
- }
- SDL_Flip(Screen);
- if (Shot.get_ticks() > 2000)
- {
- Projectiles.erase(Projectiles.begin(),Projectiles.end());
- MissileVector.erase(MissileVector.begin(),MissileVector.end());
- }
- while (SDL_PollEvent(&event))
- {
- if (event.type == SDL_QUIT) Quit = true;
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym == SDLK_x)
- {
- if(CurrentSelection == 0)
- {
- if(Lasers > 0 && LaserFiring == false)
- {
- if (Lasers = 1) CurrentSelection = 2;
- LaserFiring = true;
- Lasers--;
- }
- }
- else if(CurrentSelection == 1)
- {
- if (Missiles > 0)
- {
- if (Missiles == 1) CurrentSelection = 2;
- Missiles--;
- StartShake(10,4);
- if (PlaySound == true) Mix_PlayChannel( -1, ProjectileFired, 0 );
- MissileVector.push_back(Ship.x);
- MissileVector.push_back(Ship.y + 10);
- MissileVector.push_back(0);
- MissileVector.push_back(0);
- MissileVector.push_back(0);
- MissileVector.push_back(1);
- Shot.start();
- }
- }
- else if(CurrentSelection == 2)
- {
- if (PlaySound == true) Mix_PlayChannel( -1, ProjectileFired, 0 );
- StartShake(10,4);
- Projectiles.push_back(Ship.x);
- Projectiles.push_back(Ship.y + 10);
- Projectiles.push_back(0);
- Projectiles.push_back(1);
- Projectiles.push_back(0);
- Shot.start();
- }
- }
- if (event.key.keysym.sym == SDLK_SPACE)
- {
- WeaponsMenuFunction();
- }
- if (event.key.keysym.sym == SDLK_ESCAPE)
- {
- STATE = MAINMENU;
- }
- if (event.key.keysym.sym == SDLK_e)
- {
- StartShake(60,20);
- }
- if (event.key.keysym.sym == SDLK_TAB)
- {
- if (Name1 == "SKY") DebugBool = !DebugBool;
- }
- }
- }
- if( FPS.get_ticks() < 1000 / 60 )
- {
- SDL_Delay( ( 1000 / 60 ) - FPS.get_ticks() );
- }
- }
- }
- void Options()
- {
- MusicPlaying = false;
- while (Quit == false && STATE == OPTIONS)
- {
- if (PlayMusic == false) Mix_HaltMusic();
- if (OptionSelection < 1) OptionSelection = 3;
- if (OptionSelection > 3) OptionSelection = 1;
- ApplySurface(0,0,BlackScreen,Screen);
- std::stringstream Difficulty;
- Difficulty.str("");
- Difficulty << "Difficulty: ";
- if (CasualMode == true) Difficulty << "Casual babby mode";
- else Difficulty << "Normal mode";
- Message = TTF_RenderText_Solid(Font,Difficulty.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message->w) / 2, ((ScreenHeight - Message->h) / 2) - 30, Message, Screen);
- Difficulty.str("");
- Difficulty << "Music: ";
- if (PlayMusic == true) Difficulty << "On";
- else Difficulty << "Off";
- Message2 = TTF_RenderText_Solid(Font,Difficulty.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message2->w) / 2, (ScreenHeight - Message2->h) / 2, Message2, Screen);
- Difficulty.str("");
- Difficulty << "Sounds: ";
- if (PlaySound == true) Difficulty << "On";
- else Difficulty << "Off";
- Message3 = TTF_RenderText_Solid(Font,Difficulty.str().c_str(),TextColour);
- ApplySurface((ScreenWidth - Message3->w) / 2, ((ScreenHeight - Message3->h) / 2) + 30, Message3, Screen);
- switch(OptionSelection)
- {
- case 1:
- ApplySurface((ScreenWidth - Message->w) / 2 - 40, (ScreenHeight - Message->h) / 2 - 30, Character, Screen,&ShipFrames[0]);
- break;
- case 2:
- ApplySurface((ScreenWidth - Message2->w) / 2 - (Message2->w /2) + 30, (ScreenHeight - Message2->h) / 2, Character, Screen,&ShipFrames[0]);
- break;
- case 3:
- ApplySurface((ScreenWidth - Message3->w) / 2 - (Message3->w /2) + 40, (ScreenHeight - Message3->h) / 2 + 30, Character, Screen,&ShipFrames[0]);
- break;
- }
- SDL_Flip(Screen);
- while (SDL_PollEvent(&event))
- {
- if (event.type == SDL_QUIT) Quit = true;
- if (event.type == SDL_KEYDOWN)
- {
- if (event.key.keysym.sym == SDLK_UP) --OptionSelection;
- if (event.key.keysym.sym == SDLK_DOWN) ++OptionSelection;
- if (event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_RIGHT)
- {
- if (OptionSelection == 1) CasualMode = !CasualMode;
- else if (OptionSelection == 2) PlayMusic = !PlayMusic;
- else PlaySound = !PlaySound;
- }
- if (event.key.keysym.sym == SDLK_RETURN) STATE = MAINMENU;
- }
- }
- }
- }
- int main (int argc, char* argv [])
- {
- /*Initiating and loading files*/
- if (Initiate() == false) return -1;
- if (LoadFiles() == false) return -1;
- SetClips();
- while (Quit == false)
- {
- switch (STATE)
- {
- case INTRO:
- if (Intro() == -1) return -1;
- break;
- case MAINMENU:
- if (Lazy == true)
- {
- Lazy = false;
- STATE = GAME;
- }
- else
- {
- GoToState = Menu();
- switch (GoToState)
- {
- case 1: STATE = GAME; break;
- case 2: STATE = SCORES; break;
- case 3: STATE = OPTIONS; break;
- }
- }
- break;
- case SCORES:
- Scores();
- break;
- case GAME:
- Game();
- break;
- case OPTIONS:
- Options();
- break;
- }
- }
- CleanUp();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment