From 9bbcc571cf6af83e4117c2a5a6d6e92020d43cd8 Mon Sep 17 00:00:00 2001 From: Willems Davy Date: Wed, 10 May 2023 22:50:03 +0200 Subject: [PATCH] Use Tabs for identation + fix wrongfull whitespaces --- src/CAudio.cpp | 356 +++---- src/CAudio.h | 66 +- src/CFont.cpp | 268 +++--- src/CFont.h | 18 +- src/CGame.cpp | 1542 ++++++++++++++++--------------- src/CGame.h | 138 +-- src/CImage.cpp | 350 +++---- src/CImage.h | 60 +- src/CInput.cpp | 498 +++++----- src/CInput.h | 32 +- src/CSprites.cpp | 624 ++++++------- src/CSprites.h | 144 +-- src/CTween.cpp | 102 +- src/CTween.h | 12 +- src/Common.cpp | 260 +++--- src/Common.h | 42 +- src/Intro.cpp | 160 ++-- src/RetroTime.cpp | 8 +- src/SubScoreScreen.cpp | 317 ++++--- src/TitleScreen.cpp | 1079 +++++++++++---------- src/Vec2F.cpp | 17 +- src/Vec2F.h | 122 +-- src/games/BlockStackerBlocks.h | 365 ++++---- src/games/CGameBase.cpp | 932 ++++++++++--------- src/games/CGameBase.h | 50 +- src/games/CGameBlockStacker.cpp | 72 +- src/games/CGameBlockStacker.h | 60 +- src/games/CGameBreakOut.cpp | 359 +++---- src/games/CGameBreakOut.h | 84 +- src/games/CGameFastEddy.cpp | 667 ++++++------- src/games/CGameFastEddy.h | 162 ++-- src/games/CGameFrog.cpp | 213 ++--- src/games/CGameFrog.h | 233 +++-- src/games/CGameInvaders.cpp | 394 ++++---- src/games/CGameInvaders.h | 162 ++-- src/games/CGamePang.cpp | 425 ++++----- src/games/CGamePang.h | 126 +-- src/games/CGameRamIt.cpp | 233 +++-- src/games/CGameRamIt.h | 68 +- src/games/CGameSnake.cpp | 263 +++--- src/games/CGameSnake.h | 60 +- src/games/CSpriteObject.h | 42 +- 42 files changed, 5621 insertions(+), 5564 deletions(-) diff --git a/src/CAudio.cpp b/src/CAudio.cpp index cf9b6dd..56cfeb7 100644 --- a/src/CAudio.cpp +++ b/src/CAudio.cpp @@ -9,280 +9,280 @@ using namespace std; CAudio::CAudio(string AssetsPath, bool ADebugInfo) { - DataPath = AssetsPath; - DebugInfo = ADebugInfo; - if (SDL_Init(SDL_INIT_AUDIO) == 0) - { - if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) < 0) - { - GlobalSoundEnabled = false; - SDL_Log("Failed to initialise sound: %s\n", Mix_GetError()); - } - else - { - SDL_Log("Audio Succesfully initialised!\n"); - } - } - else - { - GlobalSoundEnabled = false; - SDL_Log("Failed to initialise sound: %s\n", SDL_GetError()); - } - - for (int i=0; i < SND_Max; i++) - Sounds[i] = nullptr; - - for (int i=0; i < MUS_Max; i++) - Music[i] = nullptr; + DataPath = AssetsPath; + DebugInfo = ADebugInfo; + if (SDL_Init(SDL_INIT_AUDIO) == 0) + { + if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 1024) < 0) + { + GlobalSoundEnabled = false; + SDL_Log("Failed to initialise sound: %s\n", Mix_GetError()); + } + else + { + SDL_Log("Audio Succesfully initialised!\n"); + } + } + else + { + GlobalSoundEnabled = false; + SDL_Log("Failed to initialise sound: %s\n", SDL_GetError()); + } + + for (int i=0; i < SND_Max; i++) + Sounds[i] = nullptr; + + for (int i=0; i < MUS_Max; i++) + Music[i] = nullptr; } CAudio::~CAudio() { - UnloadSounds(); - UnloadMusics(); - if (GlobalSoundEnabled) - Mix_CloseAudio(); + UnloadSounds(); + UnloadMusics(); + if (GlobalSoundEnabled) + Mix_CloseAudio(); } // set the volume of the music -void CAudio::SetVolumeMusic(const int VolumeIn) +void CAudio::SetVolumeMusic(const int VolumeIn) { - if (GlobalSoundEnabled) - { - VolumeMusic = VolumeIn; - Mix_VolumeMusic(VolumeIn); - } + if (GlobalSoundEnabled) + { + VolumeMusic = VolumeIn; + Mix_VolumeMusic(VolumeIn); + } } // set the volume of sound -void CAudio::SetVolumeSound(const int VolumeIn) +void CAudio::SetVolumeSound(const int VolumeIn) { - if (GlobalSoundEnabled) - { - VolumeSound = VolumeIn; - Mix_Volume(-1, VolumeIn); - } + if (GlobalSoundEnabled) + { + VolumeSound = VolumeIn; + Mix_Volume(-1, VolumeIn); + } } // increase the music volume with 4 -void CAudio::IncVolumeMusic() +void CAudio::IncVolumeMusic() { - if (GlobalSoundEnabled) - { - if (VolumeMusic < 128) - { - VolumeMusic += 4; - SetVolumeMusic(VolumeMusic); - } - } + if (GlobalSoundEnabled) + { + if (VolumeMusic < 128) + { + VolumeMusic += 4; + SetVolumeMusic(VolumeMusic); + } + } } // increase the sound volume with 4 -void CAudio::IncVolumeSound() +void CAudio::IncVolumeSound() { - if (GlobalSoundEnabled) - { - if (VolumeSound < 128) - { - VolumeSound += 4; - SetVolumeSound(VolumeSound); - } - } + if (GlobalSoundEnabled) + { + if (VolumeSound < 128) + { + VolumeSound += 4; + SetVolumeSound(VolumeSound); + } + } } // decrease the volume with 4 -void CAudio::DecVolumeMusic() +void CAudio::DecVolumeMusic() { - if (GlobalSoundEnabled) - { - if (VolumeMusic > 0) - { - VolumeMusic -= 4; - SetVolumeMusic(VolumeMusic); - } - } + if (GlobalSoundEnabled) + { + if (VolumeMusic > 0) + { + VolumeMusic -= 4; + SetVolumeMusic(VolumeMusic); + } + } } // decrease the volume with 4 -void CAudio::DecVolumeSound() +void CAudio::DecVolumeSound() { - if (GlobalSoundEnabled) - { - if (VolumeSound > 0) - { - VolumeSound -= 4; - SetVolumeSound(VolumeSound); - } - } + if (GlobalSoundEnabled) + { + if (VolumeSound > 0) + { + VolumeSound -= 4; + SetVolumeSound(VolumeSound); + } + } } void CAudio::StopMusic() { - if(GlobalSoundEnabled) - Mix_HaltMusic(); + if(GlobalSoundEnabled) + Mix_HaltMusic(); } bool CAudio::IsMusicPlaying() { - if(!GlobalSoundEnabled) - return false; + if(!GlobalSoundEnabled) + return false; - return (Mix_PlayingMusic() > 0); + return (Mix_PlayingMusic() > 0); } void CAudio::UnLoadMusic(int MusicdID) { - if ((MusicdID < 0) || (MusicdID > MUS_Max) || !GlobalSoundEnabled) - return; - - if (Music[MusicdID] == nullptr) - return; - - else - { - Mix_FreeMusic(Music[MusicdID]); - Music[MusicdID] = nullptr; - } + if ((MusicdID < 0) || (MusicdID > MUS_Max) || !GlobalSoundEnabled) + return; + + if (Music[MusicdID] == nullptr) + return; + + else + { + Mix_FreeMusic(Music[MusicdID]); + Music[MusicdID] = nullptr; + } } -void CAudio::UnloadMusics() +void CAudio::UnloadMusics() { - StopMusic(); - for (int i=0; i < MUS_Max; i++) - UnLoadMusic(i); + StopMusic(); + for (int i=0; i < MUS_Max; i++) + UnLoadMusic(i); } int CAudio::LoadMusic(string FileName) { - if(!GlobalSoundEnabled) - return -1; - - string FullFileName= DataPath + "music/" + FileName; - for (int i=0; i < MUS_Max; i++) - if(Music[i] == nullptr) - { - Mix_Music* Tmp = Mix_LoadMUS(FullFileName.c_str()); - if(!Tmp) - SDL_Log("Failed Loading Music %s\n", FullFileName.c_str()); - else - { - Music[i] = Tmp; - if(DebugInfo) - SDL_Log("Loaded Music %s\n", FullFileName.c_str()); - return i; - } - - } - return -1; + if(!GlobalSoundEnabled) + return -1; + + string FullFileName= DataPath + "music/" + FileName; + for (int i=0; i < MUS_Max; i++) + if(Music[i] == nullptr) + { + Mix_Music* Tmp = Mix_LoadMUS(FullFileName.c_str()); + if(!Tmp) + SDL_Log("Failed Loading Music %s\n", FullFileName.c_str()); + else + { + Music[i] = Tmp; + if(DebugInfo) + SDL_Log("Loaded Music %s\n", FullFileName.c_str()); + return i; + } + + } + return -1; } int CAudio::MusicSlotsUsed() { - int c = 0; - for (int i=0; i < MUS_Max; i++) - { - if(Music[i] != nullptr) - c++; - } - return c; + int c = 0; + for (int i=0; i < MUS_Max; i++) + { + if(Music[i] != nullptr) + c++; + } + return c; } int CAudio::MusicSlotsMax() { - return MUS_Max; + return MUS_Max; } void CAudio::PlayMusic(int MusicID, int loops) { - if ((MusicID < 0) || (MusicID > MUS_Max) || !GlobalSoundEnabled) - return; + if ((MusicID < 0) || (MusicID > MUS_Max) || !GlobalSoundEnabled) + return; - // Mix_VolumeMusic(VolumeMusic); - Mix_PlayMusic(Music[MusicID], loops); + // Mix_VolumeMusic(VolumeMusic); + Mix_PlayMusic(Music[MusicID], loops); } int CAudio::GetVolumeMusic() { - return VolumeMusic; + return VolumeMusic; } int CAudio::SoundSlotsUsed() { - int c = 0; - for (int i=0; i < SND_Max; i++) - { - if(Sounds[i] != nullptr) - c++; - } - return c; + int c = 0; + for (int i=0; i < SND_Max; i++) + { + if(Sounds[i] != nullptr) + c++; + } + return c; } int CAudio::SoundSlotsMax() { - return SND_Max; + return SND_Max; } void CAudio::PlaySound(int SoundID, int loops) { - if ((SoundID < 0) || (SoundID > SND_Max) || !GlobalSoundEnabled) - return; - //Mix_Volume(-1, VolumeSound); - Mix_PlayChannel(-1, Sounds[SoundID], loops); + if ((SoundID < 0) || (SoundID > SND_Max) || !GlobalSoundEnabled) + return; + //Mix_Volume(-1, VolumeSound); + Mix_PlayChannel(-1, Sounds[SoundID], loops); } int CAudio::LoadSound(string FileName) { - if(!GlobalSoundEnabled) - return -1; - - string FullFileName = DataPath + "sound/" + FileName; - for (int i=0; i < SND_Max; i++) - if(Sounds[i] == nullptr) - { - Mix_Chunk *Tmp = Mix_LoadWAV(FullFileName.c_str()); - if(!Tmp) - SDL_Log("Failed Loading Sound %s\n", FullFileName.c_str()); - else - { - Sounds[i] = Tmp; - if(DebugInfo) - SDL_Log("Loaded Sound %s\n", FullFileName.c_str()); - return i; - } - } - return -1; + if(!GlobalSoundEnabled) + return -1; + + string FullFileName = DataPath + "sound/" + FileName; + for (int i=0; i < SND_Max; i++) + if(Sounds[i] == nullptr) + { + Mix_Chunk *Tmp = Mix_LoadWAV(FullFileName.c_str()); + if(!Tmp) + SDL_Log("Failed Loading Sound %s\n", FullFileName.c_str()); + else + { + Sounds[i] = Tmp; + if(DebugInfo) + SDL_Log("Loaded Sound %s\n", FullFileName.c_str()); + return i; + } + } + return -1; } void CAudio::UnLoadSound(int SoundID) { - if ((SoundID < 0) || (SoundID > SND_Max) || !GlobalSoundEnabled) - return; - - if (Sounds[SoundID] == nullptr) - return; - else - { - Mix_FreeChunk(Sounds[SoundID]); - Sounds[SoundID] = nullptr; - } + if ((SoundID < 0) || (SoundID > SND_Max) || !GlobalSoundEnabled) + return; + + if (Sounds[SoundID] == nullptr) + return; + else + { + Mix_FreeChunk(Sounds[SoundID]); + Sounds[SoundID] = nullptr; + } } -void CAudio::UnloadSounds() +void CAudio::UnloadSounds() { - StopSound(); + StopSound(); - for (int i=0; i < SND_Max; i++) - UnLoadSound(i); + for (int i=0; i < SND_Max; i++) + UnLoadSound(i); } int CAudio::GetVolumeSound() { - return VolumeSound; + return VolumeSound; } void CAudio::StopSound() { - if(GlobalSoundEnabled) - Mix_HaltChannel(-1); + if(GlobalSoundEnabled) + Mix_HaltChannel(-1); } \ No newline at end of file diff --git a/src/CAudio.h b/src/CAudio.h index e0174a6..9a37197 100644 --- a/src/CAudio.h +++ b/src/CAudio.h @@ -14,39 +14,39 @@ constexpr int MUS_Max = 20; class CAudio { private: - bool DebugInfo; - int VolumeMusic, VolumeSound; - Mix_Chunk *Sounds[SND_Max]; - Mix_Music *Music[MUS_Max]; - string DataPath; + bool DebugInfo; + int VolumeMusic, VolumeSound; + Mix_Chunk *Sounds[SND_Max]; + Mix_Music *Music[MUS_Max]; + string DataPath; public: - bool GlobalSoundEnabled = true; - CAudio(string AssetsPath, bool ADebugInfo); - ~CAudio(); - void IncVolumeMusic(); - void DecVolumeMusic(); - void SetVolumeMusic(const int VolumeIn); - int GetVolumeMusic(); - - void IncVolumeSound(); - void DecVolumeSound(); - void SetVolumeSound(const int VolumeIn); - int GetVolumeSound(); - - int LoadMusic(string FileName); - int LoadSound(string FileName); - int MusicSlotsUsed(); - int MusicSlotsMax(); - int SoundSlotsUsed(); - int SoundSlotsMax(); - void UnLoadMusic(int MusicdID); - void UnLoadSound(int SoundID); - void UnloadSounds(); - void UnloadMusics(); - void PlayMusic(int MusicID, int loops); - void PlaySound(int SoundID, int loops); - bool IsMusicPlaying(); - void StopMusic(); - void StopSound(); + bool GlobalSoundEnabled = true; + CAudio(string AssetsPath, bool ADebugInfo); + ~CAudio(); + void IncVolumeMusic(); + void DecVolumeMusic(); + void SetVolumeMusic(const int VolumeIn); + int GetVolumeMusic(); + + void IncVolumeSound(); + void DecVolumeSound(); + void SetVolumeSound(const int VolumeIn); + int GetVolumeSound(); + + int LoadMusic(string FileName); + int LoadSound(string FileName); + int MusicSlotsUsed(); + int MusicSlotsMax(); + int SoundSlotsUsed(); + int SoundSlotsMax(); + void UnLoadMusic(int MusicdID); + void UnLoadSound(int SoundID); + void UnloadSounds(); + void UnloadMusics(); + void PlayMusic(int MusicID, int loops); + void PlaySound(int SoundID, int loops); + bool IsMusicPlaying(); + void StopMusic(); + void StopSound(); }; \ No newline at end of file diff --git a/src/CFont.cpp b/src/CFont.cpp index b5ec9bd..9910445 100644 --- a/src/CFont.cpp +++ b/src/CFont.cpp @@ -10,159 +10,159 @@ using namespace std; CFont::CFont(string AssetsPath, bool DebugInfo) { - DataPath = AssetsPath; - DebugInfo = DebugInfo; - GlobalFontEnabled = (TTF_Init() == 0); - if (GlobalFontEnabled) - SDL_Log("Succesfully initialized TTF\n"); - else - SDL_Log("Failed initializing SDL_ttf %s\n", SDL_GetError()); + DataPath = AssetsPath; + DebugInfo = DebugInfo; + GlobalFontEnabled = (TTF_Init() == 0); + if (GlobalFontEnabled) + SDL_Log("Succesfully initialized TTF\n"); + else + SDL_Log("Failed initializing SDL_ttf %s\n", SDL_GetError()); } CFont::~CFont() { - if(GlobalFontEnabled) - { - map::iterator i; - for (i = FontCache.begin(); i != FontCache.end(); i++) - TTF_CloseFont(i->second); - TTF_Quit(); - } + if(GlobalFontEnabled) + { + map::iterator i; + for (i = FontCache.begin(); i != FontCache.end(); i++) + TTF_CloseFont(i->second); + TTF_Quit(); + } } int CFont::TextWidth(string Font, int FontSize, string Tekst, size_t NrOfChars) { - SDL_Point Tmp = TextSize(Font, FontSize, Tekst, NrOfChars, 0); - return Tmp.x; + SDL_Point Tmp = TextSize(Font, FontSize, Tekst, NrOfChars, 0); + return Tmp.x; } SDL_Point CFont::TextSize(string Font, int FontSize, string Tekst, size_t NrOfChars, int YSpacing) { - SDL_Point Result = {0,0}; - if(!GlobalFontEnabled || (NrOfChars == 0)) - return Result; + SDL_Point Result = {0,0}; + if(!GlobalFontEnabled || (NrOfChars == 0)) + return Result; - TTF_Font *FontIn; - map::iterator i; - string FontNameSize = string(Font) + to_string(FontSize); - i = FontCache.find(FontNameSize); - if (i != FontCache.end()) - FontIn = i->second; - else - { - string Filename = DataPath + "fonts/" + Font + ".ttf"; - FontIn = TTF_OpenFont(Filename.c_str(), FontSize); - if (!FontIn) - { - SDL_Log("Failed Loading Font %s %d\n", SDL_GetError(), FontSize); - return Result; - } - if(DebugInfo) - SDL_Log("Loaded Font %s %d\n", Filename.c_str(), FontSize); - TTF_SetFontStyle(FontIn, TTF_STYLE_NORMAL); + TTF_Font *FontIn; + map::iterator i; + string FontNameSize = string(Font) + to_string(FontSize); + i = FontCache.find(FontNameSize); + if (i != FontCache.end()) + FontIn = i->second; + else + { + string Filename = DataPath + "fonts/" + Font + ".ttf"; + FontIn = TTF_OpenFont(Filename.c_str(), FontSize); + if (!FontIn) + { + SDL_Log("Failed Loading Font %s %d\n", SDL_GetError(), FontSize); + return Result; + } + if(DebugInfo) + SDL_Log("Loaded Font %s %d\n", Filename.c_str(), FontSize); + TTF_SetFontStyle(FontIn, TTF_STYLE_NORMAL); - FontCache[FontNameSize] = FontIn; - } + FontCache[FontNameSize] = FontIn; + } - char List[100][255]; - size_t Lines, Teller, Chars; - Lines = 0; - Chars = 0; - for (Teller = 0; Teller < NrOfChars; Teller++) - { - if (Lines > 100) - break; - if ((Tekst[Teller] == '\n') || (Chars == 255)) - { - List[Lines][Chars] = '\0'; - Lines++; - Chars = 0; - } - else - { - List[Lines][Chars] = Tekst[Teller]; - Chars++; - } - } - List[Lines][Chars] = '\0'; - int w,h; - Result.y = (Lines)*TTF_FontLineSkip(FontIn) + (Lines * YSpacing); - for (Teller = 0; Teller <= Lines; Teller++) - { - TTF_SizeText(FontIn, List[Teller], &w, &h); - if (w > Result.x) - Result.x = w; - } - return Result; + char List[100][255]; + size_t Lines, Teller, Chars; + Lines = 0; + Chars = 0; + for (Teller = 0; Teller < NrOfChars; Teller++) + { + if (Lines > 100) + break; + if ((Tekst[Teller] == '\n') || (Chars == 255)) + { + List[Lines][Chars] = '\0'; + Lines++; + Chars = 0; + } + else + { + List[Lines][Chars] = Tekst[Teller]; + Chars++; + } + } + List[Lines][Chars] = '\0'; + int w,h; + Result.y = (Lines)*TTF_FontLineSkip(FontIn) + (Lines * YSpacing); + for (Teller = 0; Teller <= Lines; Teller++) + { + TTF_SizeText(FontIn, List[Teller], &w, &h); + if (w > Result.x) + Result.x = w; + } + return Result; } -void CFont::WriteText(SDL_Renderer *Renderer, string Font, int FontSize, string Tekst, size_t NrOfChars, int X, int Y, int YSpacing, SDL_Color ColorIn) +void CFont::WriteText(SDL_Renderer *Renderer, string Font, int FontSize, string Tekst, size_t NrOfChars, int X, int Y, int YSpacing, SDL_Color ColorIn) { - if(!GlobalFontEnabled || (NrOfChars == 0)) - return; - TTF_Font *FontIn; - map::iterator i; - string FontNameSize = string(Font) + to_string(FontSize); - i = FontCache.find(FontNameSize); - if (i != FontCache.end()) - FontIn = i->second; - else - { - string Filename = DataPath + "fonts/" + Font + ".ttf"; - FontIn = TTF_OpenFont(Filename.c_str(), FontSize); - if (!FontIn) - { - SDL_Log("Failed Loading Font %s %d\n", Filename.c_str(), FontSize); - return; - } - if(DebugInfo) - SDL_Log("Loaded Font %s %d\n", Filename.c_str(), FontSize); - TTF_SetFontStyle(FontIn, TTF_STYLE_NORMAL); + if(!GlobalFontEnabled || (NrOfChars == 0)) + return; + TTF_Font *FontIn; + map::iterator i; + string FontNameSize = string(Font) + to_string(FontSize); + i = FontCache.find(FontNameSize); + if (i != FontCache.end()) + FontIn = i->second; + else + { + string Filename = DataPath + "fonts/" + Font + ".ttf"; + FontIn = TTF_OpenFont(Filename.c_str(), FontSize); + if (!FontIn) + { + SDL_Log("Failed Loading Font %s %d\n", Filename.c_str(), FontSize); + return; + } + if(DebugInfo) + SDL_Log("Loaded Font %s %d\n", Filename.c_str(), FontSize); + TTF_SetFontStyle(FontIn, TTF_STYLE_NORMAL); - FontCache[FontNameSize] = FontIn; - } + FontCache[FontNameSize] = FontIn; + } - char List[100][255]; - size_t Lines, Teller, Chars; - SDL_Rect DstRect; - SDL_Surface *TextureBuffer1Surface1; - SDL_Texture *TextureBuffer1Texture; - Lines = 0; - Chars = 0; - for (Teller = 0; Teller < NrOfChars; Teller++) - { - if (Lines > 100) - break; - if ((Tekst[Teller] == '\n') || (Chars == 255)) - { - List[Lines][Chars] = '\0'; - Lines++; - Chars = 0; - } - else - { - List[Lines][Chars] = Tekst[Teller]; - Chars++; - } - } - List[Lines][Chars] = '\0'; - for (Teller = 0; Teller <= Lines; Teller++) - { - if (strlen(List[Teller]) > 0) - { - TextureBuffer1Surface1 = TTF_RenderText_Blended(FontIn, List[Teller], ColorIn); - if (TextureBuffer1Surface1) - { - TextureBuffer1Texture = SDL_CreateTextureFromSurface(Renderer, TextureBuffer1Surface1); - DstRect.x = X; - DstRect.y = Y + (Teller)*TTF_FontLineSkip(FontIn) + (Teller * YSpacing); - DstRect.w = TextureBuffer1Surface1->w; - DstRect.h = TextureBuffer1Surface1->h; + char List[100][255]; + size_t Lines, Teller, Chars; + SDL_Rect DstRect; + SDL_Surface *TextureBuffer1Surface1; + SDL_Texture *TextureBuffer1Texture; + Lines = 0; + Chars = 0; + for (Teller = 0; Teller < NrOfChars; Teller++) + { + if (Lines > 100) + break; + if ((Tekst[Teller] == '\n') || (Chars == 255)) + { + List[Lines][Chars] = '\0'; + Lines++; + Chars = 0; + } + else + { + List[Lines][Chars] = Tekst[Teller]; + Chars++; + } + } + List[Lines][Chars] = '\0'; + for (Teller = 0; Teller <= Lines; Teller++) + { + if (strlen(List[Teller]) > 0) + { + TextureBuffer1Surface1 = TTF_RenderText_Blended(FontIn, List[Teller], ColorIn); + if (TextureBuffer1Surface1) + { + TextureBuffer1Texture = SDL_CreateTextureFromSurface(Renderer, TextureBuffer1Surface1); + DstRect.x = X; + DstRect.y = Y + (Teller)*TTF_FontLineSkip(FontIn) + (Teller * YSpacing); + DstRect.w = TextureBuffer1Surface1->w; + DstRect.h = TextureBuffer1Surface1->h; - SDL_RenderCopy(Renderer, TextureBuffer1Texture, NULL, &DstRect); - SDL_DestroyTexture(TextureBuffer1Texture); - SDL_FreeSurface(TextureBuffer1Surface1); - } - } - } + SDL_RenderCopy(Renderer, TextureBuffer1Texture, NULL, &DstRect); + SDL_DestroyTexture(TextureBuffer1Texture); + SDL_FreeSurface(TextureBuffer1Surface1); + } + } + } } \ No newline at end of file diff --git a/src/CFont.h b/src/CFont.h index 2cba57b..f414fbc 100644 --- a/src/CFont.h +++ b/src/CFont.h @@ -13,14 +13,14 @@ using namespace std; class CFont { private: - string DataPath; - bool DebugInfo; - bool GlobalFontEnabled = true; - map FontCache; + string DataPath; + bool DebugInfo; + bool GlobalFontEnabled = true; + map FontCache; public: - CFont(string AssetsPath, bool DebugInfo); - ~CFont(); - int TextWidth(string Font, int FontSize, string Tekst, size_t NrOfChars); - SDL_Point TextSize(string Font, int FontSize, string Tekst, size_t NrOfChars, int YSpacing); - void WriteText(SDL_Renderer *Renderer, string Font, int FontSize, string Tekst, size_t NrOfChars, int X, int Y, int YSpacing, SDL_Color ColorIn); + CFont(string AssetsPath, bool DebugInfo); + ~CFont(); + int TextWidth(string Font, int FontSize, string Tekst, size_t NrOfChars); + SDL_Point TextSize(string Font, int FontSize, string Tekst, size_t NrOfChars, int YSpacing); + void WriteText(SDL_Renderer *Renderer, string Font, int FontSize, string Tekst, size_t NrOfChars, int X, int Y, int YSpacing, SDL_Color ColorIn); }; \ No newline at end of file diff --git a/src/CGame.cpp b/src/CGame.cpp index 31ce5da..454c2c0 100644 --- a/src/CGame.cpp +++ b/src/CGame.cpp @@ -26,111 +26,111 @@ using namespace std; -CGame::CGame() +CGame::CGame() { - + } -CGame::~CGame() +CGame::~CGame() { } void CGame::DeInit() { - if (ActiveGame != nullptr) - { - ActiveGame->deinit(); - delete ActiveGame; - } - for(int i = 0; i < Games; i++) - SDL_DestroyTexture(GameScreenShots[i]); - SDL_DestroyTexture(ScreenShotRandom); + if (ActiveGame != nullptr) + { + ActiveGame->deinit(); + delete ActiveGame; + } + for(int i = 0; i < Games; i++) + SDL_DestroyTexture(GameScreenShots[i]); + SDL_DestroyTexture(ScreenShotRandom); } void CGame::Init() { - //Main State Variables and such - CurrentGameMusicID = -1; - GameState = GSIntroInit; - Game = 0; - GameMode = GMGame; - Alpha = MaxAlpha; - SubStateTime = 0; - Timer = 0.0f; - SubStateCounter = 0; - TimerTicks = 0; - SubGameState = SGNone; - NextSubState = 0; - NextSubStateCounter = 0; - NextSubStateTimeAdd = 0; - TexCrt = nullptr; - ActiveGame = nullptr; - ReCreateCrt(); - - //Clear score values - ResetScores(); - - //menubackground related - pinc = ScreenWidth; - menubackground = rand() % Games; - menubackgroundcounter = 0; - menubackgroundx = rand() % ScreenWidth; - menubackgroundy = rand() % ScreenHeight; - menubackgrounddx = rand() % 2 == 0 ? 1: -1; - menubackgrounddy = rand() % 2 == 0 ? 1: -1; - - ActiveGame = nullptr; - for (int i = 0; i < Games; i++) - GameScreenShots[i] = nullptr; - ScreenShotRandom = nullptr; - - CreateScreenshotsAndBackground(); + //Main State Variables and such + CurrentGameMusicID = -1; + GameState = GSIntroInit; + Game = 0; + GameMode = GMGame; + Alpha = MaxAlpha; + SubStateTime = 0; + Timer = 0.0f; + SubStateCounter = 0; + TimerTicks = 0; + SubGameState = SGNone; + NextSubState = 0; + NextSubStateCounter = 0; + NextSubStateTimeAdd = 0; + TexCrt = nullptr; + ActiveGame = nullptr; + ReCreateCrt(); + + //Clear score values + ResetScores(); + + //menubackground related + pinc = ScreenWidth; + menubackground = rand() % Games; + menubackgroundcounter = 0; + menubackgroundx = rand() % ScreenWidth; + menubackgroundy = rand() % ScreenHeight; + menubackgrounddx = rand() % 2 == 0 ? 1: -1; + menubackgrounddy = rand() % 2 == 0 ? 1: -1; + + ActiveGame = nullptr; + for (int i = 0; i < Games; i++) + GameScreenShots[i] = nullptr; + ScreenShotRandom = nullptr; + + CreateScreenshotsAndBackground(); } void CGame::CreateScreenshotsAndBackground() -{ - //need to create a temporary sprites holder & replace it because - //games could be running and already have sprites assigned - CSprites *TmpSprites = Sprites; - Sprites = new CSprites(Image); - CGameRamIt *TmpGameRamIt = new CGameRamIt(this, true); - CGameBlockStacker *TmpGameBlockStacker = new CGameBlockStacker(this, true); - CGameSnake *TmpGameSnake = new CGameSnake(this, true); - CGameFastEddy *TmpGameFastEddy = new CGameFastEddy(this, true); - CGameFrog *TmpGameFrog = new CGameFrog(this, true); - CGameBreakOut *TmpGameBreakOut = new CGameBreakOut(this, true); - CGamePang *TmpGamePang = new CGamePang(this,true); - CGameInvaders *TmpGameInvaders = new CGameInvaders(this,true); - int ScreenShotNr = 0; - SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); - GameScreenShots[ScreenShotNr++] = TmpGameInvaders->screenshot(); - SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); - GameScreenShots[ScreenShotNr++] = TmpGameBreakOut->screenshot(); - SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); - GameScreenShots[ScreenShotNr++] = TmpGameFrog->screenshot(); - SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); - GameScreenShots[ScreenShotNr++] = TmpGameSnake->screenshot(); - SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); - GameScreenShots[ScreenShotNr++] = TmpGamePang->screenshot(); - SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); - GameScreenShots[ScreenShotNr++] = TmpGameBlockStacker->screenshot(); - SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); - GameScreenShots[ScreenShotNr++] = TmpGameRamIt->screenshot(); - SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); - GameScreenShots[ScreenShotNr++] = TmpGameFastEddy->screenshot(); - SDL_DestroyTexture(ScreenShotRandom); - ScreenShotRandom = RandomScreenshot(0.25); - delete TmpGameInvaders; - delete TmpGamePang; - delete TmpGameBreakOut; - delete TmpGameFrog; - delete TmpGameRamIt; - delete TmpGameBlockStacker; - delete TmpGameSnake; - delete TmpGameFastEddy; - delete Sprites; - Sprites = TmpSprites; +{ + //need to create a temporary sprites holder & replace it because + //games could be running and already have sprites assigned + CSprites *TmpSprites = Sprites; + Sprites = new CSprites(Image); + CGameRamIt *TmpGameRamIt = new CGameRamIt(this, true); + CGameBlockStacker *TmpGameBlockStacker = new CGameBlockStacker(this, true); + CGameSnake *TmpGameSnake = new CGameSnake(this, true); + CGameFastEddy *TmpGameFastEddy = new CGameFastEddy(this, true); + CGameFrog *TmpGameFrog = new CGameFrog(this, true); + CGameBreakOut *TmpGameBreakOut = new CGameBreakOut(this, true); + CGamePang *TmpGamePang = new CGamePang(this,true); + CGameInvaders *TmpGameInvaders = new CGameInvaders(this,true); + int ScreenShotNr = 0; + SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); + GameScreenShots[ScreenShotNr++] = TmpGameInvaders->screenshot(); + SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); + GameScreenShots[ScreenShotNr++] = TmpGameBreakOut->screenshot(); + SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); + GameScreenShots[ScreenShotNr++] = TmpGameFrog->screenshot(); + SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); + GameScreenShots[ScreenShotNr++] = TmpGameSnake->screenshot(); + SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); + GameScreenShots[ScreenShotNr++] = TmpGamePang->screenshot(); + SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); + GameScreenShots[ScreenShotNr++] = TmpGameBlockStacker->screenshot(); + SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); + GameScreenShots[ScreenShotNr++] = TmpGameRamIt->screenshot(); + SDL_DestroyTexture(GameScreenShots[ScreenShotNr]); + GameScreenShots[ScreenShotNr++] = TmpGameFastEddy->screenshot(); + SDL_DestroyTexture(ScreenShotRandom); + ScreenShotRandom = RandomScreenshot(0.25); + delete TmpGameInvaders; + delete TmpGamePang; + delete TmpGameBreakOut; + delete TmpGameFrog; + delete TmpGameRamIt; + delete TmpGameBlockStacker; + delete TmpGameSnake; + delete TmpGameFastEddy; + delete Sprites; + Sprites = TmpSprites; } void CGame::ResetHighScores() @@ -150,17 +150,17 @@ void CGame::ResetScores() } void CGame::LoadMusic() { - MusMenu = Audio->LoadMusic("main/music.ogg"); + MusMenu = Audio->LoadMusic("main/music.ogg"); } void CGame::UnLoadMusic() { - Audio->UnloadMusics(); + Audio->UnloadMusics(); } -void CGame::UnLoadGraphics() +void CGame::UnLoadGraphics() { - Image->UnloadImages(); + Image->UnloadImages(); } void CGame::DrawTitleBackground(bool k) @@ -175,794 +175,800 @@ void CGame::DrawTitleBackground(bool k) menubackgrounddy *= -1; SDL_Rect Src = {menubackgroundx, menubackgroundy, ScreenWidth, ScreenHeight}; - SDL_Rect Dst = {0, 0, ScreenWidth, ScreenHeight}; - SDL_RenderCopy(Renderer, ScreenShotRandom, &Src, &Dst); - - SDL_SetRenderDrawBlendMode(Renderer, SDL_BLENDMODE_BLEND); - SDL_SetRenderDrawColor(Renderer, 0,0,0,128); - SDL_RenderFillRect(Renderer, &Dst); - - // //DrawCrt(); - - // SDL_Point Pos = {ScreenWidth / 2, ScreenHeight / 2}; - // Vec2F Scale = {10.6f / 4, 10.6f}; - // Image->DrawImageFuze(Renderer, GFXFrameID, &Pos, 0, &Scale, 255, 255, 255, 255); - - if (k) - { - for(size_t i = 0; i < msg.length(); i++) - { - SDL_Color color = {255, Uint8(128 + (sin(i*25 % 360))*127), 0, 64*3}; - string T = msg.substr(i, 1); - Font->WriteText(Renderer, "Roboto-Regular", 100, T, T.length(), pinc + i * 75, ((ScreenHeight / 2) -100) + (sin((((pinc + (i*15)) % 360)*3.14159265/180)) * 200), 0, color); - } + SDL_Rect Dst = {0, 0, ScreenWidth, ScreenHeight}; + SDL_RenderCopy(Renderer, ScreenShotRandom, &Src, &Dst); + + SDL_SetRenderDrawBlendMode(Renderer, SDL_BLENDMODE_BLEND); + SDL_SetRenderDrawColor(Renderer, 0,0,0,128); + SDL_RenderFillRect(Renderer, &Dst); + + // //DrawCrt(); + + // SDL_Point Pos = {ScreenWidth / 2, ScreenHeight / 2}; + // Vec2F Scale = {10.6f / 4, 10.6f}; + // Image->DrawImageFuze(Renderer, GFXFrameID, &Pos, 0, &Scale, 255, 255, 255, 255); + + if (k) + { + for(size_t i = 0; i < msg.length(); i++) + { + SDL_Color color = {255, Uint8(128 + (sin(i*25 % 360))*127), 0, 64*3}; + string T = msg.substr(i, 1); + Font->WriteText(Renderer, "Roboto-Regular", 100, T, T.length(), pinc + i * 75, ((ScreenHeight / 2) -100) + (sin((((pinc + (i*15)) % 360)*3.14159265/180)) * 200), 0, color); + } pinc = pinc- 3; - if (pinc < int(msg.length() * -75) ) - { - pinc = ScreenWidth; - } - } + if (pinc < int(msg.length() * -75)) + { + pinc = ScreenWidth; + } + } } SDL_Texture* CGame::RandomScreenshot(double Scale) { SDL_Texture* prev = SDL_GetRenderTarget(Renderer); - SDL_Texture* image = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth*2, ScreenHeight*2); - SDL_SetRenderTarget(Renderer, image); + SDL_Texture* image = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth*2, ScreenHeight*2); + SDL_SetRenderTarget(Renderer, image); SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); - SDL_RenderClear(Renderer); + SDL_RenderClear(Renderer); int x = 0; int y = 0; int r = rand() % Games; int prevr = r; while (y < ScreenHeight * 2) - { + { x = 0; while(r == prevr) r = rand() % Games; prevr = r; - - while (x < ScreenWidth * 2) - { + + while (x < ScreenWidth * 2) + { r += 1; if (r == Games) r = 0; - SDL_Rect Dst = {x, y, int(ScreenWidth * Scale), int(ScreenHeight * Scale)}; - SDL_Rect Src = {0, 0, ScreenWidth, ScreenHeight}; + SDL_Rect Dst = {x, y, int(ScreenWidth * Scale), int(ScreenHeight * Scale)}; + SDL_Rect Src = {0, 0, ScreenWidth, ScreenHeight}; SDL_RenderCopy(Renderer, GameScreenShots[r], &Src, &Dst); x += int(ScreenWidth * Scale); - } + } y += int(ScreenHeight * Scale); - } - SDL_SetRenderTarget(Renderer, prev); - return image; -} + } + SDL_SetRenderTarget(Renderer, prev); + return image; +} void CGame::AddToScore(long long int Value) { long long int AScore = Value; - if (AScore < 0) + if (AScore < 0) if (GameMode == GMGame) AScore = 0; - + Scores[Game][GameMode] += AScore; if (Scores[Game][GameMode] < 0) Scores[Game][GameMode] = 0; } void CGame::DrawCrt() -{ - int w,h; - SDL_GetWindowSize(SdlWindow, &w , &h); - SDL_Point size; - SDL_QueryTexture(TexCrt, NULL, NULL, &size.x, &size.y); - if ((w != size.x) || (h != size.y)) - ReCreateCrt(); - - //don't put it over scorebar - int w2, h2, y; - float ScaleX = (float)w / (float)ScreenWidth; - float ScaleY = (float)h / (float)ScreenHeight; - int ScaledScoreBarHeight = (ScoreBarHeight) * ScaleY; - h2 = ScreenHeight * ScaleY; - w2 = ScreenWidth * ScaleY; - if (w2 > w) - { - h2 = ScreenHeight * ScaleX; - ScaledScoreBarHeight = (ScoreBarHeight) * ScaleX; - } - y = ((h - h2) / 2); - SDL_Rect Rect = {0,y + ScaledScoreBarHeight,w, h-(y + ScaledScoreBarHeight)}; - SDL_RenderCopy(Renderer, TexCrt, &Rect, &Rect); +{ + int w,h; + SDL_GetWindowSize(SdlWindow, &w , &h); + SDL_Point size; + SDL_QueryTexture(TexCrt, NULL, NULL, &size.x, &size.y); + if ((w != size.x) || (h != size.y)) + ReCreateCrt(); + + //don't put it over scorebar + int w2, h2, y; + float ScaleX = (float)w / (float)ScreenWidth; + float ScaleY = (float)h / (float)ScreenHeight; + int ScaledScoreBarHeight = (ScoreBarHeight) * ScaleY; + h2 = ScreenHeight * ScaleY; + w2 = ScreenWidth * ScaleY; + if (w2 > w) + { + h2 = ScreenHeight * ScaleX; + ScaledScoreBarHeight = (ScoreBarHeight) * ScaleX; + } + y = ((h - h2) / 2); + SDL_Rect Rect = {0,y + ScaledScoreBarHeight,w, h-(y + ScaledScoreBarHeight)}; + SDL_RenderCopy(Renderer, TexCrt, &Rect, &Rect); } void CGame::CreateCrt(int type) { SDL_Texture* prev = SDL_GetRenderTarget(Renderer); - SDL_DestroyTexture(TexCrt); - int w,h; - SDL_GetWindowSize(SdlWindow, &w , &h); - TexCrt = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, w, h); - SDL_SetTextureBlendMode(TexCrt, SDL_BLENDMODE_BLEND); - SDL_SetRenderTarget(Renderer, TexCrt); - SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 0); - SDL_RenderClear(Renderer); + SDL_DestroyTexture(TexCrt); + int w,h; + SDL_GetWindowSize(SdlWindow, &w , &h); + TexCrt = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, w, h); + SDL_SetTextureBlendMode(TexCrt, SDL_BLENDMODE_BLEND); + SDL_SetRenderTarget(Renderer, TexCrt); + SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 0); + SDL_RenderClear(Renderer); if (type > 0) - { + { if (type < 4) - { + { int steps = 2; if (type == 1) steps = 2; - + if (type == 2) steps = 4; - + if (type == 3) steps = 8; - SDL_SetRenderDrawColor(Renderer, 0,0,0, 255); + SDL_SetRenderDrawColor(Renderer, 0,0,0, 255); for(int y = 0; y < h; y+=steps) - SDL_RenderDrawLine(Renderer, 0, y, w, y); - } + SDL_RenderDrawLine(Renderer, 0, y, w, y); + } else - { - if(type < 5) //dots - { - int size = 2; - int xsteps = 1; - int ysteps = 1; - SDL_Texture* img = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, w, ysteps+size); - SDL_SetRenderTarget(Renderer, img); - SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 0); - SDL_RenderClear(Renderer); - SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); - for(int x = 0; x < w + xsteps + size; x+= xsteps + size) - { - SDL_RenderDrawPoint(Renderer, x, 0); - SDL_RenderDrawPoint(Renderer, x+1, 0); - SDL_RenderDrawPoint(Renderer, x, 1); - SDL_RenderDrawPoint(Renderer, x+1, 1); - } - - SDL_SetRenderTarget(Renderer, TexCrt); - for(int y = 0; y < h + ysteps + size; y+= ysteps + size) + { + if(type < 5) //dots + { + int size = 2; + int xsteps = 1; + int ysteps = 1; + SDL_Texture* img = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, w, ysteps+size); + SDL_SetRenderTarget(Renderer, img); + SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 0); + SDL_RenderClear(Renderer); + SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); + for(int x = 0; x < w + xsteps + size; x+= xsteps + size) + { + SDL_RenderDrawPoint(Renderer, x, 0); + SDL_RenderDrawPoint(Renderer, x+1, 0); + SDL_RenderDrawPoint(Renderer, x, 1); + SDL_RenderDrawPoint(Renderer, x+1, 1); + } + + SDL_SetRenderTarget(Renderer, TexCrt); + for(int y = 0; y < h + ysteps + size; y+= ysteps + size) { - SDL_Rect r = {0, y, w, ysteps + size}; - SDL_RenderCopy(Renderer, img, NULL, &r); - } - SDL_DestroyTexture(img); - } - else - { - if (type < 6) //cross - { - int size = 3; - int xsteps = 1; - int ysteps = 1; - SDL_Texture* img = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, w, ysteps+size); - SDL_SetRenderTarget(Renderer, img); - SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 0); - SDL_RenderClear(Renderer); - SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); - - for(int x = 0; x < w + xsteps + size; x+= xsteps + size) - { - SDL_RenderDrawLine(Renderer, x + 1, 1, x + size, size); - SDL_RenderDrawLine(Renderer, x + 1, size, x + size, 1); - } - SDL_SetRenderTarget(Renderer, TexCrt); - for(int y = 0; y < h + ysteps + size; y+= ysteps + size) - { - SDL_Rect r = {0, y, w, ysteps + size}; - SDL_RenderCopy(Renderer, img, NULL, &r); - } - SDL_DestroyTexture(img); - } - } - } - } + SDL_Rect r = {0, y, w, ysteps + size}; + SDL_RenderCopy(Renderer, img, NULL, &r); + } + SDL_DestroyTexture(img); + } + else + { + if (type < 6) //cross + { + int size = 3; + int xsteps = 1; + int ysteps = 1; + SDL_Texture* img = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, w, ysteps+size); + SDL_SetRenderTarget(Renderer, img); + SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 0); + SDL_RenderClear(Renderer); + SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); + + for(int x = 0; x < w + xsteps + size; x+= xsteps + size) + { + SDL_RenderDrawLine(Renderer, x + 1, 1, x + size, size); + SDL_RenderDrawLine(Renderer, x + 1, size, x + size, 1); + } + SDL_SetRenderTarget(Renderer, TexCrt); + for(int y = 0; y < h + ysteps + size; y+= ysteps + size) + { + SDL_Rect r = {0, y, w, ysteps + size}; + SDL_RenderCopy(Renderer, img, NULL, &r); + } + SDL_DestroyTexture(img); + } + } + } + } SDL_SetRenderTarget(Renderer, prev); } void CGame::ReCreateCrt() { - CreateCrt(Crt); + CreateCrt(Crt); } void CGame::LoadSound() { - SfxTimeOver = Audio->LoadSound("common/timeover.wav"); - SfxReadyGo = Audio->LoadSound("common/readygo.wav"); - SfxOne = Audio->LoadSound("common/one.wav"); - SfxTwo = Audio->LoadSound("common/two.wav"); - SfxThree = Audio->LoadSound("common/three.wav"); - SfxOneMinute = Audio->LoadSound("common/oneminute.wav"); - SfxConfirm = Audio->LoadSound("main/confirm.wav"); - SfxBack = Audio->LoadSound("main/back.wav"); - SfxSelect = Audio->LoadSound("main/select.wav"); - SfxScore = Audio->LoadSound("main/score.ogg"); + SfxTimeOver = Audio->LoadSound("common/timeover.wav"); + SfxReadyGo = Audio->LoadSound("common/readygo.wav"); + SfxOne = Audio->LoadSound("common/one.wav"); + SfxTwo = Audio->LoadSound("common/two.wav"); + SfxThree = Audio->LoadSound("common/three.wav"); + SfxOneMinute = Audio->LoadSound("common/oneminute.wav"); + SfxConfirm = Audio->LoadSound("main/confirm.wav"); + SfxBack = Audio->LoadSound("main/back.wav"); + SfxSelect = Audio->LoadSound("main/select.wav"); + SfxScore = Audio->LoadSound("main/score.ogg"); } void CGame::UnLoadSound() { - Audio->UnloadSounds(); + Audio->UnloadSounds(); } -void CGame::LoadGraphics() { - GFXFrameID = Image->LoadImage(Renderer, "main/frame.png"); - GFXMedal = Image->LoadImage(Renderer, "main/medal.png"); +void CGame::LoadGraphics() +{ + GFXFrameID = Image->LoadImage(Renderer, "main/frame.png"); + GFXMedal = Image->LoadImage(Renderer, "main/medal.png"); } -void CGame::ToggleFullscreen() +void CGame::ToggleFullscreen() { - - //return; - Uint32 FullscreenFlag = SDL_WINDOW_FULLSCREEN_DESKTOP; - bool IsFullscreen = SDL_GetWindowFlags(SdlWindow) & FullscreenFlag; - // reset window size first before we go fullscreen - // it will give more fps on the rpi if we for example scaled the window - // first - // if (!IsFullscreen) - // SDL_SetWindowSize(SdlWindow, ScreenWidth, ScreenWidth); - SDL_SetWindowFullscreen(SdlWindow, IsFullscreen ? 0 : FullscreenFlag); - IsFullscreen = SDL_GetWindowFlags(SdlWindow) & FullscreenFlag; - if (!IsFullscreen) - { - //SDL_SetWindowSize(SdlWindow, ScreenWidth, ScreenHeight); - //SDL_SetWindowPosition(SdlWindow, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); - } - //SDL_ShowCursor(SDL_ENABLE); - //ScreenShotRandom = RandomScreenshot(0.25); + + //return; + Uint32 FullscreenFlag = SDL_WINDOW_FULLSCREEN_DESKTOP; + bool IsFullscreen = SDL_GetWindowFlags(SdlWindow) & FullscreenFlag; + // reset window size first before we go fullscreen + // it will give more fps on the rpi if we for example scaled the window + // first + // if (!IsFullscreen) + // SDL_SetWindowSize(SdlWindow, ScreenWidth, ScreenWidth); + SDL_SetWindowFullscreen(SdlWindow, IsFullscreen ? 0 : FullscreenFlag); + IsFullscreen = SDL_GetWindowFlags(SdlWindow) & FullscreenFlag; + if (!IsFullscreen) + { + //SDL_SetWindowSize(SdlWindow, ScreenWidth, ScreenHeight); + //SDL_SetWindowPosition(SdlWindow, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); + } + //SDL_ShowCursor(SDL_ENABLE); + //ScreenShotRandom = RandomScreenshot(0.25); } -void CGame::LoadHighScores() +void CGame::LoadHighScores() { - FILE *ScoreFile; - string FileName = "./.retrotimesscores"; - - char *EnvHome = getenv("HOME"); - char *EnvHomeDrive = getenv("HOMEDRIVE"); - char *EnvHomePath = getenv("HOMEPATH"); - - if (EnvHome) //linux systems normally - FileName = string(EnvHome) + "/.retrotimesscores"; - else - if(EnvHomeDrive && EnvHomePath) //windows systems normally - FileName = string(EnvHomeDrive) + string(EnvHomePath) + "/.retrotimesscores"; - - ScoreFile = fopen(FileName.c_str(), "r"); - if (ScoreFile) - { - fscanf(ScoreFile, "RetroCarousel=%llu\n", &RetroCarouselHighScore); - for (int i = 0; i < Games; i++) - for (int j = 0; j < Modes; j++) - fscanf(ScoreFile, string("Game_" + to_string(i) + "_Mode_" + to_string(j) + "=%llu\n").c_str(), &HighScores[i][j]); - fclose(ScoreFile); - } - else - { - ResetHighScores(); - } + FILE *ScoreFile; + string FileName = "./.retrotimesscores"; + + char *EnvHome = getenv("HOME"); + char *EnvHomeDrive = getenv("HOMEDRIVE"); + char *EnvHomePath = getenv("HOMEPATH"); + + if (EnvHome) //linux systems normally + FileName = string(EnvHome) + "/.retrotimesscores"; + else + if(EnvHomeDrive && EnvHomePath) //windows systems normally + FileName = string(EnvHomeDrive) + string(EnvHomePath) + "/.retrotimesscores"; + + ScoreFile = fopen(FileName.c_str(), "r"); + if (ScoreFile) + { + fscanf(ScoreFile, "RetroCarousel=%llu\n", &RetroCarouselHighScore); + for (int i = 0; i < Games; i++) + for (int j = 0; j < Modes; j++) + fscanf(ScoreFile, string("Game_" + to_string(i) + "_Mode_" + to_string(j) + "=%llu\n").c_str(), &HighScores[i][j]); + fclose(ScoreFile); + } + else + { + ResetHighScores(); + } } -void CGame::SaveHighScores() { - FILE *ScoreFile; - string FileName = "./.retrotimesscores"; - - char *EnvHome = getenv("HOME"); - char *EnvHomeDrive = getenv("HOMEDRIVE"); - char *EnvHomePath = getenv("HOMEPATH"); - - if (EnvHome) //linux systems normally - FileName = string(EnvHome) + "/.retrotimesscores"; - else - if(EnvHomeDrive && EnvHomePath) //windows systems normally - FileName = string(EnvHomeDrive) + string(EnvHomePath) + "/.retrotimesscores"; - - ScoreFile = fopen(FileName.c_str(), "w"); - if (ScoreFile) - { - fprintf(ScoreFile, "RetroCarousel=%llu\n", RetroCarouselHighScore); - for (int i = 0; i < Games; i++) - for (int j = 0; j < Modes; j++) - fprintf(ScoreFile, string("Game_" + to_string(i) + "_Mode_" + to_string(j) + "=%llu\n").c_str(), HighScores[i][j]); - fclose(ScoreFile); - } +void CGame::SaveHighScores() +{ + FILE *ScoreFile; + string FileName = "./.retrotimesscores"; + + char *EnvHome = getenv("HOME"); + char *EnvHomeDrive = getenv("HOMEDRIVE"); + char *EnvHomePath = getenv("HOMEPATH"); + + if (EnvHome) //linux systems normally + FileName = string(EnvHome) + "/.retrotimesscores"; + else + if(EnvHomeDrive && EnvHomePath) //windows systems normally + FileName = string(EnvHomeDrive) + string(EnvHomePath) + "/.retrotimesscores"; + + ScoreFile = fopen(FileName.c_str(), "w"); + if (ScoreFile) + { + fprintf(ScoreFile, "RetroCarousel=%llu\n", RetroCarouselHighScore); + for (int i = 0; i < Games; i++) + for (int j = 0; j < Modes; j++) + fprintf(ScoreFile, string("Game_" + to_string(i) + "_Mode_" + to_string(j) + "=%llu\n").c_str(), HighScores[i][j]); + fclose(ScoreFile); + } } -void CGame::LoadSettings() { - FILE *SettingsFile; - string FileName = "./.retrotimesettings"; - - char *EnvHome = getenv("HOME"); - char *EnvHomeDrive = getenv("HOMEDRIVE"); - char *EnvHomePath = getenv("HOMEPATH"); - - if (EnvHome) //linux systems normally - FileName = string(EnvHome) + "/.retrotimesettings"; - else - if(EnvHomeDrive && EnvHomePath) //windows systems normally - FileName = string(EnvHomeDrive) + string(EnvHomePath) + "/.retrotimesettings"; - - SettingsFile = fopen(FileName.c_str(), "r"); - if (SettingsFile) - { - int VolumeMusic, VolumeSound, aMotionBlur; - fscanf(SettingsFile, "VolumeMusic=%d\nVolumeSound=%d\nCrt=%d\nSpriteGhosting=%d\n", &VolumeMusic, &VolumeSound, &Crt, &aMotionBlur); - MotionBlur = (aMotionBlur == 1); - Audio->SetVolumeSound(VolumeSound); - Audio->SetVolumeMusic(VolumeMusic); - fclose(SettingsFile); - } - else - { - Audio->SetVolumeMusic(128); - Audio->SetVolumeSound(128); - MotionBlur = false; - Crt = 0; - } +void CGame::LoadSettings() +{ + FILE *SettingsFile; + string FileName = "./.retrotimesettings"; + + char *EnvHome = getenv("HOME"); + char *EnvHomeDrive = getenv("HOMEDRIVE"); + char *EnvHomePath = getenv("HOMEPATH"); + + if (EnvHome) //linux systems normally + FileName = string(EnvHome) + "/.retrotimesettings"; + else + if(EnvHomeDrive && EnvHomePath) //windows systems normally + FileName = string(EnvHomeDrive) + string(EnvHomePath) + "/.retrotimesettings"; + + SettingsFile = fopen(FileName.c_str(), "r"); + if (SettingsFile) + { + int VolumeMusic, VolumeSound, aMotionBlur; + fscanf(SettingsFile, "VolumeMusic=%d\nVolumeSound=%d\nCrt=%d\nSpriteGhosting=%d\n", &VolumeMusic, &VolumeSound, &Crt, &aMotionBlur); + MotionBlur = (aMotionBlur == 1); + Audio->SetVolumeSound(VolumeSound); + Audio->SetVolumeMusic(VolumeMusic); + fclose(SettingsFile); + } + else + { + Audio->SetVolumeMusic(128); + Audio->SetVolumeSound(128); + MotionBlur = false; + Crt = 0; + } } -void CGame::SaveSettings() { - FILE *SettingsFile; - string FileName = "./.retrotimesettings"; - - char *EnvHome = getenv("HOME"); - char *EnvHomeDrive = getenv("HOMEDRIVE"); - char *EnvHomePath = getenv("HOMEPATH"); - - if (EnvHome) //linux systems normally - FileName = string(EnvHome) + "/.retrotimesettings"; - else - if(EnvHomeDrive && EnvHomePath) //windows systems normally - FileName = string(EnvHomeDrive) + string(EnvHomePath) + "/.retrotimesettings"; - - SettingsFile = fopen(FileName.c_str(), "w"); - if (SettingsFile) - { - int VolumeMusic = Audio->GetVolumeMusic(); - int VolumeSound = Audio->GetVolumeSound(); - fprintf(SettingsFile, "VolumeMusic=%d\nVolumeSound=%d\nCrt=%d\nSpriteGhosting=%d\n", VolumeMusic, VolumeSound, Crt, MotionBlur?1:0); - fclose(SettingsFile); - } +void CGame::SaveSettings() +{ + FILE *SettingsFile; + string FileName = "./.retrotimesettings"; + + char *EnvHome = getenv("HOME"); + char *EnvHomeDrive = getenv("HOMEDRIVE"); + char *EnvHomePath = getenv("HOMEPATH"); + + if (EnvHome) //linux systems normally + FileName = string(EnvHome) + "/.retrotimesettings"; + else + if(EnvHomeDrive && EnvHomePath) //windows systems normally + FileName = string(EnvHomeDrive) + string(EnvHomePath) + "/.retrotimesettings"; + + SettingsFile = fopen(FileName.c_str(), "w"); + if (SettingsFile) + { + int VolumeMusic = Audio->GetVolumeMusic(); + int VolumeSound = Audio->GetVolumeSound(); + fprintf(SettingsFile, "VolumeMusic=%d\nVolumeSound=%d\nCrt=%d\nSpriteGhosting=%d\n", VolumeMusic, VolumeSound, Crt, MotionBlur?1:0); + fclose(SettingsFile); + } } void CGame::StartCrossFade(int SetGameState, int SetNextSubState, int SetNextSubStateCounter, Uint32 SetNextSubStateTimeAdd) { - AlphaTimer = SDL_GetTicks(); - Alpha = 0; - SubGameState = SGFadeIn; - GameState = SetGameState; - NextSubState = SetNextSubState; - NextSubStateTimeAdd = SetNextSubStateTimeAdd; - NextSubStateCounter = SetNextSubStateCounter; + AlphaTimer = SDL_GetTicks(); + Alpha = 0; + SubGameState = SGFadeIn; + GameState = SetGameState; + NextSubState = SetNextSubState; + NextSubStateTimeAdd = SetNextSubStateTimeAdd; + NextSubStateCounter = SetNextSubStateCounter; } -string CGame::GetFilePath(string InputFile) { - int Teller, Pos = 0; - string Result = InputFile; - for (Teller = InputFile.length() - 1; Teller >= 0; Teller--) - if ((InputFile[Teller] == '/') || (InputFile[Teller] == '\\')) - { - Pos = Teller + 1; - break; - } - Result.resize(Pos); - return Result; +string CGame::GetFilePath(string InputFile) +{ + int Teller, Pos = 0; + string Result = InputFile; + for (Teller = InputFile.length() - 1; Teller >= 0; Teller--) + if ((InputFile[Teller] == '/') || (InputFile[Teller] == '\\')) + { + Pos = Teller + 1; + break; + } + Result.resize(Pos); + return Result; } void CGame::ResetTimer() { - Timer = 120; - if (GameMode == GMRetroCarousel) - { - Timer = 2 * 60; - } + Timer = 120; + if (GameMode == GMRetroCarousel) + { + Timer = 2 * 60; + } if (GameMode == GMTimeAttack) - { - Timer = 5 * 60; - } - TimerTicks = SDL_GetTicks(); + { + Timer = 5 * 60; + } + TimerTicks = SDL_GetTicks(); } void CGame::UpdateTimer() { - if (TimerTicks + 250 < SDL_GetTicks()) - { - TimerTicks = SDL_GetTicks(); - if (SubGameState == SGGame) - { - if (GameMode == GMGame) - Timer += 0.25f; - else - { - Timer -= 0.25f; - - if (Timer == 60) - Audio->PlaySound(SfxOneMinute, 0); - - if (Timer == 3) - Audio->PlaySound(SfxThree, 0); - - if (Timer == 2) - Audio->PlaySound(SfxTwo, 0); - - if (Timer == 1) - Audio->PlaySound(SfxOne, 0); - - - if (Timer <= 0) - { - Audio->PlaySound(SfxTimeOver, 0); - SubGameState = SGTimeUp; - SubStateTime = SDL_GetTicks() + 750; - SubStateCounter = 0; - } - } - } - } + if (TimerTicks + 250 < SDL_GetTicks()) + { + TimerTicks = SDL_GetTicks(); + if (SubGameState == SGGame) + { + if (GameMode == GMGame) + Timer += 0.25f; + else + { + Timer -= 0.25f; + + if (Timer == 60) + Audio->PlaySound(SfxOneMinute, 0); + + if (Timer == 3) + Audio->PlaySound(SfxThree, 0); + + if (Timer == 2) + Audio->PlaySound(SfxTwo, 0); + + if (Timer == 1) + Audio->PlaySound(SfxOne, 0); + + + if (Timer <= 0) + { + Audio->PlaySound(SfxTimeOver, 0); + SubGameState = SGTimeUp; + SubStateTime = SDL_GetTicks() + 750; + SubStateCounter = 0; + } + } + } + } } void CGame::CreateActiveGame() { - if(ActiveGame != nullptr) - { - ActiveGame->deinit(); - delete ActiveGame; - ActiveGame = nullptr; - } - - switch (GameState) - { - case GSSnakeInit: - ActiveGame = new CGameSnake(this); - break; - case GSTetrisInit: - ActiveGame = new CGameBlockStacker(this); - break; - case GSRamItInit: - ActiveGame = new CGameRamIt(this); - break; - case GSEddyInit: - ActiveGame = new CGameFastEddy(this); - break; - case GSFrogInit: - ActiveGame = new CGameFrog(this); - break; - case GSBreakoutInit: - ActiveGame = new CGameBreakOut(this); - break; - case GSPangInit: - ActiveGame = new CGamePang(this); - break; - case GSSpaceInvadersInit: - ActiveGame = new CGameInvaders(this); - break; - default: - ActiveGame = nullptr; - } + if(ActiveGame != nullptr) + { + ActiveGame->deinit(); + delete ActiveGame; + ActiveGame = nullptr; + } + + switch (GameState) + { + case GSSnakeInit: + ActiveGame = new CGameSnake(this); + break; + case GSTetrisInit: + ActiveGame = new CGameBlockStacker(this); + break; + case GSRamItInit: + ActiveGame = new CGameRamIt(this); + break; + case GSEddyInit: + ActiveGame = new CGameFastEddy(this); + break; + case GSFrogInit: + ActiveGame = new CGameFrog(this); + break; + case GSBreakoutInit: + ActiveGame = new CGameBreakOut(this); + break; + case GSPangInit: + ActiveGame = new CGamePang(this); + break; + case GSSpaceInvadersInit: + ActiveGame = new CGameInvaders(this); + break; + default: + ActiveGame = nullptr; + } } void CGame::MainLoop() { - Init(); + Init(); Uint64 TotalFrames = 0; - Uint64 TotalFramePerf = 0; - Uint32 Fps = 0; - double AvgFrameTime = 0.0f; - Uint32 Ticks = SDL_GetTicks(); - while (GameState != GSQuit) - { - TotalFrames++; - Uint64 FrameStartPerf = SDL_GetPerformanceCounter(); - - UpdateTimer(); - - Input->Update(); - - //Need to recreate screenshots and background - if(Input->Buttons.RenderReset) - { - SDL_Log("Render Reset, Recreating crt and background, Reloading Game Graphics"); - Image->UnloadImages(); - LoadGraphics(); - if(ActiveGame != nullptr) - ActiveGame->LoadGraphics(); - CreateScreenshotsAndBackground(); - ReCreateCrt(); - } - - if(Input->Buttons.ButFullscreen && !Input->PrevButtons.ButFullscreen) - ToggleFullscreen(); - - if(Input->Buttons.ButQuit) - GameState = GSQuit; - - SDL_SetRenderTarget(Renderer, TexOffScreen); - - switch (GameState) - { - case GSIntroInit: - case GSIntro: - Intro(this); - break; - - case GSSubScoreInit: - case GSSubScore: - SubScoreScreen(this); - break; - - case GSTitleScreenInit: - case GSTitleScreen: - //to clear the game data & set nullptr to ActiveGame - CreateActiveGame(); - TitleScreen(this); - break; - - case GSPangInit: - case GSBreakoutInit: - case GSFrogInit: - case GSEddyInit: - case GSSnakeInit: - case GSTetrisInit: - case GSRamItInit: - case GSSpaceInvadersInit: - CreateActiveGame(); - ActiveGame->init(); - ResetTimer(); - StartCrossFade(ActiveGame->GameStateID, SGReadyGo, 3, 500); - break; - - case GSPang: - case GSBreakout: - case GSFrog: - case GSEddy: - case GSSnake: - case GSTetris: - case GSRamIt: - case GSSpaceInvaders: - ActiveGame->UpdateLogic(); - ActiveGame->Draw(); - break; - default: - break; - } - if (Alpha < MaxAlpha) - { - Alpha = trunc(MaxAlpha * ((double)(SDL_GetTicks() - AlphaTimer) / MaxAlphaTime)); - if (Alpha + AlphaIncrease >= MaxAlpha) - { - //SDL_SetTextureBlendMode(TexOffScreen, SDL_BLENDMODE_NONE); - Alpha = MaxAlpha; - SubGameState = NextSubState; - SubStateTime = SDL_GetTicks() + NextSubStateTimeAdd; - SubStateCounter = NextSubStateCounter; - } - else - { - SDL_SetTextureBlendMode(TexOffScreen, SDL_BLENDMODE_BLEND); - SDL_SetTextureAlphaMod(TexOffScreen, Alpha); - } - } - SDL_SetRenderTarget(Renderer, TexScreen); - SDL_RenderCopy(Renderer, TexOffScreen, NULL, NULL); - - SDL_SetRenderTarget(Renderer, NULL); - SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); - SDL_RenderClear(Renderer); - - int w, h, w2, h2, x, y; - SDL_GetWindowSize(SdlWindow, &w , &h); - float ScaleX = (float)w / (float)ScreenWidth; - float ScaleY = (float)h / (float)ScreenHeight; - h2 = ScreenHeight * ScaleY; - w2 = ScreenWidth * ScaleY; - if (w2 > w) - { - h2 = ScreenHeight * ScaleX; - w2 = ScreenWidth * ScaleX; - } - x = ((w - w2) / 2); - y = ((h - h2) / 2); - - SDL_Rect Rect = { x, y, w2, h2}; - SDL_RenderCopy(Renderer, TexScreen, NULL, &Rect); - - if((ActiveGame != nullptr) && (GameState != GSSubScore) && (GameState != GSTitleScreenInit)) - DrawCrt(); - - if (debugInfo || ShowFPS) - { - string Text = "FPS: " + to_string(Fps) + "\n"; - if(debugInfo) - { - Text += "FrameTime: " + to_string(AvgFrameTime) + "\n"; - Text += "GFX Slots: " + to_string(Image->ImageSlotsUsed()) + "/" + to_string(Image->ImageSlotsMax()) + "\n"; - Text += "SND Slots: " + to_string(Audio->SoundSlotsUsed()) + "/" + to_string(Audio->SoundSlotsMax()) + "\n"; - Text += "MUS Slots: " + to_string(Audio->MusicSlotsUsed()) + "/" + to_string(Audio->MusicSlotsMax()) + "\n"; - Text += "SPR Slots: " + to_string(Sprites->SpriteSlotsUsed()) + "/" + to_string(Sprites->SpriteSlotsMax()) + "\n"; - } - int tw = Font->TextWidth("RobotoMono-Bold", 16, Text, Text.length()); - Font->WriteText(Renderer, "RobotoMono-Bold", 16, Text, Text.length(), w - tw, 0, 0, {255, 0, 255, 255}); - } - SDL_RenderPresent(Renderer); - - Uint64 FrameEndPerf = SDL_GetPerformanceCounter(); - Uint64 FramePerf = FrameEndPerf - FrameStartPerf; - double FrameTime = FramePerf / (double)SDL_GetPerformanceFrequency() * 1000.0f; - TotalFramePerf += FramePerf; - - if(SDL_GetTicks() - Ticks >= 1000) - { - AvgFrameTime = (TotalFramePerf / TotalFrames) / (double)SDL_GetPerformanceFrequency() * 1000.0f; - Fps = TotalFrames; - TotalFrames = 0; - TotalFramePerf = 0; - Ticks = SDL_GetTicks(); - } - - int RequiredDelay = 1000.0f/DesiredFps - FrameTime; - if (RequiredDelay > 0) - SDL_Delay(RequiredDelay); - } - DeInit(); + Uint64 TotalFramePerf = 0; + Uint32 Fps = 0; + double AvgFrameTime = 0.0f; + Uint32 Ticks = SDL_GetTicks(); + while (GameState != GSQuit) + { + TotalFrames++; + Uint64 FrameStartPerf = SDL_GetPerformanceCounter(); + + UpdateTimer(); + + Input->Update(); + + //Need to recreate screenshots and background + if(Input->Buttons.RenderReset) + { + SDL_Log("Render Reset, Recreating crt and background, Reloading Game Graphics"); + Image->UnloadImages(); + LoadGraphics(); + if(ActiveGame != nullptr) + ActiveGame->LoadGraphics(); + CreateScreenshotsAndBackground(); + ReCreateCrt(); + } + + if(Input->Buttons.ButFullscreen && !Input->PrevButtons.ButFullscreen) + ToggleFullscreen(); + + if(Input->Buttons.ButQuit) + GameState = GSQuit; + + SDL_SetRenderTarget(Renderer, TexOffScreen); + + switch (GameState) + { + case GSIntroInit: + case GSIntro: + Intro(this); + break; + + case GSSubScoreInit: + case GSSubScore: + SubScoreScreen(this); + break; + + case GSTitleScreenInit: + case GSTitleScreen: + //to clear the game data & set nullptr to ActiveGame + CreateActiveGame(); + TitleScreen(this); + break; + + case GSPangInit: + case GSBreakoutInit: + case GSFrogInit: + case GSEddyInit: + case GSSnakeInit: + case GSTetrisInit: + case GSRamItInit: + case GSSpaceInvadersInit: + CreateActiveGame(); + ActiveGame->init(); + ResetTimer(); + StartCrossFade(ActiveGame->GameStateID, SGReadyGo, 3, 500); + break; + + case GSPang: + case GSBreakout: + case GSFrog: + case GSEddy: + case GSSnake: + case GSTetris: + case GSRamIt: + case GSSpaceInvaders: + ActiveGame->UpdateLogic(); + ActiveGame->Draw(); + break; + default: + break; + } + if (Alpha < MaxAlpha) + { + Alpha = trunc(MaxAlpha * ((double)(SDL_GetTicks() - AlphaTimer) / MaxAlphaTime)); + if (Alpha + AlphaIncrease >= MaxAlpha) + { + //SDL_SetTextureBlendMode(TexOffScreen, SDL_BLENDMODE_NONE); + Alpha = MaxAlpha; + SubGameState = NextSubState; + SubStateTime = SDL_GetTicks() + NextSubStateTimeAdd; + SubStateCounter = NextSubStateCounter; + } + else + { + SDL_SetTextureBlendMode(TexOffScreen, SDL_BLENDMODE_BLEND); + SDL_SetTextureAlphaMod(TexOffScreen, Alpha); + } + } + SDL_SetRenderTarget(Renderer, TexScreen); + SDL_RenderCopy(Renderer, TexOffScreen, NULL, NULL); + + SDL_SetRenderTarget(Renderer, NULL); + SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); + SDL_RenderClear(Renderer); + + int w, h, w2, h2, x, y; + SDL_GetWindowSize(SdlWindow, &w , &h); + float ScaleX = (float)w / (float)ScreenWidth; + float ScaleY = (float)h / (float)ScreenHeight; + h2 = ScreenHeight * ScaleY; + w2 = ScreenWidth * ScaleY; + if (w2 > w) + { + h2 = ScreenHeight * ScaleX; + w2 = ScreenWidth * ScaleX; + } + x = ((w - w2) / 2); + y = ((h - h2) / 2); + + SDL_Rect Rect = { x, y, w2, h2}; + SDL_RenderCopy(Renderer, TexScreen, NULL, &Rect); + + if((ActiveGame != nullptr) && (GameState != GSSubScore) && (GameState != GSTitleScreenInit)) + DrawCrt(); + + if (debugInfo || ShowFPS) + { + string Text = "FPS: " + to_string(Fps) + "\n"; + if(debugInfo) + { + Text += "FrameTime: " + to_string(AvgFrameTime) + "\n"; + Text += "GFX Slots: " + to_string(Image->ImageSlotsUsed()) + "/" + to_string(Image->ImageSlotsMax()) + "\n"; + Text += "SND Slots: " + to_string(Audio->SoundSlotsUsed()) + "/" + to_string(Audio->SoundSlotsMax()) + "\n"; + Text += "MUS Slots: " + to_string(Audio->MusicSlotsUsed()) + "/" + to_string(Audio->MusicSlotsMax()) + "\n"; + Text += "SPR Slots: " + to_string(Sprites->SpriteSlotsUsed()) + "/" + to_string(Sprites->SpriteSlotsMax()) + "\n"; + } + int tw = Font->TextWidth("RobotoMono-Bold", 16, Text, Text.length()); + Font->WriteText(Renderer, "RobotoMono-Bold", 16, Text, Text.length(), w - tw, 0, 0, {255, 0, 255, 255}); + } + SDL_RenderPresent(Renderer); + + Uint64 FrameEndPerf = SDL_GetPerformanceCounter(); + Uint64 FramePerf = FrameEndPerf - FrameStartPerf; + double FrameTime = FramePerf / (double)SDL_GetPerformanceFrequency() * 1000.0f; + TotalFramePerf += FramePerf; + + if(SDL_GetTicks() - Ticks >= 1000) + { + AvgFrameTime = (TotalFramePerf / TotalFrames) / (double)SDL_GetPerformanceFrequency() * 1000.0f; + Fps = TotalFrames; + TotalFrames = 0; + TotalFramePerf = 0; + Ticks = SDL_GetTicks(); + } + + int RequiredDelay = 1000.0f/DesiredFps - FrameTime; + if (RequiredDelay > 0) + SDL_Delay(RequiredDelay); + } + DeInit(); } -void CGame::Run(int argc, char *argv[]) { - - bool useSoftwareRenderer = false; - bool useLinear = false; //causes issues in for example frog from scaling textures and then bleeding into each other - bool useVsync = false; - bool useFullScreenAtStartup = true; - string StartPath = GetFilePath(string(argv[0])); - DataPath = StartPath + "retrotimefs/"; - int c; - while ((c = getopt(argc, argv, "?dsfw")) != -1) - { - switch (c) - { - case '?': - // i use sdl log because on windows printf did not show up - SDL_Log("\nZnax Version 1.0.2\n\n\ +void CGame::Run(int argc, char *argv[]) +{ + bool useSoftwareRenderer = false; + bool useLinear = false; //causes issues in for example frog from scaling textures and then bleeding into each other + bool useVsync = false; + bool useFullScreenAtStartup = true; + string StartPath = GetFilePath(string(argv[0])); + DataPath = StartPath + "retrotimefs/"; + int c; + while ((c = getopt(argc, argv, "?dsfw")) != -1) + { + switch (c) + { + case '?': + // i use sdl log because on windows printf did not show up + SDL_Log("\nZnax Version 1.0.2\n\n\ Usage: Znax [Options]\n\n\ Possible options are:\n\ -?: show this help message\n\ -s: Use Software Renderer\n\ -f: Show FPS\n\ -w: Run windowed at startup (by default starts up fullscreen)\n"); - exit(0); - break; - case 'd': - useLinear = false; - break; - case 's': - useSoftwareRenderer = true; - break; - case 'f': - ShowFPS = true; - break; - case 'w': - useFullScreenAtStartup = false; - break; - } - } - - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) == 0) - { - string controllerdb = DataPath + "data/gamecontrollerdb.txt"; - if (SDL_GameControllerAddMappingsFromFile(controllerdb.c_str()) == -1) - SDL_Log("Warning: Failed to load game controller mappings: %s", SDL_GetError()); - - Uint32 WindowFlags = SDL_WINDOW_RESIZABLE; - if (useFullScreenAtStartup) { - WindowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP; - } - - SdlWindow = SDL_CreateWindow("RetroTime", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, ScreenWidth, ScreenHeight, WindowFlags); - - if (SdlWindow) - { - Uint32 flags = 0; - if (useSoftwareRenderer) - flags |= SDL_RENDERER_SOFTWARE; - else - flags |= SDL_RENDERER_ACCELERATED; - if (useVsync) - flags |= SDL_RENDERER_PRESENTVSYNC; - - SDL_Log("Succesfully Set %dx%d\n", ScreenWidth, ScreenHeight); - Renderer = SDL_CreateRenderer(SdlWindow, -1, flags); - if (Renderer) - { - SDL_RendererInfo rendererInfo; - SDL_GetRendererInfo(Renderer, &rendererInfo); - SDL_Log("Using Renderer:%s\n", rendererInfo.name); - - if (useLinear) - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); - - SDL_Log("Succesfully Created Buffer\n"); - srand(time(NULL)); - - Audio = new CAudio(DataPath, debugInfo); - Font = new CFont(DataPath, debugInfo); - Image = new CImage(DataPath, debugInfo); - Input = new CInput(); - Sprites = new CSprites(Image); - Sprites->SetForceShowCollisionShape(debugShowCollisionShapes); - - // Main game loop that loops untile the gamestate = GSQuit - // and calls the procedure according to the gamestate. - LoadSettings(); - LoadHighScores(); - LoadGraphics(); - LoadMusic(); - LoadSound(); - - SDL_SetRenderTarget(Renderer, NULL); - SDL_SetRenderDrawColor(Renderer, 0x00, 0x00, 0x00, 0xFF); - SDL_RenderClear(Renderer); - - TexScreen = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetRenderTarget(Renderer, TexScreen); - SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); - SDL_RenderClear(Renderer); - - TexCrt = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetTextureBlendMode(TexCrt, SDL_BLENDMODE_BLEND); - SDL_SetRenderTarget(Renderer, TexCrt); - SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 0); - SDL_RenderClear(Renderer); - - TexTmp = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetTextureBlendMode(TexTmp, SDL_BLENDMODE_BLEND); - SDL_SetRenderTarget(Renderer, TexTmp); - SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); - SDL_RenderClear(Renderer); - - TexOffScreen = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetRenderTarget(Renderer, TexOffScreen); - SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); - SDL_RenderClear(Renderer); - - SDL_SetRenderDrawBlendMode(Renderer, SDL_BLENDMODE_BLEND); - - MainLoop(); - - SDL_DestroyTexture(TexCrt); - SDL_DestroyTexture(TexOffScreen); - SDL_DestroyTexture(TexScreen); - SDL_DestroyTexture(TexTmp); - UnLoadMusic(); - UnLoadGraphics(); - UnLoadSound(); - SaveSettings(); - SaveHighScores(); - - delete Audio; - delete Font; - delete Image; - delete Input; - delete Sprites; - SDL_DestroyRenderer(Renderer); - } - else - { - SDL_Log("Failed to create renderer: %s\n", SDL_GetError()); - } - } - else - { - SDL_Log("Failed to Set Videomode (%dx%d): %s\n", ScreenWidth, ScreenHeight, SDL_GetError()); - } - SDL_DestroyWindow(SdlWindow); - SDL_Quit(); - } - else - SDL_Log("Failed to initialise SDL: %s\n", SDL_GetError()); + exit(0); + break; + case 'd': + useLinear = false; + break; + case 's': + useSoftwareRenderer = true; + break; + case 'f': + ShowFPS = true; + break; + case 'w': + useFullScreenAtStartup = false; + break; + } + } + + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) == 0) + { + string controllerdb = DataPath + "data/gamecontrollerdb.txt"; + if (SDL_GameControllerAddMappingsFromFile(controllerdb.c_str()) == -1) + SDL_Log("Warning: Failed to load game controller mappings: %s", SDL_GetError()); + + Uint32 WindowFlags = SDL_WINDOW_RESIZABLE; + if (useFullScreenAtStartup) + { + WindowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP; + } + + SdlWindow = SDL_CreateWindow("RetroTime", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, ScreenWidth, ScreenHeight, WindowFlags); + + if (SdlWindow) + { + Uint32 flags = 0; + if (useSoftwareRenderer) + flags |= SDL_RENDERER_SOFTWARE; + else + flags |= SDL_RENDERER_ACCELERATED; + if (useVsync) + flags |= SDL_RENDERER_PRESENTVSYNC; + + SDL_Log("Succesfully Set %dx%d\n", ScreenWidth, ScreenHeight); + Renderer = SDL_CreateRenderer(SdlWindow, -1, flags); + if (Renderer) + { + SDL_RendererInfo rendererInfo; + SDL_GetRendererInfo(Renderer, &rendererInfo); + SDL_Log("Using Renderer:%s\n", rendererInfo.name); + + if (useLinear) + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); + + SDL_Log("Succesfully Created Buffer\n"); + srand(time(NULL)); + + Audio = new CAudio(DataPath, debugInfo); + Font = new CFont(DataPath, debugInfo); + Image = new CImage(DataPath, debugInfo); + Input = new CInput(); + Sprites = new CSprites(Image); + Sprites->SetForceShowCollisionShape(debugShowCollisionShapes); + + // Main game loop that loops untile the gamestate = GSQuit + // and calls the procedure according to the gamestate. + LoadSettings(); + LoadHighScores(); + LoadGraphics(); + LoadMusic(); + LoadSound(); + + SDL_SetRenderTarget(Renderer, NULL); + SDL_SetRenderDrawColor(Renderer, 0x00, 0x00, 0x00, 0xFF); + SDL_RenderClear(Renderer); + + TexScreen = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); + SDL_SetRenderTarget(Renderer, TexScreen); + SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); + SDL_RenderClear(Renderer); + + TexCrt = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); + SDL_SetTextureBlendMode(TexCrt, SDL_BLENDMODE_BLEND); + SDL_SetRenderTarget(Renderer, TexCrt); + SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 0); + SDL_RenderClear(Renderer); + + TexTmp = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); + SDL_SetTextureBlendMode(TexTmp, SDL_BLENDMODE_BLEND); + SDL_SetRenderTarget(Renderer, TexTmp); + SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); + SDL_RenderClear(Renderer); + + TexOffScreen = SDL_CreateTexture(Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); + SDL_SetRenderTarget(Renderer, TexOffScreen); + SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 255); + SDL_RenderClear(Renderer); + + SDL_SetRenderDrawBlendMode(Renderer, SDL_BLENDMODE_BLEND); + + MainLoop(); + + SDL_DestroyTexture(TexCrt); + SDL_DestroyTexture(TexOffScreen); + SDL_DestroyTexture(TexScreen); + SDL_DestroyTexture(TexTmp); + UnLoadMusic(); + UnLoadGraphics(); + UnLoadSound(); + SaveSettings(); + SaveHighScores(); + + delete Audio; + delete Font; + delete Image; + delete Input; + delete Sprites; + SDL_DestroyRenderer(Renderer); + } + else + { + SDL_Log("Failed to create renderer: %s\n", SDL_GetError()); + } + } + else + { + SDL_Log("Failed to Set Videomode (%dx%d): %s\n", ScreenWidth, ScreenHeight, SDL_GetError()); + } + SDL_DestroyWindow(SdlWindow); + SDL_Quit(); + } + else + SDL_Log("Failed to initialise SDL: %s\n", SDL_GetError()); } diff --git a/src/CGame.h b/src/CGame.h index 5531b13..5987de1 100644 --- a/src/CGame.h +++ b/src/CGame.h @@ -23,76 +23,76 @@ class CGameBase; class CGame { -private: - string DataPath; +private: + string DataPath; - Uint8 Alpha = 0; - Uint32 AlphaTimer; - Uint32 TimerTicks; - Uint64 Score; - int NextSubStateCounter, NextSubState, NextSubStateTimeAdd; - - //for main (menu) background drawing - int menubackground, menubackgroundcounter, menubackgroundx, menubackgroundy, menubackgrounddx, menubackgrounddy; - int pinc; - SDL_Texture* ScreenShotRandom; - - SDL_Texture* RandomScreenshot(double Scale); - void UpdateTimer(); - void MainLoop(); - void Init(); - void DeInit(); - void CreateCrt(int type); - void CreateActiveGame(); + Uint8 Alpha = 0; + Uint32 AlphaTimer; + Uint32 TimerTicks; + Uint64 Score; + int NextSubStateCounter, NextSubState, NextSubStateTimeAdd; + + //for main (menu) background drawing + int menubackground, menubackgroundcounter, menubackgroundx, menubackgroundy, menubackgrounddx, menubackgrounddy; + int pinc; + SDL_Texture* ScreenShotRandom; + + SDL_Texture* RandomScreenshot(double Scale); + void UpdateTimer(); + void MainLoop(); + void Init(); + void DeInit(); + void CreateCrt(int type); + void CreateActiveGame(); public: - SDL_Window *SdlWindow; - bool ShowFPS = false; - CGameBase *ActiveGame; - CAudio *Audio; - CFont *Font; - CInput *Input; - CImage *Image; - CSprites *Sprites; - SDL_Renderer *Renderer; - SDL_Texture *TexOffScreen, *TexScreen, *TexCrt, *TexTmp; - SDL_Texture* GameScreenShots[Games]; - long long int RetroCarouselHighScore, RetroCarouselScore; - long long int HighScores[Games][Modes]; + SDL_Window *SdlWindow; + bool ShowFPS = false; + CGameBase *ActiveGame; + CAudio *Audio; + CFont *Font; + CInput *Input; + CImage *Image; + CSprites *Sprites; + SDL_Renderer *Renderer; + SDL_Texture *TexOffScreen, *TexScreen, *TexCrt, *TexTmp; + SDL_Texture* GameScreenShots[Games]; + long long int RetroCarouselHighScore, RetroCarouselScore; + long long int HighScores[Games][Modes]; long long int Scores[Games][Modes]; - int GameState, SubGameState, GameMode, Game, Crt; - float SubStateCounter; - int MusMenu; - int SfxConfirm, SfxBack, SfxSelect, SfxScore, SfxOne, SfxTwo, SfxThree, SfxTimeOver, SfxReadyGo, SfxOneMinute; - double Timer; - Uint32 SubStateTime; - bool MotionBlur; - int GFXFrameID, GFXMedal; - int CurrentGameMusicID; - CGame(); - ~CGame(); - - void InitSubScore(); - void SubScore(); - void LoadSound(); - void UnLoadSound(); - void LoadMusic(); - void UnLoadMusic(); - void UnLoadGraphics(); - void LoadGraphics(); - void LoadSettings(); - void SaveSettings(); - void LoadHighScores(); - void SaveHighScores(); - void ResetTimer(); - void ResetScores(); - void ResetHighScores(); - void AddToScore(long long int Value); - void DrawTitleBackground(bool k); - string GetFilePath(string InputFile); - void DrawCrt(); - void Run(int argc, char **argv); - void ReCreateCrt(); - void CreateScreenshotsAndBackground(); - void StartCrossFade(int SetGameState, int SetNextSubState, int SetNextSubStateCounter, Uint32 SetNextSubStateTimeAdd); - void ToggleFullscreen(); + int GameState, SubGameState, GameMode, Game, Crt; + float SubStateCounter; + int MusMenu; + int SfxConfirm, SfxBack, SfxSelect, SfxScore, SfxOne, SfxTwo, SfxThree, SfxTimeOver, SfxReadyGo, SfxOneMinute; + double Timer; + Uint32 SubStateTime; + bool MotionBlur; + int GFXFrameID, GFXMedal; + int CurrentGameMusicID; + CGame(); + ~CGame(); + + void InitSubScore(); + void SubScore(); + void LoadSound(); + void UnLoadSound(); + void LoadMusic(); + void UnLoadMusic(); + void UnLoadGraphics(); + void LoadGraphics(); + void LoadSettings(); + void SaveSettings(); + void LoadHighScores(); + void SaveHighScores(); + void ResetTimer(); + void ResetScores(); + void ResetHighScores(); + void AddToScore(long long int Value); + void DrawTitleBackground(bool k); + string GetFilePath(string InputFile); + void DrawCrt(); + void Run(int argc, char **argv); + void ReCreateCrt(); + void CreateScreenshotsAndBackground(); + void StartCrossFade(int SetGameState, int SetNextSubState, int SetNextSubStateCounter, Uint32 SetNextSubStateTimeAdd); + void ToggleFullscreen(); }; diff --git a/src/CImage.cpp b/src/CImage.cpp index 5d144c0..abb5071 100644 --- a/src/CImage.cpp +++ b/src/CImage.cpp @@ -12,252 +12,252 @@ using namespace std; CImage::CImage(string AssetsPath, bool ADebugInfo) { - ImgEnabled = true; - DebugInfo = ADebugInfo; - if (IMG_Init(IMG_INIT_PNG) == 0) - { - ImgEnabled = false; - SDL_Log("Failed to initialise images: %s\n", IMG_GetError()); - } - else - { - SDL_Log("Images Succesfully initialised!\n"); - } - DataPath = AssetsPath; - - for (int i=0; i < GFX_Max; i++) - Images[i] = nullptr; + ImgEnabled = true; + DebugInfo = ADebugInfo; + if (IMG_Init(IMG_INIT_PNG) == 0) + { + ImgEnabled = false; + SDL_Log("Failed to initialise images: %s\n", IMG_GetError()); + } + else + { + SDL_Log("Images Succesfully initialised!\n"); + } + DataPath = AssetsPath; + + for (int i=0; i < GFX_Max; i++) + Images[i] = nullptr; } CImage::~CImage() { - UnloadImages(); - IMG_Quit(); + UnloadImages(); + IMG_Quit(); } int CImage::LoadImage(SDL_Renderer* Renderer, string FileName) { - if(!ImgEnabled) - return -1; - - string FullFileName = DataPath + "graphics/" + FileName; - for (int i=0; i < GFX_Max; i++) - if(Images[i] == nullptr) - { - SDL_Surface* Img = IMG_Load(FullFileName.c_str()); - if(Img) - { - Images[i] = SDL_CreateTextureFromSurface(Renderer, Img); - SDL_FreeSurface(Img); - if(DebugInfo) - SDL_Log("Loaded Graphic %s\n", FullFileName.c_str()); - return i; - } - else - { - SDL_Log("Failed Loading Graphic %s\n", FullFileName.c_str()); - return -1; - } - } - return -1; + if(!ImgEnabled) + return -1; + + string FullFileName = DataPath + "graphics/" + FileName; + for (int i=0; i < GFX_Max; i++) + if(Images[i] == nullptr) + { + SDL_Surface* Img = IMG_Load(FullFileName.c_str()); + if(Img) + { + Images[i] = SDL_CreateTextureFromSurface(Renderer, Img); + SDL_FreeSurface(Img); + if(DebugInfo) + SDL_Log("Loaded Graphic %s\n", FullFileName.c_str()); + return i; + } + else + { + SDL_Log("Failed Loading Graphic %s\n", FullFileName.c_str()); + return -1; + } + } + return -1; } void CImage::UnLoadImage(int GFXID) { - if(!ImgEnabled) - return; - - if ((GFXID < 0) || (GFXID >= GFX_Max)) - return; - - if (Images[GFXID] != nullptr) - { - SDL_DestroyTexture(Images[GFXID]); - Images[GFXID] = nullptr; - } + if(!ImgEnabled) + return; + + if ((GFXID < 0) || (GFXID >= GFX_Max)) + return; + + if (Images[GFXID] != nullptr) + { + SDL_DestroyTexture(Images[GFXID]); + Images[GFXID] = nullptr; + } } -void CImage::UnloadImages() +void CImage::UnloadImages() { - for (int i=0; i < GFX_Max; i++) - UnLoadImage(i); + for (int i=0; i < GFX_Max; i++) + UnLoadImage(i); } void CImage::DrawImage(SDL_Renderer* Renderer, int GFXID, SDL_Rect* Src, SDL_Rect* Dst) { - if((GFXID < 0) || (GFXID >= GFX_Max)) - return; - - DrawImage(Renderer, Images[GFXID], Src, Dst); + if((GFXID < 0) || (GFXID >= GFX_Max)) + return; + + DrawImage(Renderer, Images[GFXID], Src, Dst); } void CImage::DrawImage(SDL_Renderer* Renderer, SDL_Texture *Texture, SDL_Rect* Src, SDL_Rect* Dst) -{ - if(!ImgEnabled) - return; +{ + if(!ImgEnabled) + return; - if(Texture == nullptr) - return; + if(Texture == nullptr) + return; - SDL_RenderCopy(Renderer, Texture, Src, Dst); + SDL_RenderCopy(Renderer, Texture, Src, Dst); } void CImage::DrawImageEx(SDL_Renderer* Renderer, int GFXID, SDL_Rect* Src, SDL_Rect* Dst, double Angle, SDL_Point* Center, SDL_RendererFlip Flip) { - if((GFXID < 0) || (GFXID >= GFX_Max)) - return; + if((GFXID < 0) || (GFXID >= GFX_Max)) + return; - DrawImageEx(Renderer, Images[GFXID], Src, Dst, Angle, Center, Flip); + DrawImageEx(Renderer, Images[GFXID], Src, Dst, Angle, Center, Flip); } void CImage::DrawImageEx(SDL_Renderer* Renderer, SDL_Texture *Texture, SDL_Rect* Src, SDL_Rect* Dst, double Angle, SDL_Point* Center, SDL_RendererFlip Flip) { - if(!ImgEnabled) - return; + if(!ImgEnabled) + return; - if(Texture == nullptr) - return; + if(Texture == nullptr) + return; - SDL_RenderCopyEx(Renderer, Texture, Src, Dst, Angle, Center, Flip); + SDL_RenderCopyEx(Renderer, Texture, Src, Dst, Angle, Center, Flip); } //fuze used center points for positions and a floating point scale vector void CImage::DrawImageFuzeSrcRectTintFloat(SDL_Renderer* Renderer, int GFXID, SDL_Rect *SrcRect, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, float TintR, float TintG, float TintB, float Alpha) { - if((GFXID < 0) || (GFXID >= GFX_Max)) - return; + if((GFXID < 0) || (GFXID >= GFX_Max)) + return; - DrawImageFuze(Renderer, Images[GFXID], SrcRect, CenterImagePos, Pos, Angle, Scale, (Uint8)floor(255.0f * TintR) , (Uint8)floor(255.0f * TintG), (Uint8)floor(255.0f * TintB) , (Uint8)floor(255.0f * Alpha)); + DrawImageFuze(Renderer, Images[GFXID], SrcRect, CenterImagePos, Pos, Angle, Scale, (Uint8)floor(255.0f * TintR) , (Uint8)floor(255.0f * TintG), (Uint8)floor(255.0f * TintB) , (Uint8)floor(255.0f * Alpha)); } //fuze used center points for positions and a floating point scale vector -void CImage::DrawImageFuzeTintFloat(SDL_Renderer* Renderer, int GFXID, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, float TintR, float TintG, float TintB, float Alpha) +void CImage::DrawImageFuzeTintFloat(SDL_Renderer* Renderer, int GFXID, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, float TintR, float TintG, float TintB, float Alpha) { - if((GFXID < 0) || (GFXID >= GFX_Max)) - return; + if((GFXID < 0) || (GFXID >= GFX_Max)) + return; - DrawImageFuze(Renderer, Images[GFXID], NULL, CenterImagePos, Pos, Angle, Scale, (Uint8)floor(255.0f * TintR) , (Uint8)floor(255.0f * TintG), (Uint8)floor(255.0f * TintB) , (Uint8)floor(255.0f * Alpha)); + DrawImageFuze(Renderer, Images[GFXID], NULL, CenterImagePos, Pos, Angle, Scale, (Uint8)floor(255.0f * TintR) , (Uint8)floor(255.0f * TintG), (Uint8)floor(255.0f * TintB) , (Uint8)floor(255.0f * Alpha)); } -void CImage::DrawImageFuzeTintFloat(SDL_Renderer* Renderer, SDL_Texture *Texture, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, float TintR, float TintG, float TintB, float Alpha) +void CImage::DrawImageFuzeTintFloat(SDL_Renderer* Renderer, SDL_Texture *Texture, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, float TintR, float TintG, float TintB, float Alpha) { - if(Texture == nullptr) - return; + if(Texture == nullptr) + return; - DrawImageFuze(Renderer, Texture, NULL, CenterImagePos, Pos, Angle, Scale, (Uint8)floor(255.0f * TintR) , (Uint8)floor(255.0f * TintG), (Uint8)floor(255.0f * TintB) , (Uint8)floor(255.0f * Alpha)); + DrawImageFuze(Renderer, Texture, NULL, CenterImagePos, Pos, Angle, Scale, (Uint8)floor(255.0f * TintR) , (Uint8)floor(255.0f * TintG), (Uint8)floor(255.0f * TintB) , (Uint8)floor(255.0f * Alpha)); } -void CImage::DrawImageFuze(SDL_Renderer* Renderer, int GFXID, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, Uint8 TintR, Uint8 TintG, Uint8 TintB, Uint8 Alpha) +void CImage::DrawImageFuze(SDL_Renderer* Renderer, int GFXID, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, Uint8 TintR, Uint8 TintG, Uint8 TintB, Uint8 Alpha) { - if((GFXID < 0) || (GFXID >= GFX_Max)) - return; - - DrawImageFuze(Renderer, Images[GFXID], NULL, CenterImagePos, Pos, Angle, Scale, TintR, TintG, TintB, Alpha); + if((GFXID < 0) || (GFXID >= GFX_Max)) + return; + + DrawImageFuze(Renderer, Images[GFXID], NULL, CenterImagePos, Pos, Angle, Scale, TintR, TintG, TintB, Alpha); } //fuze used center points for positions and a floating point scale vector -void CImage::DrawImageFuze(SDL_Renderer* Renderer, SDL_Texture *Texture, SDL_Rect *SrcRect, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, Uint8 TintR, Uint8 TintG, Uint8 TintB, Uint8 Alpha) +void CImage::DrawImageFuze(SDL_Renderer* Renderer, SDL_Texture *Texture, SDL_Rect *SrcRect, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, Uint8 TintR, Uint8 TintG, Uint8 TintB, Uint8 Alpha) { - if(!ImgEnabled) - return; - - if(Texture == nullptr) - return; - float dstW; - float dstH; - - if(SrcRect) - { - dstW = (SrcRect->w * abs(Scale->x)); - dstH = (SrcRect->h * abs(Scale->y)); - } - else - { - - SDL_Point ImageTz = ImageSize(Texture); - dstW = (ImageTz.x * abs(Scale->x)); - dstH = (ImageTz.y * abs(Scale->y)); - } - SDL_Rect Dst; - if(CenterImagePos) - Dst = {(int)(Pos->x - ((dstW) / 2)), (int)(Pos->y - ((dstH) / 2)), (int)(dstW), (int)(dstH)}; - else - Dst = {Pos->x, Pos->y, (int)(dstW), (int)(dstH)}; - - //save values - SDL_BlendMode Mode; - Uint8 R,G,B,A; - - SDL_GetTextureAlphaMod(Texture, &A); - SDL_GetTextureColorMod(Texture, &R, &G, &B); - SDL_GetTextureBlendMode(Texture, &Mode); - - //Set our values - SDL_SetTextureColorMod(Texture, TintR, TintG, TintB); - SDL_SetTextureAlphaMod(Texture, Alpha); - SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND); - - SDL_RendererFlip flip = SDL_FLIP_NONE; - - if ((Scale->x < 0) && (Scale->y < 0)) - flip = (SDL_RendererFlip)(SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL); - else - { - if (Scale->x < 0) - flip = SDL_FLIP_HORIZONTAL; - else - { - if (Scale->y < 0) - flip = SDL_FLIP_VERTICAL; - } - } - - //Draw - SDL_RenderCopyEx(Renderer, Texture, SrcRect, &Dst, Angle, NULL, flip); - - //restore values - SDL_SetTextureBlendMode(Texture, Mode); - SDL_SetTextureColorMod(Texture, R, G, B); - SDL_SetTextureAlphaMod(Texture, A); + if(!ImgEnabled) + return; + + if(Texture == nullptr) + return; + float dstW; + float dstH; + + if(SrcRect) + { + dstW = (SrcRect->w * abs(Scale->x)); + dstH = (SrcRect->h * abs(Scale->y)); + } + else + { + + SDL_Point ImageTz = ImageSize(Texture); + dstW = (ImageTz.x * abs(Scale->x)); + dstH = (ImageTz.y * abs(Scale->y)); + } + SDL_Rect Dst; + if(CenterImagePos) + Dst = {(int)(Pos->x - ((dstW) / 2)), (int)(Pos->y - ((dstH) / 2)), (int)(dstW), (int)(dstH)}; + else + Dst = {Pos->x, Pos->y, (int)(dstW), (int)(dstH)}; + + //save values + SDL_BlendMode Mode; + Uint8 R,G,B,A; + + SDL_GetTextureAlphaMod(Texture, &A); + SDL_GetTextureColorMod(Texture, &R, &G, &B); + SDL_GetTextureBlendMode(Texture, &Mode); + + //Set our values + SDL_SetTextureColorMod(Texture, TintR, TintG, TintB); + SDL_SetTextureAlphaMod(Texture, Alpha); + SDL_SetTextureBlendMode(Texture, SDL_BLENDMODE_BLEND); + + SDL_RendererFlip flip = SDL_FLIP_NONE; + + if ((Scale->x < 0) && (Scale->y < 0)) + flip = (SDL_RendererFlip)(SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL); + else + { + if (Scale->x < 0) + flip = SDL_FLIP_HORIZONTAL; + else + { + if (Scale->y < 0) + flip = SDL_FLIP_VERTICAL; + } + } + + //Draw + SDL_RenderCopyEx(Renderer, Texture, SrcRect, &Dst, Angle, NULL, flip); + + //restore values + SDL_SetTextureBlendMode(Texture, Mode); + SDL_SetTextureColorMod(Texture, R, G, B); + SDL_SetTextureAlphaMod(Texture, A); } -SDL_Point CImage::ImageSize(int GFXID) +SDL_Point CImage::ImageSize(int GFXID) { - - if((GFXID < 0) || (GFXID >= GFX_Max)) - return {-1, -1}; - - return ImageSize(Images[GFXID]); + + if((GFXID < 0) || (GFXID >= GFX_Max)) + return {-1, -1}; + + return ImageSize(Images[GFXID]); } -SDL_Point CImage::ImageSize(SDL_Texture *Texture) +SDL_Point CImage::ImageSize(SDL_Texture *Texture) { - - if(!ImgEnabled) - return {-1, -1}; - - if(Texture == nullptr) - return {-1, -1}; - - SDL_Point size; - SDL_QueryTexture(Texture, NULL, NULL, &size.x, &size.y); - return size; + + if(!ImgEnabled) + return {-1, -1}; + + if(Texture == nullptr) + return {-1, -1}; + + SDL_Point size; + SDL_QueryTexture(Texture, NULL, NULL, &size.x, &size.y); + return size; } int CImage::ImageSlotsUsed() { - int c = 0; - for (int i=0; i < GFX_Max; i++) - { - if(Images[i] != nullptr) - c++; - } - return c; + int c = 0; + for (int i=0; i < GFX_Max; i++) + { + if(Images[i] != nullptr) + c++; + } + return c; } int CImage::ImageSlotsMax() { - return GFX_Max; + return GFX_Max; } diff --git a/src/CImage.h b/src/CImage.h index 129e466..f60a5bc 100644 --- a/src/CImage.h +++ b/src/CImage.h @@ -13,37 +13,37 @@ constexpr int GFX_Max = 100; class CImage { private: - SDL_Texture *Images[GFX_Max]; - string DataPath; - bool ImgEnabled; - bool DebugInfo; + SDL_Texture *Images[GFX_Max]; + string DataPath; + bool ImgEnabled; + bool DebugInfo; public: - CImage(string AssetsPath, bool ADebugInfo); - ~CImage(); - int LoadImage(SDL_Renderer* Renderer, string FileName); - void UnLoadImage(int GFXID); - void UnloadImages(); - void DrawImage(SDL_Renderer* Renderer, int GFXID, SDL_Rect* Src, SDL_Rect* Dst); - void DrawImage(SDL_Renderer* Renderer, SDL_Texture*, SDL_Rect* Src, SDL_Rect* Dst); - void DrawImageEx(SDL_Renderer* Renderer, int GFXID, SDL_Rect* Src, SDL_Rect* Dst, double Angle, SDL_Point* Center, SDL_RendererFlip Flip); - void DrawImageEx(SDL_Renderer* Renderer, SDL_Texture *Texture, SDL_Rect* Src, SDL_Rect* Dst, double Angle, SDL_Point* Center, SDL_RendererFlip Flip); - //tint & alpha value between 0.0 & 1.0 - void DrawImageFuzeSrcRectTintFloat(SDL_Renderer* Renderer, int GFXID, SDL_Rect *SrcRect, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, - float TintR, float TintG, float TintB, float Alpha); - //tint & alpha value between 0.0 & 1.0 - void DrawImageFuzeTintFloat(SDL_Renderer* Renderer, SDL_Texture *Texture, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, - float TintR, float TintG, float TintB, float Alpha); - //tint & alpha value between 0.0 & 1.0 - void DrawImageFuzeTintFloat(SDL_Renderer* Renderer, int GFXID, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, - float TintR, float TintG, float TintB, float Alpha); - void DrawImageFuze(SDL_Renderer* Renderer, int GFXID, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, - Uint8 TintR, Uint8 TintG, Uint8 TintB, Uint8 Alpha); - void DrawImageFuze(SDL_Renderer* Renderer, SDL_Texture *Texture, SDL_Rect *SrcRect, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, - Uint8 TintR, Uint8 TintG, Uint8 TintB, Uint8 Alpha); - SDL_Point ImageSize(int GFXID); - SDL_Point ImageSize(SDL_Texture *Texture); - int ImageSlotsUsed(); - int ImageSlotsMax(); + CImage(string AssetsPath, bool ADebugInfo); + ~CImage(); + int LoadImage(SDL_Renderer* Renderer, string FileName); + void UnLoadImage(int GFXID); + void UnloadImages(); + void DrawImage(SDL_Renderer* Renderer, int GFXID, SDL_Rect* Src, SDL_Rect* Dst); + void DrawImage(SDL_Renderer* Renderer, SDL_Texture*, SDL_Rect* Src, SDL_Rect* Dst); + void DrawImageEx(SDL_Renderer* Renderer, int GFXID, SDL_Rect* Src, SDL_Rect* Dst, double Angle, SDL_Point* Center, SDL_RendererFlip Flip); + void DrawImageEx(SDL_Renderer* Renderer, SDL_Texture *Texture, SDL_Rect* Src, SDL_Rect* Dst, double Angle, SDL_Point* Center, SDL_RendererFlip Flip); + //tint & alpha value between 0.0 & 1.0 + void DrawImageFuzeSrcRectTintFloat(SDL_Renderer* Renderer, int GFXID, SDL_Rect *SrcRect, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, + float TintR, float TintG, float TintB, float Alpha); + //tint & alpha value between 0.0 & 1.0 + void DrawImageFuzeTintFloat(SDL_Renderer* Renderer, SDL_Texture *Texture, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, + float TintR, float TintG, float TintB, float Alpha); + //tint & alpha value between 0.0 & 1.0 + void DrawImageFuzeTintFloat(SDL_Renderer* Renderer, int GFXID, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, + float TintR, float TintG, float TintB, float Alpha); + void DrawImageFuze(SDL_Renderer* Renderer, int GFXID, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, + Uint8 TintR, Uint8 TintG, Uint8 TintB, Uint8 Alpha); + void DrawImageFuze(SDL_Renderer* Renderer, SDL_Texture *Texture, SDL_Rect *SrcRect, bool CenterImagePos, SDL_Point* Pos, double Angle, Vec2F* Scale, + Uint8 TintR, Uint8 TintG, Uint8 TintB, Uint8 Alpha); + SDL_Point ImageSize(int GFXID); + SDL_Point ImageSize(SDL_Texture *Texture); + int ImageSlotsUsed(); + int ImageSlotsMax(); }; \ No newline at end of file diff --git a/src/CInput.cpp b/src/CInput.cpp index 19d697a..a87503e 100644 --- a/src/CInput.cpp +++ b/src/CInput.cpp @@ -4,287 +4,287 @@ CInput::CInput() { - JoystickDeadZone = 10000; - TriggerDeadZone = 10000; - ResetButtons(); - for (int i=0; i < SDL_NumJoysticks(); i++) - { - if(SDL_IsGameController(i)) - { - GameController = SDL_GameControllerOpen(i); - SDL_GameControllerEventState(SDL_ENABLE); - SDL_Log("Joystick Detected!\n"); - break; - } - } + JoystickDeadZone = 10000; + TriggerDeadZone = 10000; + ResetButtons(); + for (int i=0; i < SDL_NumJoysticks(); i++) + { + if(SDL_IsGameController(i)) + { + GameController = SDL_GameControllerOpen(i); + SDL_GameControllerEventState(SDL_ENABLE); + SDL_Log("Joystick Detected!\n"); + break; + } + } } CInput::~CInput() { - if(GameController) - { - SDL_GameControllerClose(GameController); - GameController = NULL; - } + if(GameController) + { + SDL_GameControllerClose(GameController); + GameController = NULL; + } } void CInput::Update() { - SDL_Event Event; - PrevButtons = Buttons; - Buttons.ButQuit = false; - Buttons.RenderReset = false; - while (SDL_PollEvent(&Event)) - { - if (Event.type == SDL_RENDER_TARGETS_RESET) - Buttons.RenderReset = true; + SDL_Event Event; + PrevButtons = Buttons; + Buttons.ButQuit = false; + Buttons.RenderReset = false; + while (SDL_PollEvent(&Event)) + { + if (Event.type == SDL_RENDER_TARGETS_RESET) + Buttons.RenderReset = true; + + if (Event.type == SDL_QUIT) + Buttons.ButQuit = true; + + if (Event.type == SDL_JOYDEVICEADDED) + if(GameController == NULL) + if(SDL_IsGameController(Event.jdevice.which)) + GameController = SDL_GameControllerOpen(Event.jdevice.which); - if (Event.type == SDL_QUIT) - Buttons.ButQuit = true; - - if (Event.type == SDL_JOYDEVICEADDED) - if(GameController == NULL) - if(SDL_IsGameController(Event.jdevice.which)) - GameController = SDL_GameControllerOpen(Event.jdevice.which); + if (Event.type == SDL_JOYDEVICEREMOVED) + { + SDL_Joystick* Joystick = SDL_GameControllerGetJoystick(GameController); + if (Joystick) + if (Event.jdevice.which == SDL_JoystickInstanceID(Joystick)) + { + SDL_GameControllerClose(GameController); + GameController = NULL; + } + } - if (Event.type == SDL_JOYDEVICEREMOVED) - { - SDL_Joystick* Joystick = SDL_GameControllerGetJoystick(GameController); - if (Joystick) - if (Event.jdevice.which == SDL_JoystickInstanceID(Joystick)) - { - SDL_GameControllerClose(GameController); - GameController = NULL; - } - } + if (Event.type == SDL_CONTROLLERAXISMOTION) + HandleJoystickAxisEvent(Event.jaxis.axis, Event.jaxis.value); - if (Event.type == SDL_CONTROLLERAXISMOTION) - HandleJoystickAxisEvent(Event.jaxis.axis, Event.jaxis.value); + if (Event.type == SDL_CONTROLLERBUTTONUP) + HandleJoystickButtonEvent(Event.cbutton.button, false); - if (Event.type == SDL_CONTROLLERBUTTONUP) - HandleJoystickButtonEvent(Event.cbutton.button, false); + if (Event.type == SDL_CONTROLLERBUTTONDOWN) + HandleJoystickButtonEvent(Event.cbutton.button, true); - if (Event.type == SDL_CONTROLLERBUTTONDOWN) - HandleJoystickButtonEvent(Event.cbutton.button, true); + if (Event.type == SDL_KEYUP) + HandleKeyboardEvent(Event.key.keysym.sym, false); - if (Event.type == SDL_KEYUP) - HandleKeyboardEvent(Event.key.keysym.sym, false); - - if (Event.type == SDL_KEYDOWN) - HandleKeyboardEvent(Event.key.keysym.sym, true); - } + if (Event.type == SDL_KEYDOWN) + HandleKeyboardEvent(Event.key.keysym.sym, true); + } } void CInput::ResetButtons() { - Buttons.ButLeft = false; - Buttons.ButRight = false; - Buttons.ButUp = false; - Buttons.ButDown = false; - Buttons.ButLB = false; - Buttons.ButRB = false; - Buttons.ButLT = false; - Buttons.ButRT = false; - Buttons.ButBack = false; - Buttons.ButA = false; - Buttons.ButB = false; - Buttons.ButX = false; - Buttons.ButY = false; - Buttons.ButStart = false; - Buttons.ButQuit = false; - Buttons.ButFullscreen = false; - Buttons.RenderReset = false; - Buttons.ButDpadLeft = false; - Buttons.ButDpadRight = false; - Buttons.ButDpadUp = false; - Buttons.ButDpadDown = false; - Buttons.ButLeft2 = false; - Buttons.ButRight2 = false; - Buttons.ButUp2 = false; - Buttons.ButDown2 = false; - PrevButtons = Buttons; + Buttons.ButLeft = false; + Buttons.ButRight = false; + Buttons.ButUp = false; + Buttons.ButDown = false; + Buttons.ButLB = false; + Buttons.ButRB = false; + Buttons.ButLT = false; + Buttons.ButRT = false; + Buttons.ButBack = false; + Buttons.ButA = false; + Buttons.ButB = false; + Buttons.ButX = false; + Buttons.ButY = false; + Buttons.ButStart = false; + Buttons.ButQuit = false; + Buttons.ButFullscreen = false; + Buttons.RenderReset = false; + Buttons.ButDpadLeft = false; + Buttons.ButDpadRight = false; + Buttons.ButDpadUp = false; + Buttons.ButDpadDown = false; + Buttons.ButLeft2 = false; + Buttons.ButRight2 = false; + Buttons.ButUp2 = false; + Buttons.ButDown2 = false; + PrevButtons = Buttons; } -void CInput::HandleJoystickButtonEvent(int Button, bool Value) +void CInput::HandleJoystickButtonEvent(int Button, bool Value) { - switch (Button) - { - case SDL_CONTROLLER_BUTTON_Y: - Buttons.ButY = Value; - break; - case SDL_CONTROLLER_BUTTON_X: - Buttons.ButX = Value; - break; - case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: - Buttons.ButLB = Value; - break; - case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: - Buttons.ButRB = Value; - break; - case SDL_CONTROLLER_BUTTON_DPAD_UP: - Buttons.ButDpadUp = Value; - break; - case SDL_CONTROLLER_BUTTON_DPAD_DOWN: - Buttons.ButDpadDown = Value; - break; - case SDL_CONTROLLER_BUTTON_DPAD_LEFT: - Buttons.ButDpadLeft = Value; - break; - case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: - Buttons.ButDpadRight = Value; - break; - case SDL_CONTROLLER_BUTTON_A: - Buttons.ButA = Value; - break; - case SDL_CONTROLLER_BUTTON_B: - Buttons.ButB = Value; - break; - case SDL_CONTROLLER_BUTTON_START: - Buttons.ButStart = Value; - break; - case SDL_CONTROLLER_BUTTON_BACK: - Buttons.ButBack = Value; - break; - default: - break; - } + switch (Button) + { + case SDL_CONTROLLER_BUTTON_Y: + Buttons.ButY = Value; + break; + case SDL_CONTROLLER_BUTTON_X: + Buttons.ButX = Value; + break; + case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: + Buttons.ButLB = Value; + break; + case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: + Buttons.ButRB = Value; + break; + case SDL_CONTROLLER_BUTTON_DPAD_UP: + Buttons.ButDpadUp = Value; + break; + case SDL_CONTROLLER_BUTTON_DPAD_DOWN: + Buttons.ButDpadDown = Value; + break; + case SDL_CONTROLLER_BUTTON_DPAD_LEFT: + Buttons.ButDpadLeft = Value; + break; + case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: + Buttons.ButDpadRight = Value; + break; + case SDL_CONTROLLER_BUTTON_A: + Buttons.ButA = Value; + break; + case SDL_CONTROLLER_BUTTON_B: + Buttons.ButB = Value; + break; + case SDL_CONTROLLER_BUTTON_START: + Buttons.ButStart = Value; + break; + case SDL_CONTROLLER_BUTTON_BACK: + Buttons.ButBack = Value; + break; + default: + break; + } } -void CInput::HandleKeyboardEvent(int Key, bool Value) +void CInput::HandleKeyboardEvent(int Key, bool Value) { - switch (Key) - { - case SDLK_F4: - Buttons.ButQuit = Value; - break; - case SDLK_F3: - Buttons.ButFullscreen = Value; - break; - case SDLK_b: - Buttons.ButRB = Value; - break; - case SDLK_x: - Buttons.ButLB = Value; - break; - case SDLK_UP: - Buttons.ButUp = Value; - break; - case SDLK_DOWN: - Buttons.ButDown = Value; - break; - case SDLK_LEFT: - Buttons.ButLeft = Value; - break; - case SDLK_RIGHT: - Buttons.ButRight = Value; - break; - case SDLK_RETURN: - Buttons.ButStart = Value; - break; - case SDLK_ESCAPE: - Buttons.ButBack = Value; - break; - case SDLK_SPACE: - case SDLK_c: - Buttons.ButA = Value; - break; - case SDLK_LCTRL: - case SDLK_RCTRL: - case SDLK_v: - Buttons.ButB = Value; - break; - case SDLK_LALT: - case SDLK_RALT: - case SDLK_d: - Buttons.ButX = Value; - break; - case SDLK_f: - Buttons.ButY = Value; + switch (Key) + { + case SDLK_F4: + Buttons.ButQuit = Value; + break; + case SDLK_F3: + Buttons.ButFullscreen = Value; + break; + case SDLK_b: + Buttons.ButRB = Value; + break; + case SDLK_x: + Buttons.ButLB = Value; + break; + case SDLK_UP: + Buttons.ButUp = Value; + break; + case SDLK_DOWN: + Buttons.ButDown = Value; + break; + case SDLK_LEFT: + Buttons.ButLeft = Value; + break; + case SDLK_RIGHT: + Buttons.ButRight = Value; + break; + case SDLK_RETURN: + Buttons.ButStart = Value; + break; + case SDLK_ESCAPE: + Buttons.ButBack = Value; + break; + case SDLK_SPACE: + case SDLK_c: + Buttons.ButA = Value; + break; + case SDLK_LCTRL: + case SDLK_RCTRL: + case SDLK_v: + Buttons.ButB = Value; + break; + case SDLK_LALT: + case SDLK_RALT: + case SDLK_d: + Buttons.ButX = Value; + break; + case SDLK_f: + Buttons.ButY = Value; break; case SDLK_s: - Buttons.ButLT = Value; - break; - case SDLK_g: - Buttons.ButRT = Value; - break; - default: - break; - } + Buttons.ButLT = Value; + break; + case SDLK_g: + Buttons.ButRT = Value; + break; + default: + break; + } } void CInput::HandleJoystickAxisEvent(int Axis, int Value) { - switch(Axis) - { - case SDL_CONTROLLER_AXIS_LEFTX: - if (abs(Value) < JoystickDeadZone) - { - Buttons.ButRight = false; - Buttons.ButLeft = false; - return; - } - if(Value > 0) - Buttons.ButRight = true; - else - Buttons.ButLeft = true; - break; - - case SDL_CONTROLLER_AXIS_LEFTY: - if (abs(Value) < JoystickDeadZone) - { - Buttons.ButUp = false; - Buttons.ButDown = false; - return; - } - if(Value < 0) - Buttons.ButUp = true; - else - Buttons.ButDown = true; - break; + switch(Axis) + { + case SDL_CONTROLLER_AXIS_LEFTX: + if (abs(Value) < JoystickDeadZone) + { + Buttons.ButRight = false; + Buttons.ButLeft = false; + return; + } + if(Value > 0) + Buttons.ButRight = true; + else + Buttons.ButLeft = true; + break; + + case SDL_CONTROLLER_AXIS_LEFTY: + if (abs(Value) < JoystickDeadZone) + { + Buttons.ButUp = false; + Buttons.ButDown = false; + return; + } + if(Value < 0) + Buttons.ButUp = true; + else + Buttons.ButDown = true; + break; - case SDL_CONTROLLER_AXIS_RIGHTX: - if (abs(Value) < JoystickDeadZone) - { - Buttons.ButRight2 = false; - Buttons.ButLeft2 = false; - return; - } - if(Value > 0) - Buttons.ButRight2 = true; - else - Buttons.ButLeft2 = true; - break; - - case SDL_CONTROLLER_AXIS_RIGHTY: - if (abs(Value) < JoystickDeadZone) - { - Buttons.ButUp2 = false; - Buttons.ButDown2 = false; - return; - } - if(Value < 0) - Buttons.ButUp2 = true; - else - Buttons.ButDown2 = true; - break; + case SDL_CONTROLLER_AXIS_RIGHTX: + if (abs(Value) < JoystickDeadZone) + { + Buttons.ButRight2 = false; + Buttons.ButLeft2 = false; + return; + } + if(Value > 0) + Buttons.ButRight2 = true; + else + Buttons.ButLeft2 = true; + break; - case SDL_CONTROLLER_AXIS_TRIGGERLEFT: - if (abs(Value) < TriggerDeadZone) - { - Buttons.ButLT = false; - return; - } - Buttons.ButLT = true; - break; + case SDL_CONTROLLER_AXIS_RIGHTY: + if (abs(Value) < JoystickDeadZone) + { + Buttons.ButUp2 = false; + Buttons.ButDown2 = false; + return; + } + if(Value < 0) + Buttons.ButUp2 = true; + else + Buttons.ButDown2 = true; + break; - case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: - if (abs(Value) < TriggerDeadZone) - { - Buttons.ButRT = false; - return; - } - Buttons.ButRT = true; - break; - } + case SDL_CONTROLLER_AXIS_TRIGGERLEFT: + if (abs(Value) < TriggerDeadZone) + { + Buttons.ButLT = false; + return; + } + Buttons.ButLT = true; + break; + + case SDL_CONTROLLER_AXIS_TRIGGERRIGHT: + if (abs(Value) < TriggerDeadZone) + { + Buttons.ButRT = false; + return; + } + Buttons.ButRT = true; + break; + } } \ No newline at end of file diff --git a/src/CInput.h b/src/CInput.h index 36ee218..1c46850 100644 --- a/src/CInput.h +++ b/src/CInput.h @@ -3,26 +3,26 @@ #include struct SButtons { - bool ButLeft, ButRight, ButUp, ButDown, - ButDpadLeft, ButDpadRight, ButDpadUp, ButDpadDown, - ButLeft2, ButRight2, ButUp2, ButDown2, - ButBack, ButStart, ButA, ButB, - ButX, ButY, ButLB, ButRB, ButFullscreen, ButQuit, ButRT, ButLT, - RenderReset; + bool ButLeft, ButRight, ButUp, ButDown, + ButDpadLeft, ButDpadRight, ButDpadUp, ButDpadDown, + ButLeft2, ButRight2, ButUp2, ButDown2, + ButBack, ButStart, ButA, ButB, + ButX, ButY, ButLB, ButRB, ButFullscreen, ButQuit, ButRT, ButLT, + RenderReset; }; class CInput { private: - SDL_GameController* GameController = NULL; - void HandleJoystickAxisEvent(int Axis, int Value); - void HandleJoystickButtonEvent(int Button, bool Value); - void HandleKeyboardEvent(int Key, bool Value); + SDL_GameController* GameController = NULL; + void HandleJoystickAxisEvent(int Axis, int Value); + void HandleJoystickButtonEvent(int Button, bool Value); + void HandleKeyboardEvent(int Key, bool Value); public: - SButtons Buttons, PrevButtons; - int JoystickDeadZone, TriggerDeadZone; - CInput(); - ~CInput(); - void Update(); - void ResetButtons(); + SButtons Buttons, PrevButtons; + int JoystickDeadZone, TriggerDeadZone; + CInput(); + ~CInput(); + void Update(); + void ResetButtons(); }; \ No newline at end of file diff --git a/src/CSprites.cpp b/src/CSprites.cpp index 5861bb5..3d6d7bc 100644 --- a/src/CSprites.cpp +++ b/src/CSprites.cpp @@ -9,431 +9,431 @@ CSprites::CSprites(CImage* ACImage) { - Images = ACImage; - ForceShowCollisionShape = false; - needSpriteSorting = false; - for (int i=0; i < SPR_Max; i++) - { - Sprites[i] = nullptr; - } + Images = ACImage; + ForceShowCollisionShape = false; + needSpriteSorting = false; + for (int i=0; i < SPR_Max; i++) + { + Sprites[i] = nullptr; + } } CSprites::~CSprites() { - for (int i=0; i < SPR_Max; i++) - { - RemoveSprite(Sprites[i]); - } + for (int i=0; i < SPR_Max; i++) + { + RemoveSprite(Sprites[i]); + } } void CSprites::SetForceShowCollisionShape(bool val) { - ForceShowCollisionShape = val; + ForceShowCollisionShape = val; } CSprite* CSprites::CreateSprite() { - for (int i= 0; i < SPR_Max; i++) - { - if(Sprites[i] == nullptr) - { - CSprite* Spr = new CSprite(); - Spr->index = i; - Spr->animInc = 0; - Spr->animTimer = 0; - Spr->rotation = 0; - Spr->imageID = nullptr; - Spr->xscale = 1; - Spr->yscale = 1; - Spr->xscale_speed = 0; - Spr->yscale_speed = 0; - Spr->xspeed = 0; - Spr->yspeed = 0; - Spr->tileSizeX = 0; - Spr->tileSizeY = 0; - Spr->animStartTile = 0; - Spr->animEndTile = 0; - Spr->animSpeed = 0; - Spr->animTile = 0; - Spr->collisionShape = SHAPE_BOX; - Spr->collisionAngle = 0; - Spr->collisionWidth = 0; - Spr->collisionHeight = 0; - Spr->collisionxoffset = 0; - Spr->collisionyoffset = 0; - Spr->depth = 0; - Spr->show = true; - Spr->r = 1.0; - Spr->g = 1.0; - Spr->b = 1.0; - Spr->a = 1.0; - Spr->tilesX = 1; - Spr->tilesY = 1; - Spr->rotation_speed = 0.0; - Sprites[i] = Spr; - return Spr; - } - } - return nullptr; + for (int i= 0; i < SPR_Max; i++) + { + if(Sprites[i] == nullptr) + { + CSprite* Spr = new CSprite(); + Spr->index = i; + Spr->animInc = 0; + Spr->animTimer = 0; + Spr->rotation = 0; + Spr->imageID = nullptr; + Spr->xscale = 1; + Spr->yscale = 1; + Spr->xscale_speed = 0; + Spr->yscale_speed = 0; + Spr->xspeed = 0; + Spr->yspeed = 0; + Spr->tileSizeX = 0; + Spr->tileSizeY = 0; + Spr->animStartTile = 0; + Spr->animEndTile = 0; + Spr->animSpeed = 0; + Spr->animTile = 0; + Spr->collisionShape = SHAPE_BOX; + Spr->collisionAngle = 0; + Spr->collisionWidth = 0; + Spr->collisionHeight = 0; + Spr->collisionxoffset = 0; + Spr->collisionyoffset = 0; + Spr->depth = 0; + Spr->show = true; + Spr->r = 1.0; + Spr->g = 1.0; + Spr->b = 1.0; + Spr->a = 1.0; + Spr->tilesX = 1; + Spr->tilesY = 1; + Spr->rotation_speed = 0.0; + Sprites[i] = Spr; + return Spr; + } + } + return nullptr; } void CSprites::RemoveSprite(CSprite* Spr) { - if(Spr == nullptr) - return; + if(Spr == nullptr) + return; - if((Spr->index < 0) || (Spr->index >= SPR_Max)) - return; + if((Spr->index < 0) || (Spr->index >= SPR_Max)) + return; - Sprites[Spr->index] = nullptr; - delete Spr; + Sprites[Spr->index] = nullptr; + delete Spr; } void CSprites::UpdateSprites() { - SortSprites(); - for (int i = 0; i < SPR_Max; i++) - { - if (Sprites[i] == nullptr) - continue; - - if (Sprites[i]->animSpeed != 0) - { - if (SDL_GetTicks() > Sprites[i]->animTimer) - { - Sprites[i]->animTile += Sprites[i]->animInc; - if (Sprites[i]->animInc > 0) - { - if(Sprites[i]->animTile > Sprites[i]->animEndTile) - Sprites[i]->animTile = Sprites[i]->animStartTile; - } - else - { - if (Sprites[i]->animInc < 0) - { - if(Sprites[i]->animTile < Sprites[i]->animEndTile) - Sprites[i]->animTile = Sprites[i]->animStartTile; - } - } - Sprites[i]->animTimer = SDL_GetTicks() + (int)floor(1000 / Sprites[i]->animSpeed); - } - } - - Sprites[i]->x += Sprites[i]->xspeed; - Sprites[i]->y += Sprites[i]->yspeed; - Sprites[i]->xscale += Sprites[i]->xscale_speed; - Sprites[i]->yscale += Sprites[i]->yscale_speed; - Sprites[i]->rotation += Sprites[i]->rotation_speed; - Sprites[i]->collisionAngle += Sprites[i]->rotation_speed; - Sprites[i]->collisionWidth += Sprites[i]->xscale_speed; - Sprites[i]->collisionHeight += Sprites[i]->yscale_speed; - } + SortSprites(); + for (int i = 0; i < SPR_Max; i++) + { + if (Sprites[i] == nullptr) + continue; + + if (Sprites[i]->animSpeed != 0) + { + if (SDL_GetTicks() > Sprites[i]->animTimer) + { + Sprites[i]->animTile += Sprites[i]->animInc; + if (Sprites[i]->animInc > 0) + { + if(Sprites[i]->animTile > Sprites[i]->animEndTile) + Sprites[i]->animTile = Sprites[i]->animStartTile; + } + else + { + if (Sprites[i]->animInc < 0) + { + if(Sprites[i]->animTile < Sprites[i]->animEndTile) + Sprites[i]->animTile = Sprites[i]->animStartTile; + } + } + Sprites[i]->animTimer = SDL_GetTicks() + (int)floor(1000 / Sprites[i]->animSpeed); + } + } + + Sprites[i]->x += Sprites[i]->xspeed; + Sprites[i]->y += Sprites[i]->yspeed; + Sprites[i]->xscale += Sprites[i]->xscale_speed; + Sprites[i]->yscale += Sprites[i]->yscale_speed; + Sprites[i]->rotation += Sprites[i]->rotation_speed; + Sprites[i]->collisionAngle += Sprites[i]->rotation_speed; + Sprites[i]->collisionWidth += Sprites[i]->xscale_speed; + Sprites[i]->collisionHeight += Sprites[i]->yscale_speed; + } } void CSprites::SortSprites() { - if (needSpriteSorting) - { - for (int i = 0; i< SPR_Max; i++) - { - for(int j=i+1; j < SPR_Max; j++) - { - if ((Sprites[i] != nullptr) && (Sprites[j] != nullptr)) - { - if(Sprites[i]->depth > Sprites[j]->depth) - { - CSprite* Tmp = Sprites[i]; - Sprites[i] = Sprites[j]; - Sprites[i]->index = i; - Sprites[j] = Tmp; - Sprites[j]->index = j; - } - } - } - } - needSpriteSorting = false; - } + if (needSpriteSorting) + { + for (int i = 0; i< SPR_Max; i++) + { + for(int j=i+1; j < SPR_Max; j++) + { + if ((Sprites[i] != nullptr) && (Sprites[j] != nullptr)) + { + if(Sprites[i]->depth > Sprites[j]->depth) + { + CSprite* Tmp = Sprites[i]; + Sprites[i] = Sprites[j]; + Sprites[i]->index = i; + Sprites[j] = Tmp; + Sprites[j]->index = j; + } + } + } + } + needSpriteSorting = false; + } } void CSprites::DrawSprite(SDL_Renderer* Renderer, CSprite* Spr) { - if (Spr == nullptr) - return; - - SortSprites(); - - if (Spr->show && ((*Spr->imageID > -1) && (*Spr->imageID < Images->ImageSlotsMax()))) - { - SDL_Point pos = {(int)(Spr->x), (int)(Spr->y)}; - Vec2F scale = {Spr->xscale, Spr->yscale}; - int AnimTile = Spr->animTile; - int y = (int)floor(AnimTile / Spr->tilesX); - int x = AnimTile - (y * Spr->tilesX); - SDL_Rect SrcRect = {x * Spr->tileSizeX, y* Spr->tileSizeY, Spr->tileSizeX, Spr->tileSizeY}; - Images->DrawImageFuzeSrcRectTintFloat(Renderer, *Spr->imageID, &SrcRect, true, &pos, Spr->rotation, &scale, Spr->r, Spr->g, Spr->b, Spr->a); - if (Spr->show_collision_shape || ForceShowCollisionShape) - { - SDL_SetRenderDrawColor(Renderer, 255, 0, 255, 255); - switch(Spr->collisionShape) - { - case SHAPE_BOX: - { - const SDL_Rect rect = {(int)(Spr->x + Spr->collisionxoffset - (Spr->collisionWidth * (Spr->xscale) / 2)), (int)(Spr->y + Spr->collisionyoffset - (Spr->collisionHeight * (Spr->yscale) / 2)), (int)(Spr->collisionWidth * (Spr->xscale)), (int)(Spr->collisionHeight * (Spr->yscale))}; - SDL_RenderDrawRect(Renderer, &rect); - break; - } - case SHAPE_CIRCLE: - { - if ((Spr->collisionWidth == Spr->collisionHeight) && (Spr->xscale == Spr->yscale)) - circleRGBA(Renderer, Spr->x + Spr->collisionxoffset, Spr->y + Spr->collisionyoffset,(int) ((Spr->collisionWidth * Spr->xscale) / 2), 255, 0, 255, 255); - break; - } - default: - break; - } - } - } + if (Spr == nullptr) + return; + + SortSprites(); + + if (Spr->show && ((*Spr->imageID > -1) && (*Spr->imageID < Images->ImageSlotsMax()))) + { + SDL_Point pos = {(int)(Spr->x), (int)(Spr->y)}; + Vec2F scale = {Spr->xscale, Spr->yscale}; + int AnimTile = Spr->animTile; + int y = (int)floor(AnimTile / Spr->tilesX); + int x = AnimTile - (y * Spr->tilesX); + SDL_Rect SrcRect = {x * Spr->tileSizeX, y* Spr->tileSizeY, Spr->tileSizeX, Spr->tileSizeY}; + Images->DrawImageFuzeSrcRectTintFloat(Renderer, *Spr->imageID, &SrcRect, true, &pos, Spr->rotation, &scale, Spr->r, Spr->g, Spr->b, Spr->a); + if (Spr->show_collision_shape || ForceShowCollisionShape) + { + SDL_SetRenderDrawColor(Renderer, 255, 0, 255, 255); + switch(Spr->collisionShape) + { + case SHAPE_BOX: + { + const SDL_Rect rect = {(int)(Spr->x + Spr->collisionxoffset - (Spr->collisionWidth * (Spr->xscale) / 2)), (int)(Spr->y + Spr->collisionyoffset - (Spr->collisionHeight * (Spr->yscale) / 2)), (int)(Spr->collisionWidth * (Spr->xscale)), (int)(Spr->collisionHeight * (Spr->yscale))}; + SDL_RenderDrawRect(Renderer, &rect); + break; + } + case SHAPE_CIRCLE: + { + if ((Spr->collisionWidth == Spr->collisionHeight) && (Spr->xscale == Spr->yscale)) + circleRGBA(Renderer, Spr->x + Spr->collisionxoffset, Spr->y + Spr->collisionyoffset,(int) ((Spr->collisionWidth * Spr->xscale) / 2), 255, 0, 255, 255); + break; + } + default: + break; + } + } + } } void CSprites::DrawSprites(SDL_Renderer* Renderer) { - for (int i = 0; i < SPR_Max; i++) - { - if (Sprites[i] == nullptr) - continue; + for (int i = 0; i < SPR_Max; i++) + { + if (Sprites[i] == nullptr) + continue; - DrawSprite(Renderer, Sprites[i]); - } + DrawSprite(Renderer, Sprites[i]); + } } -void SetSpriteRotationSpeed(CSprite* Spr, double rotationSpeed) +void SetSpriteRotationSpeed(CSprite* Spr, double rotationSpeed) { - Spr->rotation_speed = rotationSpeed; + Spr->rotation_speed = rotationSpeed; } void CSprites::SetSpriteColour (CSprite* Spr, float red, float green, float blue, float alpha) { - Spr->r = red; - Spr->g = green; - Spr->b = blue; - Spr->a = alpha; + Spr->r = red; + Spr->g = green; + Spr->b = blue; + Spr->a = alpha; } void CSprites::SetSpriteVisibility(CSprite* Spr, bool visibility) { - Spr->show = visibility; + Spr->show = visibility; } Vec2F CSprites::GetSpriteLocation(CSprite* Spr) { - Vec2F Result = {Spr->x, Spr->y}; - return Result; + Vec2F Result = {Spr->x, Spr->y}; + return Result; } void CSprites::SetSpriteImage(CSprite* Spr, int *AImageID) { - SetSpriteImage(Spr, AImageID, 1, 1); + SetSpriteImage(Spr, AImageID, 1, 1); } void CSprites::SetSpriteImage(CSprite* Spr, int *AImageID, int TilesX, int TilesY) { - Spr->imageID = AImageID; - SDL_Point Tz = Images->ImageSize(*AImageID); - Spr->tileSizeX = (int)floor(Tz.x / TilesX); - Spr->tileSizeY = (int)floor(Tz.y / TilesY); - Spr->tilesX = TilesX; - Spr->tilesY = TilesY; - if ((Spr->collisionHeight == 0) && (Spr->collisionWidth == 0)) - { - Spr->collisionHeight = Spr->tileSizeY; - Spr->collisionWidth = Spr->tileSizeX; - } + Spr->imageID = AImageID; + SDL_Point Tz = Images->ImageSize(*AImageID); + Spr->tileSizeX = (int)floor(Tz.x / TilesX); + Spr->tileSizeY = (int)floor(Tz.y / TilesY); + Spr->tilesX = TilesX; + Spr->tilesY = TilesY; + if ((Spr->collisionHeight == 0) && (Spr->collisionWidth == 0)) + { + Spr->collisionHeight = Spr->tileSizeY; + Spr->collisionWidth = Spr->tileSizeX; + } } void CSprites::SetSpriteScale(CSprite* Spr, Vec2F AScale) -{ - Spr->xscale = AScale.x; - Spr->yscale = AScale.y; +{ + Spr->xscale = AScale.x; + Spr->yscale = AScale.y; } -void CSprites::SetSpriteRotation(CSprite* Spr, double AAngle) +void CSprites::SetSpriteRotation(CSprite* Spr, double AAngle) { - double diffAngle = AAngle - Spr->rotation; - Spr->collisionAngle += diffAngle; - Spr->rotation = AAngle; + double diffAngle = AAngle - Spr->rotation; + Spr->collisionAngle += diffAngle; + Spr->rotation = AAngle; } void CSprites::SetSpriteAnimation(CSprite* Spr, int StartTile, int EndTile, int animSpeed) { - Spr->animStartTile = StartTile; - Spr->animEndTile = EndTile; - Spr->animSpeed = animSpeed; - Spr->animTile = StartTile; - if (animSpeed != 0) - { - Spr->animTimer = SDL_GetTicks() + (int)floor(1000 / animSpeed); - - if(EndTile < StartTile) - Spr->animInc = -1; - else - { - if(EndTile > StartTile) - Spr->animInc = 1; - else - Spr->animInc = 0; - } - } + Spr->animStartTile = StartTile; + Spr->animEndTile = EndTile; + Spr->animSpeed = animSpeed; + Spr->animTile = StartTile; + if (animSpeed != 0) + { + Spr->animTimer = SDL_GetTicks() + (int)floor(1000 / animSpeed); + + if(EndTile < StartTile) + Spr->animInc = -1; + else + { + if(EndTile > StartTile) + Spr->animInc = 1; + else + Spr->animInc = 0; + } + } } void CSprites::SetSpriteCollisionShape(CSprite* Spr, ECollisionShape shape, double width, double height, double rotation, float xoffset, float yoffset) { - Spr->collisionShape = shape; - Spr->collisionWidth = width; - Spr->collisionHeight = height; - Spr->collisionAngle = rotation; - Spr->collisionxoffset = xoffset; - Spr->collisionyoffset = yoffset; + Spr->collisionShape = shape; + Spr->collisionWidth = width; + Spr->collisionHeight = height; + Spr->collisionAngle = rotation; + Spr->collisionxoffset = xoffset; + Spr->collisionyoffset = yoffset; } void CSprites::SetSpriteLocation(CSprite* Spr, Vec2F pos ) { - Spr->x = pos.x; - Spr->y = pos.y; + Spr->x = pos.x; + Spr->y = pos.y; } void CSprites::SetSpriteDepth(CSprite* Spr, int depth) { - Spr->depth = depth; - needSpriteSorting = true; + Spr->depth = depth; + needSpriteSorting = true; } int CSprites::GetSpriteAnimFrameCount(CSprite* Spr) { - return max(Spr->animEndTile, Spr->animStartTile) - min(Spr->animEndTile, Spr->animStartTile) + 1; + return max(Spr->animEndTile, Spr->animStartTile) - min(Spr->animEndTile, Spr->animStartTile) + 1; } int CSprites::GetSpriteAnimFrame(CSprite* Spr) { - return Spr->animTile - min(Spr->animEndTile, Spr->animStartTile); + return Spr->animTile - min(Spr->animEndTile, Spr->animStartTile); } SDL_Point CSprites::TileSize(CSprite* Spr) { - return {Spr->tileSizeX, Spr->tileSizeY}; + return {Spr->tileSizeX, Spr->tileSizeY}; } //https://learnopengl.com/In-Practice/2D-Game/Collisions/Collision-Detection# bool CSprites::DetectRectCircleCollsion(CSprite* SprRect, CSprite* SprCircle) { - Vec2F center = {SprCircle->x + SprCircle->collisionxoffset /2.0f, SprCircle->y + SprCircle->collisionyoffset / 2.0f}; - // calculate AABB info (center, half-extents) - Vec2F aabb_half_extents = {abs(SprRect->collisionWidth) * abs(SprRect->xscale) / 2.0f, abs(SprRect->collisionHeight) * abs(SprRect->yscale) / 2.0f}; - Vec2F aabb_center = {SprRect->x + SprRect->collisionxoffset / 2.0f, SprRect->y + SprRect->collisionyoffset / 2.0f}; - - // get difference vector between both centers - Vec2F difference = center - aabb_center; - Vec2F clamped = clamp(difference, -aabb_half_extents, aabb_half_extents); - // add clamped value to AABB_center and we get the value of box closest to circle - Vec2F closest = aabb_center + clamped; - // retrieve vector between center circle and closest point AABB and check if length <= radius - difference = closest - center; - - return length(difference) < (abs(SprCircle->collisionWidth) * abs(SprCircle->xscale) / 2.0f); + Vec2F center = {SprCircle->x + SprCircle->collisionxoffset /2.0f, SprCircle->y + SprCircle->collisionyoffset / 2.0f}; + // calculate AABB info (center, half-extents) + Vec2F aabb_half_extents = {abs(SprRect->collisionWidth) * abs(SprRect->xscale) / 2.0f, abs(SprRect->collisionHeight) * abs(SprRect->yscale) / 2.0f}; + Vec2F aabb_center = {SprRect->x + SprRect->collisionxoffset / 2.0f, SprRect->y + SprRect->collisionyoffset / 2.0f}; + + // get difference vector between both centers + Vec2F difference = center - aabb_center; + Vec2F clamped = clamp(difference, -aabb_half_extents, aabb_half_extents); + // add clamped value to AABB_center and we get the value of box closest to circle + Vec2F closest = aabb_center + clamped; + // retrieve vector between center circle and closest point AABB and check if length <= radius + difference = closest - center; + + return length(difference) < (abs(SprCircle->collisionWidth) * abs(SprCircle->xscale) / 2.0f); } bool CSprites::DetectRectRectCollsion(CSprite* Spr, CSprite* SprOther) { - float widthA = (abs(Spr->collisionWidth) * abs(Spr->xscale)); - float heightA = (abs(Spr->collisionHeight) * abs(Spr->yscale)); - float minAx = Spr->x + Spr->collisionxoffset - (abs(Spr->collisionWidth) * abs(Spr->xscale) / 2); - float minAy = Spr->y + Spr->collisionyoffset - (abs(Spr->collisionHeight) * abs(Spr->yscale) / 2); - - float widthB = (abs(SprOther->collisionWidth) * abs(SprOther->xscale)); - float heightB = (abs(SprOther->collisionHeight) * abs(SprOther->yscale)); - float minBx = SprOther->x + SprOther->collisionxoffset - (abs(SprOther->collisionWidth) * abs(SprOther->xscale) / 2); - float minBy = SprOther->y + SprOther->collisionyoffset - (abs(SprOther->collisionHeight) * abs(SprOther->yscale) / 2); - - bool xOverlap = ((minAx >= minBx) && (minAx <= minBx + widthB)) || - ((minBx >= minAx) && (minBx <= minAx + widthA)); - - bool yOverlap = ((minAy >= minBy) && (minAy <= minBy + heightB)) || - ((minBy >= minAy) && (minBy <= minAy + heightA)); - - return xOverlap && yOverlap; + float widthA = (abs(Spr->collisionWidth) * abs(Spr->xscale)); + float heightA = (abs(Spr->collisionHeight) * abs(Spr->yscale)); + float minAx = Spr->x + Spr->collisionxoffset - (abs(Spr->collisionWidth) * abs(Spr->xscale) / 2); + float minAy = Spr->y + Spr->collisionyoffset - (abs(Spr->collisionHeight) * abs(Spr->yscale) / 2); + + float widthB = (abs(SprOther->collisionWidth) * abs(SprOther->xscale)); + float heightB = (abs(SprOther->collisionHeight) * abs(SprOther->yscale)); + float minBx = SprOther->x + SprOther->collisionxoffset - (abs(SprOther->collisionWidth) * abs(SprOther->xscale) / 2); + float minBy = SprOther->y + SprOther->collisionyoffset - (abs(SprOther->collisionHeight) * abs(SprOther->yscale) / 2); + + bool xOverlap = ((minAx >= minBx) && (minAx <= minBx + widthB)) || + ((minBx >= minAx) && (minBx <= minAx + widthA)); + + bool yOverlap = ((minAy >= minBy) && (minAy <= minBy + heightB)) || + ((minBy >= minAy) && (minBy <= minAy + heightA)); + + return xOverlap && yOverlap; } //takes no rotations into account ! bool CSprites::DetectSpriteCollision(CSprite* Spr, CSprite* SprOther) { - if((Spr == nullptr) || (SprOther == nullptr)) - return false; - - switch(Spr->collisionShape) - { - case SHAPE_BOX: - { - switch(SprOther->collisionShape) - { - case SHAPE_BOX: - return DetectRectRectCollsion(Spr, SprOther); - break; - case SHAPE_CIRCLE: - //only works for true circles not ovals! - if ((SprOther->collisionWidth == SprOther->collisionHeight) && (SprOther->xscale == SprOther->yscale)) - { // check normal rect first - //if (DetectRectRectCollsion(Spr, SprOther)) - return DetectRectCircleCollsion(Spr, SprOther); - //else - // return false; - } - else - return false; - break; - default: - return false; - } - break; - } - case SHAPE_CIRCLE: - { - switch(SprOther->collisionShape) - { - case SHAPE_BOX: - //only works for true circles not ovals! - if ((Spr->collisionWidth == Spr->collisionHeight) && (Spr->xscale == Spr->yscale)) - { - // check normal rect first - //if (DetectRectRectCollsion(Spr, SprOther)) - return DetectRectCircleCollsion(SprOther, Spr); - //else - // return false; - } - else - return false; - break; - default: - return false; - } - break; - } - default: - return false; - } + if((Spr == nullptr) || (SprOther == nullptr)) + return false; + + switch(Spr->collisionShape) + { + case SHAPE_BOX: + { + switch(SprOther->collisionShape) + { + case SHAPE_BOX: + return DetectRectRectCollsion(Spr, SprOther); + break; + case SHAPE_CIRCLE: + //only works for true circles not ovals! + if ((SprOther->collisionWidth == SprOther->collisionHeight) && (SprOther->xscale == SprOther->yscale)) + { // check normal rect first + //if (DetectRectRectCollsion(Spr, SprOther)) + return DetectRectCircleCollsion(Spr, SprOther); + //else + // return false; + } + else + return false; + break; + default: + return false; + } + break; + } + case SHAPE_CIRCLE: + { + switch(SprOther->collisionShape) + { + case SHAPE_BOX: + //only works for true circles not ovals! + if ((Spr->collisionWidth == Spr->collisionHeight) && (Spr->xscale == Spr->yscale)) + { + // check normal rect first + //if (DetectRectRectCollsion(Spr, SprOther)) + return DetectRectCircleCollsion(SprOther, Spr); + //else + // return false; + } + else + return false; + break; + default: + return false; + } + break; + } + default: + return false; + } } int CSprites::SpriteSlotsUsed() { - int c = 0; - for (int i=0; i < SPR_Max; i++) - { - if(Sprites[i] != nullptr) - c++; - } - return c; + int c = 0; + for (int i=0; i < SPR_Max; i++) + { + if(Sprites[i] != nullptr) + c++; + } + return c; } int CSprites::SpriteSlotsMax() { - return SPR_Max; + return SPR_Max; } diff --git a/src/CSprites.h b/src/CSprites.h index a7e14bb..fdc7530 100644 --- a/src/CSprites.h +++ b/src/CSprites.h @@ -10,86 +10,86 @@ constexpr int SPR_Max = 1000; enum ECollisionShape { - SHAPE_BOX, - SHAPE_TRIANGLE, - SHAPE_CIRCLE + SHAPE_BOX, + SHAPE_TRIANGLE, + SHAPE_CIRCLE }; typedef enum ECollisionShape ECollisionShape; class CSprite { - public: - int animInc; - Uint32 animTimer; - int index; - int* imageID; - float x; - float y; - float xscale; - float yscale; - float xspeed; - float yspeed; - float xscale_speed; - float yscale_speed; - double rotation; - int tileSizeX; - int tileSizeY; - int tilesX; - int tilesY; - int animTile; - int animStartTile; - int animEndTile; - int animSpeed; - ECollisionShape collisionShape; - double collisionAngle; - float collisionWidth; - float collisionHeight; - float collisionxoffset; - float collisionyoffset; - int depth; - bool show; - float r; - float g; - float b; - float a; - double rotation_speed; - bool show_collision_shape; + public: + int animInc; + Uint32 animTimer; + int index; + int* imageID; + float x; + float y; + float xscale; + float yscale; + float xspeed; + float yspeed; + float xscale_speed; + float yscale_speed; + double rotation; + int tileSizeX; + int tileSizeY; + int tilesX; + int tilesY; + int animTile; + int animStartTile; + int animEndTile; + int animSpeed; + ECollisionShape collisionShape; + double collisionAngle; + float collisionWidth; + float collisionHeight; + float collisionxoffset; + float collisionyoffset; + int depth; + bool show; + float r; + float g; + float b; + float a; + double rotation_speed; + bool show_collision_shape; }; class CSprites { private: - CSprite* Sprites[SPR_Max]; - CImage* Images; - bool ForceShowCollisionShape; - bool needSpriteSorting; - void SortSprites(); - bool DetectRectRectCollsion(CSprite* Spr, CSprite* SprOther); - bool DetectRectCircleCollsion(CSprite* SprRect, CSprite* SprCircle); + CSprite* Sprites[SPR_Max]; + CImage* Images; + bool ForceShowCollisionShape; + bool needSpriteSorting; + void SortSprites(); + bool DetectRectRectCollsion(CSprite* Spr, CSprite* SprOther); + bool DetectRectCircleCollsion(CSprite* SprRect, CSprite* SprCircle); public: - CSprites(CImage* ACImage); - ~CSprites(); - CSprite* CreateSprite(); - void RemoveSprite(CSprite* Spr); - Vec2F GetSpriteLocation(CSprite* Spr); - void SetForceShowCollisionShape(bool val); - void UpdateSprites(); - void DrawSprite(SDL_Renderer* Renderer, CSprite* Spr); - void DrawSprites(SDL_Renderer* Renderer); - int GetSpriteAnimFrame(CSprite* Spr); - int GetSpriteAnimFrameCount(CSprite* Spr); - void SetSpriteImage(CSprite* Spr, int *AImageID); - void SetSpriteImage(CSprite* Spr, int *AImageID, int TilesX, int TilesY); - void SetSpriteRotation(CSprite* Spr, double AAngle); - void SetSpriteScale(CSprite* Spr, Vec2F AScale); - void SetSpriteAnimation(CSprite* Spr, int StartTile, int EndTile, int animSpeed); - void SetSpriteCollisionShape(CSprite* Spr, ECollisionShape shape, double width, double height, double rotation, float xoffset, float yoffset); - void SetSpriteLocation(CSprite* Spr, Vec2F pos ); - void SetSpriteDepth(CSprite* Spr, int depth); - void SetSpriteColour(CSprite* Spr, float red, float green, float blue, float alpha); - void SetSpriteVisibility(CSprite* Spr, bool visibility); - void SetSpriteRotationSpeed(CSprite* Spr, double rotationSpeed); - bool DetectSpriteCollision(CSprite* Spr, CSprite* SprOther); - SDL_Point TileSize(CSprite* Spr); - int SpriteSlotsUsed(); - int SpriteSlotsMax(); + CSprites(CImage* ACImage); + ~CSprites(); + CSprite* CreateSprite(); + void RemoveSprite(CSprite* Spr); + Vec2F GetSpriteLocation(CSprite* Spr); + void SetForceShowCollisionShape(bool val); + void UpdateSprites(); + void DrawSprite(SDL_Renderer* Renderer, CSprite* Spr); + void DrawSprites(SDL_Renderer* Renderer); + int GetSpriteAnimFrame(CSprite* Spr); + int GetSpriteAnimFrameCount(CSprite* Spr); + void SetSpriteImage(CSprite* Spr, int *AImageID); + void SetSpriteImage(CSprite* Spr, int *AImageID, int TilesX, int TilesY); + void SetSpriteRotation(CSprite* Spr, double AAngle); + void SetSpriteScale(CSprite* Spr, Vec2F AScale); + void SetSpriteAnimation(CSprite* Spr, int StartTile, int EndTile, int animSpeed); + void SetSpriteCollisionShape(CSprite* Spr, ECollisionShape shape, double width, double height, double rotation, float xoffset, float yoffset); + void SetSpriteLocation(CSprite* Spr, Vec2F pos ); + void SetSpriteDepth(CSprite* Spr, int depth); + void SetSpriteColour(CSprite* Spr, float red, float green, float blue, float alpha); + void SetSpriteVisibility(CSprite* Spr, bool visibility); + void SetSpriteRotationSpeed(CSprite* Spr, double rotationSpeed); + bool DetectSpriteCollision(CSprite* Spr, CSprite* SprOther); + SDL_Point TileSize(CSprite* Spr); + int SpriteSlotsUsed(); + int SpriteSlotsMax(); }; diff --git a/src/CTween.cpp b/src/CTween.cpp index 3b5b3a3..2262933 100644 --- a/src/CTween.cpp +++ b/src/CTween.cpp @@ -2,96 +2,96 @@ float smoothstart2(float val) { - return val*val; + return val*val; } float smoothstop2(float val) { - return 1-((1-val)*(1-val)); + return 1-((1-val)*(1-val)); } float smoothstartflip2(float val) { - return 1 - smoothstart2(val); + return 1 - smoothstart2(val); } float smoothstopflip2(float val) { - return 1 - smoothstop2(val); + return 1 - smoothstop2(val); } float mix(float val1, float val2, float blendval) { - return (1-blendval)*val1 + blendval*val2; + return (1-blendval)*val1 + blendval*val2; } float smoothstep3(float val) { - return mix(smoothstart2(val), smoothstop2(val), val); + return mix(smoothstart2(val), smoothstop2(val), val); } float arch(float val) { - return 4*(val)*(1-val); + return 4*(val)*(1-val); } float tweencalcstepinc(float seconds, float FPS) { - return 1/ (FPS * seconds); + return 1/ (FPS * seconds); } float tweencalcmaxticks(float seconds, float FPS) { - return seconds * FPS; + return seconds * FPS; } CTweenInfo createtween(int id, float duration, TweenFunc tweenfunc, float multiplier, bool active, float FPS) { CTweenInfo tween; - tween.maxticks = tweencalcmaxticks(duration, FPS); - tween.ticks = 0; - tween.inc = tweencalcstepinc(duration, FPS); - tween.multiplier = multiplier; - tween.val = 0; - tween.func = tweenfunc; - tween.funcval = 0; - tween.active = active; - tween.id = id; - return tween; + tween.maxticks = tweencalcmaxticks(duration, FPS); + tween.ticks = 0; + tween.inc = tweencalcstepinc(duration, FPS); + tween.multiplier = multiplier; + tween.val = 0; + tween.func = tweenfunc; + tween.funcval = 0; + tween.active = active; + tween.id = id; + return tween; } CTweenInfo updatetween(CTweenInfo tween) { - if (tween.active) - { - if (tween.ticks < tween.maxticks) - { - tween.ticks += 1; - tween.val += tween.inc; - switch(tween.func) - { - case funcsmoothstart: - tween.funcval = smoothstart2(tween.val) * tween.multiplier; - break; - case funcsmoothstop: - tween.funcval = smoothstop2(tween.val) * tween.multiplier; - break; - case funcsmoothstartflip: - tween.funcval = smoothstartflip2(tween.val) * tween.multiplier; - break; - case funcsmoothstopflip: - tween.funcval = smoothstopflip2(tween.val) * tween.multiplier; - break; - case funcsmoothstep: - tween.funcval = smoothstep3(tween.val) * tween.multiplier; - break; - case funcarchstep: - tween.funcval = arch(smoothstep3(tween.val)) * tween.multiplier; - break; - } - } - else - tween.active = false; - } - return tween; + if (tween.active) + { + if (tween.ticks < tween.maxticks) + { + tween.ticks += 1; + tween.val += tween.inc; + switch(tween.func) + { + case funcsmoothstart: + tween.funcval = smoothstart2(tween.val) * tween.multiplier; + break; + case funcsmoothstop: + tween.funcval = smoothstop2(tween.val) * tween.multiplier; + break; + case funcsmoothstartflip: + tween.funcval = smoothstartflip2(tween.val) * tween.multiplier; + break; + case funcsmoothstopflip: + tween.funcval = smoothstopflip2(tween.val) * tween.multiplier; + break; + case funcsmoothstep: + tween.funcval = smoothstep3(tween.val) * tween.multiplier; + break; + case funcarchstep: + tween.funcval = arch(smoothstep3(tween.val)) * tween.multiplier; + break; + } + } + else + tween.active = false; + } + return tween; } \ No newline at end of file diff --git a/src/CTween.h b/src/CTween.h index a4dd296..1524012 100644 --- a/src/CTween.h +++ b/src/CTween.h @@ -2,12 +2,12 @@ enum TweenFunc { - funcsmoothstart = 0, - funcsmoothstop = 1, - funcsmoothstartflip = 3, - funcsmoothstopflip = 4, - funcsmoothstep = 5, - funcarchstep = 6 + funcsmoothstart = 0, + funcsmoothstop = 1, + funcsmoothstartflip = 3, + funcsmoothstopflip = 4, + funcsmoothstep = 5, + funcarchstep = 6 }; class CTweenInfo diff --git a/src/Common.cpp b/src/Common.cpp index 6efe228..edcd9d4 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -6,135 +6,135 @@ //Modes ModeDesc GMModes[Modes] = { - { - GMRetroCarousel, - "Retro Carousel", - "In Retro Carousel mode you will play all games for 2 minutes after each other\n" - "You can not die by losing lives. Points will be deducted from the score when\n" - "dying. The aim is to get the highest score, accumulated over all the games" - }, - { - GMGame, - "Lives Mode", - "In Lives mode you play a single game and start with a fixed amount of lives.\n" - "Dying will lose you one live. The game is over if the lives reaches 0.\n" - "The aim of the game is to get the highest score possible without dying." - }, - { - GMTimeAttack, - "Time Attack", - "In Time Attack mode you play a single game for 5 minutes. You can not die by\n" - "losing lives. Points will be deducted from the score when dying.\n" - "The aim is to get the highest score during these 5 minutes of playing." - } + { + GMRetroCarousel, + "Retro Carousel", + "In Retro Carousel mode you will play all games for 2 minutes after each other\n" + "You can not die by losing lives. Points will be deducted from the score when\n" + "dying. The aim is to get the highest score, accumulated over all the games" + }, + { + GMGame, + "Lives Mode", + "In Lives mode you play a single game and start with a fixed amount of lives.\n" + "Dying will lose you one live. The game is over if the lives reaches 0.\n" + "The aim of the game is to get the highest score possible without dying." + }, + { + GMTimeAttack, + "Time Attack", + "In Time Attack mode you play a single game for 5 minutes. You can not die by\n" + "losing lives. Points will be deducted from the score when dying.\n" + "The aim is to get the highest score during these 5 minutes of playing." + } }; //GameDescriptions GameDesc GSGames[Games] = { - { - GSSpaceInvadersInit,//GSSpaceInvaders, - "Invaders", - "Invaders is a game based on Space Invaders. Rows of enemies\n" - "are closing in you. You have to shoot them down before they\n" - "reach your mining asteroids. Shooting down enemies gains\n" - "points, shooting down all enemies gains extra points\n" - "You can move with dpad of left joystick and shoot with (A).\n" - "If enemies reach your mining asteroids you will lose a life.\n" - "Avoid being shot or you will also lose a life.", - "a game based on Space Invaders (Arcade)" - }, { - GSBreakoutInit, //gsbreakout, - "Brick Breaker", - "Brick Breaker is a game based on Breakout. Rows of blocks\n" - "have to be destroyed by touching them with the ball.\n" - "You control the paddle at the bottom of the screen with\n" - "the left joystick or dpad. Keeping (A) pressed speeds up the\n" - "paddle. You have to let the ball bounce of your paddle to\n" - "send it back in the playfield. Destroying blocks gains points.\n" - "Fail to bounce back the ball and you lose a life", - "a game based on Breakout (Arcade)" + GSSpaceInvadersInit,//GSSpaceInvaders, + "Invaders", + "Invaders is a game based on Space Invaders. Rows of enemies\n" + "are closing in you. You have to shoot them down before they\n" + "reach your mining asteroids. Shooting down enemies gains\n" + "points, shooting down all enemies gains extra points\n" + "You can move with dpad of left joystick and shoot with (A).\n" + "If enemies reach your mining asteroids you will lose a life.\n" + "Avoid being shot or you will also lose a life.", + "a game based on Space Invaders (Arcade)" + }, + { + GSBreakoutInit, //gsbreakout, + "Brick Breaker", + "Brick Breaker is a game based on Breakout. Rows of blocks\n" + "have to be destroyed by touching them with the ball.\n" + "You control the paddle at the bottom of the screen with\n" + "the left joystick or dpad. Keeping (A) pressed speeds up the\n" + "paddle. You have to let the ball bounce of your paddle to\n" + "send it back in the playfield. Destroying blocks gains points.\n" + "Fail to bounce back the ball and you lose a life", + "a game based on Breakout (Arcade)" - }, - { - GSFrogInit,//gsfrog, - "Toady", - "Toady is a game based on Frogger. You control the robot\n" - "by left joystick or dpad and you have to keep moving up.\n" - "Each time you move up to a place you had not reached yet,\n" - "you will gain points. Avoid getting hit by traffic, don't\n" - "fall into water, don't exceed the edges of the playfield\n" - "or you will lose a life. Collect diffrent fruit to gain\n" - "extra score.", - "a game based on Frogger (Arcade)" - }, + }, + { + GSFrogInit,//gsfrog, + "Toady", + "Toady is a game based on Frogger. You control the robot\n" + "by left joystick or dpad and you have to keep moving up.\n" + "Each time you move up to a place you had not reached yet,\n" + "you will gain points. Avoid getting hit by traffic, don't\n" + "fall into water, don't exceed the edges of the playfield\n" + "or you will lose a life. Collect diffrent fruit to gain\n" + "extra score.", + "a game based on Frogger (Arcade)" + }, + { + GSSnakeInit,//gssnake, + "Snakey", + "Snakey is a game based on well snake. You control a snake's\n" + "head (red block) by the left joystick or dpad. The snake\n" + "can move in four directions and wants food (green blocks).\n" + "Each time you eat food the snake's body will grow. Eat\n" + "food to gain points, the longer your snake is to more\n" + "points you will gain. Touching the snake's body or going\n" + "outside the playfield will lose you a life.", + "a game based on Snake (Nokia 3310)", + }, { - GSSnakeInit,//gssnake, - "Snakey", - "Snakey is a game based on well snake. You control a snake's\n" - "head (red block) by the left joystick or dpad. The snake\n" - "can move in four directions and wants food (green blocks).\n" - "Each time you eat food the snake's body will grow. Eat\n" - "food to gain points, the longer your snake is to more\n" - "points you will gain. Touching the snake's body or going\n" - "outside the playfield will lose you a life.", - "a game based on Snake (Nokia 3310)", - }, - { - GSPangInit,//gspang, - "Bubble Buster", - "Bubble Buster is a game based on Pang. You control a player\n" - "that needs to pop bubbles. You can control the player using the left\n" - "joystick or dpad and shoot at bubbles using (A) button. If you hit a\n" - "bubble it will split up into smaller bubbles and you gain points. Get\n" - "hit by a bubble and you will lose a life, making you temporary\n" - "invincible but you can not shoot during this time. Clearing all bubbles\n" - "gives you extra points.", - "a game based on Pang (Arcade)", - }, - { - GSTetrisInit, - "Block Stacker", - "Block Stacker is a game of tetris. You control the blocks\n" - "with the left joystick or dpad. You need to stack them in such a\n" - "manner that they form complete rows. Once this is done that row\n" - "will be removed. Speed increases gradually and having no place\n" - "at the top to place a block will lose you a life. You can rotate\n" - "blocks using (A) and quick drop them using (B).", - "a game based on Tetris" - }, - { - GSRamItInit, - "Color Invasion", - "Color Invasion is a game based on Ram-It. You control the\n" - "cannon with the left joystick or dpad. You need to shoot the invading\n" - "colored bars completely of the screen using (A). Points are awarded when\n" - "the color bar is completely of the screen, the closer a bar had gotten\n" - "to the cannon the more points you will gain. You also gain extra points\n" - "for clearing all bars from the screen. When a colored bar reaches the\n" - "cannon rail you will lose a life.", - "a game based on Ram-It (Atari 2600)" - }, - { - GSEddyInit,//gseddy, - "Faster Dave", - "Faster Dave is a game based on Fast Eddie. You control Dave with the\n" - "left joystick or dpad. You need to avoid or jump over enemies with\n" - "the (A) button while collecting the magic balls. When you collect 9\n" - "balls the end level key is reachable. You are safe on ladders. Points\n" - "are received for collecting magic balls and getting the end level\n" - "key. Collecting the 10th magic ball is not required. When you touch\n" - "an enemy you will a lose life. Every 5 levels, level layout changes.", - "a game based on Fast Eddie (Atari 2600)" - } + GSPangInit,//gspang, + "Bubble Buster", + "Bubble Buster is a game based on Pang. You control a player\n" + "that needs to pop bubbles. You can control the player using the left\n" + "joystick or dpad and shoot at bubbles using (A) button. If you hit a\n" + "bubble it will split up into smaller bubbles and you gain points. Get\n" + "hit by a bubble and you will lose a life, making you temporary\n" + "invincible but you can not shoot during this time. Clearing all bubbles\n" + "gives you extra points.", + "a game based on Pang (Arcade)", + }, + { + GSTetrisInit, + "Block Stacker", + "Block Stacker is a game of tetris. You control the blocks\n" + "with the left joystick or dpad. You need to stack them in such a\n" + "manner that they form complete rows. Once this is done that row\n" + "will be removed. Speed increases gradually and having no place\n" + "at the top to place a block will lose you a life. You can rotate\n" + "blocks using (A) and quick drop them using (B).", + "a game based on Tetris" + }, + { + GSRamItInit, + "Color Invasion", + "Color Invasion is a game based on Ram-It. You control the\n" + "cannon with the left joystick or dpad. You need to shoot the invading\n" + "colored bars completely of the screen using (A). Points are awarded when\n" + "the color bar is completely of the screen, the closer a bar had gotten\n" + "to the cannon the more points you will gain. You also gain extra points\n" + "for clearing all bars from the screen. When a colored bar reaches the\n" + "cannon rail you will lose a life.", + "a game based on Ram-It (Atari 2600)" + }, + { + GSEddyInit,//gseddy, + "Faster Dave", + "Faster Dave is a game based on Fast Eddie. You control Dave with the\n" + "left joystick or dpad. You need to avoid or jump over enemies with\n" + "the (A) button while collecting the magic balls. When you collect 9\n" + "balls the end level key is reachable. You are safe on ladders. Points\n" + "are received for collecting magic balls and getting the end level\n" + "key. Collecting the 10th magic ball is not required. When you touch\n" + "an enemy you will a lose life. Every 5 levels, level layout changes.", + "a game based on Fast Eddie (Atari 2600)" + } }; //PauseMenus //order must equal order from pmvalues !!! -PauseMenuDesc PMPauseMenus[PauseMenus] = -{ - {PMContinue, "Continue"}, - {PMQuit, "Quit"}, +PauseMenuDesc PMPauseMenus[PauseMenus] = +{ + {PMContinue, "Continue"}, + {PMQuit, "Quit"}, {PMMusicVol, "Music Volume: "}, {PMSoundVol, "Sound Volume: "}, {PMMotionBlur, "Sprite Ghosting Effect: "}, @@ -144,41 +144,41 @@ PauseMenuDesc PMPauseMenus[PauseMenus] = //GamePauseMenus GPGamePauseMenusDesc GPGamePauseMenus[Games] = { - {GSSpaceInvaders, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, - {GSBreakout, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, - {GSFrog, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, + {GSSpaceInvaders, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, + {GSBreakout, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, + {GSFrog, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, {GSSnake, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, {GSPang, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, - {GSTetris, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, + {GSTetris, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, {GSRamIt, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}}, {GSEddy, {PMContinue, PMGameHelp, PMMotionBlur, PMCrt, PMMusicVol, PMSoundVol, PMQuit}} }; //MainMenus -MainMenusDesc MMMainMenus[MainMenus] = +MainMenusDesc MMMainMenus[MainMenus] = { - {MMStart, "Start Game"}, - {MMHighScores, "High Scores"}, - {MMOptions, "Options"}, + {MMStart, "Start Game"}, + {MMHighScores, "High Scores"}, + {MMOptions, "Options"}, {MMHelp, "Help"}, {MMCredits, "Credits"}, {MMQuit, "Quit"} }; //OptionsMenus -OptionMenusDesc OMOptionMenus[OptionMenus] = +OptionMenusDesc OMOptionMenus[OptionMenus] = { {OMMusicVol, "Music Volume: "}, {OMSoundVol, "Sound Volume: "}, - {OMMotionBlur, "Sprite Ghosting Effect: "}, + {OMMotionBlur, "Sprite Ghosting Effect: "}, {OMCrt, "Crt Effect: "}, {OMResetHighScores, "Reset Highscores"}, - {OMBack, "Back"} + {OMBack, "Back"} }; //CrtOptions CrtOptDesc CrtOptions[Crts] = -{ +{ {0, "Off"}, {1, "Lines 2"}, {2, "Lines 4"}, diff --git a/src/Common.h b/src/Common.h index f8fa03b..b7998fb 100644 --- a/src/Common.h +++ b/src/Common.h @@ -112,41 +112,41 @@ constexpr int OptionMenus = 6; constexpr int Crts = 6; struct ModeDesc { - int mode; - string name; - string description; + int mode; + string name; + string description; }; struct GameDesc { - int state; - string name; - string description; - string shortdescription; + int state; + string name; + string description; + string shortdescription; }; struct PauseMenuDesc { - int menu; - string name; + int menu; + string name; }; struct GPGamePauseMenusDesc { - int game; - int menus[7]; + int game; + int menus[7]; }; struct MainMenusDesc { - int menu; - string name; + int menu; + string name; }; struct OptionMenusDesc { - int menu; - string name; + int menu; + string name; }; struct CrtOptDesc { - int crt; - string name; + int crt; + string name; }; extern GameDesc GSGames[Games]; @@ -165,8 +165,8 @@ extern SDL_Colour UintToColor(Uint32 colour); template std::string to_string_with_precision(const T a_value, const int n = 6) { - std::ostringstream out; - out.precision(n); - out << std::fixed << a_value; - return out.str(); + std::ostringstream out; + out.precision(n); + out << std::fixed << a_value; + return out.str(); } diff --git a/src/Intro.cpp b/src/Intro.cpp index 4eef0a9..2556b5c 100644 --- a/src/Intro.cpp +++ b/src/Intro.cpp @@ -18,87 +18,87 @@ SDL_Texture* screenshot; void Intro(CGame *Game) { - if(Game->GameState == GSIntroInit) - { - Game->GameState -= initDiff; - } + if(Game->GameState == GSIntroInit) + { + Game->GameState -= initDiff; + } - SDL_Color ClWhite = {255, 255, 255, 255}; - string s; - int w,h; + SDL_Color ClWhite = {255, 255, 255, 255}; + string s; + int w,h; - SDL_SetRenderTarget(Game->Renderer, Game->TexTmp); + SDL_SetRenderTarget(Game->Renderer, Game->TexTmp); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); - SDL_RenderClear(Game->Renderer); - if (scene == 0) - { - s = "Willems Davy aka Joyrider3774"; - w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); - h = tsize*2; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, (ScreenHeight - h) /2, tsize, ClWhite); - - s = "presents"; - w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); - h = tsize; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, (ScreenHeight) /2, tsize, ClWhite); - } - - if (scene == 1) - { - s = "Retro Time"; - w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, 40, tsize*2, ClWhite); - - s = "A game containing"; - w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(),(ScreenWidth - w) / 2, (ScreenHeight - 3 * (tsize + 10)) /2, tsize, ClWhite); - - s = to_string(Games) + " retro based games"; - w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, (ScreenHeight - 1 * (tsize + 10)) / 2, tsize, ClWhite); - - s = "playable in " + to_string(Modes) + " game modes"; - w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, (ScreenHeight + 1 * (tsize + 10)) /2, tsize, ClWhite); - } - - if (scene >= 2) - { - tsize = 30; - - int sheight = (0.75 * ScreenHeight); - int swidth = (0.75 * ScreenWidth); - int sy = (ScreenHeight - sheight) / 2 - tsize - 15; - SDL_Rect DstRect = {(ScreenWidth - swidth) / 2 , sy, swidth, sheight}; - Game->Image->DrawImage(Game->Renderer, Game->GameScreenShots[scene -2], NULL, &DstRect); - - s = string(GSGames[scene -2].name) + " " + string(GSGames[scene -2].shortdescription); - w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, sy + sheight + 15 + tsize/2, tsize, ClWhite); - } - - SDL_SetRenderTarget(Game->Renderer, Game->TexOffScreen); - //SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); - SDL_RenderClear(Game->Renderer); - SDL_Point Pos = {0,0}; - Vec2F Scale = {1,1}; - Game->Image->DrawImageFuzeTintFloat(Game->Renderer, Game->TexTmp, false, &Pos, 0, &Scale, 1, 1, 1, archalpha); - sceneticks += 1; - - if (sceneticks >= maxticks) - { - alpha = 0; - scene += 1; - sceneticks = 0; - } - - if (Game->Input->Buttons.ButA || Game->Input->Buttons.ButB || Game->Input->Buttons.ButBack || Game->Input->Buttons.ButStart || (scene -2 >= Games)) - Game->GameState = GSTitleScreenInit; - - if (alpha < 1) - alpha += alphastep; - else - alpha = 1; - - archalpha = arch(smoothstep3(alpha)); + SDL_RenderClear(Game->Renderer); + if (scene == 0) + { + s = "Willems Davy aka Joyrider3774"; + w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); + h = tsize*2; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, (ScreenHeight - h) /2, tsize, ClWhite); + + s = "presents"; + w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); + h = tsize; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, (ScreenHeight) /2, tsize, ClWhite); + } + + if (scene == 1) + { + s = "Retro Time"; + w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, 40, tsize*2, ClWhite); + + s = "A game containing"; + w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(),(ScreenWidth - w) / 2, (ScreenHeight - 3 * (tsize + 10)) /2, tsize, ClWhite); + + s = to_string(Games) + " retro based games"; + w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, (ScreenHeight - 1 * (tsize + 10)) / 2, tsize, ClWhite); + + s = "playable in " + to_string(Modes) + " game modes"; + w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, (ScreenHeight + 1 * (tsize + 10)) /2, tsize, ClWhite); + } + + if (scene >= 2) + { + tsize = 30; + + int sheight = (0.75 * ScreenHeight); + int swidth = (0.75 * ScreenWidth); + int sy = (ScreenHeight - sheight) / 2 - tsize - 15; + SDL_Rect DstRect = {(ScreenWidth - swidth) / 2, sy, swidth, sheight}; + Game->Image->DrawImage(Game->Renderer, Game->GameScreenShots[scene -2], NULL, &DstRect); + + s = string(GSGames[scene -2].name) + " " + string(GSGames[scene -2].shortdescription); + w = Game->Font->TextWidth("Roboto-Regular", tsize, s, s.length()); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", tsize, s, s.length(), (ScreenWidth - w) / 2, sy + sheight + 15 + tsize/2, tsize, ClWhite); + } + + SDL_SetRenderTarget(Game->Renderer, Game->TexOffScreen); + //SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); + SDL_RenderClear(Game->Renderer); + SDL_Point Pos = {0,0}; + Vec2F Scale = {1,1}; + Game->Image->DrawImageFuzeTintFloat(Game->Renderer, Game->TexTmp, false, &Pos, 0, &Scale, 1, 1, 1, archalpha); + sceneticks += 1; + + if (sceneticks >= maxticks) + { + alpha = 0; + scene += 1; + sceneticks = 0; + } + + if (Game->Input->Buttons.ButA || Game->Input->Buttons.ButB || Game->Input->Buttons.ButBack || Game->Input->Buttons.ButStart || (scene -2 >= Games)) + Game->GameState = GSTitleScreenInit; + + if (alpha < 1) + alpha += alphastep; + else + alpha = 1; + + archalpha = arch(smoothstep3(alpha)); } \ No newline at end of file diff --git a/src/RetroTime.cpp b/src/RetroTime.cpp index 7cec4ab..bd17f6a 100644 --- a/src/RetroTime.cpp +++ b/src/RetroTime.cpp @@ -2,8 +2,8 @@ int main(int argc, char *argv[]) { - CGame *Game = new CGame(); - Game->Run(argc, argv); - delete Game; - return 0; + CGame *Game = new CGame(); + Game->Run(argc, argv); + delete Game; + return 0; } diff --git a/src/SubScoreScreen.cpp b/src/SubScoreScreen.cpp index ba7fd09..ab1d817 100644 --- a/src/SubScoreScreen.cpp +++ b/src/SubScoreScreen.cpp @@ -12,180 +12,179 @@ int prevretrocarouselscore; void InitSubScoreScreen(CGame *Game) { - Game->SubGameState = SGFrame; + Game->SubGameState = SGFrame; Game->SubStateCounter = 0; - wasnewhighscorecarousel = false; + wasnewhighscorecarousel = false; wasnewhighscoregame = false; prevretrocarouselscore = Game->RetroCarouselScore; if (Game->GameMode == GMRetroCarousel) Game->RetroCarouselScore += Game->Scores[Game->Game][Game->GameMode]; - + if (Game->RetroCarouselScore > Game->RetroCarouselHighScore) - { + { Game->RetroCarouselHighScore = Game->RetroCarouselScore; wasnewhighscorecarousel = true; - } + } if (Game->Scores[Game->Game][Game->GameMode] > Game->HighScores[Game->Game][Game->GameMode]) - { + { Game->HighScores[Game->Game][Game->GameMode] = Game->Scores[Game->Game][Game->GameMode]; wasnewhighscoregame = true; - } + } - //savehighscoresoptions() + //savehighscoresoptions() Game->Audio->PlaySound(Game->SfxScore, 0); } void SubScoreScreen(CGame *Game) -{ - if(Game->GameState == GSSubScoreInit) - { - InitSubScoreScreen(Game); - Game->GameState -= initDiff; - } - - SDL_SetRenderTarget(Game->Renderer, Game->TexOffScreen); - Game->ActiveGame->Draw(); - // SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 128); - // SDL_RenderFillRect(Renderer, NULL); - - if (Game->SubGameState == SGFrame) - { - if (Game->SubStateCounter < 10.4f) - Game->SubStateCounter += 0.2f; - else - Game->SubGameState = SGCalcScore; - } - - //so we can can copy the transparant part with the blue and text from this image - SDL_Point pos = {ScreenWidth / 2, ScreenHeight / 2}; - Vec2F Scale = {Game->SubStateCounter / 4, Game->SubStateCounter}; - Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &pos, 0, &Scale, 255, 255, 255, 240); - string Text; - SDL_Point MedalTz = Game->Image->ImageSize(Game->GFXMedal); - Vec2F MedalScale = {30.0f/MedalTz.y, 30.0f/MedalTz.y}; - if (Game->SubGameState == SGCalcScore) - { - if ((Game->Game == Games -1) && (Game->GameMode == GMRetroCarousel)) - { - Text = "Final Results"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 45, Text, Text.length(), 500, 110, 0, {255,255,255,255}); - Text = "-------------------------"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 45, Text, Text.length(), 475, 135, 0, {255,255,255,255}); - } - else - { - Text = "Results"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 45, Text, Text.length(), 560, 110, 0, {255,255,255,255}); - Text = "----------------"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 45, Text, Text.length(), 535, 135, 0, {255,255,255,255}); - } - Text = "Game: " + GSGames[Game->Game].name; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 180, 0, {255,255,255,255}); - Text = "Game Mode: " + GMModes[Game->GameMode].name; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 225, 0, {255,255,255,255}); - - if (Game->GameMode == GMRetroCarousel) - { - Text = "Previous Rounds Score: " + to_string(prevretrocarouselscore); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 285, 0, {255,255,255,255}); - - Text = "Game Score: " + to_string(Game->Scores[Game->Game][Game->GameMode]); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 320, 0, {255,255,255,255}); - - if (Game->Game < Games -1) - Text = "New Total Rounds Score: " + to_string(Game->RetroCarouselScore); - else - Text = "Final Total Rounds Score: " + to_string(Game->RetroCarouselScore); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 355, 0, {255,255,255,255}); - - if (wasnewhighscoregame) - { - Text = "New Game High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 415, 0, {255,255,255,255}); - SDL_Point pos = {270, 415}; - Game->Image->DrawImageFuze(Game->Renderer, Game->GFXMedal, false, &pos, 0, &MedalScale, 255, 255, 255, 255); - } - else - { - Text = "Game High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 415, 0, {255,255,255,255}); - } - - if (wasnewhighscorecarousel) - { - Text = "New All Rounds High Score: " + to_string(Game->RetroCarouselHighScore); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 450, 0, {255,255,255,255}); - SDL_Point pos = {270, 450}; - Game->Image->DrawImageFuze(Game->Renderer, Game->GFXMedal, false, &pos, 0, &MedalScale, 255, 255, 255, 255); - } - else - { - Text = "All Rounds High Score: " + to_string(Game->RetroCarouselHighScore); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 450, 0, {255,255,255,255}); - } - - if (Game->Game < Games -1) - Text = "Press (A) for next game: " + GSGames[Game->Game+1].name; - else - Text = "Press (A) for titlescreen"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 545, 0, {255,255,255,255}); - } - else - { - Text = "Game Score: " + to_string(Game->Scores[Game->Game][Game->GameMode]); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 285, 0, {255,255,255,255}); - - - if (wasnewhighscoregame) - { - Text = "New Game High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 320, 0, {255,255,255,255}); - SDL_Point pos = {270, 320}; - Game->Image->DrawImageFuze(Game->Renderer, Game->GFXMedal, false, &pos, 0, &MedalScale, 255, 255, 255, 255); - } - else - { - Text = "Game High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 320, 0, {255,255,255,255}); - } - Text = "Press (A) for titlescreen"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 545, 0, {255,255,255,255}); - } - } - - SDL_Rect SrcRect = {245,95,790,530}; - //grab transparant part of frame + menu - SDL_Texture *Tmp = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, SrcRect.w, SrcRect.h); - SDL_Texture *TmpRender = SDL_GetRenderTarget(Game->Renderer); - SDL_SetRenderTarget(Game->Renderer, Tmp); - Game->Image->DrawImage(Game->Renderer, Game->TexOffScreen, &SrcRect, NULL); - - //draw the frame again without transparancy - SDL_SetRenderTarget(Game->Renderer, TmpRender); - Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &pos, 0, &Scale, 255, 255, 255, 255); - - //and then draw the transparant part over it now - Game->Image->DrawImage(Game->Renderer, Tmp, NULL, &SrcRect); - SDL_DestroyTexture(Tmp); - - SDL_SetRenderTarget(Game->Renderer, Game->TexScreen); - SDL_RenderCopy(Game->Renderer, Game->TexOffScreen, NULL, NULL); - - if ((!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA) || - (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || - (!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - Game->GameState = GSTitleScreenInit; - if(Game->GameMode == GMRetroCarousel) - { - if(Game->Game < Games -1) - { - Game->Game += 1; - Game->GameState = GSGames[Game->Game].state; - } - } - } +{ + if(Game->GameState == GSSubScoreInit) + { + InitSubScoreScreen(Game); + Game->GameState -= initDiff; + } + + SDL_SetRenderTarget(Game->Renderer, Game->TexOffScreen); + Game->ActiveGame->Draw(); + // SDL_SetRenderDrawColor(Renderer, 0, 0, 0, 128); + // SDL_RenderFillRect(Renderer, NULL); + + if (Game->SubGameState == SGFrame) + { + if (Game->SubStateCounter < 10.4f) + Game->SubStateCounter += 0.2f; + else + Game->SubGameState = SGCalcScore; + } + + //so we can can copy the transparant part with the blue and text from this image + SDL_Point pos = {ScreenWidth / 2, ScreenHeight / 2}; + Vec2F Scale = {Game->SubStateCounter / 4, Game->SubStateCounter}; + Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &pos, 0, &Scale, 255, 255, 255, 240); + string Text; + SDL_Point MedalTz = Game->Image->ImageSize(Game->GFXMedal); + Vec2F MedalScale = {30.0f/MedalTz.y, 30.0f/MedalTz.y}; + if (Game->SubGameState == SGCalcScore) + { + if ((Game->Game == Games -1) && (Game->GameMode == GMRetroCarousel)) + { + Text = "Final Results"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 45, Text, Text.length(), 500, 110, 0, {255,255,255,255}); + Text = "-------------------------"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 45, Text, Text.length(), 475, 135, 0, {255,255,255,255}); + } + else + { + Text = "Results"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 45, Text, Text.length(), 560, 110, 0, {255,255,255,255}); + Text = "----------------"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 45, Text, Text.length(), 535, 135, 0, {255,255,255,255}); + } + Text = "Game: " + GSGames[Game->Game].name; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 180, 0, {255,255,255,255}); + Text = "Game Mode: " + GMModes[Game->GameMode].name; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 225, 0, {255,255,255,255}); + + if (Game->GameMode == GMRetroCarousel) + { + Text = "Previous Rounds Score: " + to_string(prevretrocarouselscore); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 285, 0, {255,255,255,255}); + + Text = "Game Score: " + to_string(Game->Scores[Game->Game][Game->GameMode]); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 320, 0, {255,255,255,255}); + + if (Game->Game < Games -1) + Text = "New Total Rounds Score: " + to_string(Game->RetroCarouselScore); + else + Text = "Final Total Rounds Score: " + to_string(Game->RetroCarouselScore); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 355, 0, {255,255,255,255}); + + if (wasnewhighscoregame) + { + Text = "New Game High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 415, 0, {255,255,255,255}); + SDL_Point pos = {270, 415}; + Game->Image->DrawImageFuze(Game->Renderer, Game->GFXMedal, false, &pos, 0, &MedalScale, 255, 255, 255, 255); + } + else + { + Text = "Game High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 415, 0, {255,255,255,255}); + } + + if (wasnewhighscorecarousel) + { + Text = "New All Rounds High Score: " + to_string(Game->RetroCarouselHighScore); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 450, 0, {255,255,255,255}); + SDL_Point pos = {270, 450}; + Game->Image->DrawImageFuze(Game->Renderer, Game->GFXMedal, false, &pos, 0, &MedalScale, 255, 255, 255, 255); + } + else + { + Text = "All Rounds High Score: " + to_string(Game->RetroCarouselHighScore); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 450, 0, {255,255,255,255}); + } + + if (Game->Game < Games -1) + Text = "Press (A) for next game: " + GSGames[Game->Game+1].name; + else + Text = "Press (A) for titlescreen"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 545, 0, {255,255,255,255}); + } + else + { + Text = "Game Score: " + to_string(Game->Scores[Game->Game][Game->GameMode]); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 285, 0, {255,255,255,255}); + + if (wasnewhighscoregame) + { + Text = "New Game High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 320, 0, {255,255,255,255}); + SDL_Point pos = {270, 320}; + Game->Image->DrawImageFuze(Game->Renderer, Game->GFXMedal, false, &pos, 0, &MedalScale, 255, 255, 255, 255); + } + else + { + Text = "Game High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 320, 0, {255,255,255,255}); + } + Text = "Press (A) for titlescreen"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 545, 0, {255,255,255,255}); + } + } + + SDL_Rect SrcRect = {245,95,790,530}; + //grab transparant part of frame + menu + SDL_Texture *Tmp = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, SrcRect.w, SrcRect.h); + SDL_Texture *TmpRender = SDL_GetRenderTarget(Game->Renderer); + SDL_SetRenderTarget(Game->Renderer, Tmp); + Game->Image->DrawImage(Game->Renderer, Game->TexOffScreen, &SrcRect, NULL); + + //draw the frame again without transparancy + SDL_SetRenderTarget(Game->Renderer, TmpRender); + Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &pos, 0, &Scale, 255, 255, 255, 255); + + //and then draw the transparant part over it now + Game->Image->DrawImage(Game->Renderer, Tmp, NULL, &SrcRect); + SDL_DestroyTexture(Tmp); + + SDL_SetRenderTarget(Game->Renderer, Game->TexScreen); + SDL_RenderCopy(Game->Renderer, Game->TexOffScreen, NULL, NULL); + + if ((!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA) || + (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || + (!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + Game->GameState = GSTitleScreenInit; + if(Game->GameMode == GMRetroCarousel) + { + if(Game->Game < Games -1) + { + Game->Game += 1; + Game->GameState = GSGames[Game->Game].state; + } + } + } } diff --git a/src/TitleScreen.cpp b/src/TitleScreen.cpp index a27d3b7..bfde21e 100644 --- a/src/TitleScreen.cpp +++ b/src/TitleScreen.cpp @@ -5,7 +5,7 @@ #include "TitleScreen.h" #include "Vec2F.h" -int SelectedMenu = 0; +int SelectedMenu = 0; int CurrentMainMenu = -1; int SelMenu = 0; int SelOptions = 0; @@ -17,559 +17,552 @@ constexpr int rdcolor = 1; void InitTitleScreen(CGame *Game) { - Game->Audio->PlayMusic(Game->MusMenu, -1); - Game->StartCrossFade(Game->GameState, SGNone, 0, 0); + Game->Audio->PlayMusic(Game->MusMenu, -1); + Game->StartCrossFade(Game->GameState, SGNone, 0, 0); } void TitleScreen(CGame *Game) { - if(Game->GameState == GSTitleScreenInit) - { - InitTitleScreen(Game); - Game->GameState -= initDiff; - } - //draw everything to offscreen surface - Game->DrawTitleBackground(Game->Input->Buttons.ButLT && Game->Input->Buttons.ButRT); - SDL_SetRenderDrawColor(Game->Renderer, 25, 25, 255, 235); - //so we can can copy the transparant part with the blue and text from this image - SDL_Point FramePos = {ScreenWidth / 2, ScreenHeight / 2}; - Vec2F FrameScale = {10.6f / 4, 10.6f}; - Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &FramePos, 0, &FrameScale, 255, 255, 255, 240); - - string Text = ""; - switch (CurrentMainMenu) - { - case MMOptions: - { - - int selectedmenu = 0; - int menutextsize = 50; - int menuspacing = 65; - - selectedmenu = OMOptionMenus[SelOptions].menu; - Text = "Options"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 535, 110, 0, {255, 255, 255, 255}); - - - int menu; - SDL_Color color; - for(int i = 0; i < OptionMenus; i++) - { - menu = OMOptionMenus[i].menu; - if(menu == selectedmenu) - color = {255, 255, 255, 255}; - else - color = {255, 255, 255, 64}; - - switch(menu) - { - case OMMotionBlur: - if (Game->MotionBlur) - { - Text = OMOptionMenus[menu].name + "Yes"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 400, 185 + i * menuspacing, 0, color); - } - else - { - Text = OMOptionMenus[menu].name + "No"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 400, 185 + i * menuspacing, 0, color); - } - break; - case OMSoundVol: - Text = OMOptionMenus[menu].name + to_string((int)(Game->Audio->GetVolumeSound()*100/128)) + "%"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 400, 185 + i * menuspacing, 0, color); - break; - case OMMusicVol: - Text = OMOptionMenus[menu].name + to_string((int)(Game->Audio->GetVolumeMusic()*100/128)) + "%"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 400, 185 + i * menuspacing, 0, color); - break; - case OMCrt: - Text = OMOptionMenus[menu].name + CrtOptions[Game->Crt].name; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 400, 185 + i * menuspacing, 0, color); - break; - default: - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, OMOptionMenus[menu].name, OMOptionMenus[menu].name.length(), 400, - 185 + i * menuspacing, 0, color); - break; - } - } - Text = "Use left joystick or dpad to switch between options. (A) to select and (B) for back"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 380, 600, 0, {255, 255, 255, 255}); - - if ((!Game->Input->PrevButtons.ButDown && Game->Input->Buttons.ButDown) || - (!Game->Input->PrevButtons.ButDown2 && Game->Input->Buttons.ButDown2) || - (!Game->Input->PrevButtons.ButDpadDown && Game->Input->Buttons.ButDpadDown)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - SelOptions += 1; - if (SelOptions == OptionMenus) - SelOptions = 0; - } - - if ((!Game->Input->PrevButtons.ButUp && Game->Input->Buttons.ButUp) || - (!Game->Input->PrevButtons.ButUp2 && Game->Input->Buttons.ButUp2) || - (!Game->Input->PrevButtons.ButDpadUp && Game->Input->Buttons.ButDpadUp)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - SelOptions -= 1; - if( SelOptions == -1) - SelOptions = OptionMenus - 1; - } - - if ((!Game->Input->PrevButtons.ButLeft && Game->Input->Buttons.ButLeft) || - (!Game->Input->PrevButtons.ButLeft2 && Game->Input->Buttons.ButLeft2) || - (!Game->Input->PrevButtons.ButDpadLeft && Game->Input->Buttons.ButDpadLeft)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - bool wasplaying; - switch (selectedmenu) - { - case OMSoundVol: - Game->Audio->DecVolumeSound(); - break; - - case OMMusicVol: - wasplaying = Game->Audio->IsMusicPlaying(); - Game->Audio->DecVolumeMusic(); - if (!wasplaying) - Game->Audio->PlayMusic(Game->MusMenu, -1); - break; - - case OMMotionBlur: - Game->MotionBlur = !Game->MotionBlur; - break; - - case OMCrt: - Game->Crt -= 1; - if(Game->Crt < 0) - Game->Crt = Crts -1; - Game->ReCreateCrt(); - break; - } - //createcrt(global.crt) - //savehighscoresoptions() - } - - if ((!Game->Input->PrevButtons.ButRight && Game->Input->Buttons.ButRight) || - (!Game->Input->PrevButtons.ButRight2 && Game->Input->Buttons.ButRight2) || - (!Game->Input->PrevButtons.ButDpadRight && Game->Input->Buttons.ButDpadRight)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - bool wasplaying; - switch (selectedmenu) - { - case OMSoundVol: - Game->Audio->IncVolumeSound(); - break; - - case OMMusicVol: - wasplaying = Game->Audio->IsMusicPlaying(); - Game->Audio->IncVolumeMusic(); - if (!wasplaying) - Game->Audio->PlayMusic(Game->MusMenu, -1); - break; - case OMMotionBlur: - Game->MotionBlur = !Game->MotionBlur; - break; - case OMCrt: - Game->Crt += 1; - if(Game->Crt == Crts) - Game->Crt = 0; - Game->ReCreateCrt(); - break; - } - //createcrt(global.crt) - //savehighscoresoptions() - } - - - if ((!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || - (!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB)) - { - Game->Audio->PlaySound(Game->SfxBack, 0); - - CurrentMainMenu = -1; - } - - if ((!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart) || - (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - bool wasplaying; - switch(selectedmenu) - { - case OMBack: - CurrentMainMenu = -1; - break; - case OMResetHighScores: - Game->ResetHighScores(); - //Game->savehighscoresoptions(); - break; - case OMSoundVol: - Game->Audio->IncVolumeSound(); - break; - case OMMusicVol: - wasplaying = Game->Audio->IsMusicPlaying(); - Game->Audio->IncVolumeMusic(); - if(!wasplaying) - Game->Audio->PlayMusic(Game->MusMenu, -1); - break; - case OMMotionBlur: - Game->MotionBlur = !Game->MotionBlur; - break; - case OMCrt: - Game->Crt += 1; - if (Game->Crt == Crts) - Game->Crt = 0; - Game->ReCreateCrt(); - break; - } - //createcrt(global.crt) - //savehighscoresoptions() - } - break; - } - - - case MMHelp: - { - Text = "Help"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 570, 110, 0, {255, 255, 255, 255}); - - Text = - "Retro time is a collection of retro games, each playable in different game modes.\n" - "\n" - "You can control players in games with either the left joystick or the dpad\n" - "Some games play better with the dpad, some with the joystick. Extra actions are\n" - "available, using (A) and (B), depending on the game.\n" - "\n" + if(Game->GameState == GSTitleScreenInit) + { + InitTitleScreen(Game); + Game->GameState -= initDiff; + } + //draw everything to offscreen surface + Game->DrawTitleBackground(Game->Input->Buttons.ButLT && Game->Input->Buttons.ButRT); + SDL_SetRenderDrawColor(Game->Renderer, 25, 25, 255, 235); + //so we can can copy the transparant part with the blue and text from this image + SDL_Point FramePos = {ScreenWidth / 2, ScreenHeight / 2}; + Vec2F FrameScale = {10.6f / 4, 10.6f}; + Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &FramePos, 0, &FrameScale, 255, 255, 255, 240); + + string Text = ""; + switch (CurrentMainMenu) + { + case MMOptions: + { + int selectedmenu = 0; + int menutextsize = 50; + int menuspacing = 65; + + selectedmenu = OMOptionMenus[SelOptions].menu; + Text = "Options"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 535, 110, 0, {255, 255, 255, 255}); + + int menu; + SDL_Color color; + for(int i = 0; i < OptionMenus; i++) + { + menu = OMOptionMenus[i].menu; + if(menu == selectedmenu) + color = {255, 255, 255, 255}; + else + color = {255, 255, 255, 64}; + + switch(menu) + { + case OMMotionBlur: + if (Game->MotionBlur) + { + Text = OMOptionMenus[menu].name + "Yes"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 400, 185 + i * menuspacing, 0, color); + } + else + { + Text = OMOptionMenus[menu].name + "No"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 400, 185 + i * menuspacing, 0, color); + } + break; + case OMSoundVol: + Text = OMOptionMenus[menu].name + to_string((int)(Game->Audio->GetVolumeSound()*100/128)) + "%"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 400, 185 + i * menuspacing, 0, color); + break; + case OMMusicVol: + Text = OMOptionMenus[menu].name + to_string((int)(Game->Audio->GetVolumeMusic()*100/128)) + "%"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 400, 185 + i * menuspacing, 0, color); + break; + case OMCrt: + Text = OMOptionMenus[menu].name + CrtOptions[Game->Crt].name; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 400, 185 + i * menuspacing, 0, color); + break; + default: + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, OMOptionMenus[menu].name, OMOptionMenus[menu].name.length(), 400, + 185 + i * menuspacing, 0, color); + break; + } + } + Text = "Use left joystick or dpad to switch between options. (A) to select and (B) for back"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 380, 600, 0, {255, 255, 255, 255}); + + if ((!Game->Input->PrevButtons.ButDown && Game->Input->Buttons.ButDown) || + (!Game->Input->PrevButtons.ButDown2 && Game->Input->Buttons.ButDown2) || + (!Game->Input->PrevButtons.ButDpadDown && Game->Input->Buttons.ButDpadDown)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + SelOptions += 1; + if (SelOptions == OptionMenus) + SelOptions = 0; + } + + if ((!Game->Input->PrevButtons.ButUp && Game->Input->Buttons.ButUp) || + (!Game->Input->PrevButtons.ButUp2 && Game->Input->Buttons.ButUp2) || + (!Game->Input->PrevButtons.ButDpadUp && Game->Input->Buttons.ButDpadUp)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + SelOptions -= 1; + if( SelOptions == -1) + SelOptions = OptionMenus - 1; + } + + if ((!Game->Input->PrevButtons.ButLeft && Game->Input->Buttons.ButLeft) || + (!Game->Input->PrevButtons.ButLeft2 && Game->Input->Buttons.ButLeft2) || + (!Game->Input->PrevButtons.ButDpadLeft && Game->Input->Buttons.ButDpadLeft)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + bool wasplaying; + switch (selectedmenu) + { + case OMSoundVol: + Game->Audio->DecVolumeSound(); + break; + + case OMMusicVol: + wasplaying = Game->Audio->IsMusicPlaying(); + Game->Audio->DecVolumeMusic(); + if (!wasplaying) + Game->Audio->PlayMusic(Game->MusMenu, -1); + break; + + case OMMotionBlur: + Game->MotionBlur = !Game->MotionBlur; + break; + + case OMCrt: + Game->Crt -= 1; + if(Game->Crt < 0) + Game->Crt = Crts -1; + Game->ReCreateCrt(); + break; + } + //createcrt(global.crt) + //savehighscoresoptions() + } + + if ((!Game->Input->PrevButtons.ButRight && Game->Input->Buttons.ButRight) || + (!Game->Input->PrevButtons.ButRight2 && Game->Input->Buttons.ButRight2) || + (!Game->Input->PrevButtons.ButDpadRight && Game->Input->Buttons.ButDpadRight)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + bool wasplaying; + switch (selectedmenu) + { + case OMSoundVol: + Game->Audio->IncVolumeSound(); + break; + + case OMMusicVol: + wasplaying = Game->Audio->IsMusicPlaying(); + Game->Audio->IncVolumeMusic(); + if (!wasplaying) + Game->Audio->PlayMusic(Game->MusMenu, -1); + break; + case OMMotionBlur: + Game->MotionBlur = !Game->MotionBlur; + break; + case OMCrt: + Game->Crt += 1; + if(Game->Crt == Crts) + Game->Crt = 0; + Game->ReCreateCrt(); + break; + } + //createcrt(global.crt) + //savehighscoresoptions() + } + + + if ((!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || + (!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB)) + { + Game->Audio->PlaySound(Game->SfxBack, 0); + + CurrentMainMenu = -1; + } + + if ((!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart) || + (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + bool wasplaying; + switch(selectedmenu) + { + case OMBack: + CurrentMainMenu = -1; + break; + case OMResetHighScores: + Game->ResetHighScores(); + //Game->savehighscoresoptions(); + break; + case OMSoundVol: + Game->Audio->IncVolumeSound(); + break; + case OMMusicVol: + wasplaying = Game->Audio->IsMusicPlaying(); + Game->Audio->IncVolumeMusic(); + if(!wasplaying) + Game->Audio->PlayMusic(Game->MusMenu, -1); + break; + case OMMotionBlur: + Game->MotionBlur = !Game->MotionBlur; + break; + case OMCrt: + Game->Crt += 1; + if (Game->Crt == Crts) + Game->Crt = 0; + Game->ReCreateCrt(); + break; + } + //createcrt(global.crt) + //savehighscoresoptions() + } + break; + } + + + case MMHelp: + { + Text = "Help"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 570, 110, 0, {255, 255, 255, 255}); + + Text = "Retro time is a collection of retro games, each playable in different game modes.\n" + "\n" + "You can control players in games with either the left joystick or the dpad\n" + "Some games play better with the dpad, some with the joystick. Extra actions are\n" + "available, using (A) and (B), depending on the game.\n" + "\n" "During gameplay you can access the pause menu, by pressing (Start) button\n" - "Pressing it again will resume gameplay.\n" - "\n" + "Pressing it again will resume gameplay.\n" + "\n" "There are 3 game modes: Retro Carousel, Time Attack and Lives mode.\n" - "\n"; - Text += GMModes[0].description + "\n\n" + GMModes[1].description + "\n\n" + GMModes[2].description; - int tw = Game->Font->TextWidth("Roboto-Regular", 17, Text, Text.length()); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 17, Text, Text.length(), (ScreenWidth - tw)/2, 180, 0, {255, 255, 255, 255}); - - - if ((!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA) || - (!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB) || - (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || - (!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart)) - { - Game->Audio->PlaySound(Game->SfxBack, 0); - - CurrentMainMenu = -1; - } - break; - } - case MMCredits: - { - Text = "Credits"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 540, 110, 0, {255, 255, 255, 255}); - - Text = - "Block Stacker (logic) code is heavily inspired on this video from one lone coder (javidx9)\n" - "with my own adaptations:\n" - "https://youtu.be/8OK8_tHeCIA\n" - "\n" - "Snakey (logic) code is based on an edureka article (by Wajiha Urooj) about making snake in\n" - "python:\n" - "https://www.edureka.co/blog/snake-game-with-pygame\n" - "\n" - "Brick Breaker ball / block collision uses a detection seen in wireframe magazine nr 11:\n" - "https://wireframe.raspberrypi.org\n" - "\n" - "Toady water and grass background tiles have been created by me, Willems Davy aka joyrider3774\n" - "feel free to use them. Music is created, payed and owned by me using Strofe:\n" - "https://www.strofe.com\n" - "\n" - "All other assets (including sound) come from either payed or free asset packs.\n" - "For a complete list of credits check the github or itch.io page:\n" - "https://github.com/joyrider3774/RetroTime or https://joyrider3774.itch.io/retrotime\n" - "\n"; - - int tw = Game->Font->TextWidth("Roboto-Regular", 17, Text, Text.length()); + "\n"; + Text += GMModes[0].description + "\n\n" + GMModes[1].description + "\n\n" + GMModes[2].description; + int tw = Game->Font->TextWidth("Roboto-Regular", 17, Text, Text.length()); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 17, Text, Text.length(), (ScreenWidth - tw)/2, 180, 0, {255, 255, 255, 255}); + + + if ((!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA) || + (!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB) || + (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || + (!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart)) + { + Game->Audio->PlaySound(Game->SfxBack, 0); + + CurrentMainMenu = -1; + } + break; + } + case MMCredits: + { + Text = "Credits"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 540, 110, 0, {255, 255, 255, 255}); + + Text = + "Block Stacker (logic) code is heavily inspired on this video from one lone coder (javidx9)\n" + "with my own adaptations:\n" + "https://youtu.be/8OK8_tHeCIA\n" + "\n" + "Snakey (logic) code is based on an edureka article (by Wajiha Urooj) about making snake in\n" + "python:\n" + "https://www.edureka.co/blog/snake-game-with-pygame\n" + "\n" + "Brick Breaker ball / block collision uses a detection seen in wireframe magazine nr 11:\n" + "https://wireframe.raspberrypi.org\n" + "\n" + "Toady water and grass background tiles have been created by me, Willems Davy aka joyrider3774\n" + "feel free to use them. Music is created, payed and owned by me using Strofe:\n" + "https://www.strofe.com\n" + "\n" + "All other assets (including sound) come from either payed or free asset packs.\n" + "For a complete list of credits check the github or itch.io page:\n" + "https://github.com/joyrider3774/RetroTime or https://joyrider3774.itch.io/retrotime\n" + "\n"; + + int tw = Game->Font->TextWidth("Roboto-Regular", 17, Text, Text.length()); Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 17, Text, Text.length(), (ScreenWidth - tw) / 2, 225, 0, {255, 255, 255, 255}); - - if ((!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA) || - (!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB) || - (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || - (!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart)) - { - Game->Audio->PlaySound(Game->SfxBack, 0); - - CurrentMainMenu = -1; - } - break; - } - case MMHighScores: - { - Text = "High Scores"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 485, 110, 0, {255, 255, 255, 255}); - - Text = "Retro Carousel Total highscore: " + to_string(Game->RetroCarouselHighScore); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 300, 195, 0, {255, 255, 255, 255}); - - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, GSGames[Game->Game].name, GSGames[Game->Game].name.length(), 300, 240, 0, {255, 255, 255, 255}); - - SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); - SDL_Rect r = {300, 275, int(ScreenWidth * 0.25) + 4, int(ScreenHeight * 0.25) + 4}; - SDL_RenderFillRect(Game->Renderer, &r); - - SDL_Rect Dst = {302, 277, int(ScreenWidth * 0.25), int(ScreenHeight * 0.25)}; - SDL_Rect Src = {0, 0, ScreenWidth, ScreenHeight}; - SDL_RenderCopy(Game->Renderer, Game->GameScreenShots[Game->Game], &Src, &Dst); - - for(int mode = 0; mode < Modes; mode++) - { - Text = GMModes[mode].name + ": " + to_string(Game->HighScores[Game->Game][mode]); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 300, 470 + mode * 25, 0, {255, 255, 255, 255}); - } - - Text = "Use left joystick, dpad or (A) to switch between games. (B) for back"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 400, 600, 0, {255, 255, 255, 255}); - - if ((!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || - (!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB)) - { - Game->Audio->PlaySound(Game->SfxBack, 0); - - CurrentMainMenu = -1; - } - - if ((!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart) || - (!Game->Input->PrevButtons.ButRight && Game->Input->Buttons.ButRight) || - (!Game->Input->PrevButtons.ButRight2 && Game->Input->Buttons.ButRight2) || - (!Game->Input->PrevButtons.ButDpadRight && Game->Input->Buttons.ButDpadRight) || - (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - Game->Game += 1; - if (Game->Game == Games) - Game->Game = 0; - } - - if ((!Game->Input->PrevButtons.ButLeft && Game->Input->Buttons.ButLeft) || - (!Game->Input->PrevButtons.ButLeft2 && Game->Input->Buttons.ButLeft2) || - (!Game->Input->PrevButtons.ButDpadLeft && Game->Input->Buttons.ButDpadLeft)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - Game->Game -= 1; - if (Game->Game == -1) - Game->Game = Games - 1; - } - break; - } - case MMSelectGame: - { - int gamestate = GSGames[Game->Game].state; - Text = "Select Game"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 485, 110, 0, {255, 255, 255, 255}); - Text = GSGames[Game->Game].name; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 180, 0, {255, 255, 255, 255}); - - SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); - SDL_Rect r = {300, 215, int(ScreenWidth * 0.25) + 4, int(ScreenHeight * 0.25) + 4}; - SDL_RenderFillRect(Game->Renderer, &r); - - SDL_Rect Dst = {302, 217, int(ScreenWidth * 0.25), int(ScreenHeight * 0.25)}; - SDL_Rect Src = {0, 0, ScreenWidth, ScreenHeight}; - SDL_RenderCopy(Game->Renderer, Game->GameScreenShots[Game->Game], &Src, &Dst); - - Text = GMModes[Game->GameMode].name + " High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 300, 410, 0, {255, 255, 255, 255}); - - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, GSGames[Game->Game].description, GSGames[Game->Game].description.length(), 300, 440, 2, {255, 255, 255, 255}); - - Text = "Use left joystick or dpad to switch between games. (A) to select and (B) for back"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 330, 635, 0, {255, 255, 255, 255}); - - if ((!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || - (!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB)) - { - - Game->Audio->PlaySound(Game->SfxBack, 0); - - CurrentMainMenu = MMSelectGameMode; - } - - if ((!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart) || - (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) - { - Game->Audio->PlaySound(Game->SfxConfirm, 0); - - Game->GameState = gamestate; - Game->ResetScores(); - CurrentMainMenu = -1; - Game->Input->ResetButtons(); - } - - if ((!Game->Input->PrevButtons.ButLeft && Game->Input->Buttons.ButLeft) || - (!Game->Input->PrevButtons.ButLeft2 && Game->Input->Buttons.ButLeft2) || - (!Game->Input->PrevButtons.ButDpadLeft && Game->Input->Buttons.ButDpadLeft)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - Game->Game -= 1; - if (Game->Game == -1) - Game->Game = Games - 1; - } - if ((!Game->Input->PrevButtons.ButRight && Game->Input->Buttons.ButRight) || - (!Game->Input->PrevButtons.ButRight2 && Game->Input->Buttons.ButRight2) || - (!Game->Input->PrevButtons.ButDpadRight && Game->Input->Buttons.ButDpadRight)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - Game->Game += 1; - if (Game->Game == Games) - Game->Game = 0; - } - break; - } - case MMSelectGameMode: - { - string Text = "Select Game Mode"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 385, 110, 0, {255, 255, 255, 255}); - - int ModeIterator; - SDL_Color color; - for(int i = 0; i < Modes; i++) - { - ModeIterator = GMModes[i].mode; - if (ModeIterator == Game->GameMode) - color = {255, 255, 255, 255}; - else - color = {255, 255, 255, 64}; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, GMModes[i].name, GMModes[i].name.length(), 470, 225 + i * menuspacing, 0, color); - } - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, GMModes[Game->GameMode].description, GMModes[Game->GameMode].description.length(), - 300, 450, 0, {255,255,255,255}); - - Text = "Use left joystick or dpad to switch between game modes. (A) to select and (B) for back"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 330, 600, 0, {255,255,255,255}); - - if ((!Game->Input->PrevButtons.ButDown && Game->Input->Buttons.ButDown) || - (!Game->Input->PrevButtons.ButDown2 && Game->Input->Buttons.ButDown2) || - (!Game->Input->PrevButtons.ButDpadDown && Game->Input->Buttons.ButDpadDown)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - Game->GameMode += 1; - if (Game->GameMode == Modes) - Game->GameMode = 0; - } - - if ((!Game->Input->PrevButtons.ButUp && Game->Input->Buttons.ButUp) || - (!Game->Input->PrevButtons.ButUp2 && Game->Input->Buttons.ButUp2) || - (!Game->Input->PrevButtons.ButDpadUp && Game->Input->Buttons.ButDpadUp)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - Game->GameMode -= 1; - if (Game->GameMode == -1) - Game->GameMode = Modes - 1; - } - - if ((!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB) || - (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack)) - { - Game->Audio->PlaySound(Game->SfxBack, 0); - CurrentMainMenu = -1; - } - - if ((!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart) || - (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) - { - Game->Audio->PlaySound(Game->SfxConfirm, 0); - - if (Game->GameMode == GMRetroCarousel) - { - Game->Game = 0; - Game->ResetScores(); - CurrentMainMenu = -1; - Game->GameState = GSGames[Game->Game].state; - } - else - CurrentMainMenu = MMSelectGame; - } - break; - } - default: - { - SelMenu = MMMainMenus[SelectedMenu].menu; - - string Text = "Retro Time"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 485, 110, 0, {255, 255, 255, 255}); - - int MenuIterator; - SDL_Color color; - for (int i = 0; i < MainMenus; i++) - { - MenuIterator = MMMainMenus[i].menu; - if (MenuIterator == SelMenu) - color = {255, 255, 255, 255}; - else - color = {255, 255, 255, 64}; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, MMMainMenus[i].name, MMMainMenus[i].name.length(), 500, 200 + i * menuspacing, 0, color); - } - - if ((!Game->Input->PrevButtons.ButDown && Game->Input->Buttons.ButDown) || - (!Game->Input->PrevButtons.ButDown2 && Game->Input->Buttons.ButDown2) || - (!Game->Input->PrevButtons.ButDpadDown && Game->Input->Buttons.ButDpadDown)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - SelectedMenu += 1; - if (SelectedMenu == MainMenus) - SelectedMenu = 0; - } - - if ((!Game->Input->PrevButtons.ButUp && Game->Input->Buttons.ButUp) || - (!Game->Input->PrevButtons.ButUp2 && Game->Input->Buttons.ButUp2) || - (!Game->Input->PrevButtons.ButDpadUp && Game->Input->Buttons.ButDpadUp)) - - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - SelectedMenu -= 1; - if(SelectedMenu == -1) - SelectedMenu = MainMenus - 1; - } - - if ((!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart) || - (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) - { - CurrentMainMenu = SelMenu; - Game->Audio->PlaySound(Game->SfxConfirm, 0); - if (SelMenu == MMQuit) - Game->GameState = GSQuit; - - if (SelMenu == MMStart) - CurrentMainMenu = MMSelectGameMode; - } - } - } - - SDL_Rect SrcRect = {230,85,820,550}; - //grab transparant part of frame + menu - SDL_Texture *Tmp = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, SrcRect.w, SrcRect.h); - SDL_Texture *TmpRender = SDL_GetRenderTarget(Game->Renderer); - SDL_SetRenderTarget(Game->Renderer, Tmp); - Game->Image->DrawImage(Game->Renderer, Game->TexOffScreen, &SrcRect, NULL); - - //draw the frame again without transparancy - SDL_SetRenderTarget(Game->Renderer, TmpRender); + + if ((!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA) || + (!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB) || + (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || + (!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart)) + { + Game->Audio->PlaySound(Game->SfxBack, 0); + + CurrentMainMenu = -1; + } + break; + } + case MMHighScores: + { + Text = "High Scores"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 485, 110, 0, {255, 255, 255, 255}); + + Text = "Retro Carousel Total highscore: " + to_string(Game->RetroCarouselHighScore); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 300, 195, 0, {255, 255, 255, 255}); + + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, GSGames[Game->Game].name, GSGames[Game->Game].name.length(), 300, 240, 0, {255, 255, 255, 255}); + + SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); + SDL_Rect r = {300, 275, int(ScreenWidth * 0.25) + 4, int(ScreenHeight * 0.25) + 4}; + SDL_RenderFillRect(Game->Renderer, &r); + + SDL_Rect Dst = {302, 277, int(ScreenWidth * 0.25), int(ScreenHeight * 0.25)}; + SDL_Rect Src = {0, 0, ScreenWidth, ScreenHeight}; + SDL_RenderCopy(Game->Renderer, Game->GameScreenShots[Game->Game], &Src, &Dst); + + for(int mode = 0; mode < Modes; mode++) + { + Text = GMModes[mode].name + ": " + to_string(Game->HighScores[Game->Game][mode]); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 300, 470 + mode * 25, 0, {255, 255, 255, 255}); + } + + Text = "Use left joystick, dpad or (A) to switch between games. (B) for back"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 400, 600, 0, {255, 255, 255, 255}); + + if ((!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || + (!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB)) + { + Game->Audio->PlaySound(Game->SfxBack, 0); + + CurrentMainMenu = -1; + } + + if ((!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart) || + (!Game->Input->PrevButtons.ButRight && Game->Input->Buttons.ButRight) || + (!Game->Input->PrevButtons.ButRight2 && Game->Input->Buttons.ButRight2) || + (!Game->Input->PrevButtons.ButDpadRight && Game->Input->Buttons.ButDpadRight) || + (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + Game->Game += 1; + if (Game->Game == Games) + Game->Game = 0; + } + + if ((!Game->Input->PrevButtons.ButLeft && Game->Input->Buttons.ButLeft) || + (!Game->Input->PrevButtons.ButLeft2 && Game->Input->Buttons.ButLeft2) || + (!Game->Input->PrevButtons.ButDpadLeft && Game->Input->Buttons.ButDpadLeft)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + Game->Game -= 1; + if (Game->Game == -1) + Game->Game = Games - 1; + } + break; + } + case MMSelectGame: + { + int gamestate = GSGames[Game->Game].state; + Text = "Select Game"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 485, 110, 0, {255, 255, 255, 255}); + Text = GSGames[Game->Game].name; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 180, 0, {255, 255, 255, 255}); + + SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); + SDL_Rect r = {300, 215, int(ScreenWidth * 0.25) + 4, int(ScreenHeight * 0.25) + 4}; + SDL_RenderFillRect(Game->Renderer, &r); + + SDL_Rect Dst = {302, 217, int(ScreenWidth * 0.25), int(ScreenHeight * 0.25)}; + SDL_Rect Src = {0, 0, ScreenWidth, ScreenHeight}; + SDL_RenderCopy(Game->Renderer, Game->GameScreenShots[Game->Game], &Src, &Dst); + + Text = GMModes[Game->GameMode].name + " High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 300, 410, 0, {255, 255, 255, 255}); + + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, GSGames[Game->Game].description, GSGames[Game->Game].description.length(), 300, 440, 2, {255, 255, 255, 255}); + + Text = "Use left joystick or dpad to switch between games. (A) to select and (B) for back"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 330, 635, 0, {255, 255, 255, 255}); + + if ((!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || + (!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB)) + { + Game->Audio->PlaySound(Game->SfxBack, 0); + CurrentMainMenu = MMSelectGameMode; + } + + if ((!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart) || + (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) + { + Game->Audio->PlaySound(Game->SfxConfirm, 0); + + Game->GameState = gamestate; + Game->ResetScores(); + CurrentMainMenu = -1; + Game->Input->ResetButtons(); + } + + if ((!Game->Input->PrevButtons.ButLeft && Game->Input->Buttons.ButLeft) || + (!Game->Input->PrevButtons.ButLeft2 && Game->Input->Buttons.ButLeft2) || + (!Game->Input->PrevButtons.ButDpadLeft && Game->Input->Buttons.ButDpadLeft)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + Game->Game -= 1; + if (Game->Game == -1) + Game->Game = Games - 1; + } + if ((!Game->Input->PrevButtons.ButRight && Game->Input->Buttons.ButRight) || + (!Game->Input->PrevButtons.ButRight2 && Game->Input->Buttons.ButRight2) || + (!Game->Input->PrevButtons.ButDpadRight && Game->Input->Buttons.ButDpadRight)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + Game->Game += 1; + if (Game->Game == Games) + Game->Game = 0; + } + break; + } + case MMSelectGameMode: + { + string Text = "Select Game Mode"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 385, 110, 0, {255, 255, 255, 255}); + + int ModeIterator; + SDL_Color color; + for(int i = 0; i < Modes; i++) + { + ModeIterator = GMModes[i].mode; + if (ModeIterator == Game->GameMode) + color = {255, 255, 255, 255}; + else + color = {255, 255, 255, 64}; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, GMModes[i].name, GMModes[i].name.length(), 470, 225 + i * menuspacing, 0, color); + } + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, GMModes[Game->GameMode].description, GMModes[Game->GameMode].description.length(), + 300, 450, 0, {255,255,255,255}); + + Text = "Use left joystick or dpad to switch between game modes. (A) to select and (B) for back"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 330, 600, 0, {255,255,255,255}); + + if ((!Game->Input->PrevButtons.ButDown && Game->Input->Buttons.ButDown) || + (!Game->Input->PrevButtons.ButDown2 && Game->Input->Buttons.ButDown2) || + (!Game->Input->PrevButtons.ButDpadDown && Game->Input->Buttons.ButDpadDown)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + Game->GameMode += 1; + if (Game->GameMode == Modes) + Game->GameMode = 0; + } + + if ((!Game->Input->PrevButtons.ButUp && Game->Input->Buttons.ButUp) || + (!Game->Input->PrevButtons.ButUp2 && Game->Input->Buttons.ButUp2) || + (!Game->Input->PrevButtons.ButDpadUp && Game->Input->Buttons.ButDpadUp)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + Game->GameMode -= 1; + if (Game->GameMode == -1) + Game->GameMode = Modes - 1; + } + + if ((!Game->Input->PrevButtons.ButB && Game->Input->Buttons.ButB) || + (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack)) + { + Game->Audio->PlaySound(Game->SfxBack, 0); + CurrentMainMenu = -1; + } + + if ((!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart) || + (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) + { + Game->Audio->PlaySound(Game->SfxConfirm, 0); + + if (Game->GameMode == GMRetroCarousel) + { + Game->Game = 0; + Game->ResetScores(); + CurrentMainMenu = -1; + Game->GameState = GSGames[Game->Game].state; + } + else + CurrentMainMenu = MMSelectGame; + } + break; + } + default: + { + SelMenu = MMMainMenus[SelectedMenu].menu; + + string Text = "Retro Time"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 485, 110, 0, {255, 255, 255, 255}); + + int MenuIterator; + SDL_Color color; + for (int i = 0; i < MainMenus; i++) + { + MenuIterator = MMMainMenus[i].menu; + if (MenuIterator == SelMenu) + color = {255, 255, 255, 255}; + else + color = {255, 255, 255, 64}; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, MMMainMenus[i].name, MMMainMenus[i].name.length(), 500, 200 + i * menuspacing, 0, color); + } + + if ((!Game->Input->PrevButtons.ButDown && Game->Input->Buttons.ButDown) || + (!Game->Input->PrevButtons.ButDown2 && Game->Input->Buttons.ButDown2) || + (!Game->Input->PrevButtons.ButDpadDown && Game->Input->Buttons.ButDpadDown)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + SelectedMenu += 1; + if (SelectedMenu == MainMenus) + SelectedMenu = 0; + } + + if ((!Game->Input->PrevButtons.ButUp && Game->Input->Buttons.ButUp) || + (!Game->Input->PrevButtons.ButUp2 && Game->Input->Buttons.ButUp2) || + (!Game->Input->PrevButtons.ButDpadUp && Game->Input->Buttons.ButDpadUp)) + + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + SelectedMenu -= 1; + if(SelectedMenu == -1) + SelectedMenu = MainMenus - 1; + } + + if ((!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart) || + (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) + { + CurrentMainMenu = SelMenu; + Game->Audio->PlaySound(Game->SfxConfirm, 0); + if (SelMenu == MMQuit) + Game->GameState = GSQuit; + + if (SelMenu == MMStart) + CurrentMainMenu = MMSelectGameMode; + } + } + } + + SDL_Rect SrcRect = {230,85,820,550}; + //grab transparant part of frame + menu + SDL_Texture *Tmp = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, SrcRect.w, SrcRect.h); + SDL_Texture *TmpRender = SDL_GetRenderTarget(Game->Renderer); + SDL_SetRenderTarget(Game->Renderer, Tmp); + Game->Image->DrawImage(Game->Renderer, Game->TexOffScreen, &SrcRect, NULL); + + //draw the frame again without transparancy + SDL_SetRenderTarget(Game->Renderer, TmpRender); Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &FramePos, 0, &FrameScale, 255, 255, 255, 255); //and then draw the transparant part over it now - Game->Image->DrawImage(Game->Renderer, Tmp, NULL, &SrcRect); - SDL_DestroyTexture(Tmp); - + Game->Image->DrawImage(Game->Renderer, Tmp, NULL, &SrcRect); + SDL_DestroyTexture(Tmp); - // freeImage(surface) // stopChannel(0) } diff --git a/src/Vec2F.cpp b/src/Vec2F.cpp index 7d4aef2..b7e6399 100644 --- a/src/Vec2F.cpp +++ b/src/Vec2F.cpp @@ -2,16 +2,17 @@ #include #include "Vec2F.h" -float clamp(float value, float min, float max) { - return std::max(min, std::min(max, value)); +float clamp(float value, float min, float max) +{ + return std::max(min, std::min(max, value)); } -Vec2F clamp(Vec2F value, Vec2F min, Vec2F max) +Vec2F clamp(Vec2F value, Vec2F min, Vec2F max) { - return {clamp(value.x, min.x, max.x), clamp(value.y, min.y, max.y)}; -} + return {clamp(value.x, min.x, max.x), clamp(value.y, min.y, max.y)}; +} -float length(Vec2F value) +float length(Vec2F value) { - return sqrt(value.x*value.x + value.y*value.y); -} \ No newline at end of file + return sqrt(value.x*value.x + value.y*value.y); +} \ No newline at end of file diff --git a/src/Vec2F.h b/src/Vec2F.h index fde8b46..8672ed2 100644 --- a/src/Vec2F.h +++ b/src/Vec2F.h @@ -3,67 +3,67 @@ constexpr float epsilion = 0.000001; struct Vec2F { - float x; - float y; - - inline Vec2F operator-() { - return {-x,-y}; - } - - inline Vec2F operator-(float a) { - return {x-a,y-a}; - } - - inline Vec2F operator+(float a) { - return {x+a,y+a}; - } - - inline Vec2F operator*(float a) { - return {x*a,y*a}; - } - - inline Vec2F operator/(float a) { - return {x/a,y/a}; - } - - inline Vec2F operator-(int a) { - return {x-(float)a,y-(float)a}; - } - - inline Vec2F operator+(int a) { - return {x+(float)a,y+(float)a}; - } - - inline Vec2F operator*(int a) { - return {x*(float)a,y*(float)a}; - } - - inline Vec2F operator/(int a) { - return {x/(float)a,y/(float)a}; - } - - inline Vec2F operator+(Vec2F a) { - return {a.x+x,a.y+y}; - } - - inline Vec2F operator-(Vec2F a) { - return {x-a.x,y-a.y}; - } - - inline Vec2F operator*(Vec2F a) { - return {a.x*x,a.y*y}; - } - - inline Vec2F operator/(Vec2F a) { - return {x / a.x, y / a.y}; - } - - inline bool operator==(Vec2F a) { - if ((a.x - x < epsilion) && (a.y - y < epsilion)) - return true; - else - return false; - } + float x; + float y; + + inline Vec2F operator-() { + return {-x,-y}; + } + + inline Vec2F operator-(float a) { + return {x-a,y-a}; + } + + inline Vec2F operator+(float a) { + return {x+a,y+a}; + } + + inline Vec2F operator*(float a) { + return {x*a,y*a}; + } + + inline Vec2F operator/(float a) { + return {x/a,y/a}; + } + + inline Vec2F operator-(int a) { + return {x-(float)a,y-(float)a}; + } + + inline Vec2F operator+(int a) { + return {x+(float)a,y+(float)a}; + } + + inline Vec2F operator*(int a) { + return {x*(float)a,y*(float)a}; + } + + inline Vec2F operator/(int a) { + return {x/(float)a,y/(float)a}; + } + + inline Vec2F operator+(Vec2F a) { + return {a.x+x,a.y+y}; + } + + inline Vec2F operator-(Vec2F a) { + return {x-a.x,y-a.y}; + } + + inline Vec2F operator*(Vec2F a) { + return {a.x*x,a.y*y}; + } + + inline Vec2F operator/(Vec2F a) { + return {x / a.x, y / a.y}; + } + + inline bool operator==(Vec2F a) { + if ((a.x - x < epsilion) && (a.y - y < epsilion)) + return true; + else + return false; + } }; typedef struct Vec2F Vec2F; diff --git a/src/games/BlockStackerBlocks.h b/src/games/BlockStackerBlocks.h index 37be009..cd2020e 100644 --- a/src/games/BlockStackerBlocks.h +++ b/src/games/BlockStackerBlocks.h @@ -1,162 +1,217 @@ #pragma once -int tstetrimos[8][4][16] = { +int tstetrimos[8][4][16] = { - {0,0,1,0, - 0,0,1,0, - 0,0,1,0, - 0,0,1,0}, - - {0,0,0,0, - 1,1,1,1, - 0,0,0,0, - 0,0,0,0}, - - {0,0,1,0, - 0,0,1,0, - 0,0,1,0, - 0,0,1,0}, - - {0,0,0,0, - 1,1,1,1, - 0,0,0,0, - 0,0,0,0} -}, - - -{ - {0,0,1,0, - 0,1,1,0, - 0,0,1,0, - 0,0,0,0}, - - {0,0,1,0, - 0,1,1,1, - 0,0,0,0, - 0,0,0,0}, - - {0,0,1,0, - 0,0,1,1, - 0,0,1,0, - 0,0,0,0}, - - {0,0,0,0, - 0,1,1,1, - 0,0,1,0, - 0,0,0,0} -}, + { + { + 0,0,1,0, + 0,0,1,0, + 0,0,1,0, + 0,0,1,0 + }, + { + 0,0,0,0, + 1,1,1,1, + 0,0,0,0, + 0,0,0,0 + }, -{ - {0,0,0,0, - 0,1,1,0, - 0,1,1,0, - 0,0,0,0}, - - {0,0,0,0, - 0,1,1,0, - 0,1,1,0, - 0,0,0,0}, - - {0,0,0,0, - 0,1,1,0, - 0,1,1,0, - 0,0,0,0}, - - {0,0,0,0, - 0,1,1,0, - 0,1,1,0, - 0,0,0,0} -}, - - -{ - {0,0,1,0, - 0,1,1,0, - 0,1,0,0, - 0,0,0,0}, - - {0,1,1,0, - 0,0,1,1, - 0,0,0,0, - 0,0,0,0}, - - {0,0,1,0, - 0,1,1,0, - 0,1,0,0, - 0,0,0,0}, - - {0,1,1,0, - 0,0,1,1, - 0,0,0,0, - 0,0,0,0} -}, - -{ - {0,1,0,0, - 0,1,1,0, - 0,0,1,0, - 0,0,0,0}, - - {0,0,1,1, - 0,1,1,0, - 0,0,0,0, - 0,0,0,0}, - - {0,1,0,0, - 0,1,1,0, - 0,0,1,0, - 0,0,0,0}, - - {0,0,1,1, - 0,1,1,0, - 0,0,0,0, - 0,0,0,0} -}, - - -{ - {0,1,0,0, - 0,1,0,0, - 0,1,1,0, - 0,0,0,0}, - - {0,1,1,1, - 0,1,0,0, - 0,0,0,0, - 0,0,0,0}, - - {0,1,1,0, - 0,0,1,0, - 0,0,1,0, - 0,0,0,0}, - - {0,0,0,1, - 0,1,1,1, - 0,0,0,0, - 0,0,0,0} -}, - -{ - {0,0,1,0, - 0,0,1,0, - 0,1,1,0, - 0,0,0,0}, - - {0,1,0,0, - 0,1,1,1, - 0,0,0,0, - 0,0,0,0}, - - {0,1,1,0, - 0,1,0,0, - 0,1,0,0, - 0,0,0,0}, - - {0,1,1,1, - 0,0,0,1, - 0,0,0,0, - 0,0,0,0} -} + { + 0,0,1,0, + 0,0,1,0, + 0,0,1,0, + 0,0,1,0 + }, + + { + 0,0,0,0, + 1,1,1,1, + 0,0,0,0, + 0,0,0,0 + } + }, + + + { + { + 0,0,1,0, + 0,1,1,0, + 0,0,1,0, + 0,0,0,0 + }, + + { + 0,0,1,0, + 0,1,1,1, + 0,0,0,0, + 0,0,0,0 + }, + + { + 0,0,1,0, + 0,0,1,1, + 0,0,1,0, + 0,0,0,0 + }, + + { + 0,0,0,0, + 0,1,1,1, + 0,0,1,0, + 0,0,0,0 + } + }, + + + { + { + 0,0,0,0, + 0,1,1,0, + 0,1,1,0, + 0,0,0,0 + }, + + { + 0,0,0,0, + 0,1,1,0, + 0,1,1,0, + 0,0,0,0 + }, + + { + 0,0,0,0, + 0,1,1,0, + 0,1,1,0, + 0,0,0,0 + }, + + { + 0,0,0,0, + 0,1,1,0, + 0,1,1,0, + 0,0,0,0 + } + }, + + { + { + 0,0,1,0, + 0,1,1,0, + 0,1,0,0, + 0,0,0,0 + }, + + { + 0,1,1,0, + 0,0,1,1, + 0,0,0,0, + 0,0,0,0 + }, + + { + 0,0,1,0, + 0,1,1,0, + 0,1,0,0, + 0,0,0,0 + }, + + { + 0,1,1,0, + 0,0,1,1, + 0,0,0,0, + 0,0,0,0 + } + }, + + { + { + 0,1,0,0, + 0,1,1,0, + 0,0,1,0, + 0,0,0,0 + }, + + { + 0,0,1,1, + 0,1,1,0, + 0,0,0,0, + 0,0,0,0 + }, + + { + 0,1,0,0, + 0,1,1,0, + 0,0,1,0, + 0,0,0,0 + }, + + { + 0,0,1,1, + 0,1,1,0, + 0,0,0,0, + 0,0,0,0 + } + }, + + + { + { + 0,1,0,0, + 0,1,0,0, + 0,1,1,0, + 0,0,0,0 + }, + + { + 0,1,1,1, + 0,1,0,0, + 0,0,0,0, + 0,0,0,0 + }, + + { + 0,1,1,0, + 0,0,1,0, + 0,0,1,0, + 0,0,0,0 + }, + + { + 0,0,0,1, + 0,1,1,1, + 0,0,0,0, + 0,0,0,0 + } + }, + + { + { + 0,0,1,0, + 0,0,1,0, + 0,1,1,0, + 0,0,0,0 + }, + + { + 0,1,0,0, + 0,1,1,1, + 0,0,0,0, + 0,0,0,0 + }, + + { + 0,1,1,0, + 0,1,0,0, + 0,1,0,0, + 0,0,0,0 + }, + { + 0,1,1,1, + 0,0,0,1, + 0,0,0,0, + 0,0,0,0 + } + } }; diff --git a/src/games/CGameBase.cpp b/src/games/CGameBase.cpp index 38fa2a3..30bc40b 100644 --- a/src/games/CGameBase.cpp +++ b/src/games/CGameBase.cpp @@ -4,12 +4,12 @@ CGameBase::CGameBase(CGame *aGame, int aGameStateID, bool aUsesLevels, bool aScreenshotMode) { - Game = aGame; - ScreenshotMode = aScreenshotMode; - UsesLevels = aUsesLevels; - GameStateID = aGameStateID; - level = 0; - HealthPoints = 0; + Game = aGame; + ScreenshotMode = aScreenshotMode; + UsesLevels = aUsesLevels; + GameStateID = aGameStateID; + level = 0; + HealthPoints = 0; } CGameBase::~CGameBase() @@ -57,427 +57,425 @@ void CGameBase::PauseMenu() int prevsubgamestate = Game->SubGameState; int prevsubstatecounter = Game->SubStateCounter; Game->SubGameState = SGPauseMenu; - Game->Audio->PlaySound(Game->SfxConfirm, 0); - //subgamestate = sgframe; + Game->Audio->PlaySound(Game->SfxConfirm, 0); + //subgamestate = sgframe; //global.substatecounter = 10.6 - int selected = 0; + int selected = 0; int selectedmenu = 0; - int maxmenus = 7; + int maxmenus = 7; int menutextsize = 45; int menuspacing = 55; - Game->Input->ResetButtons(); + Game->Input->ResetButtons(); - Uint64 TotalFrames = 0; - Uint64 TotalFramePerf = 0; - Uint32 Fps = 0; - double AvgFrameTime = 0.0f; - Uint32 Ticks = SDL_GetTicks(); + Uint64 TotalFrames = 0; + Uint64 TotalFramePerf = 0; + Uint32 Fps = 0; + double AvgFrameTime = 0.0f; + Uint32 Ticks = SDL_GetTicks(); while ((Game->SubGameState == SGFrame) || (Game->SubGameState == SGPauseMenu) || (Game->SubGameState == SGGameHelp)) - { - TotalFrames++; - Uint64 FrameStartPerf = SDL_GetPerformanceCounter(); + { + TotalFrames++; + Uint64 FrameStartPerf = SDL_GetPerformanceCounter(); selectedmenu = GPGamePauseMenus[Game->Game].menus[selected]; - //draw everything to offscreen surface + //draw everything to offscreen surface SDL_SetRenderTarget(Game->Renderer, Game->TexOffScreen); - Draw(); //game - - // this seems to cause a blackscreen somehow when certain games - // are paused not sure as to why but i disabled it for now - // SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 128); - // SDL_RenderFillRect(Game->Renderer, NULL); - - //draw everything to offscreen surface - SDL_SetRenderDrawColor(Game->Renderer, 25, 25, 255, 235); - //so we can can copy the transparant part with the blue and text from this image - SDL_Point FramePos = {ScreenWidth / 2, ScreenHeight / 2}; - Vec2F FrameScale = {10.6f / 4, 10.6f}; - Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &FramePos, 0, &FrameScale, 255, 255, 255, 240); - - if (Game->SubGameState == SGPauseMenu) - { - string Text = "Paused"; + Draw(); //game + + // this seems to cause a blackscreen somehow when certain games + // are paused not sure as to why but i disabled it for now + // SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 128); + // SDL_RenderFillRect(Game->Renderer, NULL); + + //draw everything to offscreen surface + SDL_SetRenderDrawColor(Game->Renderer, 25, 25, 255, 235); + //so we can can copy the transparant part with the blue and text from this image + SDL_Point FramePos = {ScreenWidth / 2, ScreenHeight / 2}; + Vec2F FrameScale = {10.6f / 4, 10.6f}; + Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &FramePos, 0, &FrameScale, 255, 255, 255, 240); + + if (Game->SubGameState == SGPauseMenu) + { + string Text = "Paused"; Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 530, 110, 0, {255,255,255,255}); int menu; SDL_Color color; for(int i = 0; i < maxmenus; i++) - { + { menu = GPGamePauseMenus[Game->Game].menus[i]; if (menu == selectedmenu) color = {255, 255, 255, 255}; else color = {255, 255, 255, 64}; - + switch(menu) - { - case PMMotionBlur: - if (Game->MotionBlur) - Text = PMPauseMenus[menu].name + "Yes"; - else - Text = PMPauseMenus[menu].name + "No"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 300, 180 + i * menuspacing, 0, color); - break; - case PMSoundVol: - Text = PMPauseMenus[menu].name + to_string(((int)(Game->Audio->GetVolumeSound()*100/128))) + "%"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 300, 180 + i * menuspacing, 0, color); - break; - case PMMusicVol: - Text = PMPauseMenus[menu].name + to_string((int)(Game->Audio->GetVolumeMusic()*100/128)) + "%"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 300, 180 + i * menuspacing, 0, color); - break; + { + case PMMotionBlur: + if (Game->MotionBlur) + Text = PMPauseMenus[menu].name + "Yes"; + else + Text = PMPauseMenus[menu].name + "No"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 300, 180 + i * menuspacing, 0, color); + break; + case PMSoundVol: + Text = PMPauseMenus[menu].name + to_string(((int)(Game->Audio->GetVolumeSound()*100/128))) + "%"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 300, 180 + i * menuspacing, 0, color); + break; + case PMMusicVol: + Text = PMPauseMenus[menu].name + to_string((int)(Game->Audio->GetVolumeMusic()*100/128)) + "%"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 300, 180 + i * menuspacing, 0, color); + break; case PMCrt: - Text = PMPauseMenus[menu].name + CrtOptions[Game->Crt].name; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 300, 180 + i * menuspacing, 0, color); - break; - default: - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, PMPauseMenus[menu].name, PMPauseMenus[menu].name.length(), 300, 180 + i * menuspacing, 0, color); - break; - } - } + Text = PMPauseMenus[menu].name + CrtOptions[Game->Crt].name; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, Text, Text.length(), 300, 180 + i * menuspacing, 0, color); + break; + default: + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", menutextsize, PMPauseMenus[menu].name, PMPauseMenus[menu].name.length(), 300, 180 + i * menuspacing, 0, color); + break; + } + } Text = "Press (A) to select, Left joystick or dpad change values"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 330, 635, 0, {1,1,1,1}); - } - - if (Game->SubGameState == SGGameHelp) - { - string Text = "Game Help"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 505, 110, 0, {255,255,255,255}); - - Text = GSGames[Game->Game].name; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 180, 0, {255,255,255,255}); - - SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); - SDL_Rect r = {300, 215, int(ScreenWidth * 0.25) + 4, int(ScreenHeight * 0.25) + 4}; - SDL_RenderFillRect(Game->Renderer, &r); - - SDL_Rect Dst = {302, 217, int(ScreenWidth * 0.25), int(ScreenHeight * 0.25)}; - SDL_Rect Src = {0, 0, ScreenWidth, ScreenHeight}; - SDL_RenderCopy(Game->Renderer, Game->GameScreenShots[Game->Game], &Src, &Dst); - - Text = GMModes[Game->GameMode].name + " High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 300, 410, 0, {255,255,255,255}); - - Text = GSGames[Game->Game].description; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 300, 440, 0, {255,255,255,255}); - - Text = "Use (A) or (B) for back"; - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 580, 635, 0, {255,255,255,255}); - } - - Game->Input->Update(); - - if (Game->Input->Buttons.ButQuit) - { - Game->GameState = GSQuit; - Game->SubGameState = GSGame; - } - - //Need to recreate screenshots and background - if(Game->Input->Buttons.RenderReset) - { - SDL_Log("Render Reset, Recreating crt and background, Reloading Game Graphics"); - Game->Image->UnloadImages(); - LoadGraphics(); - Game->LoadGraphics(); - Game->CreateScreenshotsAndBackground(); - Game->ReCreateCrt(); - } - - if (Game->SubGameState == SGGameHelp) - { - if ((Game->Input->Buttons.ButB && !Game->Input->PrevButtons.ButB) || - (Game->Input->Buttons.ButA && !Game->Input->PrevButtons.ButA) || - (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || - (!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart)) - { - Game->Audio->PlaySound(Game->SfxBack, 0); - Game->SubGameState = SGPauseMenu; - Game->Input->ResetButtons(); - } - } - - if (Game->SubGameState == SGPauseMenu) - { - if ((!Game->Input->PrevButtons.ButLeft && Game->Input->Buttons.ButLeft) || - (!Game->Input->PrevButtons.ButLeft2 && Game->Input->Buttons.ButLeft2) || - (!Game->Input->PrevButtons.ButDpadLeft && Game->Input->Buttons.ButDpadLeft)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - switch(selectedmenu) - { - case PMSoundVol: - { - Game->Audio->DecVolumeSound(); - break; - } - - case PMMusicVol: - { - bool wasplaying = Game->Audio->IsMusicPlaying(); - Game->Audio->DecVolumeMusic(); - if (!wasplaying) - Game->Audio->PlayMusic(Game->CurrentGameMusicID, -1); - break; - } - - case PMMotionBlur: - { - Game->MotionBlur = !Game->MotionBlur; - break; - } - - case PMCrt: - { - Game->Crt -= 1; - if (Game->Crt < 0) - Game->Crt = Crts -1; - Game->ReCreateCrt(); - break; - } - } - } - - if ((!Game->Input->PrevButtons.ButRight && Game->Input->Buttons.ButRight) || - (!Game->Input->PrevButtons.ButRight2 && Game->Input->Buttons.ButRight2) || - (!Game->Input->PrevButtons.ButDpadRight && Game->Input->Buttons.ButDpadRight)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - switch(selectedmenu) - { - case PMSoundVol: - { - Game->Audio->IncVolumeSound(); - break; - } - - case PMMusicVol: - { - bool wasplaying = Game->Audio->IsMusicPlaying(); - Game->Audio->IncVolumeMusic(); - if (!wasplaying) - Game->Audio->PlayMusic(Game->CurrentGameMusicID, -1); - break; - } - - case PMMotionBlur: - { - Game->MotionBlur = !Game->MotionBlur; - break; - } - - case PMCrt: - { - Game->Crt += 1; - if (Game->Crt == Crts) - Game->Crt = 0; - Game->ReCreateCrt(); - break; - } - } - } - - if ((!Game->Input->PrevButtons.ButDown && Game->Input->Buttons.ButDown) || - (!Game->Input->PrevButtons.ButDown2 && Game->Input->Buttons.ButDown2) || - (!Game->Input->PrevButtons.ButDpadDown && Game->Input->Buttons.ButDpadDown)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - selected += 1; - if (selected == maxmenus) - selected = 0; - - } - - if ((!Game->Input->PrevButtons.ButUp && Game->Input->Buttons.ButUp) || - (!Game->Input->PrevButtons.ButUp2 && Game->Input->Buttons.ButUp2) || - (!Game->Input->PrevButtons.ButDpadUp && Game->Input->Buttons.ButDpadUp)) - { - Game->Audio->PlaySound(Game->SfxSelect, 0); - - selected -= 1; - if (selected == -1) - selected = maxmenus - 1; - - } - - if (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) - { - Game->Audio->PlaySound(Game->SfxConfirm, 0); - - Game->SubGameState = prevsubgamestate; - Game->SubStateCounter = prevsubstatecounter; - } - - if ((!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA) || - (!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart)) - { - Game->Audio->PlaySound(Game->SfxConfirm, 0); - - switch(selectedmenu) - { - case PMContinue: - { - //to fix tetris block rotating or dropping - //when choosing continue with a or a with b pressed - while (Game->Input->Buttons.ButA || Game->Input->Buttons.ButB) - Game->Input->Update(); - - Game->SubGameState = prevsubgamestate; - Game->SubStateCounter = prevsubstatecounter; - break; - } - - case PMQuit: - { - Game->StartCrossFade(GSTitleScreenInit, SGNone, 3, 500); - break; - } - - case PMSoundVol: - { - Game->Audio->IncVolumeSound(); - break; - } - - case PMMusicVol: - { - bool wasplaying = Game->Audio->IsMusicPlaying(); - Game->Audio->IncVolumeMusic(); - if(!wasplaying) - Game->Audio->PlayMusic(Game->CurrentGameMusicID, -1); - break; - } - - case PMMotionBlur: - { - Game->MotionBlur = ! Game->MotionBlur; - break; - } - - case PMCrt: - { - Game->Crt += 1; - if (Game->Crt == Crts) - Game->Crt = 0; - Game->ReCreateCrt(); - break; - } - - case PMGameHelp: - { - Game->SubGameState = SGGameHelp; - Game->Input->ResetButtons(); - break; - } - } - } - } - - SDL_Rect SrcRect = {230,85,820,550}; - //grab transparant part of frame + menu - SDL_Texture *Tmp = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, SrcRect.w, SrcRect.h); - SDL_Texture *TmpRender = SDL_GetRenderTarget(Game->Renderer); - SDL_SetRenderTarget(Game->Renderer, Tmp); - Game->Image->DrawImage(Game->Renderer, Game->TexOffScreen, &SrcRect, NULL); - - //draw the frame again without transparancy - SDL_SetRenderTarget(Game->Renderer, TmpRender); - Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &FramePos, 0, &FrameScale, 255, 255, 255, 255); - - //and then draw the transparant part over it now - Game->Image->DrawImage(Game->Renderer, Tmp, NULL, &SrcRect); - SDL_DestroyTexture(Tmp); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 330, 635, 0, {1,1,1,1}); + } + + if (Game->SubGameState == SGGameHelp) + { + string Text = "Game Help"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, Text, Text.length(), 505, 110, 0, {255,255,255,255}); + + Text = GSGames[Game->Game].name; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 30, Text, Text.length(), 300, 180, 0, {255,255,255,255}); + + SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); + SDL_Rect r = {300, 215, int(ScreenWidth * 0.25) + 4, int(ScreenHeight * 0.25) + 4}; + SDL_RenderFillRect(Game->Renderer, &r); + + SDL_Rect Dst = {302, 217, int(ScreenWidth * 0.25), int(ScreenHeight * 0.25)}; + SDL_Rect Src = {0, 0, ScreenWidth, ScreenHeight}; + SDL_RenderCopy(Game->Renderer, Game->GameScreenShots[Game->Game], &Src, &Dst); + + Text = GMModes[Game->GameMode].name + " High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 300, 410, 0, {255,255,255,255}); + + Text = GSGames[Game->Game].description; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 300, 440, 0, {255,255,255,255}); + + Text = "Use (A) or (B) for back"; + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 15, Text, Text.length(), 580, 635, 0, {255,255,255,255}); + } + + Game->Input->Update(); + + if (Game->Input->Buttons.ButQuit) + { + Game->GameState = GSQuit; + Game->SubGameState = GSGame; + } + + //Need to recreate screenshots and background + if(Game->Input->Buttons.RenderReset) + { + SDL_Log("Render Reset, Recreating crt and background, Reloading Game Graphics"); + Game->Image->UnloadImages(); + LoadGraphics(); + Game->LoadGraphics(); + Game->CreateScreenshotsAndBackground(); + Game->ReCreateCrt(); + } + + if (Game->SubGameState == SGGameHelp) + { + if ((Game->Input->Buttons.ButB && !Game->Input->PrevButtons.ButB) || + (Game->Input->Buttons.ButA && !Game->Input->PrevButtons.ButA) || + (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) || + (!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart)) + { + Game->Audio->PlaySound(Game->SfxBack, 0); + Game->SubGameState = SGPauseMenu; + Game->Input->ResetButtons(); + } + } + + if (Game->SubGameState == SGPauseMenu) + { + if ((!Game->Input->PrevButtons.ButLeft && Game->Input->Buttons.ButLeft) || + (!Game->Input->PrevButtons.ButLeft2 && Game->Input->Buttons.ButLeft2) || + (!Game->Input->PrevButtons.ButDpadLeft && Game->Input->Buttons.ButDpadLeft)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + switch(selectedmenu) + { + case PMSoundVol: + { + Game->Audio->DecVolumeSound(); + break; + } + + case PMMusicVol: + { + bool wasplaying = Game->Audio->IsMusicPlaying(); + Game->Audio->DecVolumeMusic(); + if (!wasplaying) + Game->Audio->PlayMusic(Game->CurrentGameMusicID, -1); + break; + } + + case PMMotionBlur: + { + Game->MotionBlur = !Game->MotionBlur; + break; + } + + case PMCrt: + { + Game->Crt -= 1; + if (Game->Crt < 0) + Game->Crt = Crts -1; + Game->ReCreateCrt(); + break; + } + } + } + + if ((!Game->Input->PrevButtons.ButRight && Game->Input->Buttons.ButRight) || + (!Game->Input->PrevButtons.ButRight2 && Game->Input->Buttons.ButRight2) || + (!Game->Input->PrevButtons.ButDpadRight && Game->Input->Buttons.ButDpadRight)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + switch(selectedmenu) + { + case PMSoundVol: + { + Game->Audio->IncVolumeSound(); + break; + } + + case PMMusicVol: + { + bool wasplaying = Game->Audio->IsMusicPlaying(); + Game->Audio->IncVolumeMusic(); + if (!wasplaying) + Game->Audio->PlayMusic(Game->CurrentGameMusicID, -1); + break; + } + + case PMMotionBlur: + { + Game->MotionBlur = !Game->MotionBlur; + break; + } + + case PMCrt: + { + Game->Crt += 1; + if (Game->Crt == Crts) + Game->Crt = 0; + Game->ReCreateCrt(); + break; + } + } + } + + if ((!Game->Input->PrevButtons.ButDown && Game->Input->Buttons.ButDown) || + (!Game->Input->PrevButtons.ButDown2 && Game->Input->Buttons.ButDown2) || + (!Game->Input->PrevButtons.ButDpadDown && Game->Input->Buttons.ButDpadDown)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + selected += 1; + if (selected == maxmenus) + selected = 0; + } + + if ((!Game->Input->PrevButtons.ButUp && Game->Input->Buttons.ButUp) || + (!Game->Input->PrevButtons.ButUp2 && Game->Input->Buttons.ButUp2) || + (!Game->Input->PrevButtons.ButDpadUp && Game->Input->Buttons.ButDpadUp)) + { + Game->Audio->PlaySound(Game->SfxSelect, 0); + + selected -= 1; + if (selected == -1) + selected = maxmenus - 1; + } + + if (!Game->Input->PrevButtons.ButBack && Game->Input->Buttons.ButBack) + { + Game->Audio->PlaySound(Game->SfxConfirm, 0); + + Game->SubGameState = prevsubgamestate; + Game->SubStateCounter = prevsubstatecounter; + } + + if ((!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA) || + (!Game->Input->PrevButtons.ButStart && Game->Input->Buttons.ButStart)) + { + Game->Audio->PlaySound(Game->SfxConfirm, 0); + + switch(selectedmenu) + { + case PMContinue: + { + //to fix tetris block rotating or dropping + //when choosing continue with a or a with b pressed + while (Game->Input->Buttons.ButA || Game->Input->Buttons.ButB) + Game->Input->Update(); + + Game->SubGameState = prevsubgamestate; + Game->SubStateCounter = prevsubstatecounter; + break; + } + + case PMQuit: + { + Game->StartCrossFade(GSTitleScreenInit, SGNone, 3, 500); + break; + } + + case PMSoundVol: + { + Game->Audio->IncVolumeSound(); + break; + } + + case PMMusicVol: + { + bool wasplaying = Game->Audio->IsMusicPlaying(); + Game->Audio->IncVolumeMusic(); + if(!wasplaying) + Game->Audio->PlayMusic(Game->CurrentGameMusicID, -1); + break; + } + + case PMMotionBlur: + { + Game->MotionBlur = ! Game->MotionBlur; + break; + } + + case PMCrt: + { + Game->Crt += 1; + if (Game->Crt == Crts) + Game->Crt = 0; + Game->ReCreateCrt(); + break; + } + + case PMGameHelp: + { + Game->SubGameState = SGGameHelp; + Game->Input->ResetButtons(); + break; + } + } + } + } + + SDL_Rect SrcRect = {230,85,820,550}; + //grab transparant part of frame + menu + SDL_Texture *Tmp = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, SrcRect.w, SrcRect.h); + SDL_Texture *TmpRender = SDL_GetRenderTarget(Game->Renderer); + SDL_SetRenderTarget(Game->Renderer, Tmp); + Game->Image->DrawImage(Game->Renderer, Game->TexOffScreen, &SrcRect, NULL); + + //draw the frame again without transparancy + SDL_SetRenderTarget(Game->Renderer, TmpRender); + Game->Image->DrawImageFuze(Game->Renderer, Game->GFXFrameID, true, &FramePos, 0, &FrameScale, 255, 255, 255, 255); + + //and then draw the transparant part over it now + Game->Image->DrawImage(Game->Renderer, Tmp, NULL, &SrcRect); + SDL_DestroyTexture(Tmp); SDL_SetRenderTarget(Game->Renderer, Game->TexScreen); - SDL_RenderCopy(Game->Renderer, Game->TexOffScreen, NULL, NULL); - - SDL_SetRenderTarget(Game->Renderer, NULL); - SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); - SDL_RenderClear(Game->Renderer); - - int w, h, w2, h2, x, y; - SDL_GetWindowSize(Game->SdlWindow, &w , &h); - float ScaleX = (float)w / (float)ScreenWidth; - float ScaleY = (float)h / (float)ScreenHeight; - h2 = ScreenHeight * ScaleY; - w2 = ScreenWidth * ScaleY; - if (w2 > w) - { - h2 = ScreenHeight * ScaleX; - w2 = ScreenWidth * ScaleX; - } - x = ((w - w2) / 2); - y = ((h - h2) / 2); - - SDL_Rect Rect = { x, y, w2, h2}; - SDL_RenderCopy(Game->Renderer, Game->TexScreen, NULL, &Rect); - - if (debugInfo || Game->ShowFPS) - { - string Text = "FPS: " + to_string(Fps) + "\n"; - if(debugInfo) - { - Text += "FrameTime: " + to_string(AvgFrameTime) + "\n"; - Text += "GFX Slots: " + to_string(Game->Image->ImageSlotsUsed()) + "/" + to_string(Game->Image->ImageSlotsMax()) + "\n"; - Text += "SND Slots: " + to_string(Game->Audio->SoundSlotsUsed()) + "/" + to_string(Game->Audio->SoundSlotsMax()) + "\n"; - Text += "MUS Slots: " + to_string(Game->Audio->MusicSlotsUsed()) + "/" + to_string(Game->Audio->MusicSlotsMax()) + "\n"; - Text += "SPR Slots: " + to_string(Game->Sprites->SpriteSlotsUsed()) + "/" + to_string(Game->Sprites->SpriteSlotsMax()) + "\n"; - } - int tw = Game->Font->TextWidth("RobotoMono-Bold", 16, Text, Text.length()); - Game->Font->WriteText(Game->Renderer, "RobotoMono-Bold", 16, Text, Text.length(), w - tw, 0, 0, {255, 0, 255, 255}); - } - SDL_RenderPresent(Game->Renderer); - - Uint64 FrameEndPerf = SDL_GetPerformanceCounter(); - Uint64 FramePerf = FrameEndPerf - FrameStartPerf; - double FrameTime = FramePerf / (double)SDL_GetPerformanceFrequency() * 1000.0f; - TotalFramePerf += FramePerf; - - if(SDL_GetTicks() - Ticks >= 1000) - { - AvgFrameTime = (TotalFramePerf / TotalFrames) / (double)SDL_GetPerformanceFrequency() * 1000.0f; - Fps = TotalFrames; - TotalFrames = 0; - TotalFramePerf = 0; - Ticks = SDL_GetTicks(); - } - - int RequiredDelay = 1000.0f/DesiredFps - FrameTime; - if (RequiredDelay > 0) - SDL_Delay(RequiredDelay); - } + SDL_RenderCopy(Game->Renderer, Game->TexOffScreen, NULL, NULL); + + SDL_SetRenderTarget(Game->Renderer, NULL); + SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); + SDL_RenderClear(Game->Renderer); + + int w, h, w2, h2, x, y; + SDL_GetWindowSize(Game->SdlWindow, &w , &h); + float ScaleX = (float)w / (float)ScreenWidth; + float ScaleY = (float)h / (float)ScreenHeight; + h2 = ScreenHeight * ScaleY; + w2 = ScreenWidth * ScaleY; + if (w2 > w) + { + h2 = ScreenHeight * ScaleX; + w2 = ScreenWidth * ScaleX; + } + x = ((w - w2) / 2); + y = ((h - h2) / 2); + + SDL_Rect Rect = { x, y, w2, h2}; + SDL_RenderCopy(Game->Renderer, Game->TexScreen, NULL, &Rect); + + if (debugInfo || Game->ShowFPS) + { + string Text = "FPS: " + to_string(Fps) + "\n"; + if(debugInfo) + { + Text += "FrameTime: " + to_string(AvgFrameTime) + "\n"; + Text += "GFX Slots: " + to_string(Game->Image->ImageSlotsUsed()) + "/" + to_string(Game->Image->ImageSlotsMax()) + "\n"; + Text += "SND Slots: " + to_string(Game->Audio->SoundSlotsUsed()) + "/" + to_string(Game->Audio->SoundSlotsMax()) + "\n"; + Text += "MUS Slots: " + to_string(Game->Audio->MusicSlotsUsed()) + "/" + to_string(Game->Audio->MusicSlotsMax()) + "\n"; + Text += "SPR Slots: " + to_string(Game->Sprites->SpriteSlotsUsed()) + "/" + to_string(Game->Sprites->SpriteSlotsMax()) + "\n"; + } + int tw = Game->Font->TextWidth("RobotoMono-Bold", 16, Text, Text.length()); + Game->Font->WriteText(Game->Renderer, "RobotoMono-Bold", 16, Text, Text.length(), w - tw, 0, 0, {255, 0, 255, 255}); + } + SDL_RenderPresent(Game->Renderer); + + Uint64 FrameEndPerf = SDL_GetPerformanceCounter(); + Uint64 FramePerf = FrameEndPerf - FrameStartPerf; + double FrameTime = FramePerf / (double)SDL_GetPerformanceFrequency() * 1000.0f; + TotalFramePerf += FramePerf; + + if(SDL_GetTicks() - Ticks >= 1000) + { + AvgFrameTime = (TotalFramePerf / TotalFrames) / (double)SDL_GetPerformanceFrequency() * 1000.0f; + Fps = TotalFrames; + TotalFrames = 0; + TotalFramePerf = 0; + Ticks = SDL_GetTicks(); + } + + int RequiredDelay = 1000.0f/DesiredFps - FrameTime; + if (RequiredDelay > 0) + SDL_Delay(RequiredDelay); + } Game->Input->ResetButtons(); } void CGameBase::DrawScoreBar() { - SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 100); + SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 100); SDL_Rect r = {0, 0, ScreenWidth, ScoreBarHeight}; SDL_RenderFillRect(Game->Renderer, &r); - string Text = ""; - if(UsesLevels) - Text = "Level: " + to_string(level) + " "; - - if (Game->GameMode == GMGame) - Text += "Lives: " + to_string(HealthPoints) + " Score:" + to_string(Game->Scores[Game->Game][Game->GameMode]) + - " High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); - else - { - if(Game->GameMode == GMRetroCarousel) - { - Text += "Timer: " + to_string_with_precision(Game->Timer, 2) + " Total Score:" + to_string(Game->RetroCarouselScore + - Game->Scores[Game->Game][Game->GameMode]) + " Score: " + to_string(Game->Scores[Game->Game][Game->GameMode]) + - " Previous Total high score: " + to_string(Game->RetroCarouselHighScore) + - " Previous High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); - } - else - Text += "Timer: " + to_string_with_precision(Game->Timer, 2) + " Score:" + to_string(Game->Scores[Game->Game][Game->GameMode]) + - " Previous High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); - } - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 0, 0, 0, {255,255,255,255}); + string Text = ""; + if(UsesLevels) + Text = "Level: " + to_string(level) + " "; + + if (Game->GameMode == GMGame) + Text += "Lives: " + to_string(HealthPoints) + " Score:" + to_string(Game->Scores[Game->Game][Game->GameMode]) + + " High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); + else + { + if(Game->GameMode == GMRetroCarousel) + { + Text += "Timer: " + to_string_with_precision(Game->Timer, 2) + " Total Score:" + to_string(Game->RetroCarouselScore + + Game->Scores[Game->Game][Game->GameMode]) + " Score: " + to_string(Game->Scores[Game->Game][Game->GameMode]) + + " Previous Total high score: " + to_string(Game->RetroCarouselHighScore) + + " Previous High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); + } + else + Text += "Timer: " + to_string_with_precision(Game->Timer, 2) + " Score:" + to_string(Game->Scores[Game->Game][Game->GameMode]) + + " Previous High Score: " + to_string(Game->HighScores[Game->Game][Game->GameMode]); + } + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 20, Text, Text.length(), 0, 0, 0, {255,255,255,255}); } void CGameBase::OnGameStart() @@ -487,113 +485,113 @@ void CGameBase::OnGameStart() void CGameBase::DrawSubStateText() { - //textSize(scpregamefontsize) - //tz = textWidth(text) + //textSize(scpregamefontsize) + //tz = textWidth(text) int w = Game->Font->TextWidth("Roboto-Regular", 60, SubStateText, SubStateText.length()); - Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, SubStateText, SubStateText.length(), screenleft + ((screenright - screenleft) / 2) - w/2, - screentop + ((screenbottom - screentop) / 2) - 90, 0, {255, 255, 255, 240}); + Game->Font->WriteText(Game->Renderer, "Roboto-Regular", 60, SubStateText, SubStateText.length(), screenleft + ((screenright - screenleft) / 2) - w/2, + screentop + ((screenbottom - screentop) / 2) - 90, 0, {255, 255, 255, 240}); } void CGameBase::UpdateLogic() { - if ((Game->Input->Buttons.ButStart && !Game->Input->PrevButtons.ButStart) || - (Game->Input->Buttons.ButBack && !Game->Input->PrevButtons.ButBack)) - PauseMenu(); - - if (Game->GameMode == GMGame) - { - if (Game->SubGameState == SGGame) - { - if(HealthPoints == 0) - { - Game->SubGameState = SGTimeUp; - Game->SubStateTime = SDL_GetTicks() + 750; - Game->SubStateCounter = 0; - } - } - } - - SubStateText = ""; - if (Game->SubGameState != SGFadeIn) - { + if ((Game->Input->Buttons.ButStart && !Game->Input->PrevButtons.ButStart) || + (Game->Input->Buttons.ButBack && !Game->Input->PrevButtons.ButBack)) + PauseMenu(); + + if (Game->GameMode == GMGame) + { + if (Game->SubGameState == SGGame) + { + if(HealthPoints == 0) + { + Game->SubGameState = SGTimeUp; + Game->SubStateTime = SDL_GetTicks() + 750; + Game->SubStateCounter = 0; + } + } + } + + SubStateText = ""; + if (Game->SubGameState != SGFadeIn) + { if ((Game->SubGameState == SGReadyGo)|| (Game->SubGameState == SGTimeUp)) - { + { if (Game->SubStateTime > SDL_GetTicks()) - { + { if (Game->SubStateCounter >= 0) - { + { SubStateText = to_string((int)Game->SubStateCounter); - if(Game->SubStateCounter == 2) - { - Game->Audio->PlaySound(Game->SfxReadyGo, 0); - } + if(Game->SubStateCounter == 2) + { + Game->Audio->PlaySound(Game->SfxReadyGo, 0); + } if (Game->SubStateCounter == 0) - { + { if (Game->SubGameState == SGReadyGo) - { - SubStateText = "GO"; - } + { + SubStateText = "GO"; + } else - { + { if (Game->GameMode != GMGame) - { - SubStateText = "Time Up"; - } + { + SubStateText = "Time Up"; + } else SubStateText = "Game Over"; - - } - } + + } + } } - } - else - { + } + else + { if (Game->SubStateCounter > 0) - { + { if (Game->SubStateCounter > 1) Game->SubStateTime = SDL_GetTicks() + 500; else - Game->SubStateTime = SDL_GetTicks() + 250; + Game->SubStateTime = SDL_GetTicks() + 250; Game->SubStateCounter -= 1; - } - else - { + } + else + { if (Game->SubGameState == SGReadyGo) - { - OnGameStart(); + { + OnGameStart(); Game->SubGameState = SGGame; - } + } else - { + { Game->GameState = GSSubScoreInit; - } - } + } + } } - } - } - UpdateObjects(Game->SubGameState == SGGame); - if(Game->SubGameState == SGGame) - Game->Sprites->UpdateSprites(); + } + } + UpdateObjects(Game->SubGameState == SGGame); + if(Game->SubGameState == SGGame) + Game->Sprites->UpdateSprites(); } void CGameBase::Draw() { - DrawBackground((Game->SubGameState == SGGame) && !ScreenshotMode); - if (DrawObjects()) - Game->Sprites->DrawSprites(Game->Renderer); - if(!ScreenshotMode) - { - DrawScoreBar(); - DrawSubStateText(); - } + DrawBackground((Game->SubGameState == SGGame) && !ScreenshotMode); + if (DrawObjects()) + Game->Sprites->DrawSprites(Game->Renderer); + if(!ScreenshotMode) + { + DrawScoreBar(); + DrawSubStateText(); + } } bool CGameBase::DrawObjects() { - //call drawsprites - return true; + //call drawsprites + return true; } void CGameBase::DrawBackground(bool motionblur) @@ -603,5 +601,5 @@ void CGameBase::DrawBackground(bool motionblur) SDL_Texture* CGameBase::screenshot() { - return nullptr; + return nullptr; } \ No newline at end of file diff --git a/src/games/CGameBase.h b/src/games/CGameBase.h index 2d8fbb4..b81a78c 100644 --- a/src/games/CGameBase.h +++ b/src/games/CGameBase.h @@ -13,30 +13,30 @@ using namespace std; class CGameBase { protected: - CGame *Game; - string SubStateText; - bool ScreenshotMode; - bool UsesLevels; - int level; - int screenleft, screenright, screentop, screenbottom, playfieldwidth, playfieldheight, HealthPoints; - void DrawScoreBar(); - void DrawSubStateText(); - void PauseMenu(); - virtual void OnGameStart(); + CGame *Game; + string SubStateText; + bool ScreenshotMode; + bool UsesLevels; + int level; + int screenleft, screenright, screentop, screenbottom, playfieldwidth, playfieldheight, HealthPoints; + void DrawScoreBar(); + void DrawSubStateText(); + void PauseMenu(); + virtual void OnGameStart(); public: - int GameStateID; - CGameBase(CGame *aGame, int aGameStateID, bool aUsesLevels, bool aScreenshotMode); - virtual ~CGameBase(); - virtual void init(); - virtual void deinit(); - virtual void UpdateLogic(); - virtual void Draw(); - virtual void DrawBackground(bool motionblur); - virtual void LoadGraphics(); - virtual void UnloadGraphics(); - virtual void LoadSound(); - virtual void UnLoadSound(); - virtual void UpdateObjects(bool IsGameState); - virtual bool DrawObjects(); - virtual SDL_Texture* screenshot(); + int GameStateID; + CGameBase(CGame *aGame, int aGameStateID, bool aUsesLevels, bool aScreenshotMode); + virtual ~CGameBase(); + virtual void init(); + virtual void deinit(); + virtual void UpdateLogic(); + virtual void Draw(); + virtual void DrawBackground(bool motionblur); + virtual void LoadGraphics(); + virtual void UnloadGraphics(); + virtual void LoadSound(); + virtual void UnLoadSound(); + virtual void UpdateObjects(bool IsGameState); + virtual bool DrawObjects(); + virtual SDL_Texture* screenshot(); }; \ No newline at end of file diff --git a/src/games/CGameBlockStacker.cpp b/src/games/CGameBlockStacker.cpp index 02a49d0..1f075d6 100644 --- a/src/games/CGameBlockStacker.cpp +++ b/src/games/CGameBlockStacker.cpp @@ -12,21 +12,24 @@ using namespace std; CGameBlockStacker::CGameBlockStacker(CGame* aGame, bool aScreenshotMode): CGameBase(aGame, GSTetris, true, aScreenshotMode) { - Game = aGame; + Game = aGame; MusMusic = -1; SfxDie = -1; SfxLineClear = -1; SfxDrop = -1; SfxRotate = -1; - playfieldwidth = numcols * blocksize; - playfieldheight = numrows * blocksize; + playfieldwidth = numcols * blocksize; + playfieldheight = numrows * blocksize; screenleft = (ScreenWidth - playfieldwidth) / 2; screenright = screenleft + playfieldwidth; screentop = (ScreenHeight - playfieldheight) / 2; screenbottom = screentop + playfieldheight; } -CGameBlockStacker::~CGameBlockStacker() {}; +CGameBlockStacker::~CGameBlockStacker() +{ + +} //helper funcs ---------------------------------------------------------------------------------------------------------------- @@ -39,8 +42,8 @@ bool CGameBlockStacker::piecefits(int tetrimo, int rotation, int posx, int posy) { int piece = y * 4 + x; int field = (posy + y) * numcols + posx + x; - - if ((posx + x >= 0) && (posx + x < numcols) && + + if ((posx + x >= 0) && (posx + x < numcols) && (posy + y >= 0) && (posy + y < numrows) && (tstetrimos[tetrimo][rotation % 4][piece] && (playfield[field] != -1))) { @@ -68,20 +71,20 @@ void CGameBlockStacker::updateplayer() (Game->Input->Buttons.ButDpadLeft)) if (piecefits(currpiece, rotation, plrx - 1, plry)) plrx -= 1; - + if ((Game->Input->Buttons.ButRight) || (Game->Input->Buttons.ButRight2) || (Game->Input->Buttons.ButDpadRight)) if (piecefits(currpiece, rotation, plrx + 1, plry)) plrx += 1; - + if ((Game->Input->Buttons.ButDown) || (Game->Input->Buttons.ButDown2) || (Game->Input->Buttons.ButDpadDown)) if (piecefits(currpiece, rotation, plrx, plry + 1)) plry += 1; - if (Game->Input->Buttons.ButA) + if (Game->Input->Buttons.ButA) { if (rotateblock && piecefits(currpiece, rotation +1, plrx, plry)) { @@ -93,7 +96,7 @@ void CGameBlockStacker::updateplayer() else rotateblock = true; - if (Game->Input->Buttons.ButB) + if (Game->Input->Buttons.ButB) { if (dropblock) { @@ -122,7 +125,7 @@ void CGameBlockStacker::createplayfield() void CGameBlockStacker::updateplayfield(bool force) { - if (lineclear > -1) + if (lineclear > -1) { lineclear -= 1; @@ -148,11 +151,11 @@ void CGameBlockStacker::updateplayfield(bool force) } y -=1; } - } + } } else { - speedcount += 1; + speedcount += 1; if (speedcount % ticksinputidle == 0) updateplayer(); @@ -161,15 +164,14 @@ void CGameBlockStacker::updateplayfield(bool force) { speedcount = 0; piececount += 1; - //level increase if (piececount % 40 == 0) - if (speed >= 5) + if (speed >= 5) { speed -= 1; level += 1; - } - + } + //can we move the piece down ? if (piecefits(currpiece, rotation, plrx, plry +1)) plry += 1; @@ -177,7 +179,7 @@ void CGameBlockStacker::updateplayfield(bool force) { if(!force) Game->Audio->PlaySound(SfxDrop, 0); - + //lock it in place for(int x = 0; x < 4; x++) @@ -187,7 +189,7 @@ void CGameBlockStacker::updateplayfield(bool force) if (tstetrimos[currpiece][rotation % 4][piece]) playfield[(plry + y) * numcols + plrx + x] = currpiece; } - + //check for lines int numlines = 0; bool linedone = true; @@ -198,12 +200,12 @@ void CGameBlockStacker::updateplayfield(bool force) linedone = true; for(int x = 1; x < numcols -1; x++) linedone = linedone && (playfield[(plry + y) * numcols + x] > -1); - + if (linedone) { numlines += 1; for(int x = 1; x < numcols -1; x++) - playfield[(plry + y) * numcols + x] = -3; + playfield[(plry + y) * numcols + x] = -3; } } } @@ -217,12 +219,12 @@ void CGameBlockStacker::updateplayfield(bool force) lineclear = 30; Game->Audio->PlaySound(SfxLineClear, 0); } - + plrx = numcols / 2 -2; plry = 0; rotation = 0; currpiece = rand() % 7; - + if (!piecefits(currpiece, rotation, plrx, plry)) { Game->Audio->PlaySound(SfxDie, 0); @@ -266,16 +268,16 @@ void CGameBlockStacker::drawplayfieldcell(int x, int y, int piece) if (piece == 5) color = {0xA5, 0x2A, 0x2A, 255}; - + if (piece == 6) color = {255, 0, 255, 255}; if (piece == -2) color = {128, 128, 128, 255}; - - if (piece == -3) + + if (piece == -3) color = {255, 255, 255, 255}; - + SDL_Rect r = {screenleft + x * blocksize, screentop + y * blocksize, blocksize, blocksize}; SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); SDL_RenderFillRect(Game->Renderer, &r); @@ -292,17 +294,17 @@ void CGameBlockStacker::drawplayfield() for(int y = 0; y < numrows; y++) { int piece = playfield[y * numcols + x]; - drawplayfieldcell(x,y, piece); + drawplayfieldcell(x,y, piece); } - + for(int x = 0; x < 4; x++) for(int y = 0; y < 4; y++) { int piece = y * 4 + x; if(tstetrimos[currpiece][rotation % 4][piece]) drawplayfieldcell(plrx + x, plry + y, currpiece); - - } + + } } //background ---------------------------------------------------------------------------------------------------------------- @@ -341,7 +343,7 @@ void CGameBlockStacker::init() dropblock = true; level = 1; lineclear = 0; - createplayfield(); + createplayfield(); } void CGameBlockStacker::LoadGraphics() @@ -386,13 +388,13 @@ void CGameBlockStacker::deinit() } UnloadGraphics(); } - + SDL_Texture* CGameBlockStacker::screenshot() { SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); SDL_Texture* image = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetRenderTarget(Game->Renderer, image); + SDL_SetRenderTarget(Game->Renderer, image); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); SDL_RenderClear(Game->Renderer); init(); @@ -400,7 +402,7 @@ SDL_Texture* CGameBlockStacker::screenshot() for(int i = 0; i < numrows * 2; i++) updateplayfield(true); - Draw(); + Draw(); SDL_RenderPresent(Game->Renderer); SDL_SetRenderTarget(Game->Renderer, prev); diff --git a/src/games/CGameBlockStacker.h b/src/games/CGameBlockStacker.h index d17fca6..ca9b0e7 100644 --- a/src/games/CGameBlockStacker.h +++ b/src/games/CGameBlockStacker.h @@ -15,37 +15,37 @@ using namespace std; class CGameBlockStacker: public CGameBase { private: - static const int numcols = 12; - static const int numrows = 18; - static const int blocksize = ScreenHeight / numrows; - static const int ticksidle = 3; - static const int ticksinputidle = 4; - - int background; - SDL_Point backgroundtz; + static const int numcols = 12; + static const int numrows = 18; + static const int blocksize = ScreenHeight / numrows; + static const int ticksidle = 3; + static const int ticksinputidle = 4; + + int background; + SDL_Point backgroundtz; int playfield[numcols * numrows]; int currpiece, rotation,speed, speedcount, piececount, lineclear, plrx, plry; - bool rotateblock, dropblock; - int MusMusic, SfxDie, SfxLineClear, SfxDrop, SfxRotate; - - bool piecefits(int tetrimo, int rotation, int posx, int posy); - void updateplayer(); - - void createplayfield(); - void updateplayfield(bool force); - void drawplayfieldcell(int x, int y, int piece); - void drawplayfield(); + bool rotateblock, dropblock; + int MusMusic, SfxDie, SfxLineClear, SfxDrop, SfxRotate; + + bool piecefits(int tetrimo, int rotation, int posx, int posy); + void updateplayer(); + + void createplayfield(); + void updateplayfield(bool force); + void drawplayfieldcell(int x, int y, int piece); + void drawplayfield(); public: - CGameBlockStacker(CGame* aGame, bool aScreenshotMode = false); - ~CGameBlockStacker(); - SDL_Texture* screenshot() override; - void DrawBackground(bool motionblur) override; - void init() override; - void deinit() override; - void UnloadGraphics() override; - void LoadGraphics() override; - void LoadSound() override; - void UnLoadSound() override; - void UpdateObjects(bool IsGameState) override; - bool DrawObjects() override; + CGameBlockStacker(CGame* aGame, bool aScreenshotMode = false); + ~CGameBlockStacker(); + SDL_Texture* screenshot() override; + void DrawBackground(bool motionblur) override; + void init() override; + void deinit() override; + void UnloadGraphics() override; + void LoadGraphics() override; + void LoadSound() override; + void UnLoadSound() override; + void UpdateObjects(bool IsGameState) override; + bool DrawObjects() override; }; \ No newline at end of file diff --git a/src/games/CGameBreakOut.cpp b/src/games/CGameBreakOut.cpp index 7d1cbc8..1b4fed9 100644 --- a/src/games/CGameBreakOut.cpp +++ b/src/games/CGameBreakOut.cpp @@ -12,22 +12,24 @@ using namespace std; CGameBreakOut::CGameBreakOut(CGame* aGame, bool aScreenshotMode): CGameBase(aGame, GSBreakout, false, aScreenshotMode) { - Game = aGame; + Game = aGame; MusMusic = -1; - SfxSucces = -1; - SfxDie = -1; - SfxBrick = -1; - SfxBat = -1; - screenleft = 0; - screenright = ScreenWidth; - screentop = 0; - screenbottom = ScreenHeight; + SfxSucces = -1; + SfxDie = -1; + SfxBrick = -1; + SfxBat = -1; + screenleft = 0; + screenright = ScreenWidth; + screentop = 0; + screenbottom = ScreenHeight; } -CGameBreakOut::~CGameBreakOut() {}; +CGameBreakOut::~CGameBreakOut() +{ +} -//blocks ---------------------------------------------------------------------------------------------------------------- +//blocks ---------------------------------------------------------------------------------------------------------------- void CGameBreakOut::updateblockinfo() { @@ -39,28 +41,28 @@ void CGameBreakOut::updateblockinfo() int x2 = screenleft - 1; int y = screentop - 1; for (int i = 0; i < numblocks; i++) - { + { if (blocks[i].alive) - { + { if (blocks[i].pos.x < x1) - { + { x1 = blocks[i].pos.x; blockinfo.mostleft = i; - } + } if (blocks[i].pos.x > x2) - { + { x2 = blocks[i].pos.x; blockinfo.mostright = i; - } - + } + if (blocks[i].pos.y > y) - { + { y = blocks[i].pos.y; blockinfo.mostbottom = i; - } - } - } + } + } + } } @@ -73,37 +75,37 @@ void CGameBreakOut::destroyallblocks() void CGameBreakOut::destroyblock(int index) { if(blocks[index].alive) - { + { Game->Sprites->RemoveSprite(blocks[index].spr); blocks[index].alive = false; - } + } } void CGameBreakOut::createblocks(bool setlocation) { pattern = rand() % 5; for (int x = 0; x < blockcols; x++) - { + { for(int y = 0; y < blockrows; y++) - { + { tweens[x + y * blockcols][tweenblockpositions] = createtween(tweenblockpositions, 1+ ((rand() %(6)) / 10), funcsmoothstop, 1, true, DesiredFps); blocks[x + y * blockcols].spr = Game->Sprites->CreateSprite(); blocks[x + y * blockcols].state = 0; blocks[x + y * blockcols].alive = true; Game->Sprites->SetSpriteImage(blocks[x + y * blockcols].spr, &spritesheetblocks, 6, 1); SDL_Point tz = Game->Sprites->TileSize(blocks[x + y * blockcols].spr); - tz.x = tz.x * blockspritecale.x; - tz.y = tz.y * blockspritecale.y; + tz.x = tz.x * blockspritecale.x; + tz.y = tz.y * blockspritecale.y; blocks[x + y * blockcols].tz = tz; Game->Sprites->SetSpriteAnimation(blocks[x + y * blockcols].spr, y % 6, y % 6, 0); Game->Sprites->SetSpriteScale(blocks[x + y * blockcols].spr, blockspritecale); - blocks[x + y * blockcols].pos = { screenleft + blockxoffset + (x * tz.x), screentop + blockyoffset + y * tz.y}; + blocks[x + y * blockcols].pos = { screenleft + blockxoffset + (x * tz.x), screentop + blockyoffset + y * tz.y}; if (setlocation) Game->Sprites->SetSpriteLocation(blocks[x + y * blockcols].spr, blocks[x + y * blockcols].pos); - - } - } + + } + } updateblockinfo(); } @@ -111,63 +113,62 @@ void CGameBreakOut::createblocks(bool setlocation) void CGameBreakOut::updateblocks() { for(int x = 0; x < blockcols; x++) - { + { for(int y = 0; y < blockrows; y++) - { + { if(blocks[x + y * blockcols].alive) - { + { if(tweens[x + y * blockcols][tweenblockpositions].active) - { + { tweens[x + y * blockcols][tweenblockpositions] = updatetween(tweens[x + y * blockcols][tweenblockpositions]); Vec2F pos = blocks[x + y * blockcols].pos; if (pattern == 0) - { + { if (x < blockcols / 3) - pos.x = pos.x * tweens[x + y * blockcols][tweenblockpositions].funcval; + pos.x = pos.x * tweens[x + y * blockcols][tweenblockpositions].funcval; else - { + { if( x > blockcols * 2 / 3) pos.x = screenright - (screenright - pos.x) * tweens[x + y * blockcols][tweenblockpositions].funcval; - - } + } if (y < blockrows / 2) pos.y = pos.y * tweens[x + y * blockcols][tweenblockpositions].funcval; - } - else - { + } + else + { if(pattern == 1) pos.y = pos.y * tweens[x + y * blockcols][tweenblockpositions].funcval; else - { + { if (pattern == 2) - { - if (x < blockcols / 2) + { + if (x < blockcols / 2) pos.x = pos.x * tweens[x + y * blockcols][tweenblockpositions].funcval; - else + else pos.x = screenright - (screenright - pos.x) * tweens[x + y * blockcols][tweenblockpositions].funcval; - } + } else - { + { if (pattern == 3) pos.x = pos.x * tweens[x + y * blockcols][tweenblockpositions].funcval; else - { + { if (pattern == 4) pos.x = screenright - (screenright - pos.x) * tweens[x + y * blockcols][tweenblockpositions].funcval; - } - } - } - } - + } + } + } + } + // setSpriteLocation(blocks[x + y * blockcols].spr, pos) blocks[x + y * blockcols].spr->x = int(pos.x); blocks[x + y * blockcols].spr->y = int(pos.y); - - } + + } if (blocks[x + y * blockcols].state == blockstatedeath) - { + { if (tweens[x + y * blockcols][tweenblockdeath].active) - { + { tweens[x + y * blockcols][tweenblockdeath] = updatetween(tweens[x + y * blockcols][tweenblockdeath]); Vec2F pos = blocks[x + y * blockcols].pos; pos.y = pos.y + (50 * tweens[x + y * blockcols][tweenblockdeath].funcval); @@ -177,24 +178,24 @@ void CGameBreakOut::updateblocks() blocks[x + y * blockcols].spr->y = int(pos.y); Game->Sprites->SetSpriteRotation(blocks[x + y * blockcols].spr, 720 * tweens[x + y * blockcols][tweenblockdeath].funcval); Game->Sprites->SetSpriteColour(blocks[x + y * blockcols].spr, 1,1,1, 1- tweens[x + y * blockcols][tweenblockdeath].funcval); - } + } else - { + { destroyblock(x + y * blockcols); updateblockinfo(); - } - } + } + } - } - } - } + } + } + } if (blockinfo.mostleft == -1) - { + { Game->AddToScore(500); createblocks(false); Game->Audio->PlaySound(SfxSucces, 0); - } + } } //player ---------------------------------------------------------------------------------------------------------------- @@ -202,10 +203,10 @@ void CGameBreakOut::updateblocks() void CGameBreakOut::destroyplayer() { if (player.alive) - { + { Game->Sprites->RemoveSprite(player.spr); player.alive = false; - } + } } void CGameBreakOut::createplayer() @@ -214,9 +215,9 @@ void CGameBreakOut::createplayer() Game->Sprites->SetSpriteImage(player.spr, &spritesheetbat); Game->Sprites->SetSpriteScale(player.spr, spritescale); player.tz = Game->Image->ImageSize(spritesheetbat); - player.tz.x = player.tz.x * spritescale.x; - player.tz.y = player.tz.y * spritescale.y; - player.pos = { (float)(screenright - screenleft) / 2,(float)screenbottom - 20 - (player.tz.y / 2)}; + player.tz.x = player.tz.x * spritescale.x; + player.tz.y = player.tz.y * spritescale.y; + player.pos = { (float)(screenright - screenleft) / 2,(float)screenbottom - 20 - (player.tz.y / 2)}; HealthPoints = 5; Game->Sprites->SetSpriteLocation(player.spr, player.pos); player.alive = true; @@ -226,43 +227,43 @@ void CGameBreakOut::updateplayer() { Game->Sprites->SetSpriteVisibility(player.spr, player.alive); if (player.alive) - { + { float speedmultiplier = 1; - + if (Game->Input->Buttons.ButA) speedmultiplier = 2; - + if ((Game->Input->Buttons.ButLeft) || (Game->Input->Buttons.ButLeft2) || (Game->Input->Buttons.ButDpadLeft)) - { + { if (player.pos.x - player.tz.x / 2 - (playerspeed * speedmultiplier) > screenleft) player.pos.x -= playerspeed * speedmultiplier; else player.pos.x = screenleft + player.tz.x / 2; - } + } if ((Game->Input->Buttons.ButRight) || (Game->Input->Buttons.ButRight2) || (Game->Input->Buttons.ButDpadRight)) - { + { if ( player.pos.x + player.tz.x / 2 + (playerspeed * speedmultiplier) < screenright) player.pos.x += playerspeed * speedmultiplier; else player.pos.x = screenright - player.tz.x / 2; - } + } //setSpriteLocation(player.spr, player.pos) player.spr->x = int(player.pos.x); player.spr->y = int(player.pos.y); - } + } else - { + { if (player.freeze > 0) player.freeze -= 1; else player.alive = true; - } + } } @@ -271,12 +272,12 @@ void CGameBreakOut::updateplayer() void CGameBreakOut::destroyball() { if (ball.alive) - { + { Game->Sprites->RemoveSprite(ball.spr); ball.alive = false; - } + } } - + void CGameBreakOut::createball() { ball.spr = Game->Sprites->CreateSprite(); @@ -293,61 +294,61 @@ void CGameBreakOut::createball() void CGameBreakOut::updateball() { if (ball.alive) - { + { if (ball.freeze > 0) ball.freeze -= 1; else - { - float steps = curballspeed / ballvelsegments; - + { + float steps = curballspeed / ballvelsegments; + for (int j = 1; j screenright) - { + { ball.vel.x *= -1; ball.pos.x = screenright; - } - + } + if (ball.pos.y < screentop) - { + { ball.pos.y = screentop; ball.vel.y *= -1; - } + } Game->Sprites->SetSpriteLocation(ball.spr, ball.pos); - + if (ball.pos.y >= screenbottom) - { + { destroyball(); createball(); ball.freeze = 45; HealthPoints -= 1; Game->AddToScore(-100); Game->Audio->PlaySound(SfxDie, 0); - } + } for (int k = 0; k < numblocks; k++) - { + { if (blocks[k].alive && (blocks[k].state != blockstatedeath)) - { + { if (Game->Sprites->DetectSpriteCollision(ball.spr, blocks[k].spr)) - { + { //seen this in wireframe issue 11 not sure what it actually //calculates but seems to work more or less ok float dx = (ball.pos.x - blocks[k].pos.x) / blocks[k].tz.x; float dy = (ball.pos.y - blocks[k].pos.y) / blocks[k].tz.y; if (abs(dx) > abs(dy)) ball.vel.x = abs(ball.vel.x) * dx / abs(dx); - else + else ball.vel.y = abs(ball.vel.y) * dy / abs(dy); Game->AddToScore(20); @@ -357,98 +358,98 @@ void CGameBreakOut::updateball() blocks[k].state = blockstatedeath; Game->Sprites->SetSpriteDepth(blocks[k].spr, 5); tweens[k][tweenblockdeath] = createtween(tweenblockdeath, 1, funcsmoothstep, 1, true, DesiredFps); - } - } - } - + } + } + } + if (player.alive) - { + { if (Game->Sprites->DetectSpriteCollision(ball.spr, player.spr)) - { + { //touched top part of bat if (ball.pos.y < player.pos.y + player.tz.y / 3) - { + { //set ball to top part - 1 so it can't callide again ball.pos.y = player.pos.y - player.tz.y / 2 - 1; Game->Sprites->SetSpriteLocation(ball.spr, ball.pos); - + //inverrt y velocity - ball.vel.y = -ball.vel.y; + ball.vel.y = -ball.vel.y; //touch far right of bat if (ball.pos.x >= player.pos.x + ((player.tz.x / 2) * 5 / 7)) - { + { //and bal is moving to the left if (ball.vel.x < 0) - { + { //reverse x velocity ball.vel.x = -ball.vel.x; //add some randomness float rnd = (rand() % 100) / 500; - if (rand() % 2 == 0) + if (rand() % 2 == 0) rnd *= -1; ball.vel.x += rnd; - } - } + } + } else - { + { //touched far left of bat if (ball.pos.x <= player.pos.x - ((player.tz.x / 2) * 5 / 7)) - { + { //and ball moving to the right if (ball.vel.x > 0) - { + { //reverse x velocity ball.vel.x = -ball.vel.x; //add some randomness float rnd = (rand() % 100) / 500; - if (rand() % 2 == 0) - rnd *= -1; + if (rand() % 2 == 0) + rnd *= -1; ball.vel.x += rnd; - } - } - } - } + } + } + } + } else - { + { //bottom parts = loss of ball // ball is on the right if (ball.pos.x > player.pos.x) - { + { //ball is moving towards bat to left if (ball.vel.x < 0) //reverse x velocity ball.vel.x = -ball.vel.x; - } + } else - { + { //ball is on the left and moving to the right if (ball.vel.x > 0) //reverse x velocity ball.vel.x = -ball.vel.x; - } - } - - //increase ballspeed + } + } + + //increase ballspeed curballspeed += ballspeedinc; - + //just a safety while (Game->Sprites->DetectSpriteCollision(ball.spr, player.spr)) - { - ball.pos.x += (steps * ball.vel.x); - ball.pos.y += (steps * ball.vel.y); + { + ball.pos.x += (steps * ball.vel.x); + ball.pos.y += (steps * ball.vel.y); Game->Sprites->SetSpriteLocation(ball.spr, ball.pos); - } - + } + Game->Audio->PlaySound(SfxBat, 0); - } - } - } - } - } + } + } + } + } + } } - + //background ---------------------------------------------------------------------------------------------------------------- void CGameBreakOut::DrawBackground(bool motionblur) @@ -456,8 +457,8 @@ void CGameBreakOut::DrawBackground(bool motionblur) float alpha = 1; if ((motionblur) && (Game->MotionBlur)) alpha = 0.3; - SDL_Point Pos = { ScreenWidth / 2, ScreenHeight / 2}; - Vec2F Scale = {(float)ScreenWidth / backgroundtz.x, (float)ScreenHeight / backgroundtz.y}; + SDL_Point Pos = { ScreenWidth / 2, ScreenHeight / 2}; + Vec2F Scale = {(float)ScreenWidth / backgroundtz.x, (float)ScreenHeight / backgroundtz.y}; Game->Image->DrawImageFuzeTintFloat(Game->Renderer, background, true, &Pos, 0, &Scale, 1, 1, 1, alpha); } @@ -465,12 +466,12 @@ void CGameBreakOut::DrawBackground(bool motionblur) void CGameBreakOut::init() { - LoadGraphics(); - createblocks(ScreenshotMode); + LoadGraphics(); + createblocks(ScreenshotMode); createplayer(); createball(); - if(!ScreenshotMode) + if(!ScreenshotMode) { LoadSound(); Game->CurrentGameMusicID = MusMusic; @@ -482,9 +483,9 @@ void CGameBreakOut::LoadSound() { SfxDie = Game->Audio->LoadSound("common/die.wav"); SfxSucces = Game->Audio->LoadSound("common/succes.wav"); - SfxBat = Game->Audio->LoadSound("breakout/bat.wav"); - SfxBrick = Game->Audio->LoadSound("breakout/brick.wav"); - MusMusic = Game->Audio->LoadMusic("breakout/music.ogg"); + SfxBat = Game->Audio->LoadSound("breakout/bat.wav"); + SfxBrick = Game->Audio->LoadSound("breakout/brick.wav"); + MusMusic = Game->Audio->LoadMusic("breakout/music.ogg"); } void CGameBreakOut::UnLoadSound() @@ -492,15 +493,15 @@ void CGameBreakOut::UnLoadSound() Game->Audio->StopMusic(); Game->Audio->StopSound(); Game->Audio->UnLoadMusic(MusMusic); - Game->Audio->UnLoadSound(SfxSucces); - Game->Audio->UnLoadSound(SfxDie); - Game->Audio->UnLoadSound(SfxBrick); - Game->Audio->UnLoadSound(SfxBat); + Game->Audio->UnLoadSound(SfxSucces); + Game->Audio->UnLoadSound(SfxDie); + Game->Audio->UnLoadSound(SfxBrick); + Game->Audio->UnLoadSound(SfxBat); } void CGameBreakOut::deinit() { - destroyplayer(); + destroyplayer(); destroyallblocks(); destroyball(); if (!ScreenshotMode) @@ -517,33 +518,33 @@ void CGameBreakOut::LoadGraphics() { background = Game->Image->LoadImage(Game->Renderer, "breakout/background.png"); backgroundtz = Game->Image->ImageSize(background); - spritesheetblocks = Game->Image->LoadImage(Game->Renderer, "breakout/blocks.png"); - spritesheetbat = Game->Image->LoadImage(Game->Renderer, "breakout/paddle.png"); - spritesheetball = Game->Image->LoadImage(Game->Renderer, "breakout/ball.png"); + spritesheetblocks = Game->Image->LoadImage(Game->Renderer, "breakout/blocks.png"); + spritesheetbat = Game->Image->LoadImage(Game->Renderer, "breakout/paddle.png"); + spritesheetball = Game->Image->LoadImage(Game->Renderer, "breakout/ball.png"); } void CGameBreakOut::UnloadGraphics() { Game->Image->UnLoadImage(background); - Game->Image->UnLoadImage(spritesheetblocks); - Game->Image->UnLoadImage(spritesheetbat); - Game->Image->UnLoadImage(spritesheetball); + Game->Image->UnLoadImage(spritesheetblocks); + Game->Image->UnLoadImage(spritesheetbat); + Game->Image->UnLoadImage(spritesheetball); } SDL_Texture* CGameBreakOut::screenshot() { SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); SDL_Texture* image = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetRenderTarget(Game->Renderer, image); + SDL_SetRenderTarget(Game->Renderer, image); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); SDL_RenderClear(Game->Renderer); init(); - - Draw(); - + + Draw(); + SDL_RenderPresent(Game->Renderer); SDL_SetRenderTarget(Game->Renderer, prev); - deinit(); + deinit(); return image; } @@ -552,9 +553,9 @@ SDL_Texture* CGameBreakOut::screenshot() void CGameBreakOut::UpdateObjects(bool IsGameState) { updateblocks(); - if (IsGameState) + if (IsGameState) { - updateplayer(); - updateball(); - } + updateplayer(); + updateball(); + } } diff --git a/src/games/CGameBreakOut.h b/src/games/CGameBreakOut.h index bcc3201..ce08e74 100644 --- a/src/games/CGameBreakOut.h +++ b/src/games/CGameBreakOut.h @@ -24,25 +24,25 @@ typedef struct sblockinfo sblockinfo; class CGameBreakOut: public CGameBase { private: - static const int tweenblockpositions = 0; - static const int tweenblockdeath = 1; - static const int blockstatedeath = 1; - static constexpr float ballspeed = 6.0; - static constexpr float ballspeedinc = 0.1; - static const int ballvelsegments = 5; - static constexpr float playerspeed = 8; - static constexpr float blockxoffset = 120; - static constexpr float blockyoffset = 80; - static const int blockrows = 10; - static const int blockcols = 17; - static const int numblocks = blockrows * blockcols; + static const int tweenblockpositions = 0; + static const int tweenblockdeath = 1; + static const int blockstatedeath = 1; + static constexpr float ballspeed = 6.0; + static constexpr float ballspeedinc = 0.1; + static const int ballvelsegments = 5; + static constexpr float playerspeed = 8; + static constexpr float blockxoffset = 120; + static constexpr float blockyoffset = 80; + static const int blockrows = 10; + static const int blockcols = 17; + static const int numblocks = blockrows * blockcols; - const Vec2F spritescale = {2.5,2.5}; - const Vec2F blockspritecale = {1,2}; - - int MusMusic, SfxDie, SfxSucces, SfxBat, SfxBrick; - int background, spritesheetblocks, spritesheetbat, spritesheetball; - SDL_Point backgroundtz; + const Vec2F spritescale = {2.5,2.5}; + const Vec2F blockspritecale = {1,2}; + + int MusMusic, SfxDie, SfxSucces, SfxBat, SfxBrick; + int background, spritesheetblocks, spritesheetbat, spritesheetball; + SDL_Point backgroundtz; float curballspeed; int pattern; @@ -52,31 +52,31 @@ class CGameBreakOut: public CGameBase { CSpriteObject player; CSpriteObject ball; - void updateball(); - void createball(); - void destroyball(); + void updateball(); + void createball(); + void destroyball(); + + void updateplayer(); + void createplayer(); + void destroyplayer(); - void updateplayer(); - void createplayer(); - void destroyplayer(); + void updateblocks(); + void createblocks(bool setlocation); + void destroyblock(int index); + void destroyallblocks(); - void updateblocks(); - void createblocks(bool setlocation); - void destroyblock(int index); - void destroyallblocks(); - - void drawbackground(bool motionblur); - void updateblockinfo(); + void drawbackground(bool motionblur); + void updateblockinfo(); public: - CGameBreakOut(CGame* aGame, bool aScreenshotMode = false); - ~CGameBreakOut(); - SDL_Texture* screenshot() override; - void init() override; - void deinit() override; - void UnloadGraphics() override; - void LoadGraphics() override; - void LoadSound() override; - void UnLoadSound() override; - void UpdateObjects(bool IsGameState) override; - void DrawBackground(bool motionblur) override; + CGameBreakOut(CGame* aGame, bool aScreenshotMode = false); + ~CGameBreakOut(); + SDL_Texture* screenshot() override; + void init() override; + void deinit() override; + void UnloadGraphics() override; + void LoadGraphics() override; + void LoadSound() override; + void UnLoadSound() override; + void UpdateObjects(bool IsGameState) override; + void DrawBackground(bool motionblur) override; }; \ No newline at end of file diff --git a/src/games/CGameFastEddy.cpp b/src/games/CGameFastEddy.cpp index aeb9386..28fb60c 100644 --- a/src/games/CGameFastEddy.cpp +++ b/src/games/CGameFastEddy.cpp @@ -11,48 +11,51 @@ using namespace std; CGameFastEddy::CGameFastEddy(CGame* aGame, bool aScreenshotMode): CGameBase(aGame, GSEddy, true, aScreenshotMode) { - Game = aGame; + Game = aGame; MusMusic = -1; - SfxSucces = -1; - SfxDie = -1; + SfxSucces = -1; + SfxDie = -1; - playfieldwidth = 1280; - playfieldheight = 720; - screenleft = (ScreenWidth - playfieldwidth) / 2; + playfieldwidth = 1280; + playfieldheight = 720; + screenleft = (ScreenWidth - playfieldwidth) / 2; screenright = screenleft + playfieldwidth; screentop = (ScreenHeight - playfieldheight) / 2; screenbottom = screentop + playfieldheight; - numfloortilesperrow = playfieldwidth / rowfloorsize; - maxfloortiles = numfloortilesperrow * rows; - rowspacingsize = playfieldheight / rows; - ladderwidth = playfieldwidth / laddersfitrows; - rowsize = rowspacingsize - rowfloorsize; - playerheight = rowsize * 3 / 4; - enemyheight = rowsize * 2 / 5; - playerjumpheight = rowsize * 2/ 4; - collectableheight = rowsize / 2; - keyheight = rowsize / 4; - playerjumpspeeddec = playerjumpspeed / playerjumpheight; + numfloortilesperrow = playfieldwidth / rowfloorsize; + maxfloortiles = numfloortilesperrow * rows; + rowspacingsize = playfieldheight / rows; + ladderwidth = playfieldwidth / laddersfitrows; + rowsize = rowspacingsize - rowfloorsize; + playerheight = rowsize * 3 / 4; + enemyheight = rowsize * 2 / 5; + playerjumpheight = rowsize * 2/ 4; + collectableheight = rowsize / 2; + keyheight = rowsize / 4; + playerjumpspeeddec = playerjumpspeed / playerjumpheight; } -CGameFastEddy::~CGameFastEddy() {}; +CGameFastEddy::~CGameFastEddy() +{ + +} -//end level key ---------------------------------------------------------------------------------------------------------------- +//end level key ---------------------------------------------------------------------------------------------------------------- void CGameFastEddy::createkey() { - key.spr = Game->Sprites->CreateSprite(); + key.spr = Game->Sprites->CreateSprite(); key.alive = true; SDL_Point tz = Game->Image->ImageSize(spritesheetkey); Vec2F scale = {keyheight / tz.y, keyheight / tz.y}; key.tz.x = tz.x * scale.x; - key.tz.y = tz.y * scale.y; + key.tz.y = tz.y * scale.y; Game->Sprites->SetSpriteImage(key.spr, &spritesheetkey, 1, 1); Game->Sprites->SetSpriteScale(key.spr, scale); Game->Sprites->SetSpriteAnimation(key.spr, 0, 0, 0); - Game->Sprites->SetSpriteCollisionShape(key.spr, SHAPE_BOX, tz.x - 20, tz.y, 0, 0, 0); + Game->Sprites->SetSpriteCollisionShape(key.spr, SHAPE_BOX, tz.x - 20, tz.y, 0, 0, 0); key.pos.y = enemies[rowzeroenemyindex].pos.y - enemies[rowzeroenemyindex].tz.y; key.pos.x = enemies[rowzeroenemyindex].pos.x; Game->Sprites->SetSpriteLocation(key.spr, key.pos); @@ -61,25 +64,25 @@ void CGameFastEddy::createkey() void CGameFastEddy::destroykey() { if (key.alive) - { + { Game->Sprites->RemoveSprite(key.spr); - key.alive = false; - } + key.alive = false; + } } void CGameFastEddy::updatekey() { if (key.alive) - { + { key.pos.x = enemies[rowzeroenemyindex].pos.x; key.pos.y = enemies[rowzeroenemyindex].pos.y - enemies[rowzeroenemyindex].tz.y; Game->Sprites->SetSpriteLocation(key.spr, key.pos); - + if (Game->Sprites->DetectSpriteCollision(key.spr, player.spr)) - { + { Game->Audio->PlaySound(SfxSucces, 0); Game->AddToScore(200); - SDL_Delay(500); + SDL_Delay(500); level += 1; collecteditems = 0; collectedcreated = 0; @@ -93,8 +96,8 @@ void CGameFastEddy::updatekey() createenemies(true); createcollectables(-1); createkey(); - } - } + } + } } //collectables ---------------------------------------------------------------------------------------------------------------- @@ -108,90 +111,90 @@ void CGameFastEddy::destroyallcollectables() void CGameFastEddy::destroycollectable(int index) { if (collectables[index].alive) - { + { Game->Sprites->RemoveSprite(collectables[index].spr); collectables[index].alive = false; - } + } } void CGameFastEddy::createcollectables(int ignorerow) { - SDL_Point tz = {128, 128}; + SDL_Point tz = {128, 128}; for (int i = 0; i < maxcollectables; i++) - { + { if(collectedcreated < 10) - { + { if (!collectables[i].alive) - { + { bool bok = false; int row = ignorerow; while (!bok) - { + { row = 1 + (rand() % (rows-1)); while(row == ignorerow) row = 1 + (rand() % (rows-1)); bool bnocollision = true; for(int j = 0; j < maxcollectables; j++) - { + { if(collectables[j].alive) - { + { if(collectables[j].row == row) - { + { bnocollision = false; break; - } - } - } + } + } + } bok = bnocollision; - } - + } + collectables[i].spr = Game->Sprites->CreateSprite(); collectables[i].alive = true; collectables[i].row = row; collectables[i].state = rand() % 3; Vec2F scale = {collectableheight / tz.y, collectableheight / tz.y}; collectables[i].tz.x = tz.x * scale.x; - collectables[i].tz.y = tz.y * scale.y; + collectables[i].tz.y = tz.y * scale.y; Game->Sprites->SetSpriteImage(collectables[i].spr, &spritesheetcollectable, 5, 1); Game->Sprites->SetSpriteScale(collectables[i].spr, scale); Game->Sprites->SetSpriteAnimation(collectables[i].spr, ((level-1) % 5), ((level-1) % 5), 0); Game->Sprites->SetSpriteCollisionShape(collectables[i].spr, SHAPE_CIRCLE, tz.x - 66, tz.y - 66, 0, 0, 0); - //Game->Sprites->SetSpriteCollisionShape(collectables[i].spr, SHAPE_BOX, tz.x - 66, tz.y - 66, 0, 0, 0); + //Game->Sprites->SetSpriteCollisionShape(collectables[i].spr, SHAPE_BOX, tz.x - 66, tz.y - 66, 0, 0, 0); collectables[i].pos.y = (row) * rowspacingsize + rowfloorsize / 2; - collectables[i].pos.x = ((screenright - screenleft) /7) + + collectables[i].pos.x = ((screenright - screenleft) /7) + (rand() % (screenright - screenleft - ((screenright - screenleft) /6 ))); Game->Sprites->SetSpriteLocation(collectables[i].spr, collectables[i].pos); collectedcreated += 1; - } - } - } + } + } + } } void CGameFastEddy::updatecollectables() { for(int i = 0; i < maxcollectables; i++) - { + { if (collectables[i].alive) - { + { if (collectables[i].state == collectablestatemoveleft) - { + { collectables[i].pos.x -= collectablespeed; if (collectables[i].pos.x + collectables[i].tz.x / 2 < screenleft) collectables[i].pos.x = screenright + collectables[i].tz.x / 2; Game->Sprites->SetSpriteLocation(collectables[i].spr, collectables[i].pos); - } + } if (collectables[i].state == collectablestatemoveright) - { + { collectables[i].pos.x += collectablespeed; if(collectables[i].pos.x - collectables[i].tz.x / 2 > screenright) collectables[i].pos.x = screenleft - collectables[i].tz.x / 2; Game->Sprites->SetSpriteLocation(collectables[i].spr, collectables[i].pos); - } + } if (Game->Sprites->DetectSpriteCollision(collectables[i].spr, player.spr)) - { - Game->Audio->PlaySound(SfxCollect, 0); + { + Game->Audio->PlaySound(SfxCollect, 0); int ignorerow = collectables[i].row; destroycollectable(i); collecteditems += 1; @@ -199,9 +202,9 @@ void CGameFastEddy::updatecollectables() if(collecteditems >= 9) enemyenablelevelend(); createcollectables(ignorerow); - } - } - } + } + } + } } //enemies ---------------------------------------------------------------------------------------------------------------- @@ -209,13 +212,13 @@ void CGameFastEddy::updatecollectables() void CGameFastEddy::destroyenemies() { for(int i = 0; i < maxenemies; i++) - { + { if (enemies[i].alive) - { + { Game->Sprites->RemoveSprite(enemies[i].spr); enemies[i].alive = false; - } - } + } + } } void CGameFastEddy::enemyenablelevelend() @@ -224,10 +227,10 @@ void CGameFastEddy::enemyenablelevelend() SDL_Point tz = {32, 32}; Vec2F scale = {enemyheight / tz.y, enemyheight / tz.y}; enemies[index].tz.x = tz.x * scale.x; - enemies[index].tz.y = tz.y * scale.y; + enemies[index].tz.y = tz.y * scale.y; enemies[index].pos.y = (0 + 1) * rowspacingsize - rowfloorsize / 2 - enemies[index].tz.y / 2; Game->Sprites->SetSpriteScale(enemies[index].spr, scale); - Game->Sprites->SetSpriteCollisionShape(enemies[index].spr, SHAPE_BOX, tz.x - 10, tz.y-10,0, 0, 0); + Game->Sprites->SetSpriteCollisionShape(enemies[index].spr, SHAPE_BOX, tz.x - 10, tz.y-10,0, 0, 0); Game->Sprites->SetSpriteLocation(enemies[index].spr, enemies[index].pos); } @@ -235,9 +238,9 @@ void CGameFastEddy::createenemy(int row, float x, int state, int group, int mult { SDL_Point tz = {32, 32}; for (int i = 0; i < maxenemies; i++) - { + { if (!enemies[i].alive) - { + { if(row == 0) rowzeroenemyindex = i; enemies[i].spr = Game->Sprites->CreateSprite(); @@ -247,7 +250,7 @@ void CGameFastEddy::createenemy(int row, float x, int state, int group, int mult enemies[i].state = state; Vec2F scale = {enemyheight / tz.y * multiply, enemyheight / tz.y * multiply}; enemies[i].tz.x = tz.x * scale.x; - enemies[i].tz.y = tz.y * scale.y; + enemies[i].tz.y = tz.y * scale.y; Game->Sprites->SetSpriteImage(enemies[i].spr, &spritesheetenemy, 3, 4); Game->Sprites->SetSpriteScale(enemies[i].spr, scale); if (enemies[i].state == enemystatemoveright) @@ -258,55 +261,55 @@ void CGameFastEddy::createenemy(int row, float x, int state, int group, int mult if (enemies[i].state == enemystatemoveleft) Game->Sprites->SetSpriteAnimation(enemies[i].spr, 3, 5, 10); - + if (enemies[i].state == enemystatewaitmove) - { + { enemies[i].stateticks = 60 * 6; Game->Sprites->SetSpriteAnimation(enemies[i].spr, 0, 2, 10); - } - - Game->Sprites->SetSpriteCollisionShape(enemies[i].spr, SHAPE_BOX, tz.x - 10, tz.y-10,0, 0, 0); + } + + Game->Sprites->SetSpriteCollisionShape(enemies[i].spr, SHAPE_BOX, tz.x - 10, tz.y-10,0, 0, 0); enemies[i].pos.y = (row + 1) * rowspacingsize - rowfloorsize / 2 - enemies[i].tz.y / 2; enemies[i].pos.x = x; Game->Sprites->SetSpriteLocation(enemies[i].spr, enemies[i].pos); break; - } - } + } + } } void CGameFastEddy::createenemies(bool levelsucces) { if (level-1 < 5) - { + { createenemy(0, (screenright - screenleft) / 2, enemystatemoveright, 0, 2); if (levelsucces) createenemy(1, (screenright - screenleft) * 4 / 10, enemystatemoveright, 1, 1); else createenemy(1, (screenright - screenleft) / 10, enemystateidle, 1, 1); - createenemy(2, (screenright - screenleft) / 2, enemystatemoveright, 2, 1); + createenemy(2, (screenright - screenleft) / 2, enemystatemoveright, 2, 1); if (levelsucces) createenemy(3, (screenright - screenleft) * 6 / 10, enemystatemoveright, 3, 1); else createenemy(3, (screenright - screenleft) * 6 / 10, enemystateidle, 3, 1); createenemy(4, (screenright - screenleft) / 10, enemystatewaitmove, 4, 1); - } + } else - { + { if (level-1 < 10) - { + { createenemy(0, (screenright - screenleft) / 2, enemystatemoveright, 0, 2); createenemy(1, (screenright - screenleft) * 4 / 10, enemystatemoveright, 1, 1); createenemy(1, (screenright - screenleft) * 5 / 10, enemystatemoveright, 1, 1); createenemy(2, (screenright - screenleft) / 2, enemystatemoveright, 2, 1); createenemy(3, (screenright - screenleft) * 6 / 10, enemystatemoveleft, 3, 1); createenemy(4, (screenright - screenleft) / 10, enemystatewaitmove, 4, 1); - } + } else - { + { if (level-1 < 15) - { + { createenemy(0, (screenright - screenleft) / 2, enemystatemoveright, 0, 2); createenemy(1, (screenright - screenleft) * 4 / 10, enemystatemoveright, 1, 1); createenemy(1, (screenright - screenleft) * 5 / 10, enemystatemoveright, 1, 1); @@ -314,9 +317,9 @@ void CGameFastEddy::createenemies(bool levelsucces) createenemy(3, (screenright - screenleft) * 6 / 10, enemystatemoveleft, 3, 1); createenemy(3, (screenright - screenleft) * 7 / 10, enemystatemoveleft, 3, 1); createenemy(4, (screenright - screenleft) / 10, enemystatewaitmove, 4, 1); - } + } else - { + { createenemy(0, (screenright - screenleft) / 2, enemystatemoveright, 0, 2); createenemy(1, (screenright - screenleft) * 4 / 10, enemystatemoveright, 1, 1); createenemy(1, (screenright - screenleft) * 5 / 10, enemystatemoveright, 1, 1); @@ -324,83 +327,83 @@ void CGameFastEddy::createenemies(bool levelsucces) createenemy(3, (screenright - screenleft) * 1 / 10, enemystatemoveright, 3, 1); createenemy(3, (screenright - screenleft) * 6 / 10, enemystatemoveright, 4, 1); createenemy(4, (screenright - screenleft) / 10, enemystatewaitmove, 5, 1); - } - } - } + } + } + } } void CGameFastEddy::updateenemies() { for (int i = 0; i < maxenemies; i++) - { + { if (enemies[i].alive) - { + { if (enemies[i].state == enemystatewaitmove) - { + { if (enemies[i].stateticks > 0) enemies[i].stateticks -= 1; else - { + { enemies[i].state = enemystatemoveright; Game->Sprites->SetSpriteAnimation(enemies[i].spr, 6, 8, 10); - } - } + } + } - if (enemies[i].state == enemystatemoveright) - { + if (enemies[i].state == enemystatemoveright) + { if (enemies[i].pos.x + enemies[i].tz.x / 2 + playerspeed < screenright) enemies[i].pos.x += playerspeed; else - { + { for(int j = 0; j < maxenemies; j++) - { + { if (enemies[j].alive) - { + { if(enemies[i].group == enemies[j].group) - { + { enemies[j].state = enemystatemoveleft; Game->Sprites->SetSpriteAnimation(enemies[j].spr, 3, 5, 10); - } - } - } - } - } + } + } + } + } + } if(enemies[i].state == enemystatemoveleft) - { + { if ( enemies[i].pos.x - enemies[i].tz.x / 2 - playerspeed > screenleft) enemies[i].pos.x -= playerspeed; else - { + { for(int j = 0; j < maxenemies; j++) - { + { if(enemies[j].alive) - { + { if(enemies[i].group == enemies[j].group) - { + { enemies[j].state = enemystatemoveright; Game->Sprites->SetSpriteAnimation(enemies[j].spr, 6, 8, 10); - } - } - } - } - } + } + } + } + } + } Game->Sprites->SetSpriteLocation(enemies[i].spr, enemies[i].pos); if (Game->Sprites->DetectSpriteCollision(enemies[i].spr, player.spr)) - { - if (((player.state != playerstateclimbup) && + { + if (((player.state != playerstateclimbup) && (player.state != playerstateclimbdown) && (player.state != playerstateunknown)) || (enemies[i].row == 0)) - { + { Game->Audio->PlaySound(SfxDie, 0); - if (Game->GameMode == GMGame) + if (Game->GameMode == GMGame) HealthPoints -= 1; if (HealthPoints > 0) - { + { Game->AddToScore(-100); SDL_Delay(500); destroyenemies(); @@ -411,23 +414,23 @@ void CGameFastEddy::updateenemies() createkey(); if (collecteditems >= 9) enemyenablelevelend(); - } + } break; - } - } - } - } + } + } + } + } } -//player ---------------------------------------------------------------------------------------------------------------- +//player ---------------------------------------------------------------------------------------------------------------- void CGameFastEddy::destroyplayer() { if (player.alive) - { + { Game->Sprites->RemoveSprite(player.spr); player.alive = false; - } + } } void CGameFastEddy::createplayer() @@ -437,14 +440,14 @@ void CGameFastEddy::createplayer() SDL_Point tz = {238, 342}; Vec2F scale = {playerheight / tz.y, playerheight / tz.y}; player.tz.x = tz.x * scale.x; - player.tz.y = tz.y * scale.y; + player.tz.y = tz.y * scale.y; player.state = playerstateunknown; Game->Sprites->SetSpriteDepth(player.spr, 5); Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayeridle, 1, 15); Game->Sprites->SetSpriteScale(player.spr, scale); Game->Sprites->SetSpriteAnimation(player.spr, 0, 14, 10); Game->Sprites->SetSpriteCollisionShape(player.spr, SHAPE_BOX, tz.x - 120, tz.y-30,0,0,0); - player.pos = { (float)(screenright - screenleft) / 2, 5 * rowspacingsize - rowfloorsize / 2 - player.tz.y / 2}; + player.pos = { (float)(screenright - screenleft) / 2, 5 * rowspacingsize - rowfloorsize / 2 - player.tz.y / 2}; Game->Sprites->SetSpriteLocation(player.spr, player.pos); } @@ -452,17 +455,17 @@ void CGameFastEddy::updateplayer() { bool jump = false; bool left = false; - bool right = false; + bool right = false; bool down = false; bool up = false; if (player.alive) - { + { if ((player.state != playerstatejump) && (player.state != playerstateleftjump) && (player.state != playerstaterightjump) && (player.state != playerstateclimbup) && (player.state != playerstateclimbdown)) - { + { //if fedebugmode and (!global.prevc.b and global.c.b) then // feenemyenablelevelend() @@ -480,23 +483,23 @@ void CGameFastEddy::updateplayer() (Game->Input->Buttons.ButDown2) || (Game->Input->Buttons.ButDpadDown)) down = true; - - if ((Game->Input->Buttons.ButLeft) || + + if ((Game->Input->Buttons.ButLeft) || (Game->Input->Buttons.ButLeft2) || (Game->Input->Buttons.ButDpadLeft)) left = true; - + if ((Game->Input->Buttons.ButRight) || (Game->Input->Buttons.ButRight2) || (Game->Input->Buttons.ButDpadRight)) right = true; if (jump) - { + { if (left) - { + { if (player.state != playerstateleftjump) - { + { Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayerjump, 1, 6); Game->Sprites->SetSpriteAnimation(player.spr, 3, 3, 10); @@ -504,14 +507,14 @@ void CGameFastEddy::updateplayer() player.floory = player.pos.y; player.jumpdown = false; player.force = playerjumpspeed; - } - } + } + } else - { + { if (right) - { + { if (player.state != playerstaterightjump) - { + { Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayerjump, 1, 6); Game->Sprites->SetSpriteAnimation(player.spr, 3, 3, 10); @@ -519,66 +522,66 @@ void CGameFastEddy::updateplayer() player.state = playerstaterightjump; player.jumpdown = false; player.force = playerjumpspeed; - } - } + } + } else - { + { if(player.state != playerstatejump) - { + { Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayerjump, 1, 6); Game->Sprites->SetSpriteAnimation(player.spr, 3, 3, 10); player.floory = player.pos.y; player.state = playerstatejump; player.jumpdown = false; player.force = playerjumpspeed; - } - } - } - } + } + } + } + } else - { + { if(up) - { + { player.pos.y -= rowspacingsize/4; Game->Sprites->SetSpriteLocation(player.spr, player.pos); bool found = false; for (int i = 0; i < maxladders; i++) - { + { if (Game->Sprites->DetectSpriteCollision(player.spr, ladders[i].spr)) - { + { Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayerclimb, 1, 15); Game->Sprites->SetSpriteAnimation(player.spr, 0, 14, 20); - + player.pos.x = ladders[i].pos.x; player.state = playerstateclimbup; player.floory = player.pos.y + rowspacingsize/4; found = true; break; - }; - }; + }; + }; player.pos.y += rowspacingsize/4; Game->Sprites->SetSpriteLocation(player.spr, player.pos); if (!found) - { - if (player.state != playerstateidle) - { - Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayeridle, 1, 15); - Game->Sprites->SetSpriteAnimation(player.spr, 0, 14, 10); - player.state = playerstateidle; - } - } - } + { + if (player.state != playerstateidle) + { + Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayeridle, 1, 15); + Game->Sprites->SetSpriteAnimation(player.spr, 0, 14, 10); + player.state = playerstateidle; + } + } + } else - { + { if (down) - { + { player.pos.y += rowspacingsize - playerheight / 4; Game->Sprites->SetSpriteLocation(player.spr, player.pos); bool found = false; for (int i = 0; i < maxladders; i++) - { + { if (Game->Sprites->DetectSpriteCollision(player.spr, ladders[i].spr)) - { + { Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayerclimb, 1, 15); Game->Sprites->SetSpriteAnimation(player.spr, 14, 0, 20); @@ -587,235 +590,235 @@ void CGameFastEddy::updateplayer() player.floory = player.pos.y - rowspacingsize + playerheight / 4; found = true; break; - }; - }; + }; + }; player.pos.y -= rowspacingsize - playerheight / 4; Game->Sprites->SetSpriteLocation(player.spr, player.pos); if (!found) - { - if (player.state != playerstateidle) - { - Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayeridle, 1, 15); - Game->Sprites->SetSpriteAnimation(player.spr, 0, 14, 10); - player.state = playerstateidle; - } - } - } + { + if (player.state != playerstateidle) + { + Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayeridle, 1, 15); + Game->Sprites->SetSpriteAnimation(player.spr, 0, 14, 10); + player.state = playerstateidle; + } + } + } else - { + { if (left) - { + { if (player.state != playerstateleft) - { + { Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayerrun, 1, 7); Game->Sprites->SetSpriteAnimation(player.spr, 0, 6, 10); player.spr->xscale = -(abs(player.spr->xscale)); player.state = playerstateleft; - } - } + } + } else - { + { if (right) - { + { if (player.state != playerstateright) - { + { Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayerrun, 1, 7); Game->Sprites->SetSpriteAnimation(player.spr, 0, 6, 10); player.spr->xscale = (abs(player.spr->xscale)); player.state = playerstateright; - } - } + } + } else - { + { if (player.state != playerstateidle) - { - Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayeridle, 1, 15) ; + { + Game->Sprites->SetSpriteImage(player.spr, &spritesheetplayeridle, 1, 15); Game->Sprites->SetSpriteAnimation(player.spr, 0, 14, 10); player.state = playerstateidle; - } - } - } - } - } - } - } + } + } + } + } + } + } + } if (player.state == playerstateclimbup) - { + { if (player.pos.y > player.floory - rowspacingsize) player.pos.y -= playerclimbspeed; else - { + { player.pos.y = player.floory - rowspacingsize; player.state = playerstateunknown; - } - + } + Game->Sprites->SetSpriteLocation(player.spr, player.pos); - } + } if (player.state == playerstateclimbdown) - { + { if (player.pos.y < player.floory + rowspacingsize) player.pos.y += playerclimbspeed; else - { + { player.pos.y = player.floory + rowspacingsize; player.state = playerstateunknown; - } + } Game->Sprites->SetSpriteLocation(player.spr, player.pos); - }; + }; if (player.state == playerstatejump) - { + { if (!player.jumpdown) - { + { if (player.pos.y > player.floory - playerjumpheight) - { + { player.pos.y -= player.force; player.force -= playerjumpspeeddec; - } + } else player.jumpdown = true; - } + } else - { + { if (player.pos.y < player.floory) - { + { player.pos.y += player.force; player.force += playerjumpspeeddec; - } + } else - { + { player.pos.y = player.floory; player.state = playerstateunknown; - } - } + } + } Game->Sprites->SetSpriteLocation(player.spr, player.pos); - if (player.pos.y < player.floory - 5/6 * playerjumpheight) + if (player.pos.y < player.floory - 5/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 5, 5, 0); else - { - if (player.pos.y < player.floory - 4/6 * playerjumpheight) + { + if (player.pos.y < player.floory - 4/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 4, 4, 0); else - { - if(player.pos.y < player.floory - 3/6 * playerjumpheight) + { + if(player.pos.y < player.floory - 3/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 3, 3, 0); else - { - if(player.pos.y < player.floory - 2/6 * playerjumpheight) + { + if(player.pos.y < player.floory - 2/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 2, 2, 0); else - { - if(player.pos.y < player.floory - 1/6 * playerjumpheight) + { + if(player.pos.y < player.floory - 1/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 1, 1, 0); else - { - if (player.pos.y < player.floory - 0/6 * playerjumpheight) + { + if (player.pos.y < player.floory - 0/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 0, 0, 0); - } - } - } - } - } - } - + } + } + } + } + } + } + if ((player.state == playerstateleftjump) || (player.state == playerstaterightjump)) - { + { if (! player.jumpdown) - { + { if (player.pos.y > player.floory - playerjumpheight) - { + { player.pos.y -= player.force; player.force -= playerjumpspeeddec; - } + } else player.jumpdown = true; - } + } else - { + { if (player.pos.y < player.floory) - { + { player.pos.y += player.force; player.force += playerjumpspeeddec; - } + } else - { + { player.pos.y = player.floory; player.state = playerstateunknown; - } - } + } + } if (player.spr->xscale / abs(player.spr->xscale) == 1) - { + { if ( player.pos.x + player.tz.x / 2 + playerspeed < screenright) player.pos.x += playerspeed ; else player.pos.x = screenright - player.tz.x / 2; - } + } else - { + { if ( player.pos.x - player.tz.x / 2 - playerspeed > screenleft) player.pos.x -= playerspeed; else player.pos.x = screenleft + player.tz.x / 2; - } - - if (player.pos.y < player.floory - 5/6 * playerjumpheight) + } + + if (player.pos.y < player.floory - 5/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 5, 5, 0); else - { - if (player.pos.y < player.floory - 4/6 * playerjumpheight) + { + if (player.pos.y < player.floory - 4/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 4, 4, 0); else - { - if (player.pos.y < player.floory - 3/6 * playerjumpheight) + { + if (player.pos.y < player.floory - 3/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 3, 3, 0); else - { - if (player.pos.y < player.floory - 2/6 * playerjumpheight) + { + if (player.pos.y < player.floory - 2/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 2, 2, 0); else - { - if(player.pos.y < player.floory - 1/6 * playerjumpheight) + { + if(player.pos.y < player.floory - 1/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 1, 1, 0); else - { - if(player.pos.y < player.floory - 0/6 * playerjumpheight) + { + if(player.pos.y < player.floory - 0/6 * playerjumpheight) Game->Sprites->SetSpriteAnimation(player.spr, 0, 0, 0); - } - } - } - } - } + } + } + } + } + } Game->Sprites->SetSpriteLocation(player.spr, player.pos); - } + } if (player.state == playerstateright) - { + { if ( player.pos.x + player.tz.x / 2 + playerspeed < screenright) player.pos.x += playerspeed; else player.pos.x = screenright - player.tz.x / 2; Game->Sprites->SetSpriteLocation(player.spr, player.pos); - } + } if (player.state == playerstateleft) - { + { if ( player.pos.x - player.tz.x / 2 - playerspeed > screenleft) player.pos.x -= playerspeed; else player.pos.x = screenleft + player.tz.x / 2; Game->Sprites->SetSpriteLocation(player.spr, player.pos); - } - } + } + } } -//floors ---------------------------------------------------------------------------------------------------------------- +//floors ---------------------------------------------------------------------------------------------------------------- void CGameFastEddy::destroyfloors() { @@ -828,11 +831,11 @@ void CGameFastEddy::createfloors() int tilenr = 0; int i = 0; //SDL_Point tz = {64,64}; - SDL_Point tz = Game->Image->ImageSize(spritesheetladder); + SDL_Point tz = Game->Image->ImageSize(spritesheetladder); for (int y = 0; y < rows; y++) - { + { for (int x = 0; x < numfloortilesperrow; x++) - { + { floors[i].spr = Game->Sprites->CreateSprite(); floors[i].alive = true; Game->Sprites->SetSpriteImage(floors[i].spr, &spritesheet, 9, 10); @@ -840,20 +843,20 @@ void CGameFastEddy::createfloors() Game->Sprites->SetSpriteScale(floors[i].spr, {(float)rowfloorsize / tz.x , (float)rowfloorsize / tz.y}); if (x == 0) tilenr = 36; - else - { + else + { if (x == numfloortilesperrow -1) tilenr = 38; else tilenr = 37; - } + } Game->Sprites->SetSpriteAnimation(floors[i].spr, tilenr, tilenr, 0); i += 1; - } - } -} + } + } +} -//ladders ---------------------------------------------------------------------------------------------------------------- +//ladders ---------------------------------------------------------------------------------------------------------------- void CGameFastEddy::destroyladders() { @@ -866,7 +869,7 @@ void CGameFastEddy::createladders() int i = 0; SDL_Point tz = Game->Image->ImageSize(spritesheetladder); for (int y = 1; y < rows; y++) - { + { int x1 = 1 + rand() % (int(laddersfitrows / 2)-1); ladders[i].spr = Game->Sprites->CreateSprite(); ladders[i].alive = true; @@ -879,15 +882,15 @@ void CGameFastEddy::createladders() i += 1; int x2 = x1 + int(laddersfitrows / 2); - ladders[i].spr = Game->Sprites->CreateSprite(); + ladders[i].spr = Game->Sprites->CreateSprite(); ladders[i].alive = true; ladders[i].pos = {x2 * ladderwidth + ladderwidth / 2 , y * rowspacingsize + rowspacingsize / 2 - rowfloorsize / 2}; Game->Sprites->SetSpriteImage(ladders[i].spr, &spritesheetladder); - Game->Sprites->SetSpriteCollisionShape(ladders[i].spr, SHAPE_BOX, tz.x - 20, tz.y-10,0,0,0); + Game->Sprites->SetSpriteCollisionShape(ladders[i].spr, SHAPE_BOX, tz.x - 20, tz.y-10,0,0,0); Game->Sprites->SetSpriteLocation(ladders[i].spr, ladders[i].pos ); Game->Sprites->SetSpriteScale(ladders[i].spr, {ladderwidth / tz.x , (rowspacingsize + rowfloorsize/2) / tz.y}); i += 1; - } + } } //background ---------------------------------------------------------------------------------------------------------------- @@ -897,8 +900,8 @@ void CGameFastEddy::DrawBackground(bool motionblur) float alpha = 1; if ((motionblur) && (Game->MotionBlur)) alpha = 0.3; - SDL_Point Pos = { ScreenWidth / 2, ScreenHeight / 2}; - Vec2F Scale = {(float)ScreenWidth / backgroundtz.x, (float)ScreenHeight / backgroundtz.y}; + SDL_Point Pos = { ScreenWidth / 2, ScreenHeight / 2}; + Vec2F Scale = {(float)ScreenWidth / backgroundtz.x, (float)ScreenHeight / backgroundtz.y}; Game->Image->DrawImageFuzeTintFloat(Game->Renderer, background, true, &Pos, 0, &Scale, 1, 1, 1, alpha); } @@ -906,11 +909,11 @@ void CGameFastEddy::DrawBackground(bool motionblur) void CGameFastEddy::init() { - collecteditems = 0; + collecteditems = 0; collectedcreated = 0; - level = 1; + level = 1; HealthPoints = 3; - LoadGraphics(); + LoadGraphics(); createfloors(); createladders(); createenemies(false); @@ -928,11 +931,11 @@ void CGameFastEddy::init() void CGameFastEddy::deinit() { destroyfloors(); - destroyladders(); - destroyenemies(); - destroyallcollectables(); - destroykey(); - destroyplayer(); + destroyladders(); + destroyenemies(); + destroyallcollectables(); + destroykey(); + destroyplayer(); if (!ScreenshotMode) { UnLoadSound(); @@ -947,8 +950,8 @@ void CGameFastEddy::LoadSound() { SfxDie = Game->Audio->LoadSound("common/die.wav"); SfxSucces = Game->Audio->LoadSound("common/succes.wav"); - SfxCollect = Game->Audio->LoadSound("common/coin.wav"); - MusMusic = Game->Audio->LoadMusic("fasterdave/music.ogg"); + SfxCollect = Game->Audio->LoadSound("common/coin.wav"); + MusMusic = Game->Audio->LoadMusic("fasterdave/music.ogg"); } void CGameFastEddy::UnLoadSound() @@ -966,46 +969,46 @@ void CGameFastEddy::LoadGraphics() background = Game->Image->LoadImage(Game->Renderer, "fasterdave/background.png"); backgroundtz = Game->Image->ImageSize(background); - spritesheet = Game->Image->LoadImage(Game->Renderer, "fasterdave/floortileset.png"); - spritesheetladder = Game->Image->LoadImage(Game->Renderer, "fasterdave/ladder.png"); + spritesheet = Game->Image->LoadImage(Game->Renderer, "fasterdave/floortileset.png"); + spritesheetladder = Game->Image->LoadImage(Game->Renderer, "fasterdave/ladder.png"); - spritesheetplayerclimb = Game->Image->LoadImage(Game->Renderer, "fasterdave/Character_character_climb.png"); - spritesheetplayerrun = Game->Image->LoadImage(Game->Renderer, "fasterdave/Character_character_run.png"); - spritesheetplayeridle = Game->Image->LoadImage(Game->Renderer, "fasterdave/Character_character_idle.png"); - spritesheetplayerjump = Game->Image->LoadImage(Game->Renderer, "fasterdave/Character_character_jump_up.png"); - spritesheetenemy = Game->Image->LoadImage(Game->Renderer, "fasterdave/enemy.png"); - spritesheetcollectable = Game->Image->LoadImage(Game->Renderer, "fasterdave/orbs.png"); - spritesheetkey = Game->Image->LoadImage(Game->Renderer, "fasterdave/key.png"); + spritesheetplayerclimb = Game->Image->LoadImage(Game->Renderer, "fasterdave/Character_character_climb.png"); + spritesheetplayerrun = Game->Image->LoadImage(Game->Renderer, "fasterdave/Character_character_run.png"); + spritesheetplayeridle = Game->Image->LoadImage(Game->Renderer, "fasterdave/Character_character_idle.png"); + spritesheetplayerjump = Game->Image->LoadImage(Game->Renderer, "fasterdave/Character_character_jump_up.png"); + spritesheetenemy = Game->Image->LoadImage(Game->Renderer, "fasterdave/enemy.png"); + spritesheetcollectable = Game->Image->LoadImage(Game->Renderer, "fasterdave/orbs.png"); + spritesheetkey = Game->Image->LoadImage(Game->Renderer, "fasterdave/key.png"); } void CGameFastEddy::UnloadGraphics() { Game->Image->UnLoadImage(background); - Game->Image->UnLoadImage(spritesheet); - Game->Image->UnLoadImage(spritesheetladder); - Game->Image->UnLoadImage(spritesheetplayerclimb); - Game->Image->UnLoadImage(spritesheetplayerrun); - Game->Image->UnLoadImage(spritesheetplayeridle); - Game->Image->UnLoadImage(spritesheetplayerjump); - Game->Image->UnLoadImage(spritesheetenemy); - Game->Image->UnLoadImage(spritesheetcollectable); - Game->Image->UnLoadImage(spritesheetkey); + Game->Image->UnLoadImage(spritesheet); + Game->Image->UnLoadImage(spritesheetladder); + Game->Image->UnLoadImage(spritesheetplayerclimb); + Game->Image->UnLoadImage(spritesheetplayerrun); + Game->Image->UnLoadImage(spritesheetplayeridle); + Game->Image->UnLoadImage(spritesheetplayerjump); + Game->Image->UnLoadImage(spritesheetenemy); + Game->Image->UnLoadImage(spritesheetcollectable); + Game->Image->UnLoadImage(spritesheetkey); } SDL_Texture* CGameFastEddy::screenshot() { SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); SDL_Texture* image = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetRenderTarget(Game->Renderer, image); + SDL_SetRenderTarget(Game->Renderer, image); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); SDL_RenderClear(Game->Renderer); init(); - + Draw(); - + SDL_RenderPresent(Game->Renderer); SDL_SetRenderTarget(Game->Renderer, prev); - deinit(); + deinit(); return image; } diff --git a/src/games/CGameFastEddy.h b/src/games/CGameFastEddy.h index 6ebe785..0c2a92e 100644 --- a/src/games/CGameFastEddy.h +++ b/src/games/CGameFastEddy.h @@ -15,66 +15,66 @@ using namespace std; class CGameFastEddy: public CGameBase { private: - static const int playerstateunknown = -1; - static const int playerstateidle = 0; - static const int playerstateleft = 1; - static const int playerstateleftjump = 2; - static const int playerstateright = 3; - static const int playerstaterightjump = 4; - static const int playerstatejump = 5; - static const int playerstateclimbup = 6; - static const int playerstateclimbdown = 7; + static const int playerstateunknown = -1; + static const int playerstateidle = 0; + static const int playerstateleft = 1; + static const int playerstateleftjump = 2; + static const int playerstateright = 3; + static const int playerstaterightjump = 4; + static const int playerstatejump = 5; + static const int playerstateclimbup = 6; + static const int playerstateclimbdown = 7; - static const int enemystateidle = 0; - static const int enemystatemoveleft = 1; - static const int enemystatewaitmove = 2; - static const int enemystatemoveright = 3; + static const int enemystateidle = 0; + static const int enemystatemoveleft = 1; + static const int enemystatewaitmove = 2; + static const int enemystatemoveright = 3; - static const int collectablestatemoveleft = 0; - static const int collectablestatemoveright = 1; - static const int collectablestateidle = 2; + static const int collectablestatemoveleft = 0; + static const int collectablestatemoveright = 1; + static const int collectablestateidle = 2; - static const int laddersfitrows = 10; - static const int rowfloorsize = 32; //tilesize / 2 oroginals are 64x64 - static const int rows = 5; + static const int laddersfitrows = 10; + static const int rowfloorsize = 32; //tilesize / 2 oroginals are 64x64 + static const int rows = 5; - static constexpr float playerspeed = 6; - static constexpr float playerjumpspeed = 2.8; - static constexpr float playerclimbspeed = 2; - static constexpr float collectablespeed = 2; + static constexpr float playerspeed = 6; + static constexpr float playerjumpspeed = 2.8; + static constexpr float playerclimbspeed = 2; + static constexpr float collectablespeed = 2; - static const int maxenemies = 10; - static const int maxcollectables = 2; + static const int maxenemies = 10; + static const int maxcollectables = 2; - static const int maxladders = (rows - 1) * 2; - float playerjumpspeeddec; + static const int maxladders = (rows - 1) * 2; + float playerjumpspeeddec; - int numfloortilesperrow; - int maxfloortiles; - float rowspacingsize; - float ladderwidth; - float rowsize; - float playerheight; - float enemyheight; - float playerjumpheight; - float collectableheight; - float keyheight; - - int spritesheet;// = loadImage("EderMuniz/SnowyForestTiles") - int spritesheetladder;// = loadImage("EderMuniz/SnowyForestLadder") - int spritesheetplayerclimb;// = loadImage("Ravenmore/characterClimb") - int spritesheetplayerrun;// = loadImage("Ravenmore/characterRun") - int spritesheetplayeridle;// = loadImage("Ravenmore/characterIdle") - int spritesheetplayerjump;// = loadImage("Ravenmore/characterJumpUp") - int spritesheetenemy;// = loadImage("Pipo/char59") - int spritesheetcollectable;// = loadImage("Ravenmore/platformPickups") - int spritesheetkey;// = loadImage("Ravenmore/PlatformDefaultProps") - int background;// = loadImage("EderMuniz/SnowyForestBackA") - SDL_Point backgroundtz;// = imageSize(febackground) + int numfloortilesperrow; + int maxfloortiles; + float rowspacingsize; + float ladderwidth; + float rowsize; + float playerheight; + float enemyheight; + float playerjumpheight; + float collectableheight; + float keyheight; - int MusMusic, SfxSucces, SfxCollect, SfxDie; + int spritesheet;// = loadImage("EderMuniz/SnowyForestTiles") + int spritesheetladder;// = loadImage("EderMuniz/SnowyForestLadder") + int spritesheetplayerclimb;// = loadImage("Ravenmore/characterClimb") + int spritesheetplayerrun;// = loadImage("Ravenmore/characterRun") + int spritesheetplayeridle;// = loadImage("Ravenmore/characterIdle") + int spritesheetplayerjump;// = loadImage("Ravenmore/characterJumpUp") + int spritesheetenemy;// = loadImage("Pipo/char59") + int spritesheetcollectable;// = loadImage("Ravenmore/platformPickups") + int spritesheetkey;// = loadImage("Ravenmore/PlatformDefaultProps") + int background;// = loadImage("EderMuniz/SnowyForestBackA") + SDL_Point backgroundtz;// = imageSize(febackground) - int rowzeroenemyindex = 0; + int MusMusic, SfxSucces, SfxCollect, SfxDie; + + int rowzeroenemyindex = 0; int collecteditems = 0; int collectedcreated = 0; CSpriteObject player; @@ -84,35 +84,35 @@ class CGameFastEddy: public CGameBase { CSpriteObject collectables[maxcollectables]; CSpriteObject key; - void createkey(); - void destroykey(); - void updatekey(); - void createladders(); - void destroyladders(); - void createfloors(); - void destroyfloors(); - void updateplayer(); - void createplayer(); - void destroyplayer(); - void updateenemies(); - void createenemies(bool levelsucces); - void createenemy(int row, float x, int state, int group, int multiply); - void enemyenablelevelend(); - void destroyenemies(); - void updatecollectables(); - void createcollectables(int ignorerow); - void destroycollectable(int index); - void destroyallcollectables(); + void createkey(); + void destroykey(); + void updatekey(); + void createladders(); + void destroyladders(); + void createfloors(); + void destroyfloors(); + void updateplayer(); + void createplayer(); + void destroyplayer(); + void updateenemies(); + void createenemies(bool levelsucces); + void createenemy(int row, float x, int state, int group, int multiply); + void enemyenablelevelend(); + void destroyenemies(); + void updatecollectables(); + void createcollectables(int ignorerow); + void destroycollectable(int index); + void destroyallcollectables(); public: - CGameFastEddy(CGame* aGame, bool aScreenshotMode = false); - ~CGameFastEddy(); - SDL_Texture* screenshot() override; - void init() override; - void deinit() override; - void UnloadGraphics() override; - void LoadGraphics() override; - void LoadSound() override; - void UnLoadSound() override; - void UpdateObjects(bool IsGameState) override; - void DrawBackground(bool motionblur); + CGameFastEddy(CGame* aGame, bool aScreenshotMode = false); + ~CGameFastEddy(); + SDL_Texture* screenshot() override; + void init() override; + void deinit() override; + void UnloadGraphics() override; + void LoadGraphics() override; + void LoadSound() override; + void UnLoadSound() override; + void UpdateObjects(bool IsGameState) override; + void DrawBackground(bool motionblur); }; \ No newline at end of file diff --git a/src/games/CGameFrog.cpp b/src/games/CGameFrog.cpp index 8cc6318..75c6625 100644 --- a/src/games/CGameFrog.cpp +++ b/src/games/CGameFrog.cpp @@ -11,10 +11,10 @@ using namespace std; CGameFrog::CGameFrog(CGame* aGame, bool aScreenshotMode): CGameBase(aGame, GSFrog, true, aScreenshotMode) { - Game = aGame; + Game = aGame; MusMusic = -1; - SfxDie = -1; - SfxCollect = -1; + SfxDie = -1; + SfxCollect = -1; SfxPlayerMove = -1; prevrowtype = -1; playfieldwidth = numcols * playerspeed; @@ -26,10 +26,14 @@ CGameFrog::CGameFrog(CGame* aGame, bool aScreenshotMode): CGameBase(aGame, GSFro } -CGameFrog::~CGameFrog() {}; +CGameFrog::~CGameFrog() +{ + +} -//objects ---------------------------------------------------------------------------------------------------------------- +//objects ---------------------------------------------------------------------------------------------------------------- + void CGameFrog::createobjects(bool initialize) { int rowtype = prevrowtype; @@ -63,7 +67,7 @@ void CGameFrog::createobjects(bool initialize) else { if (nextrowtype == rowtypewater) - { + { rowtype = rowtypewaterstart + rand() % (rowtypewaterend - rowtypewaterstart + 1); if (rowtype == prevrowtype) { @@ -72,17 +76,17 @@ void CGameFrog::createobjects(bool initialize) rowtype = rowtypewaterstart; } } - + prevrowtype = rowtype; } - if(nextrowtypecount == nextrowtypecountmax) - { + if(nextrowtypecount == nextrowtypecountmax) + { rowtype = lenrowtypes -1; nextrowtypecountmax = 2+(rand() %(maxrowsbeforesafetyrow-1)); nextrowtypecount = 0; - r = rand() % 2; + r = rand() % 2; if (r == 0) nextrowtype = rowtyperoad; @@ -90,14 +94,14 @@ void CGameFrog::createobjects(bool initialize) { if (r == 1) nextrowtype = rowtypewater; - + } - } + } else nextrowtypecount += 1; createobjectrow(i, rowtype); - + } i+=1; @@ -135,15 +139,15 @@ void CGameFrog::createobjects(bool initialize) prevrowtype = rowtype; } } - + if(nextrowtypecount == nextrowtypecountmax) { rowtype = lenrowtypes -1; nextrowtypecountmax = 2+(rand() % (maxrowsbeforesafetyrow-1)); //for debugging finding max objects count -// nextrowtypecountmax = 4 + //nextrowtypecountmax = 4 nextrowtypecount = 0; - r = rand() % 2; + r = rand() % 2; if (r == 0) nextrowtype = rowtyperoad; else @@ -190,14 +194,14 @@ int CGameFrog::createobject(int rownr, int col, int id, int arowtype, float spee { if (!objects[i].alive) { - object.spr = Game->Sprites->CreateSprite(); - + object.spr = Game->Sprites->CreateSprite(); + if ((id == idwater) || (id == idroad) || (id == idgrass)) { tilenr = rowtypes[arowtype].backgroundtile; endtilenr = rowtypes[arowtype].backgroundtileend; Game->Sprites->SetSpriteImage(object.spr, &spritesheetbackground,6,3); - tz = Game->Sprites->TileSize(object.spr); + tz = Game->Sprites->TileSize(object.spr); Game->Sprites->SetSpriteAnimation(object.spr, tilenr, endtilenr, 6); Game->Sprites->SetSpriteDepth(object.spr, 0); object.vel = {0,0}; @@ -211,98 +215,98 @@ int CGameFrog::createobject(int rownr, int col, int id, int arowtype, float spee { tilenr = 1; Game->Sprites->SetSpriteImage(object.spr, &spritesheetplant, 2, 1); - tz = Game->Sprites->TileSize(object.spr); - + tz = Game->Sprites->TileSize(object.spr); + Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); Game->Sprites->SetSpriteDepth(object.spr, 1); //scale = {(playerspeed - int(playerspeed / 48)) / tz.x, (playerspeed - int(playerspeed / 48)) / tz.y} scale = {playerspeed / tz.x, playerspeed / tz.y}; visualscale = scale; - object.vel = {dir*speed,0}; + object.vel = {dir*speed,0}; object.tz.x = tz.x * scale.x; object.tz.y = tz.y * scale.y; } if (id == idenemycar1) - { - tilenr = 0; + { + tilenr = 0; if (dir == -1) tilenr = 1; - + Game->Sprites->SetSpriteImage(object.spr, &spritesheetcar1, 2, 1); tz = Game->Sprites->TileSize(object.spr); - Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); + Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); Game->Sprites->SetSpriteDepth(object.spr, 3); object.vel = {dir*speed,0}; - scale = {(playerspeed - (playerspeed / 6)) / tz.x, (playerspeed - (playerspeed / 6))/ tz.y}; + scale = {(playerspeed - (playerspeed / 6)) / tz.x, (playerspeed - (playerspeed / 6))/ tz.y}; visualscale = scale; object.tz.x = tz.x * scale.x; object.tz.y = tz.y * scale.y; } if (id == idenemycar2) - { - tilenr = 0; + { + tilenr = 0; if (dir == -1) tilenr = 1; - + Game->Sprites->SetSpriteImage(object.spr, &spritesheetcar2, 2, 1); tz = Game->Sprites->TileSize(object.spr); - Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); + Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); Game->Sprites->SetSpriteDepth(object.spr, 3); object.vel = {dir*speed,0}; - scale = {(playerspeed - (playerspeed / 6)) / tz.x, (playerspeed - (playerspeed / 6))/ tz.y}; + scale = {(playerspeed - (playerspeed / 6)) / tz.x, (playerspeed - (playerspeed / 6))/ tz.y}; visualscale = scale; object.tz.x = tz.x * scale.x; object.tz.y = tz.y * scale.y; } if (id == idenemycar3) - { - tilenr = 0; + { + tilenr = 0; if (dir == -1) tilenr = 1; - + Game->Sprites->SetSpriteImage(object.spr, &spritesheetcar3, 2, 1); tz = Game->Sprites->TileSize(object.spr); - Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); + Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); Game->Sprites->SetSpriteDepth(object.spr, 3); object.vel = {dir*speed,0}; - scale = {(playerspeed - (playerspeed / 6)) / tz.x, (playerspeed - (playerspeed / 6))/ tz.y}; + scale = {(playerspeed - (playerspeed / 6)) / tz.x, (playerspeed - (playerspeed / 6))/ tz.y}; visualscale = scale; object.tz.x = tz.x * scale.x; object.tz.y = tz.y * scale.y; } if (id == idenemycar4) - { - tilenr = 0; + { + tilenr = 0; if (dir == -1) tilenr = 1; - + Game->Sprites->SetSpriteImage(object.spr, &spritesheetcar4, 2, 1); tz = Game->Sprites->TileSize(object.spr); - Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); + Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); Game->Sprites->SetSpriteDepth(object.spr, 3); object.vel = {dir*speed,0}; - scale = {(playerspeed - (playerspeed / 6)) / tz.x, (playerspeed - (playerspeed / 6))/ tz.y}; + scale = {(playerspeed - (playerspeed / 6)) / tz.x, (playerspeed - (playerspeed / 6))/ tz.y}; visualscale = scale; object.tz.x = tz.x * scale.x; object.tz.y = tz.y * scale.y; } if (id == idenemycar5) - { - tilenr = 0; + { + tilenr = 0; if (dir == -1) tilenr = 1; - + Game->Sprites->SetSpriteImage(object.spr, &spritesheetcar5, 2, 1); tz = Game->Sprites->TileSize(object.spr); - Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); + Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); Game->Sprites->SetSpriteDepth(object.spr, 3); object.vel = {dir*speed,0}; - scale = {(playerspeed - (playerspeed / 6)) / tz.x, (playerspeed - (playerspeed / 6))/ tz.y}; + scale = {(playerspeed - (playerspeed / 6)) / tz.x, (playerspeed - (playerspeed / 6))/ tz.y}; visualscale = scale; object.tz.x = tz.x * scale.x; object.tz.y = tz.y * scale.y; @@ -310,40 +314,40 @@ int CGameFrog::createobject(int rownr, int col, int id, int arowtype, float spee if (id == idcherry) - { + { tilenr = 0; Game->Sprites->SetSpriteImage(object.spr, &spritesheetfruit1); tz = Game->Sprites->TileSize(object.spr); Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); object.vel = {dir*speed,0}; - scale = {playerspeed / tz.x, playerspeed / tz.y}; + scale = {playerspeed / tz.x, playerspeed / tz.y}; visualscale = {(playerspeed - (playerspeed / 2)) / tz.x, (playerspeed - (playerspeed / 2))/ tz.y}; Game->Sprites->SetSpriteDepth(object.spr, 3); } - - if (id == idlemon) - { + + if (id == idlemon) + { tilenr = 0; Game->Sprites->SetSpriteImage(object.spr, &spritesheetfruit2); tz = Game->Sprites->TileSize(object.spr); Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); object.vel = {dir*speed,0}; - scale = {playerspeed / tz.x, playerspeed / tz.y}; + scale = {playerspeed / tz.x, playerspeed / tz.y}; visualscale = {(playerspeed - (playerspeed / 2)) / tz.x, (playerspeed - (playerspeed / 2))/ tz.y}; Game->Sprites->SetSpriteDepth(object.spr, 3); } - if (id == idapple) - { + if (id == idapple) + { tilenr = 0; Game->Sprites->SetSpriteImage(object.spr, &spritesheetfruit3); tz = Game->Sprites->TileSize(object.spr); Game->Sprites->SetSpriteAnimation(object.spr, tilenr, tilenr, 0); object.vel = {dir*speed,0}; - scale = {playerspeed / tz.x, playerspeed / tz.y}; + scale = {playerspeed / tz.x, playerspeed / tz.y}; visualscale = {(playerspeed - (playerspeed / 2)) / tz.x, (playerspeed - (playerspeed / 2))/ tz.y}; Game->Sprites->SetSpriteDepth(object.spr, 3); } @@ -351,7 +355,7 @@ int CGameFrog::createobject(int rownr, int col, int id, int arowtype, float spee Game->Sprites->SetSpriteScale(object.spr, visualscale); object.tz.x = tz.x * scale.x; object.tz.y = tz.y * scale.y; - object.pos = {screenleft + (col * playerspeed) + (playerspeed / 2), + object.pos = {screenleft + (col * playerspeed) + (playerspeed / 2), screenbottom - ((rownr+1) * playerspeed) + (playerspeed / 2)}; //Game->Sprites->SetSpriteLocation(object.spr, object.pos) object.spr->x = (int)object.pos.x; @@ -380,15 +384,15 @@ void CGameFrog::createobjectrow(int rownr, int arowtype) int dir = rand() % 2; if (dir == 0) dir = -1; - + float speed = (rowtypes[arowtype].speed - speeddeviation) + ((rand() % (int)(speeddeviation*100)/100)); int index = 0; for (int x = 0; x < numcols; x++) - { + { if (type == rowtyperoad) { index = createobject(rownr, x, idroad, arowtype, 0, 0, index); - + if ((x - lastplaced > minspace) || (repeats < maxrepeats)) { if (x - lastplaced > minspace) @@ -417,7 +421,7 @@ void CGameFrog::createobjectrow(int rownr, int arowtype) repeats += 1; index = createobject(rownr, x, id, arowtype, speed, dir, index); plantsspawned += 1; - + if (plantsspawned % cherryspawntrigger == 0) index = createobject(rownr, x, idcherry, arowtype, speed, dir, index); @@ -426,7 +430,7 @@ void CGameFrog::createobjectrow(int rownr, int arowtype) if (plantsspawned % applespawntrigger == 0) index = createobject(rownr, x, idapple, arowtype, speed, dir, index); - } + } } else { @@ -453,7 +457,7 @@ void CGameFrog::updateobjects() int id = -1; bool plantcol = false; bool stopcheckplantcol = false; - + for (int i = 0; i < maxobjects; i++) { if(objects[i].alive) @@ -467,11 +471,11 @@ void CGameFrog::updateobjects() //} //if (floatequal(objects[i].pos.y,player.pos.y)) - { + { if (Game->Sprites->DetectSpriteCollision(objects[i].spr, player.spr)) { id = objects[i].id; - + if (!playermoved && (id == idenemyplant) && !playerdeath && (player.pos.x - player.tz.x / 4 <= objects[i].pos.x + objects[i].tz.x / 2) && (player.pos.x + player.tz.x / 4 >= objects[i].pos.x - objects[i].tz.x / 2)) @@ -481,7 +485,7 @@ void CGameFrog::updateobjects() player.spr->y = (int)player.pos.y; if ((player.pos.x < screenleft) || (player.pos.x > screenright)) playerdeath = true; - + playermoved = true; plantcol = true; } @@ -520,14 +524,14 @@ void CGameFrog::updateobjects() } } } - } - - - if ((!stopcheckplantcol) && (!plantcol) && (id == idwater) && (!playerdeath)) + } + + + if ((!stopcheckplantcol) && (!plantcol) && (id == idwater) && (!playerdeath)) { stopcheckplantcol = true; for (int j = i + 1; j < maxobjects;j++) - { + { if ((objects[j].alive) /*&& floatequal(objects[j].pos.y,player.pos.y)*/) { if(Game->Sprites->DetectSpriteCollision(objects[j].spr, player.spr)) @@ -543,21 +547,21 @@ void CGameFrog::updateobjects() } } } - } + } } } } } - + if (objects[i].alive) { objects[i].pos.y = objects[i].pos.y + worldspeed + levelincspeeds[level-1]; if (objects[i].pos.y - objects[i].tz.y / 2 > screenbottom) destroyobject(i); - else + else { - objects[i].pos.x = objects[i].pos.x + objects[i].vel.x; - objects[i].pos.y = objects[i].pos.y + objects[i].vel.y; + objects[i].pos.x = objects[i].pos.x + objects[i].vel.x; + objects[i].pos.y = objects[i].pos.y + objects[i].vel.y; if (objects[i].vel.x < 0) { if (objects[i].pos.x + objects[i].tz.x / 2 < screenleft) @@ -565,15 +569,14 @@ void CGameFrog::updateobjects() } else { - if (objects[i].pos.x - objects[i].tz.x / 2 > screenright) - objects[i].pos.x = screenleft + (objects[i].pos.x - screenright) - objects[i].tz.x / 2 - objects[i].tz.x / 2; - + if (objects[i].pos.x - objects[i].tz.x / 2 > screenright) + objects[i].pos.x = screenleft + (objects[i].pos.x - screenright) - objects[i].tz.x / 2 - objects[i].tz.x / 2; } objects[i].spr->x = (int)objects[i].pos.x; objects[i].spr->y = (int)objects[i].pos.y; if ((objects[i].id == idwater) || (objects[i].id == idroad) || (objects[i].id == idgrass)) - { + { if (objects[i].pos.x < x1) { x1 = objects[i].pos.x; @@ -587,20 +590,19 @@ void CGameFrog::updateobjects() objectinfo.mostright = i; } } - + if (objects[i].pos.y > y) { y = objects[i].pos.y; objectinfo.mostbottom = i; } - else + else { if (objects[i].pos.y < y2) { y2 = objects[i].pos.y; objectinfo.mosttop = i; } - } } } @@ -618,7 +620,7 @@ void CGameFrog::updateobjects() dolevelinc = true; } } - + if (!playermoved) playerdeath = true; } @@ -626,7 +628,7 @@ void CGameFrog::updateobjects() //player ---------------------------------------------------------------------------------------------------------------- void CGameFrog::destroyplayer() -{ +{ Game->Sprites->RemoveSprite(player.spr); player.alive = false; } @@ -634,8 +636,8 @@ void CGameFrog::destroyplayer() void CGameFrog::createplayer() { player.spr = Game->Sprites->CreateSprite(); - Game->Sprites->SetSpriteDepth(player.spr, 2); - Game->Sprites->SetSpriteImage(player.spr, &spritesheetfrog, 3, 4); + Game->Sprites->SetSpriteDepth(player.spr, 2); + Game->Sprites->SetSpriteImage(player.spr, &spritesheetfrog, 3, 4); Game->Sprites->SetSpriteAnimation(player.spr, 11, 11, 10); SDL_Point tz = Game->Sprites->TileSize(player.spr); Vec2F scale = {(playerspeed -8) / tz.x, (playerspeed -8) / tz.y}; @@ -643,7 +645,7 @@ void CGameFrog::createplayer() Game->Sprites->SetSpriteCollisionShape(player.spr, SHAPE_BOX, (int)(playerspeed / 3), (int)(playerspeed/3), 0, 0, (int)(playerspeed/12)); player.tz.x = tz.x * scale.x; player.tz.y = tz.y * scale.y; - player.pos = {screenleft + (numcols / 2) * playerspeed + playerspeed / 2, screenbottom - playerstartrow * playerspeed + playerspeed / 2}; + player.pos = {screenleft + (numcols / 2) * playerspeed + playerspeed / 2, screenbottom - playerstartrow * playerspeed + playerspeed / 2}; HealthPoints = 3; Game->Sprites->SetSpriteLocation(player.spr, player.pos); playermaxrow = 0; @@ -655,12 +657,12 @@ void CGameFrog::updateplayer() { Game->Sprites->SetSpriteVisibility(player.spr, player.alive); if (player.alive) - { + { if ((!Game->Input->PrevButtons.ButLeft && Game->Input->Buttons.ButLeft) || (!Game->Input->PrevButtons.ButLeft2 && Game->Input->Buttons.ButLeft2) || (!Game->Input->PrevButtons.ButDpadLeft && Game->Input->Buttons.ButDpadLeft)) { - Game->Sprites->SetSpriteAnimation(player.spr, 4, 4, 10); + Game->Sprites->SetSpriteAnimation(player.spr, 4, 4, 10); if ((player.pos.x - player.tz.x / 2) - playerspeed >= screenleft) { @@ -676,7 +678,7 @@ void CGameFrog::updateplayer() (!Game->Input->PrevButtons.ButRight2 && Game->Input->Buttons.ButRight2) || (!Game->Input->PrevButtons.ButDpadRight && Game->Input->Buttons.ButDpadRight)) { - Game->Sprites->SetSpriteAnimation(player.spr, 7, 7, 10); + Game->Sprites->SetSpriteAnimation(player.spr, 7, 7, 10); if ((player.pos.x + player.tz.x / 2) + playerspeed <= screenright) { @@ -750,7 +752,7 @@ void CGameFrog::updateplayer() void CGameFrog::DrawBackground(bool motionblur) { - Vec2F Scale = {(float)ScreenWidth / backgroundtz.x, (float)ScreenHeight / backgroundtz.x}; + Vec2F Scale = {(float)ScreenWidth / backgroundtz.x, (float)ScreenHeight / backgroundtz.x}; SDL_Point Pos = { 0, 0}; SDL_Rect Rect = {0, 0, (int)(screenleft / Scale.x), (int)(ScreenHeight / Scale.y)}; Game->Image->DrawImageFuzeSrcRectTintFloat(Game->Renderer, background, &Rect, false, &Pos, 0, &Scale, 1, 1, 1, 1); @@ -767,13 +769,13 @@ void CGameFrog::DrawBackground(bool motionblur) //init - deinit ---------------------------------------------------------------------------------------------------------------- void CGameFrog::init() -{ +{ LoadGraphics(); level = 1; dolevelinc = false; rowsspawned = 0; plantsspawned = 0; - numobjects = 0; + numobjects = 0; worldspeed = globalworldspeed; createplayer(); createobjects(true); @@ -820,7 +822,7 @@ void CGameFrog::UnLoadSound() void CGameFrog::LoadGraphics() { background = Game->Image->LoadImage(Game->Renderer, "frog/background.png"); - backgroundtz = Game->Image->ImageSize(background); + backgroundtz = Game->Image->ImageSize(background); spritesheetfrog = Game->Image->LoadImage(Game->Renderer, "frog/player.png"); spritesheetbackground = Game->Image->LoadImage(Game->Renderer, "frog/watergrass.png"); spritesheetcar1 = Game->Image->LoadImage(Game->Renderer, "frog/carblue.png"); @@ -832,7 +834,7 @@ void CGameFrog::LoadGraphics() spritesheetplant = Game->Image->LoadImage(Game->Renderer, "frog/waterplant.png"); spritesheetfruit1 = Game->Image->LoadImage(Game->Renderer, "frog/apple.png"); spritesheetfruit2 = Game->Image->LoadImage(Game->Renderer, "frog/lemon.png"); - spritesheetfruit3 = Game->Image->LoadImage(Game->Renderer, "frog/cherry.png") ; + spritesheetfruit3 = Game->Image->LoadImage(Game->Renderer, "frog/cherry.png"); } void CGameFrog::UnloadGraphics() @@ -849,30 +851,29 @@ void CGameFrog::UnloadGraphics() Game->Image->UnLoadImage(spritesheetfruit1); Game->Image->UnLoadImage(spritesheetfruit2); Game->Image->UnLoadImage(spritesheetfruit3); - } SDL_Texture* CGameFrog::screenshot() { SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); SDL_Texture* image = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetRenderTarget(Game->Renderer, image); + SDL_SetRenderTarget(Game->Renderer, image); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); SDL_RenderClear(Game->Renderer); init(); - - worldspeed = playerspeed; + + worldspeed = playerspeed; for (int i = 0; i < 5; i++) { updateplayer(); updateobjects(); Game->Sprites->UpdateSprites(); - } + } Draw(); - + SDL_RenderPresent(Game->Renderer); SDL_SetRenderTarget(Game->Renderer, prev); - deinit(); + deinit(); return image; } @@ -885,7 +886,7 @@ void CGameFrog::OnGameStart() void CGameFrog::UpdateLogic() { - CGameBase::UpdateLogic(); + CGameBase::UpdateLogic(); if (Game->SubGameState == SGGame) { updateplayer(); @@ -907,7 +908,7 @@ void CGameFrog::UpdateLogic() if (playerdeath) - { + { Game->Audio->PlaySound(SfxDie, 0); Game->AddToScore(-150); if(HealthPoints > 1) @@ -931,7 +932,7 @@ void CGameFrog::Draw() Game->Sprites->DrawSprites(Game->Renderer); DrawBackground(false); if(!ScreenshotMode) - { + { DrawScoreBar(); DrawSubStateText(); } diff --git a/src/games/CGameFrog.h b/src/games/CGameFrog.h index 6afc247..b033292 100644 --- a/src/games/CGameFrog.h +++ b/src/games/CGameFrog.h @@ -16,22 +16,22 @@ using namespace std; #define FLOORING(x,y) (((x) + (y) - 1) / (y)); struct SRowType { - int type; - int backgroundtile; - int backgroundtileend; - bool deadlyground; - int id; - float speed; - int minspace; - int maxrepeats; + int type; + int backgroundtile; + int backgroundtileend; + bool deadlyground; + int id; + float speed; + int minspace; + int maxrepeats; }; typedef struct SRowType SRowType; struct SObjectInfo { - int mostleft = -1; - int mostright = -1; - int mostbottom = -1; - int mosttop = -1; + int mostleft = -1; + int mostright = -1; + int mostbottom = -1; + int mosttop = -1; }; typedef struct SObjectInfo SObjectInfo; @@ -40,61 +40,61 @@ typedef struct SObjectInfo SObjectInfo; class CGameFrog: public CGameBase { private: - - static const int debugmode = false; - static constexpr float playerspeed = 16*3; - static constexpr float globalworldspeed = 0.5; - - static const int rowtypewater = 0; - static const int rowtyperoad = 1; - static const int rowtypesafety = 2; - - static const int idenemycar1 = 0; - static const int idenemycar2 = 1; - static const int idenemycar3 = 2; - static const int idenemycar4 = 3; - static const int idenemycar5 = 4; - static const int idenemyplant = 5; - static const int idenemylog = 6; - static const int idnone = 7; - static const int idwater = 8; - static const int idroad = 9; - static const int idgrass = 10; - static const int idcherry = 11; - static const int idapple = 12; - static const int idlemon = 13; - - - static const int cherryspawntrigger = 103; - static const int applespawntrigger = 57; - static const int lemonspawntrigger = 23; - - static const int lemonscore = 10; - static const int applescore = 25; - static const int cherryscore = 50; - - static const int lenlevelincspeeds = 5; - float levelincspeeds[lenlevelincspeeds] = {0, 0.25, 0.5, 1.0, 1.5}; - int levelincspawns[lenlevelincspeeds] = {30, 90, 240, 570, 0}; - - static const int numcols = 14; - static const int generatorrows = 1; - static const int maxrowsbeforesafetyrow = 4; - static const int visiblerows = (int)CEILING(ScreenHeight, (int)playerspeed); - static const int numrows = visiblerows + generatorrows; - static const int playerstartrow = (int)FLOORING(visiblerows, 2) - - static constexpr float speeddeviation = 0.25; - - static const int rowtypewaterstart = 0; - static const int rowtypewaterend = 2; - static const int rowtyperoadstart = 3; - static const int rowtyperoadend = 7; - static const int maxobjects = (int)((visiblerows + generatorrows) * numcols * 1.57); - - static const int lenrowtypes = 9; - - SRowType rowtypes[lenrowtypes] = { + + static const int debugmode = false; + static constexpr float playerspeed = 16*3; + static constexpr float globalworldspeed = 0.5; + + static const int rowtypewater = 0; + static const int rowtyperoad = 1; + static const int rowtypesafety = 2; + + static const int idenemycar1 = 0; + static const int idenemycar2 = 1; + static const int idenemycar3 = 2; + static const int idenemycar4 = 3; + static const int idenemycar5 = 4; + static const int idenemyplant = 5; + static const int idenemylog = 6; + static const int idnone = 7; + static const int idwater = 8; + static const int idroad = 9; + static const int idgrass = 10; + static const int idcherry = 11; + static const int idapple = 12; + static const int idlemon = 13; + + + static const int cherryspawntrigger = 103; + static const int applespawntrigger = 57; + static const int lemonspawntrigger = 23; + + static const int lemonscore = 10; + static const int applescore = 25; + static const int cherryscore = 50; + + static const int lenlevelincspeeds = 5; + float levelincspeeds[lenlevelincspeeds] = {0, 0.25, 0.5, 1.0, 1.5}; + int levelincspawns[lenlevelincspeeds] = {30, 90, 240, 570, 0}; + + static const int numcols = 14; + static const int generatorrows = 1; + static const int maxrowsbeforesafetyrow = 4; + static const int visiblerows = (int)CEILING(ScreenHeight, (int)playerspeed); + static const int numrows = visiblerows + generatorrows; + static const int playerstartrow = (int)FLOORING(visiblerows, 2) + + static constexpr float speeddeviation = 0.25; + + static const int rowtypewaterstart = 0; + static const int rowtypewaterend = 2; + static const int rowtyperoadstart = 3; + static const int rowtyperoadend = 7; + static const int maxobjects = (int)((visiblerows + generatorrows) * numcols * 1.57); + + static const int lenrowtypes = 9; + + SRowType rowtypes[lenrowtypes] = { {rowtypewater, 6, 10, true, idenemyplant, 1, 2, 4}, {rowtypewater, 6, 10, true, idenemyplant, 2, 3, 2}, {rowtypewater, 6, 10, true, idenemyplant, 3, 4, 3}, @@ -106,32 +106,31 @@ class CGameFrog: public CGameBase { {rowtyperoad, 0, 0, false, idenemycar5, 2.5, 3, 2}, //jeep {rowtypesafety, 12, 12,false, idnone, 2, 2, 2} - }; - - - float worldspeed; - int nextrowtype; - int nextrowtypecountmax; - int nextrowtypecount; - int numobjects; - int previd; - int prevrowtype; - int playerdeath; - int playermaxrow; - int playerrow; - int plantsspawned; - int rowsspawned; - int dolevelinc; - SDL_Point backgroundtz; - CSpriteObject objects[maxobjects]; - CSpriteObject player; - SObjectInfo objectinfo; - - - - int MusMusic, SfxSucces, SfxCollect, SfxDie, SfxPlayerMove; - - int background; + }; + + + float worldspeed; + int nextrowtype; + int nextrowtypecountmax; + int nextrowtypecount; + int numobjects; + int previd; + int prevrowtype; + int playerdeath; + int playermaxrow; + int playerrow; + int plantsspawned; + int rowsspawned; + int dolevelinc; + SDL_Point backgroundtz; + CSpriteObject objects[maxobjects]; + CSpriteObject player; + SObjectInfo objectinfo; + + + int MusMusic, SfxSucces, SfxCollect, SfxDie, SfxPlayerMove; + + int background; int spritesheetfrog; int spritesheetbackground; int spritesheetcar1; @@ -144,29 +143,29 @@ class CGameFrog: public CGameBase { int spritesheetfruit1; int spritesheetfruit2; int spritesheetfruit3; - - - void updateplayer(); - void createplayer(); - void destroyplayer(); - void updateobjects(); - void createobjectrow(int rownr, int arowtype); - int createobject(int rownr, int col, int id, int arowtype, float speed, int dir, int startobjectindex); - void destroyobject(int index); - void destroyallobjects(); - void createobjects(bool initialize); - void OnGameStart() override; + + + void updateplayer(); + void createplayer(); + void destroyplayer(); + void updateobjects(); + void createobjectrow(int rownr, int arowtype); + int createobject(int rownr, int col, int id, int arowtype, float speed, int dir, int startobjectindex); + void destroyobject(int index); + void destroyallobjects(); + void createobjects(bool initialize); + void OnGameStart() override; public: - CGameFrog(CGame* aGame, bool aScreenshotMode = false); - ~CGameFrog(); - SDL_Texture* screenshot() override; - void init() override; - void deinit() override; - void UpdateLogic() override; - void Draw() override; - void UnloadGraphics() override; - void LoadGraphics() override; - void LoadSound() override; - void UnLoadSound() override; - void DrawBackground(bool motionblur); + CGameFrog(CGame* aGame, bool aScreenshotMode = false); + ~CGameFrog(); + SDL_Texture* screenshot() override; + void init() override; + void deinit() override; + void UpdateLogic() override; + void Draw() override; + void UnloadGraphics() override; + void LoadGraphics() override; + void LoadSound() override; + void UnLoadSound() override; + void DrawBackground(bool motionblur); }; \ No newline at end of file diff --git a/src/games/CGameInvaders.cpp b/src/games/CGameInvaders.cpp index 07c1b5e..2e2bea8 100644 --- a/src/games/CGameInvaders.cpp +++ b/src/games/CGameInvaders.cpp @@ -11,18 +11,18 @@ using namespace std; CGameInvaders::CGameInvaders(CGame* aGame, bool aScreenshotMode): CGameBase(aGame, GSSpaceInvaders, false, aScreenshotMode) { - Game = aGame; + Game = aGame; MusMusic = -1; - SfxSucces = -1; - SfxPlayerShoot = -1; - SfxPlayerDeath = -1; - SfxEnemyShoot = -1; - SfxEnemyDeath = -1; - SfxDie = -1; - screenleft = 0; - screenright = ScreenWidth; - screentop = 0; - screenbottom = ScreenHeight; + SfxSucces = -1; + SfxPlayerShoot = -1; + SfxPlayerDeath = -1; + SfxEnemyShoot = -1; + SfxEnemyDeath = -1; + SfxDie = -1; + screenleft = 0; + screenright = ScreenWidth; + screentop = 0; + screenbottom = ScreenHeight; } @@ -33,15 +33,15 @@ CGameInvaders::~CGameInvaders(){}; void CGameInvaders::checkexplosions() { for(int i = 0; i < maxexplosion; i++) - { + { if (explosions[i].alive) - { + { if (Game->Sprites->GetSpriteAnimFrame(explosions[i].spr) == Game->Sprites->GetSpriteAnimFrameCount(explosions[i].spr) -1) - { + { destroyexploison(i); - } - } - } + } + } + } } void CGameInvaders::destroyallexplosion() @@ -53,7 +53,7 @@ void CGameInvaders::destroyallexplosion() void CGameInvaders::destroyexploison(int index) { if (explosions[index].alive) - { + { Game->Sprites->RemoveSprite(explosions[index].spr); explosions[index].alive = false; } @@ -62,9 +62,9 @@ void CGameInvaders::destroyexploison(int index) void CGameInvaders::createexplosion(Vec2F pos) { for(int i = 0; i < maxexplosion;i++) - { + { if (!explosions[i].alive) - { + { explosions[i].spr = Game->Sprites->CreateSprite(); Game->Sprites->SetSpriteImage(explosions[i].spr, &spritesheetExplosion, 7, 1); Game->Sprites->SetSpriteScale(explosions[i].spr, {1.5,1.5}); @@ -82,25 +82,25 @@ void CGameInvaders::createexplosion(Vec2F pos) void CGameInvaders::destroyallenemybullet() { - for(int i = 0; i < maxenemybullets; i++) + for(int i = 0; i < maxenemybullets; i++) destroyenemybullet(i); } void CGameInvaders::destroyenemybullet(int index) { - if (enemybullets[index].alive) - { + if (enemybullets[index].alive) + { Game->Sprites->RemoveSprite(enemybullets[index].spr); enemybullets[index].alive = false; } } - + void CGameInvaders::createnemybullet(Vec2F pos) { - for(int i = 0; i < maxenemybullets; i++) - { + for(int i = 0; i < maxenemybullets; i++) + { if (!enemybullets[i].alive) - { + { enemybullets[i].spr = Game->Sprites->CreateSprite(); Game->Sprites->SetSpriteImage(enemybullets[i].spr, &spritesheetBullet, 2, 1); Game->Sprites->SetSpriteColour(enemybullets[i].spr, 1,0,0,1); @@ -108,8 +108,8 @@ void CGameInvaders::createnemybullet(Vec2F pos) Game->Sprites->SetSpriteScale(enemybullets[i].spr, enemyscale); Game->Sprites->SetSpriteDepth(enemybullets[i].spr, -1); enemybullets[i].tz = Game->Sprites->TileSize(enemybullets[i].spr); - enemybullets[i].tz.x = enemybullets[i].tz.x * enemyscale.x; - enemybullets[i].tz.y = enemybullets[i].tz.y * enemyscale.y; + enemybullets[i].tz.x = enemybullets[i].tz.x * enemyscale.x; + enemybullets[i].tz.y = enemybullets[i].tz.y * enemyscale.y; enemybullets[i].pos = pos; enemybullets[i].vel = {0, bulletspeed}; enemybullets[i].alive = true; @@ -122,19 +122,19 @@ void CGameInvaders::createnemybullet(Vec2F pos) void CGameInvaders::updateenemybullet() { if (!tweenactive(tweenenemypositions)) - { + { if (rand() % (enemybulletrandomizer) == 0) - { + { int col = rand() % (enemycols); int y = 0; bool fired = false; while (!fired) - { + { y = enemyrows -1; while (y >= 0) - { + { if (enemies[col + y * enemycols].alive) - { + { createnemybullet(enemies[col + y * enemycols].pos); fired = true; break; @@ -147,21 +147,21 @@ void CGameInvaders::updateenemybullet() } } } - - for(int i = 0; i < maxenemybullets; i++) - { + + for(int i = 0; i < maxenemybullets; i++) + { if (enemybullets[i].alive) - { + { enemybullets[i].pos.x += enemybullets[i].vel.x; - enemybullets[i].pos.y += enemybullets[i].vel.y; + enemybullets[i].pos.y += enemybullets[i].vel.y; Game->Sprites->SetSpriteLocation(enemybullets[i].spr, enemybullets[i].pos); if (enemybullets[i].pos.y >= screenbottom) destroyenemybullet(i); - + if (enemybullets[i].alive && player.alive) - { + { if (Game->Sprites->DetectSpriteCollision(enemybullets[i].spr, player.spr)) - { + { player.alive = false; player.freeze = 30; createexplosion(player.pos); @@ -172,21 +172,21 @@ void CGameInvaders::updateenemybullet() Game->Audio->PlaySound(SfxDie, 0); } } - - + + for (int j = 0; j < maxasteroids; j++) - { + { if (enemybullets[i].alive && asteroids[j].alive) - { + { if (Game->Sprites->DetectSpriteCollision(enemybullets[i].spr, asteroids[j].spr)) - { + { createexplosion(enemybullets[i].pos); destroyenemybullet(i); asteroids[j].healthpoints -= 1; if (asteroids[j].healthpoints == 0) destroyasteroid(j); } - } + } } } @@ -197,14 +197,14 @@ void CGameInvaders::updateenemybullet() void CGameInvaders::destroyallasteroids() { - for(int i = 0; i < maxasteroids; i++) + for(int i = 0; i < maxasteroids; i++) destroyasteroid(i); } void CGameInvaders::destroyasteroid(int index) { if (asteroids[index].alive) - { + { Game->Sprites->RemoveSprite(asteroids[index].spr); asteroids[index].alive = false; } @@ -213,7 +213,7 @@ void CGameInvaders::destroyasteroid(int index) void CGameInvaders::createasteroids() { for(int i = 0; i < maxasteroids; i++) - { + { asteroids[i].spr = Game->Sprites->CreateSprite(); asteroids[i].healthpoints = asteroidmaxhealthpoints; asteroids[i].alive = true; @@ -229,11 +229,11 @@ void CGameInvaders::createasteroids() void CGameInvaders::updateasteroids() { for(int i = 0; i < maxasteroids;i++) - { + { if (asteroids[i].alive) - { - Game->Sprites->SetSpriteScale(asteroids[i].spr, - {asteroidscale - ((asteroidscale / asteroidmaxhealthpoints) * (asteroidmaxhealthpoints - asteroids[i].healthpoints)) , + { + Game->Sprites->SetSpriteScale(asteroids[i].spr, + {asteroidscale - ((asteroidscale / asteroidmaxhealthpoints) * (asteroidmaxhealthpoints - asteroids[i].healthpoints)), asteroidscale - ((asteroidscale / asteroidmaxhealthpoints) * (asteroidmaxhealthpoints - asteroids[i].healthpoints))}); Game->Sprites->SetSpriteRotation(asteroids[i].spr, asteroids[i].spr->rotation + 0.5); } @@ -245,15 +245,15 @@ void CGameInvaders::updateasteroids() void CGameInvaders::createbullet() { if (!bullet.alive) - { + { bullet.spr = Game->Sprites->CreateSprite(); Game->Sprites->SetSpriteImage(bullet.spr, &spritesheetBullet, 2, 1); Game->Sprites->SetSpriteAnimation(bullet.spr, 1, 1, 0); Game->Sprites->SetSpriteScale(bullet.spr, enemyscale); Game->Sprites->SetSpriteDepth(bullet.spr, -1); bullet.tz = Game->Sprites->TileSize(bullet.spr); - bullet.tz.x = bullet.tz.x * enemyscale.x; - bullet.tz.y = bullet.tz.y * enemyscale.y; + bullet.tz.x = bullet.tz.x * enemyscale.x; + bullet.tz.y = bullet.tz.y * enemyscale.y; bullet.pos = player.pos ; bullet.vel = {0, -bulletspeed}; bullet.alive = true; @@ -264,7 +264,7 @@ void CGameInvaders::createbullet() void CGameInvaders::destroybullet() { if (bullet.alive) - { + { Game->Sprites->RemoveSprite(bullet.spr); bullet.alive = false; } @@ -273,26 +273,26 @@ void CGameInvaders::destroybullet() void CGameInvaders::updatebullet() { if (bullet.alive) - { + { bullet.pos.x += bullet.vel.x; - bullet.pos.y += bullet.vel.y; + bullet.pos.y += bullet.vel.y; Game->Sprites->SetSpriteLocation(bullet.spr, bullet.pos); - + for (int x = 0; x < enemycols; x++) - { + { for(int y = 0; y < enemyrows; y++) - { + { if (bullet.alive && enemies[y * enemycols + x].alive) - { + { if (Game->Sprites->DetectSpriteCollision(bullet.spr, enemies[y * enemycols + x].spr)) - { - createexplosion(enemies[y * enemycols + x].pos); + { + createexplosion(enemies[y * enemycols + x].pos); destroybullet(); destroyinvader(y * enemycols + x); if (y < 1) Game->AddToScore(25); else - { + { if (y < 3) Game->AddToScore(20); else @@ -303,22 +303,22 @@ void CGameInvaders::updatebullet() } } } - + for(int i = 0; i < maxasteroids; i++) - { + { if (bullet.alive && asteroids[i].alive) - { + { if (Game->Sprites->DetectSpriteCollision(bullet.spr, asteroids[i].spr)) - { + { createexplosion(bullet.pos); destroybullet(); asteroids[i].healthpoints -= 1; if (asteroids[i].healthpoints == 0) destroyasteroid(i); } - } + } } - + if (bullet.pos.y < screentop) destroybullet(); } @@ -334,23 +334,23 @@ void CGameInvaders::updateenemyinfo() float x1 = screenright + 1; float x2 = screenleft - 1; - float y = screentop - 1; + float y = screentop - 1; for(int i = 0; i < enemycols * enemyrows; i++) - { + { if (enemies[i].alive) - { + { if (enemies[i].pos.x < x1) - { + { x1 = enemies[i].pos.x; enemyinfo.mostleft = i; } if (enemies[i].pos.x > x2) - { + { x2 = enemies[i].pos.x; enemyinfo.mostright = i; } if (enemies[i].pos.y > y) - { + { y = enemies[i].pos.y; enemyinfo.mostbottom = i; } @@ -360,14 +360,14 @@ void CGameInvaders::updateenemyinfo() void CGameInvaders::destroyallinvaders() { - for(int i = 0; i < enemycols * enemyrows; i++) - { + for(int i = 0; i < enemycols * enemyrows; i++) + { if (enemies[i].alive) - { + { tweens[i][tweenenemypositions].active = false; Game->Sprites->RemoveSprite(enemies[i].spr); } - } + } } void CGameInvaders::destroyinvader(int index) @@ -380,61 +380,61 @@ bool CGameInvaders::tweenactive(int id) { bool result = false; for(int i = 0; i < enemyrows * enemycols; i++) - { + { if (enemies[i].alive && tweens[i][id].active) - { + { result = true; break; } - } - return result; + } + return result; } void CGameInvaders::createinvaders(bool setposition) { pattern = rand() % (5); for (int x = 0; x < enemycols; x++) - { + { for (int y = 0; y < enemyrows; y++) - { + { tweens[x + y * enemycols][tweenenemypositions] = createtween(tweenenemypositions, 1+ (rand() % ((int)DesiredFps))/100, funcsmoothstop, 1, true, DesiredFps); enemies[x + y * enemycols].alive = true; enemies[x + y * enemycols].spr = Game->Sprites->CreateSprite(); - enemies[x + y * enemycols].pos = {(float) x * (enemyspacing + enemyhorzspacing) + enemystartxoffset,(float)y * enemyspacing + enemystartyoffset}; + enemies[x + y * enemycols].pos = {(float) x * (enemyspacing + enemyhorzspacing) + enemystartxoffset,(float)y * enemyspacing + enemystartyoffset}; if (setposition) Game->Sprites->SetSpriteLocation(enemies[x + y * enemycols].spr, enemies[x + y * enemycols].pos); SDL_Point tz = {1,1}; if (y < 1) - { - Game->Sprites->SetSpriteImage(enemies[x + y * enemycols].spr, &spritesheetEnemy3, 4, 1); - Game->Sprites->SetSpriteScale(enemies[x + y * enemycols].spr, enemyscale); + { + Game->Sprites->SetSpriteImage(enemies[x + y * enemycols].spr, &spritesheetEnemy3, 4, 1); + Game->Sprites->SetSpriteScale(enemies[x + y * enemycols].spr, enemyscale); Game->Sprites->SetSpriteAnimation(enemies[x + y * enemycols].spr, 0, 3, 5); tz = Game->Sprites->TileSize(enemies[x + y * enemycols].spr); Game->Sprites->SetSpriteCollisionShape(enemies[x + y * enemycols].spr, SHAPE_BOX, tz.x-8, tz.y - 26,0, 0 , 6); - } + } else - { + { if (y < 3 ) - { - Game->Sprites->SetSpriteImage(enemies[x + y * enemycols].spr, &spritesheetEnemy2, 4, 1); - Game->Sprites->SetSpriteScale(enemies[x + y * enemycols].spr, enemyscale); - + { + Game->Sprites->SetSpriteImage(enemies[x + y * enemycols].spr, &spritesheetEnemy2, 4, 1); + Game->Sprites->SetSpriteScale(enemies[x + y * enemycols].spr, enemyscale); + Game->Sprites->SetSpriteAnimation(enemies[x + y * enemycols].spr, 0, 3, 5); tz = Game->Sprites->TileSize(enemies[x + y * enemycols].spr); Game->Sprites->SetSpriteCollisionShape(enemies[x + y * enemycols].spr, SHAPE_BOX, tz.x-15, tz.y - 18,0, 0 , -2); - } + } else - { - Game->Sprites->SetSpriteImage(enemies[x + y * enemycols].spr, &spritesheetEnemy1, 5, 1); - Game->Sprites->SetSpriteScale(enemies[x + y * enemycols].spr, enemyscale); - + { + Game->Sprites->SetSpriteImage(enemies[x + y * enemycols].spr, &spritesheetEnemy1, 5, 1); + Game->Sprites->SetSpriteScale(enemies[x + y * enemycols].spr, enemyscale); + Game->Sprites->SetSpriteAnimation(enemies[x + y * enemycols].spr,0, 4, 5); tz = Game->Sprites->TileSize(enemies[x + y * enemycols].spr); Game->Sprites->SetSpriteCollisionShape(enemies[x + y * enemycols].spr, SHAPE_BOX, tz.x-17, tz.y - 12,0, 0 , -2); } } enemies[x + y * enemycols].tz.x = tz.x * enemyscale.x; - enemies[x + y * enemycols].tz.y = tz.y * enemyscale.y; + enemies[x + y * enemycols].tz.y = tz.y * enemyscale.y; } } } @@ -442,10 +442,10 @@ void CGameInvaders::createinvaders(bool setposition) void CGameInvaders::updateinvaders() { updateenemyinfo(); - + //all enemies cleared if (enemyinfo.mostleft == -1) - { + { Game->AddToScore(250); enemyvel = {enemyspeed, 0}; createinvaders(false); @@ -453,62 +453,62 @@ void CGameInvaders::updateinvaders() destroyallenemybullet(); Game->Audio->PlaySound(SfxSucces, 0); } - + bool btweenactive = tweenactive(tweenenemypositions); - + //enemies reached horizontal screen boundaries if (((enemies[enemyinfo.mostleft].pos.x - enemies[enemyinfo.mostleft].tz.x / 2 + enemyvel.x < screenleft) || (enemies[enemyinfo.mostright].pos.x + enemies[enemyinfo.mostright].tz.x / 2 + enemyvel.x > screenright)) && !btweenactive) - { + { for(int i = 0; i < enemycols * enemyrows; i++) - { + { if (enemies[i].alive) enemies[i].pos.y += enemyspacing / 4; } enemyvel.x *= -1; - enemyvel.y *= -1; + enemyvel.y *= -1; } - + //update enemy positions for(int i = 0; i < enemycols * enemyrows; i++) - { + { if (enemies[i].alive) - { + { if (btweenactive) - { + { tweens[i][tweenenemypositions] = updatetween( tweens[i][tweenenemypositions]); Vec2F pos = enemies[i].pos; - + if (pattern == 0) - { + { if ((i % enemycols) < enemycols / 3) pos.x = pos.x * tweens[i][tweenenemypositions].funcval; - else - { + else + { if ((i % enemycols) > enemycols * 2 / 3) pos.x = screenright - (screenright - pos.x) * tweens[i][tweenenemypositions].funcval; } pos.y = pos.y * tweens[i][tweenenemypositions].funcval; - } - else - { + } + else + { if(pattern == 1) pos.y = pos.y * tweens[i][tweenenemypositions].funcval; else - { + { if (pattern == 2) - { + { if (i % enemycols < enemycols / 2) pos.x = pos.x * tweens[i][tweenenemypositions].funcval; - else + else pos.x = screenright - (screenright - pos.x) * tweens[i][tweenenemypositions].funcval; } else - { + { if( pattern == 3) pos.x = pos.x * tweens[i][tweenenemypositions].funcval; else - { + { if (pattern == 4) pos.x = screenright - (screenright - pos.x) * tweens[i][tweenenemypositions].funcval; } @@ -516,22 +516,22 @@ void CGameInvaders::updateinvaders() } } Game->Sprites->SetSpriteLocation(enemies[i].spr, pos); - } + } else - { + { if (Game->SubGameState == SGGame) - { + { enemies[i].pos.x += enemyvel.x; - enemies[i].pos.y += enemyvel.y; + enemies[i].pos.y += enemyvel.y; Game->Sprites->SetSpriteLocation(enemies[i].spr, enemies[i].pos); } } } - } + } //enemies reached bottom if ((player.pos.y - enemies[enemyinfo.mostbottom].pos.y) < endscreenconstant) - { + { Game->AddToScore(-250); enemyvel = {enemyspeed, 0}; destroyallinvaders(); @@ -558,10 +558,10 @@ void CGameInvaders::createplayer() Game->Sprites->SetSpriteAnimation(player.spr, 0, 0, 0); Game->Sprites->SetSpriteScale(player.spr, enemyscale); player.tz = Game->Sprites->TileSize(player.spr); - Game->Sprites->SetSpriteCollisionShape(player.spr, SHAPE_BOX, player.tz.x-20, player.tz.y - 12,0, 0, 12); - player.tz.x = player.tz.x * enemyscale.x; - player.tz.y = player.tz.y * enemyscale.y; - player.pos = { (float)(screenright - screenleft) / 2, (float)screenbottom - player.tz.y / 2}; + Game->Sprites->SetSpriteCollisionShape(player.spr, SHAPE_BOX, player.tz.x-20, player.tz.y - 12,0, 0, 12); + player.tz.x = player.tz.x * enemyscale.x; + player.tz.y = player.tz.y * enemyscale.y; + player.pos = { (float)(screenright - screenleft) / 2, (float)screenbottom - player.tz.y / 2}; HealthPoints = 3; player.freeze = 0; Game->Sprites->SetSpriteLocation(player.spr, player.pos); @@ -571,13 +571,13 @@ void CGameInvaders::updateplayer() { Game->Sprites->SetSpriteVisibility(player.spr, player.alive); if (player.alive) - { + { Game->Sprites->SetSpriteAnimation(player.spr, 0, 0, 0); if ((Game->Input->Buttons.ButLeft) || (Game->Input->Buttons.ButLeft2) || (Game->Input->Buttons.ButDpadLeft)) - { + { if (player.pos.x - player.tz.x / 2 - playerspeed > screenleft) player.pos.x -= playerspeed; else @@ -588,7 +588,7 @@ void CGameInvaders::updateplayer() if ((Game->Input->Buttons.ButRight) || (Game->Input->Buttons.ButRight2) || (Game->Input->Buttons.ButDpadRight)) - { + { if ( player.pos.x + player.tz.x / 2 + playerspeed < screenright) player.pos.x += playerspeed; else @@ -596,12 +596,12 @@ void CGameInvaders::updateplayer() Game->Sprites->SetSpriteAnimation(player.spr, 4, 4, 0); } Game->Sprites->SetSpriteLocation(player.spr, player.pos); - + if (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA) createbullet(); - } + } else - { + { if (player.freeze > 0) player.freeze -= 1; else @@ -618,47 +618,47 @@ void CGameInvaders::DrawBackground(bool motionblur) if ((motionblur) && (Game->MotionBlur)) alpha = 0.3; - backgroundfade += backgroundfadeinc; + backgroundfade += backgroundfadeinc; if (backgroundfade >= 100) - { + { backgroundfadeinc *= -1; backgroundfade = 100; - } + } if (backgroundfade <= 0) - { + { backgroundfadeinc *= -1; backgroundfade = 0; - } - SDL_Point Pos = { ScreenWidth / 2, ScreenHeight / 2}; - Vec2F Scale = {(float)ScreenWidth / backgroundtz.x, (float)ScreenHeight / backgroundtz.y}; + } + SDL_Point Pos = { ScreenWidth / 2, ScreenHeight / 2}; + Vec2F Scale = {(float)ScreenWidth / backgroundtz.x, (float)ScreenHeight / backgroundtz.y}; Game->Image->DrawImageFuzeTintFloat(Game->Renderer, background, true, &Pos, 0, &Scale, 1, 1, 1, alpha); - Scale = {(float)ScreenWidth / background2tz.x, (float)ScreenHeight / background2tz.y}; + Scale = {(float)ScreenWidth / background2tz.x, (float)ScreenHeight / background2tz.y}; Game->Image->DrawImageFuzeTintFloat(Game->Renderer, background2, true, &Pos, 0, &Scale, 1, 1, 1, 0.3 - (backgroundfade / 450)); - SDL_Rect SrcRect = {0, 0, background3tz.x, background3tz.y}; - SDL_Rect DstRect = {0, 0, ScreenWidth, ScreenHeight}; + SDL_Rect SrcRect = {0, 0, background3tz.x, background3tz.y}; + SDL_Rect DstRect = {0, 0, ScreenWidth, ScreenHeight}; Game->Image->DrawImage(Game->Renderer, background3, &SrcRect , &DstRect); - Scale = {4,4}; - Pos = {800, 400}; - Game->Image->DrawImageFuzeTintFloat(Game->Renderer, backgrounditem, true, &Pos, 45, &Scale, 1, 1, 1, 1); + Scale = {4,4}; + Pos = {800, 400}; + Game->Image->DrawImageFuzeTintFloat(Game->Renderer, backgrounditem, true, &Pos, 45, &Scale, 1, 1, 1, 1); } //init - deinit ---------------------------------------------------------------------------------------------------------------- void CGameInvaders::init() { - LoadGraphics(); + LoadGraphics(); - deaths = 0; + deaths = 0; backgroundfade = 0; backgroundfadeinc = 1; enemyvel = {enemyspeed, 0}; - - createinvaders(ScreenshotMode); + + createinvaders(ScreenshotMode); createplayer(); createasteroids(); @@ -672,7 +672,7 @@ void CGameInvaders::init() void CGameInvaders::deinit() { - destroyplayer(); + destroyplayer(); destroyallinvaders(); destroybullet(); destroyallasteroids(); @@ -714,64 +714,64 @@ void CGameInvaders::UnLoadSound() void CGameInvaders::LoadGraphics() { - spritesheetBullet = Game->Image->LoadImage(Game->Renderer, "invaders/bullet.png"); - spritesheetExplosion = Game->Image->LoadImage(Game->Renderer, "invaders/explosion.png"); - spritesheetAsteroid = Game->Image->LoadImage(Game->Renderer, "invaders/asteroid-01.png"); - spritesheetEnemy1 = Game->Image->LoadImage(Game->Renderer, "invaders/enemy1.png"); //bottom - spritesheetEnemy2 = Game->Image->LoadImage(Game->Renderer, "invaders/enemy2.png"); //middle - spritesheetEnemy3 = Game->Image->LoadImage(Game->Renderer, "invaders/enemy3.png"); //top - spritesheetPlayer = Game->Image->LoadImage(Game->Renderer, "invaders/player.png"); //top - background = Game->Image->LoadImage(Game->Renderer, "invaders/background.png"); - background2 = Game->Image->LoadImage(Game->Renderer, "invaders/parallax-space-stars.png"); - background3 = Game->Image->LoadImage(Game->Renderer, "invaders/parallax-space-far-planets.png"); - backgrounditem = Game->Image->LoadImage(Game->Renderer, "invaders/parallax-space-ring-planet.png"), + spritesheetBullet = Game->Image->LoadImage(Game->Renderer, "invaders/bullet.png"); + spritesheetExplosion = Game->Image->LoadImage(Game->Renderer, "invaders/explosion.png"); + spritesheetAsteroid = Game->Image->LoadImage(Game->Renderer, "invaders/asteroid-01.png"); + spritesheetEnemy1 = Game->Image->LoadImage(Game->Renderer, "invaders/enemy1.png"); //bottom + spritesheetEnemy2 = Game->Image->LoadImage(Game->Renderer, "invaders/enemy2.png"); //middle + spritesheetEnemy3 = Game->Image->LoadImage(Game->Renderer, "invaders/enemy3.png"); //top + spritesheetPlayer = Game->Image->LoadImage(Game->Renderer, "invaders/player.png"); //top + background = Game->Image->LoadImage(Game->Renderer, "invaders/background.png"); + background2 = Game->Image->LoadImage(Game->Renderer, "invaders/parallax-space-stars.png"); + background3 = Game->Image->LoadImage(Game->Renderer, "invaders/parallax-space-far-planets.png"); + backgrounditem = Game->Image->LoadImage(Game->Renderer, "invaders/parallax-space-ring-planet.png"), - backgroundtz = Game->Image->ImageSize(background); - background2tz = Game->Image->ImageSize(background2); - background3tz = Game->Image->ImageSize(background3); - backgrounditemtz = Game->Image->ImageSize(backgrounditem); + backgroundtz = Game->Image->ImageSize(background); + background2tz = Game->Image->ImageSize(background2); + background3tz = Game->Image->ImageSize(background3); + backgrounditemtz = Game->Image->ImageSize(backgrounditem); } void CGameInvaders::UnloadGraphics() { Game->Image->UnLoadImage(spritesheetBullet); - Game->Image->UnLoadImage(spritesheetExplosion); - Game->Image->UnLoadImage(spritesheetAsteroid); - Game->Image->UnLoadImage(spritesheetEnemy1); - Game->Image->UnLoadImage(spritesheetEnemy2); - Game->Image->UnLoadImage(spritesheetEnemy3); - Game->Image->UnLoadImage(spritesheetPlayer); - Game->Image->UnLoadImage(background); - Game->Image->UnLoadImage(background2); - Game->Image->UnLoadImage(background3); - Game->Image->UnLoadImage(backgrounditem); + Game->Image->UnLoadImage(spritesheetExplosion); + Game->Image->UnLoadImage(spritesheetAsteroid); + Game->Image->UnLoadImage(spritesheetEnemy1); + Game->Image->UnLoadImage(spritesheetEnemy2); + Game->Image->UnLoadImage(spritesheetEnemy3); + Game->Image->UnLoadImage(spritesheetPlayer); + Game->Image->UnLoadImage(background); + Game->Image->UnLoadImage(background2); + Game->Image->UnLoadImage(background3); + Game->Image->UnLoadImage(backgrounditem); } SDL_Texture* CGameInvaders::screenshot() { SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); SDL_Texture* image = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetRenderTarget(Game->Renderer, image); + SDL_SetRenderTarget(Game->Renderer, image); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); SDL_RenderClear(Game->Renderer); init(); - + Draw(); - + SDL_RenderPresent(Game->Renderer); SDL_SetRenderTarget(Game->Renderer, prev); - deinit(); + deinit(); return image; } //Update ---------------------------------------------------------------------------------------------------------------- void CGameInvaders::UpdateObjects(bool IsGameState) -{ +{ updateinvaders(); - if (IsGameState) + if (IsGameState) { - updateenemybullet(); + updateenemybullet(); updateplayer(); updatebullet(); updateasteroids(); @@ -780,8 +780,8 @@ void CGameInvaders::UpdateObjects(bool IsGameState) bool CGameInvaders::DrawObjects() { - //need todo this here so last frame is also drawn - checkexplosions(); + //need todo this here so last frame is also drawn + checkexplosions(); //call drawsprites in base class return true; } diff --git a/src/games/CGameInvaders.h b/src/games/CGameInvaders.h index 92d8dd4..08979ef 100644 --- a/src/games/CGameInvaders.h +++ b/src/games/CGameInvaders.h @@ -26,30 +26,30 @@ typedef struct senemyinfo senemyinfo; class CGameInvaders: public CGameBase { private: - static const int tweenenemypositions = 0; - static const int tweenenemydeath = 1; - - - static const int enemyrows = 5; - static const int enemycols = 7; - static const int enemystartxoffset = 50; - static const int enemystartyoffset = 50; - static const int enemyspacing = 60; - static const int enemyhorzspacing = 50; - Vec2F enemyscale = {1.5,1.5}; - static const int enemyspeed = 1; - static constexpr float enemyspeedinc = 0.15; - static const int playerspeed = 8; - static const int bulletspeed = 10; - static const int asteroidsoffset = 150; - static const int endscreenconstant = 45 + asteroidsoffset; - static const int maxexplosion = 10; - static const int maxasteroids = 6; - static constexpr float asteroidscale = 2.5 ; - static const int asteroidmaxhealthpoints = 50; - static const int maxenemybullets = 5; - static const int enemybulletrandomizer = 100; - + static const int tweenenemypositions = 0; + static const int tweenenemydeath = 1; + + + static const int enemyrows = 5; + static const int enemycols = 7; + static const int enemystartxoffset = 50; + static const int enemystartyoffset = 50; + static const int enemyspacing = 60; + static const int enemyhorzspacing = 50; + Vec2F enemyscale = {1.5,1.5}; + static const int enemyspeed = 1; + static constexpr float enemyspeedinc = 0.15; + static const int playerspeed = 8; + static const int bulletspeed = 10; + static const int asteroidsoffset = 150; + static const int endscreenconstant = 45 + asteroidsoffset; + static const int maxexplosion = 10; + static const int maxasteroids = 6; + static constexpr float asteroidscale = 2.5; + static const int asteroidmaxhealthpoints = 50; + static const int maxenemybullets = 5; + static const int enemybulletrandomizer = 100; + int deaths = 0; int pattern = 0; @@ -64,64 +64,64 @@ class CGameInvaders: public CGameBase { CSpriteObject explosions[maxexplosion]; CSpriteObject asteroids[maxasteroids]; CSpriteObject enemybullets[maxenemybullets]; - + CTweenInfo tweens[enemycols * enemycols][2]; - int background; - int background2; - int background3; - int backgrounditem; - - int spritesheetBullet; - int spritesheetExplosion; - int spritesheetAsteroid; - int spritesheetEnemy1; - int spritesheetEnemy2; - int spritesheetEnemy3; - int spritesheetPlayer; - - SDL_Point backgroundtz; - SDL_Point background2tz; - SDL_Point background3tz; - SDL_Point backgrounditemtz; - - int MusMusic, SfxPlayerShoot, SfxPlayerDeath, SfxEnemyShoot, SfxEnemyDeath, SfxSucces, SfxDie; - - void updateplayer(); - void createplayer(); - void destroyplayer(); - void updateinvaders(); - void createinvaders(bool setposition); - bool tweenactive(int id); - void destroyinvader(int index); - void destroyallinvaders(); - void updateenemyinfo(); - void updatebullet(); - void destroybullet(); - void createbullet(); - void updateasteroids(); - void createasteroids(); - void destroyasteroid(int index); - void destroyallasteroids(); - void updateenemybullet(); - void createnemybullet(Vec2F pos); - void destroyenemybullet(int index); - void destroyallenemybullet(); - void createexplosion(Vec2F pos); - void destroyexploison(int index); - void destroyallexplosion(); - void checkexplosions(); + int background; + int background2; + int background3; + int backgrounditem; + + int spritesheetBullet; + int spritesheetExplosion; + int spritesheetAsteroid; + int spritesheetEnemy1; + int spritesheetEnemy2; + int spritesheetEnemy3; + int spritesheetPlayer; + + SDL_Point backgroundtz; + SDL_Point background2tz; + SDL_Point background3tz; + SDL_Point backgrounditemtz; + + int MusMusic, SfxPlayerShoot, SfxPlayerDeath, SfxEnemyShoot, SfxEnemyDeath, SfxSucces, SfxDie; + + void updateplayer(); + void createplayer(); + void destroyplayer(); + void updateinvaders(); + void createinvaders(bool setposition); + bool tweenactive(int id); + void destroyinvader(int index); + void destroyallinvaders(); + void updateenemyinfo(); + void updatebullet(); + void destroybullet(); + void createbullet(); + void updateasteroids(); + void createasteroids(); + void destroyasteroid(int index); + void destroyallasteroids(); + void updateenemybullet(); + void createnemybullet(Vec2F pos); + void destroyenemybullet(int index); + void destroyallenemybullet(); + void createexplosion(Vec2F pos); + void destroyexploison(int index); + void destroyallexplosion(); + void checkexplosions(); public: - CGameInvaders(CGame* aGame, bool aScreenshotMode = false); - ~CGameInvaders(); - SDL_Texture* screenshot() override; - void init() override; - void deinit() override; - void UnloadGraphics() override; - void LoadGraphics() override; - void LoadSound() override; - void UnLoadSound() override; - void UpdateObjects(bool IsGameState) override; - bool DrawObjects() override; - void DrawBackground(bool motionblur); + CGameInvaders(CGame* aGame, bool aScreenshotMode = false); + ~CGameInvaders(); + SDL_Texture* screenshot() override; + void init() override; + void deinit() override; + void UnloadGraphics() override; + void LoadGraphics() override; + void LoadSound() override; + void UnLoadSound() override; + void UpdateObjects(bool IsGameState) override; + bool DrawObjects() override; + void DrawBackground(bool motionblur); }; \ No newline at end of file diff --git a/src/games/CGamePang.cpp b/src/games/CGamePang.cpp index 7203fd1..cb1dee8 100644 --- a/src/games/CGamePang.cpp +++ b/src/games/CGamePang.cpp @@ -11,19 +11,22 @@ using namespace std; CGamePang::CGamePang(CGame* aGame, bool aScreenshotMode): CGameBase(aGame, GSPang, true, aScreenshotMode) { - Game = aGame; + Game = aGame; MusMusic = -1; - SfxSucces = -1; - SfxDie = -1; - SfxShoot = -1; - SfxPop = -1; - screenleft = 0; - screenright = ScreenWidth; - screentop = 0; - screenbottom = ScreenHeight; + SfxSucces = -1; + SfxDie = -1; + SfxShoot = -1; + SfxPop = -1; + screenleft = 0; + screenright = ScreenWidth; + screentop = 0; + screenbottom = ScreenHeight; } -CGamePang::~CGamePang() {}; +CGamePang::~CGamePang() +{ + +} @@ -38,39 +41,39 @@ void CGamePang::destroyallballs() void CGamePang::destroyball(int index, bool nocreate) { if (!nocreate) - { + { if (balls[index].id > ballsmall) - { + { createball(balls[index].id - 1, balls[index].pos.x - 25, balls[index].pos.y, -10); createball(balls[index].id - 1, balls[index].pos.x + 25, balls[index].pos.y, 10); - } - } + } + } if (balls[index].alive) - { + { Game->Sprites->RemoveSprite(balls[index].spr); balls[index].alive = false; - } + } } void CGamePang::createball(int size, float x, float y, float speed) { for (int i = 0; i < maxballs; i++) - { + { if (!balls[i].alive) - { + { balls[i].spr = Game->Sprites->CreateSprite(); Game->Sprites->SetSpriteImage(balls[i].spr, &spritesheetball); - Game->Sprites->SetSpriteCollisionShape(balls[i].spr, SHAPE_CIRCLE, 35,35,0,0,0); + Game->Sprites->SetSpriteCollisionShape(balls[i].spr, SHAPE_CIRCLE, 35,35,0,0,0); //Game->Sprites->SetSpriteCollisionShape(balls[i].spr, SHAPE_BOX, 27,27,0,0,0); - Game->Sprites->SetSpriteColour(balls[i].spr, 1, 1, 1, 0.7f); + Game->Sprites->SetSpriteColour(balls[i].spr, 1, 1, 1, 0.7f); Vec2F Scale = ballscale; - Scale.x = Scale.x * size; - Scale.y = Scale.y * size; - Game->Sprites->SetSpriteScale(balls[i].spr, Scale); + Scale.x = Scale.x * size; + Scale.y = Scale.y * size; + Game->Sprites->SetSpriteScale(balls[i].spr, Scale); Game->Sprites->SetSpriteDepth(balls[i].spr, 6); balls[i].tz = Game->Image->ImageSize(spritesheetball); - balls[i].tz.x = balls[i].tz.x * Scale.x; - balls[i].tz.x = balls[i].tz.y * Scale.y; + balls[i].tz.x = balls[i].tz.x * Scale.x; + balls[i].tz.x = balls[i].tz.y * Scale.y; balls[i].pos = { x, y}; Game->Sprites->SetSpriteLocation(balls[i].spr, balls[i].pos); balls[i].alive = true; @@ -79,47 +82,47 @@ void CGamePang::createball(int size, float x, float y, float speed) balls[i].curforce = balls[i].force/3; balls[i].id = size; break; - } - } + } + } } void CGamePang::updateballs() { levelcleared = true; for (int i = 0; i < maxballs; i++) - { + { if (balls[i].alive) - { + { levelcleared = false; - if (balls[i].pos.x + balls[i].speed > screenright) - { + if (balls[i].pos.x + balls[i].speed > screenright) + { if (balls[i].speed > 0) balls[i].speed = -abs(balls[i].speed); - } - + } + if (balls[i].pos.x + balls[i].speed < screenleft) - { + { if (balls[i].speed < 0) balls[i].speed = abs(balls[i].speed); - } - - + } + + balls[i].pos.x += balls[i].speed*2; if (balls[i].id == ballbig) balls[i].curforce += 0.1; - else - { + else + { if(balls[i].id == ballmedium) balls[i].curforce += 0.15; else - { + { if (balls[i].id == ballsmall) balls[i].curforce += 0.25; - } - } - + } + } + balls[i].pos.y += balls[i].curforce; if (balls[i].id == ballbig) @@ -129,54 +132,54 @@ void CGamePang::updateballs() if (balls[i].id == ballmedium) if (balls[i].pos.y >= screenbottom - 100) balls[i].curforce = balls[i].force; - + if (balls[i].id == ballsmall) if (balls[i].pos.y >= screenbottom - 75) balls[i].curforce = balls[i].force; Game->Sprites->SetSpriteLocation(balls[i].spr, balls[i].pos); - + if (!playerstate(playerstatereviving) && Game->Sprites->DetectSpriteCollision(balls[i].spr, player.spr)) - { + { Game->AddToScore(-25); HealthPoints -= 1; addplayerstate(playerstatereviving); remplayerstate(playerstateshoot); player.stateticks = 90; Game->Audio->PlaySound(SfxDie, 0); - } - + } + if (bullet.alive && (bullet.freeze == 0)) - { + { if (Game->Sprites->DetectSpriteCollision(balls[i].spr, bullet.spr)) - { + { Game->AddToScore(balls[i].id * 7); destroyball(i, false); bullet.freeze = 4; Game->Sprites->SetSpriteAnimation(bullet.spr, 0, 1, 10); Game->Audio->PlaySound(SfxPop, 0); - } - } - } - } - if (levelcleared) - { + } + } + } + } + if (levelcleared) + { if (level < maxbigballs) level += 1; Game->Audio->PlaySound(SfxSucces, 0); Game->AddToScore(100); createballs(); - } + } } void CGamePang::drawballs() { for (int i = 0; i < maxballs; i++) - { + { if (balls[i].alive) Game->Sprites->DrawSprite(Game->Renderer, balls[i].spr); - - } + + } } void CGamePang::createballs() @@ -184,16 +187,16 @@ void CGamePang::createballs() int added = 0; int speed = 10; for (int i = screenleft; i < screenright; i += int((screenright - screenleft) / (level + 1)) + 1) - { + { if ((i > screenleft) && (i < screenright)) - { + { createball(ballbig, i, 160, speed); speed *= -1; added += 1; if (added >= level) break; } - } + } } //bullet ---------------------------------------------------------------------------------------------------------------- @@ -201,10 +204,10 @@ void CGamePang::createballs() void CGamePang::destroybullet() { if (bullet.alive) - { + { Game->Sprites->RemoveSprite(bullet.spr); bullet.alive = false; - } + } } void CGamePang::createbullet() @@ -218,8 +221,8 @@ void CGamePang::createbullet() Game->Sprites->SetSpriteScale(bullet.spr, bulletscale); Game->Sprites->SetSpriteDepth(bullet.spr, 3); bullet.tz = Game->Sprites->TileSize(bullet.spr); - bullet.tz.x = bullet.tz.x * bulletscale.x; - bullet.tz.y = bullet.tz.y * bulletscale.y; + bullet.tz.x = bullet.tz.x * bulletscale.x; + bullet.tz.y = bullet.tz.y * bulletscale.y; int tmpx = bullet.tz.x; bullet.tz.x = bullet.tz.y; bullet.tz.y = tmpx; @@ -232,47 +235,47 @@ void CGamePang::createbullet() void CGamePang::updatebullet() { if (bullet.alive) - { + { if (bullet.freeze > 0) - { + { bullet.freeze -= 1; if (bullet.freeze == 0) - { + { remplayerstate(playerstateshoot); destroybullet(); - } - } + } + } else - { + { bullet.pos.x += bullet.vel.x; - bullet.pos.y += bullet.vel.y; + bullet.pos.y += bullet.vel.y; if (bullet.pos.y - bullet.tz.y /2 <= screentop) - { + { bullet.freeze = 6; Game->Sprites->SetSpriteAnimation(bullet.spr, 0, 1, 10); - } + } Game->Sprites->SetSpriteLocation(bullet.spr, bullet.pos); - } - } + } + } } void CGamePang::drawbullet() { if (bullet.alive) - { - //copy whats on screen to a temporary buffer (i know this already contains the background) - SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); - SDL_SetRenderTarget(Game->Renderer, Game->TexTmp); - Game->Image->DrawImage(Game->Renderer, prev, NULL, NULL); - SDL_SetRenderTarget(Game->Renderer, prev); - //draw the sprite + { + //copy whats on screen to a temporary buffer (i know this already contains the background) + SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); + SDL_SetRenderTarget(Game->Renderer, Game->TexTmp); + Game->Image->DrawImage(Game->Renderer, prev, NULL, NULL); + SDL_SetRenderTarget(Game->Renderer, prev); + //draw the sprite Game->Sprites->DrawSprite(Game->Renderer, bullet.spr); - //draw bottom part of what was previously on screen back to the screen to obscure bottom part of the chain texture - //this makes it seem as if the texture is created on the ground instead of at the bottom of the screen, like it is - //in real time. - SDL_Rect Rect = {0, screenbottom - backgroundcopyheight, screenright, backgroundcopyheight}; - Game->Image->DrawImage(Game->Renderer, Game->TexTmp, &Rect, &Rect); - } + //draw bottom part of what was previously on screen back to the screen to obscure bottom part of the chain texture + //this makes it seem as if the texture is created on the ground instead of at the bottom of the screen, like it is + //in real time. + SDL_Rect Rect = {0, screenbottom - backgroundcopyheight, screenright, backgroundcopyheight}; + Game->Image->DrawImage(Game->Renderer, Game->TexTmp, &Rect, &Rect); + } } //player ---------------------------------------------------------------------------------------------------------------- @@ -280,10 +283,10 @@ void CGamePang::drawbullet() void CGamePang::destroyplayer() { if(player.alive) - { + { Game->Sprites->RemoveSprite(player.spr); player.alive = false; - } + } } void CGamePang::createplayer() @@ -297,9 +300,9 @@ void CGamePang::createplayer() Game->Sprites->SetSpriteDepth(player.spr, 37); player.state = playerstateidle; player.tz = Game->Sprites->TileSize(player.spr); - player.tz.x = player.tz.x * playerscale.x; - player.tz.y = player.tz.y * playerscale.y; - player.pos = { (float)(screenright - screenleft) / 2,(float)screenbottom -10- player.tz.y / 2}; + player.tz.x = player.tz.x * playerscale.x; + player.tz.y = player.tz.y * playerscale.y; + player.pos = { (float)(screenright - screenleft) / 2,(float)screenbottom -10- player.tz.y / 2}; HealthPoints = 3; Game->Sprites->SetSpriteLocation(player.spr, player.pos); player.alive = true; @@ -313,7 +316,7 @@ void CGamePang::addplayerstate(int state) bool CGamePang::playerstate(int state) { - return ((player.state & state) == state); + return ((player.state & state) == state); } void CGamePang::remplayerstate(int state) @@ -327,82 +330,82 @@ void CGamePang::updateplayer() Game->Sprites->SetSpriteVisibility(player.spr, player.alive); if (player.alive) - { + { if (player.stateticks > 0) player.stateticks -= 1; else - { + { if (playerstate(playerstateshoot)) remplayerstate(playerstateshoot); else - { + { if (playerstate(playerstatereviving)) remplayerstate(playerstatereviving); - } - } - + } + } + if (!playerstate(playerstateshoot)) - { + { if ((Game->Input->Buttons.ButLeft) || (Game->Input->Buttons.ButLeft2) || (Game->Input->Buttons.ButDpadLeft)) - { + { if ( player.pos.x - player.tz.x / 2 - playerspeed > screenleft) - { + { player.pos.x -=playerspeed; if (!playerstate(playerstatemoveleft)) - { + { addplayerstate(playerstatemoveleft); Game->Sprites->SetSpriteAnimation(player.spr, 12, 14, 10); - } - } + } + } else - { + { player.pos.x = screenleft + player.tz.x / 2; if (playerstate(playerstatemoveleft)) - { + { remplayerstate(playerstatemoveleft); Game->Sprites->SetSpriteAnimation(player.spr, 37, 37, 0); - } - } - } + } + } + } else - { + { if ((Game->Input->Buttons.ButRight) || (Game->Input->Buttons.ButRight2) || (Game->Input->Buttons.ButDpadRight)) - { + { if ( player.pos.x + player.tz.x / 2 + playerspeed < screenright) - { + { player.pos.x += playerspeed; if (!playerstate(playerstatemoveright)) - { + { addplayerstate(playerstatemoveright); Game->Sprites->SetSpriteAnimation(player.spr, 24, 26, 10); - } - } + } + } else - { + { player.pos.x = screenright - player.tz.x / 2; if (playerstate(playerstatemoveleft)) - { + { remplayerstate(playerstatemoveright); Game->Sprites->SetSpriteAnimation(player.spr,37, 37, 0); - } - } - } + } + } + } else - { + { remplayerstate(playerstatemoveright); remplayerstate(playerstatemoveleft); Game->Sprites->SetSpriteAnimation(player.spr, 37, 37, 0); - } - } + } + } if ((!playerstate(playerstatereviving)) && (!Game->Input->PrevButtons.ButA && Game->Input->Buttons.ButA)) - { + { if (!bullet.alive) - { + { addplayerstate(playerstateshoot); remplayerstate(playerstatemoveright); remplayerstate(playerstatemoveleft); @@ -410,32 +413,32 @@ void CGamePang::updateplayer() player.stateticks = 15; createbullet(); Game->Audio->PlaySound(SfxShoot, 0); - } - } + } + } Game->Sprites->SetSpriteLocation(player.spr, player.pos); - } - } + } + } else - { + { if (player.freeze > 0) player.freeze -= 1; else player.alive = true; - } + } } void CGamePang::drawplayer() { if (player.alive) - { + { if (playerstate(playerstatereviving)) - { + { if (player.stateticks % 3 == 0) Game->Sprites->DrawSprite(Game->Renderer, player.spr); - } + } else Game->Sprites->DrawSprite(Game->Renderer, player.spr); - } + } } @@ -447,59 +450,57 @@ void CGamePang::DrawBackground(bool motionblur) if ((motionblur) && (Game->MotionBlur)) alpha = 0.3*255; - SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); - SDL_SetRenderTarget(Game->Renderer, Game->TexTmp); - SDL_SetRenderDrawColor(Game->Renderer, 0.3*255, 0.6*255,0.9*255,255); - SDL_RenderClear(Game->Renderer); - SDL_Point Pos = { 0, 0}; - Vec2F Scale = {(float)(screenright - screenleft) / backgroundcloudtz.x, 4}; + SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); + SDL_SetRenderTarget(Game->Renderer, Game->TexTmp); + SDL_SetRenderDrawColor(Game->Renderer, 0.3*255, 0.6*255,0.9*255,255); + SDL_RenderClear(Game->Renderer); + SDL_Point Pos = { 0, 0}; + Vec2F Scale = {(float)(screenright - screenleft) / backgroundcloudtz.x, 4}; Game->Image->DrawImageFuze(Game->Renderer, backgroundcloud, false, &Pos, 0, &Scale, 255, 255, 255, 255 ); - - Scale = {2,2}; + + Scale = {2,2}; for (int x = -20; x < screenright; x += backgroundtreestz.x) - { - Pos = {x, screenbottom - 345-160}; - + { + Pos = {x, screenbottom - 345-160}; Game->Image->DrawImageFuze(Game->Renderer, backgroundtrees, false, &Pos, 0, &Scale, 255, 255, 255, 255); - } + } - Scale = {2,2}; + Scale = {2,2}; for (int x = -20; x < screenright; x += backgroundtreestz.x) - { - Pos = {x, screenbottom - 315-130}; + { + Pos = {x, screenbottom - 315-130}; Game->Image->DrawImageFuze(Game->Renderer, backgroundtrees, false, &Pos, 0, &Scale, 255, 255, 255, 255); - } - - Scale = {2,2}; - for (int x = -60; x < screenright; x += backgroundtreestz.x) - { - Pos = {x, screenbottom - 275-100}; + } + + Scale = {2,2}; + for (int x = -60; x < screenright; x += backgroundtreestz.x) + { + Pos = {x, screenbottom - 275-100}; Game->Image->DrawImageFuze(Game->Renderer, backgroundtrees, false, &Pos, 0, &Scale, 255, 255, 255, 255); - } + } - Scale = {2,2}; + Scale = {2,2}; for (int x = -35; x < screenright; x += backgroundtreestz.x) - { - Pos = {x, screenbottom - 225-150}; + { + Pos = {x, screenbottom - 225-150}; Game->Image->DrawImageFuze(Game->Renderer, backgroundtrees, false, &Pos, 0, &Scale, 255, 255, 255, 255); - } + } - Pos = {(int)((screenright - screenleft) * 0.55), screenbottom - 390}; - Scale = {3.5,3.5}; + Pos = {(int)((screenright - screenleft) * 0.55), screenbottom - 390}; + Scale = {3.5,3.5}; Game->Image->DrawImageFuze(Game->Renderer, backgroundtree, false, &Pos, 0, &Scale, 255, 255, 255, 255); - - Scale = {1,1}; + + Scale = {1,1}; for (int x = 0; x < screenright; x+= backgroundgrasstz.x) - { - Pos = {x, screenbottom - backgroundgrasstz.y}; + { + Pos = {x, screenbottom - backgroundgrasstz.y}; Game->Image->DrawImageFuze(Game->Renderer, backgroundgrass, false, &Pos, 0, &Scale, 255, 255, 255, 255); - } + } - SDL_SetRenderTarget(Game->Renderer, prev); - Scale = {1,1}; - Pos = {0,0}; - Game->Image->DrawImageFuze(Game->Renderer, Game->TexTmp, NULL, false, &Pos, 0, &Scale, 255, 255, 255, alpha); - + SDL_SetRenderTarget(Game->Renderer, prev); + Scale = {1,1}; + Pos = {0,0}; + Game->Image->DrawImageFuze(Game->Renderer, Game->TexTmp, NULL, false, &Pos, 0, &Scale, 255, 255, 255, alpha); } //init - deinit ---------------------------------------------------------------------------------------------------------------- @@ -507,20 +508,20 @@ void CGamePang::DrawBackground(bool motionblur) void CGamePang::init() { LoadGraphics(); - level = 1; + level = 1; if(!ScreenshotMode) { LoadSound(); - createplayer(); - createballs(); + createplayer(); + createballs(); Game->CurrentGameMusicID = MusMusic; Game->Audio->PlayMusic(MusMusic, -1); } } void CGamePang::deinit() -{ - destroyplayer(); +{ + destroyplayer(); destroyallballs(); destroybullet(); if (!ScreenshotMode) @@ -555,66 +556,66 @@ void CGamePang::UnLoadSound() void CGamePang::LoadGraphics() { - spritesheetplayer = Game->Image->LoadImage(Game->Renderer, "pang/character.png"); - spritesheetbullet = Game->Image->LoadImage(Game->Renderer, "pang/weapon.png"); - spritesheetball = Game->Image->LoadImage(Game->Renderer, "pang/ball.png"); - backgroundgrass = Game->Image->LoadImage(Game->Renderer, "pang/grass.png"); - backgroundcloud = Game->Image->LoadImage(Game->Renderer, "pang/clouds.png"); - backgroundtrees = Game->Image->LoadImage(Game->Renderer, "pang/trees.png"); - backgroundtree = Game->Image->LoadImage(Game->Renderer, "pang/tree.png"); - backgroundgrasstz = Game->Image->ImageSize(backgroundgrass); - backgroundcloudtz = Game->Image->ImageSize(backgroundcloud); - backgroundtreestz = Game->Image->ImageSize(backgroundtrees); - backgroundtreetz = Game->Image->ImageSize(backgroundtree); - spritesheetballtz = Game->Image->ImageSize(spritesheetball); + spritesheetplayer = Game->Image->LoadImage(Game->Renderer, "pang/character.png"); + spritesheetbullet = Game->Image->LoadImage(Game->Renderer, "pang/weapon.png"); + spritesheetball = Game->Image->LoadImage(Game->Renderer, "pang/ball.png"); + backgroundgrass = Game->Image->LoadImage(Game->Renderer, "pang/grass.png"); + backgroundcloud = Game->Image->LoadImage(Game->Renderer, "pang/clouds.png"); + backgroundtrees = Game->Image->LoadImage(Game->Renderer, "pang/trees.png"); + backgroundtree = Game->Image->LoadImage(Game->Renderer, "pang/tree.png"); + backgroundgrasstz = Game->Image->ImageSize(backgroundgrass); + backgroundcloudtz = Game->Image->ImageSize(backgroundcloud); + backgroundtreestz = Game->Image->ImageSize(backgroundtrees); + backgroundtreetz = Game->Image->ImageSize(backgroundtree); + spritesheetballtz = Game->Image->ImageSize(spritesheetball); } void CGamePang::UnloadGraphics() { Game->Image->UnLoadImage(spritesheetplayer); - Game->Image->UnLoadImage(spritesheetbullet); - Game->Image->UnLoadImage(spritesheetball); - Game->Image->UnLoadImage(backgroundgrass); - Game->Image->UnLoadImage(backgroundcloud); - Game->Image->UnLoadImage(backgroundtrees); - Game->Image->UnLoadImage(backgroundtree); + Game->Image->UnLoadImage(spritesheetbullet); + Game->Image->UnLoadImage(spritesheetball); + Game->Image->UnLoadImage(backgroundgrass); + Game->Image->UnLoadImage(backgroundcloud); + Game->Image->UnLoadImage(backgroundtrees); + Game->Image->UnLoadImage(backgroundtree); } SDL_Texture* CGamePang::screenshot() { SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); SDL_Texture* image = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetRenderTarget(Game->Renderer, image); + SDL_SetRenderTarget(Game->Renderer, image); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); SDL_RenderClear(Game->Renderer); init(); - level = 3; - - createplayer(); + level = 3; + + createplayer(); createballs(); createbullet(); for (int i = 0; i < 35; i++) - { + { updateballs(); updatebullet(); - } + } - Draw(); + Draw(); SDL_RenderPresent(Game->Renderer); SDL_SetRenderTarget(Game->Renderer, prev); - deinit(); + deinit(); return image; } //Update ---------------------------------------------------------------------------------------------------------------- -void CGamePang::UpdateObjects(bool IsGameState) +void CGamePang::UpdateObjects(bool IsGameState) { if (IsGameState) { - updateplayer(); + updateplayer(); updateballs(); updatebullet(); } @@ -622,7 +623,7 @@ void CGamePang::UpdateObjects(bool IsGameState) bool CGamePang::DrawObjects() { - drawballs(); + drawballs(); drawbullet(); drawplayer(); //don't call drawsprites in base class diff --git a/src/games/CGamePang.h b/src/games/CGamePang.h index 78d5034..e6583e6 100644 --- a/src/games/CGamePang.h +++ b/src/games/CGamePang.h @@ -16,84 +16,84 @@ using namespace std; class CGamePang: public CGameBase { private: - static const int backgroundcopyheight = 30; - Vec2F playerscale = {2,2}; - Vec2F bulletscale = {1,0.8}; - Vec2F ballscale = {1.5,1.5}; + static const int backgroundcopyheight = 30; + Vec2F playerscale = {2,2}; + Vec2F bulletscale = {1,0.8}; + Vec2F ballscale = {1.5,1.5}; - static const int enemyspeed = 1; - static const int playerspeed = 8; - static const int bulletspeed = 10; + static const int enemyspeed = 1; + static const int playerspeed = 8; + static const int bulletspeed = 10; - static const int playerstateidle = 0; - static const int playerstatemoveleft = 2; - static const int playerstatemoveright = 4; - static const int playerstateshoot = 8; - static const int playerstatereviving = 16; + static const int playerstateidle = 0; + static const int playerstatemoveleft = 2; + static const int playerstatemoveright = 4; + static const int playerstateshoot = 8; + static const int playerstatereviving = 16; - static const int ballbig = 3; - static const int ballmedium = 2; - static const int ballsmall = 1; + static const int ballbig = 3; + static const int ballmedium = 2; + static const int ballsmall = 1; - static const int maxbigballs = 6; - static const int maxballs = maxbigballs * 7; + static const int maxbigballs = 6; + static const int maxballs = maxbigballs * 7; - int background; - int spritesheetplayer; - int spritesheetbullet; - int spritesheetball; - int backgroundgrass; - int backgroundcloud; - int backgroundtrees; - int backgroundtree; + int background; + int spritesheetplayer; + int spritesheetbullet; + int spritesheetball; + int backgroundgrass; + int backgroundcloud; + int backgroundtrees; + int backgroundtree; - SDL_Point backgroundtz; + SDL_Point backgroundtz; SDL_Point backgroundgrasstz; - SDL_Point backgroundcloudtz; - SDL_Point backgroundtreestz; - SDL_Point backgroundtreetz; - SDL_Point spritesheetballtz; + SDL_Point backgroundcloudtz; + SDL_Point backgroundtreestz; + SDL_Point backgroundtreetz; + SDL_Point spritesheetballtz; - int deaths = 0; + int deaths = 0; int levelcleared = false; CSpriteObject balls[maxballs]; CSpriteObject player; CSpriteObject bullet; - int MusMusic, SfxSucces, SfxDie, SfxShoot, SfxPop; - - - void drawplayer(); - void updateplayer(); - void remplayerstate(int state); - bool playerstate(int state); - void addplayerstate(int state); - void createplayer(); - void destroyplayer(); - void drawbullet(); - void updatebullet(); - void createbullet(); - void destroybullet(); - void createballs(); - void drawballs(); - void updateballs(); - void createball(int size, float x, float y, float speed); - void destroyball(int index, bool nocreate); - void destroyallballs(); + int MusMusic, SfxSucces, SfxDie, SfxShoot, SfxPop; + + + void drawplayer(); + void updateplayer(); + void remplayerstate(int state); + bool playerstate(int state); + void addplayerstate(int state); + void createplayer(); + void destroyplayer(); + void drawbullet(); + void updatebullet(); + void createbullet(); + void destroybullet(); + void createballs(); + void drawballs(); + void updateballs(); + void createball(int size, float x, float y, float speed); + void destroyball(int index, bool nocreate); + void destroyallballs(); public: - CGamePang(CGame* aGame, bool aScreenshotMode = false); - ~CGamePang(); - SDL_Texture* screenshot() override; - void init() override; - void deinit() override; - void UnloadGraphics() override; - void LoadGraphics() override; - void LoadSound() override; - void UnLoadSound() override; - void UpdateObjects(bool IsGameState) override; - bool DrawObjects() override; - void DrawBackground(bool motionblur); + CGamePang(CGame* aGame, bool aScreenshotMode = false); + ~CGamePang(); + SDL_Texture* screenshot() override; + void init() override; + void deinit() override; + void UnloadGraphics() override; + void LoadGraphics() override; + void LoadSound() override; + void UnLoadSound() override; + void UpdateObjects(bool IsGameState) override; + bool DrawObjects() override; + void DrawBackground(bool motionblur); }; \ No newline at end of file diff --git a/src/games/CGameRamIt.cpp b/src/games/CGameRamIt.cpp index d6caa5f..f69188b 100644 --- a/src/games/CGameRamIt.cpp +++ b/src/games/CGameRamIt.cpp @@ -10,8 +10,8 @@ using namespace std; CGameRamIt::CGameRamIt(CGame* aGame, bool aScreenshotMode): CGameBase(aGame, GSRamIt, true, aScreenshotMode) { - Game = aGame; - speed = 0; + Game = aGame; + speed = 0; speedcount = 0; SfxShoot = -1; SfxHit = -1; @@ -19,14 +19,14 @@ CGameRamIt::CGameRamIt(CGame* aGame, bool aScreenshotMode): CGameBase(aGame, GSR SfxSucces = -1; MusMusic = -1; riblocksize = int(ScreenHeight / (numblocks+1)) - 2 * blockspacing; - riblocksizespacing = riblocksize + 2 * blockspacing; + riblocksizespacing = riblocksize + 2 * blockspacing; playfieldwidth = ScreenWidth - 1 * riblocksize; - segmentwidth = int(((playfieldwidth / 2) / blocksegments)); - playfieldheight = numblocks * riblocksizespacing; - screenleft = (ScreenWidth - playfieldwidth) / 2; - screenright = screenleft + playfieldwidth; - screentop = (ScreenHeight - playfieldheight) / 2; - screenbottom = screentop + playfieldheight; + segmentwidth = int(((playfieldwidth / 2) / blocksegments)); + playfieldheight = numblocks * riblocksizespacing; + screenleft = (ScreenWidth - playfieldwidth) / 2; + screenright = screenleft + playfieldwidth; + screentop = (ScreenHeight - playfieldheight) / 2; + screenbottom = screentop + playfieldheight; } CGameRamIt::~CGameRamIt() {} @@ -34,15 +34,15 @@ CGameRamIt::~CGameRamIt() {} bool CGameRamIt::createbullet() { bool result = false; - if (!bulletalive) - { + if (!bulletalive) + { bulletalive = true; bulletpos = playerpos; bulletvel.x = playerdx * bulletspeed; - bulletvel.y = 0; + bulletvel.y = 0; result = true; - } - return result; + } + return result; } //BULLET ---------------------------------------------------------------------------------------------------------------- @@ -50,81 +50,81 @@ bool CGameRamIt::createbullet() void CGameRamIt::updatebullet() { if (bulletalive) - { + { bool destroybullet = false; bool playaudiobullet = false; for(int steps = 0; steps < bulletsteps; steps++) - { + { bulletpos.x += bulletvel.x; - bulletpos.y += bulletvel.y; + bulletpos.y += bulletvel.y; if (bulletpos.x + riblocksize / 2 < screenleft) destroybullet = true; if (bulletpos.x - riblocksize / 2 > screenright) destroybullet = true; - + for (int side = 0; side < sides; side++) - { + { for (int block = 0; block < numblocks; block++) - { + { if (playfield[side][block].segments > 0) - { - if ((bulletpos.y + riblocksize / 6 >= screentop + + { + if ((bulletpos.y + riblocksize / 6 >= screentop + block * riblocksizespacing + blockspacing) && - (bulletpos.y - riblocksize / 6 <= screentop + + (bulletpos.y - riblocksize / 6 <= screentop + block * riblocksizespacing + blockspacing + riblocksize)) - { - if (side == 0) - { - if ((bulletpos.x - riblocksize / 2) <= screenleft + + { + if (side == 0) + { + if ((bulletpos.x - riblocksize / 2) <= screenleft + playfield[side][block].segments * segmentwidth) - { + { playfield[side][block].segments -= 1; if (playfield[side][block].segments == 0) if(!ScreenshotMode) - Game->AddToScore((level + 1) * 2*playfield[side][block].maxsegments); + Game->AddToScore((level + 1) * 2*playfield[side][block].maxsegments); playaudiobullet = true; destroybullet = true; - } - } + } + } else - { + { if ((bulletpos.x - riblocksize / 2) >= screenright - playfield[side][block].segments * segmentwidth) - { + { playfield[side][block].segments -= 1; if (playfield[side][block].segments == 0) if(!ScreenshotMode) - Game->AddToScore((level + 2) * 2 * playfield[side][block].maxsegments); + Game->AddToScore((level + 2) * 2 * playfield[side][block].maxsegments); playaudiobullet = true; destroybullet = true; - } - } - } - } - } - } - - if(destroybullet) - { - if (playaudiobullet) + } + } + } + } + } + } + + if(destroybullet) + { + if (playaudiobullet) Game->Audio->PlaySound(SfxHit, 0); bulletalive = false; break; - } - } - } + } + } + } } void CGameRamIt::drawbullet() { if (bulletalive) - { + { SDL_Rect r = {bulletpos.x - riblocksize / 2, bulletpos.y - riblocksize / 6, riblocksize, riblocksize / 3}; SDL_SetRenderDrawColor(Game->Renderer, 255, 255, 255, 255); SDL_RenderFillRect(Game->Renderer, &r); - } + } } //PLAYER ---------------------------------------------------------------------------------------------------------------- @@ -132,27 +132,27 @@ void CGameRamIt::drawbullet() void CGameRamIt::createplayer() { playerpos.x = screenleft + (screenright - screenleft) / 2; - playerpos.y = screentop + (screenbottom - screentop) / 2; + playerpos.y = screentop + (screenbottom - screentop) / 2; playerdx = 1; } void CGameRamIt::drawplayer() { SDL_Rect r; - + SDL_SetRenderDrawColor(Game->Renderer, 128, 128, 128, 255); - r = {screenleft + (screenright - screenleft -playerrailwidth) / 2, screentop, playerrailwidth, screenbottom - screentop }; + r = {screenleft + (screenright - screenleft -playerrailwidth) / 2, screentop, playerrailwidth, screenbottom - screentop }; SDL_RenderFillRect(Game->Renderer, &r); - + SDL_SetRenderDrawColor(Game->Renderer, 255, 255, 255, 255); r = {playerpos.x - riblocksize / 2, playerpos.y - riblocksize / 2, riblocksize, riblocksize}; - SDL_RenderFillRect(Game->Renderer, &r); + SDL_RenderFillRect(Game->Renderer, &r); SDL_SetRenderDrawColor(Game->Renderer, 255, 0, 0, 255); if (playerdx == 1) r ={playerpos.x + riblocksize / 2, playerpos.y - riblocksize / 4, riblocksize / 2, riblocksize / 2}; - else - r ={playerpos.x - riblocksize, playerpos.y - riblocksize / 4, riblocksize / 2, riblocksize / 2}; + else + r ={playerpos.x - riblocksize, playerpos.y - riblocksize / 4, riblocksize / 2, riblocksize / 2}; SDL_RenderFillRect(Game->Renderer, &r); } @@ -162,42 +162,42 @@ void CGameRamIt::updateplayer() { return; } - + if ((Game->Input->Buttons.ButLeft) || (Game->Input->Buttons.ButLeft2) || (Game->Input->Buttons.ButDpadLeft)) playerdx = -1; - + if ((Game->Input->Buttons.ButRight) || (Game->Input->Buttons.ButRight2) || (Game->Input->Buttons.ButDpadRight)) playerdx = 1; - + if ((Game->Input->Buttons.ButDown) || (Game->Input->Buttons.ButDown2) || (Game->Input->Buttons.ButDpadDown)) - { + { if (playerpos.y + riblocksize / 2 + playerspeed < screenbottom) playerpos.y += playerspeed; else playerpos.y = screenbottom - riblocksize / 2; - } + } if ((Game->Input->Buttons.ButUp) || (Game->Input->Buttons.ButUp2) || (Game->Input->Buttons.ButDpadUp)) - { + { if (playerpos.y - riblocksize / 2 - playerspeed > screentop) playerpos.y -= playerspeed; else playerpos.y = screentop + riblocksize / 2; - } + } if (Game->Input->Buttons.ButA && !Game->Input->PrevButtons.ButA) if (createbullet()) - { + { Game->Audio->PlaySound(SfxShoot, 0); - } + } } //playfield ---------------------------------------------------------------------------------------------------------------- @@ -208,14 +208,14 @@ void CGameRamIt::createplayfield() int piece = -1; SDL_Color color; for (int side = 0 ; side < sides; side++) - { + { for (int block = 0; block < numblocks; block++) - { + { while(prevpiece == piece) piece = rand() % 17; prevpiece = piece; - + if (piece == 0) color = {0x00, 0x00, 0xFF, 0xFF}; @@ -230,7 +230,7 @@ void CGameRamIt::createplayfield() if (piece == 4) color = {0xA0, 0x20, 0xF0, 0xFF}; - + if (piece == 5) color = {0xA5, 0x2A, 0x2A, 0xFF}; @@ -271,7 +271,7 @@ void CGameRamIt::createplayfield() playfield[side][block].segments = 2; playfield[side][block].maxsegments = 2; } - } + } } void CGameRamIt::updateplayfield(bool force) @@ -279,64 +279,63 @@ void CGameRamIt::updateplayfield(bool force) speedcount += 1; if (force || (speedcount >= speed - ((level-1) * tickslevelmul))) - { + { speedcount = 0; - int stageclear = true; + int stageclear = true; int numalive = 0; - int side; - int block; + int side; + int block; for (side = 0; side < sides; side++) for(block = 0; block < numblocks; block++) if (playfield[side][block].segments != 0) - { + { stageclear = false; numalive += 1; - } - + } + if (stageclear) - { + { Game->Audio->PlaySound(SfxSucces, 0); createplayfield(); level += 1; if(!ScreenshotMode) Game->AddToScore((level-1) * 100); - } - + } + if (!stageclear) - { + { int r = 1; if (numalive <= 5) r = rand() % 2; if (r == 1) - { + { side = rand() % sides; block = rand() % numblocks; while (playfield[side][block].segments == 0) - { + { side = rand() % sides; - block = rand() % numblocks; - } + block = rand() % numblocks; + } playfield[side][block].segments += 2; if (playfield[side][block].segments > blocksegments) playfield[side][block].segments = blocksegments; - + if (playfield[side][block].segments > playfield[side][block].maxsegments) playfield[side][block].maxsegments = playfield[side][block].segments; - + //death for (side = 0; side < sides; side++) for (block = 0; block < numblocks; block++) if (playfield[side][block].segments == blocksegments) - { + { playerdeath = true; break; - } - - } - } - } -} + } + } + } + } +} void CGameRamIt::drawplayfield() { @@ -345,15 +344,15 @@ void CGameRamIt::drawplayfield() { SDL_Rect r; if (side == 0) - r = {screenleft, screentop + block * riblocksizespacing + blockspacing, - playfield[side][block].segments * segmentwidth, + r = {screenleft, screentop + block * riblocksizespacing + blockspacing, + playfield[side][block].segments * segmentwidth, riblocksize}; else - r = { screenright - playfield[side][block].segments * segmentwidth , - screentop + block * riblocksizespacing + blockspacing, - playfield[side][block].segments * segmentwidth, - riblocksize}; - SDL_SetRenderDrawColor(Game->Renderer, playfield[side][block].color.r, playfield[side][block].color.g, playfield[side][block].color.b, + r = { screenright - playfield[side][block].segments * segmentwidth , + screentop + block * riblocksizespacing + blockspacing, + playfield[side][block].segments * segmentwidth, + riblocksize}; + SDL_SetRenderDrawColor(Game->Renderer, playfield[side][block].color.r, playfield[side][block].color.g, playfield[side][block].color.b, playfield[side][block].color.a); SDL_RenderFillRect(Game->Renderer, &r); } @@ -364,7 +363,7 @@ void CGameRamIt::drawplayfield() void CGameRamIt::DrawBackground(bool motionblur) { SDL_SetRenderDrawColor(Game->Renderer, 150, 150, 150, 255); - SDL_RenderClear(Game->Renderer); + SDL_RenderClear(Game->Renderer); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); SDL_Rect r = {screenleft, screentop, playfieldwidth, playfieldheight}; SDL_RenderFillRect(Game->Renderer, &r); @@ -406,7 +405,7 @@ void CGameRamIt::LoadSound() SfxHit = Game->Audio->LoadSound("ramit/hit.wav"); SfxDie = Game->Audio->LoadSound("common/die.wav"); SfxSucces = Game->Audio->LoadSound("common/succes.wav"); - MusMusic = Game->Audio->LoadMusic("ramit/music.ogg"); + MusMusic = Game->Audio->LoadMusic("ramit/music.ogg"); } void CGameRamIt::UnLoadSound() @@ -424,7 +423,7 @@ SDL_Texture* CGameRamIt::screenshot() { SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); SDL_Texture* image = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetRenderTarget(Game->Renderer, image); + SDL_SetRenderTarget(Game->Renderer, image); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); SDL_RenderClear(Game->Renderer); init(); @@ -440,7 +439,7 @@ SDL_Texture* CGameRamIt::screenshot() SDL_RenderPresent(Game->Renderer); SDL_SetRenderTarget(Game->Renderer, prev); - deinit(); + deinit(); return image; } @@ -448,34 +447,34 @@ SDL_Texture* CGameRamIt::screenshot() void CGameRamIt::UpdateObjects(bool IsGameState) { - if (IsGameState) - { - updateplayer(); - updateplayfield(false); - updatebullet(); + if (IsGameState) + { + updateplayer(); + updateplayfield(false); + updatebullet(); if (playerdeath) - { + { Game->Audio->PlaySound(SfxDie, 0); if (Game->GameMode == GMGame) if (!ScreenshotMode) HealthPoints -= 1; - + if (HealthPoints > 0) { - SDL_Delay(500); + SDL_Delay(500); createplayfield(); - } + } playerdeath = false; - } + } } } bool CGameRamIt::DrawObjects() { drawbullet(); - drawplayer(); - drawplayfield(); + drawplayer(); + drawplayfield(); //don't call drawsprites in base class return false; } diff --git a/src/games/CGameRamIt.h b/src/games/CGameRamIt.h index 6b3e4ba..6b9efe0 100644 --- a/src/games/CGameRamIt.h +++ b/src/games/CGameRamIt.h @@ -12,7 +12,7 @@ using namespace std; -struct ramitblock +struct ramitblock { int maxsegments; int segments; @@ -22,46 +22,46 @@ struct ramitblock class CGameRamIt: public CGameBase { private: - static const int bulletsteps = 8; - static const int playerrailwidth = 10; - static const int playerspeed = 10; - static const int bulletspeed = 5; - static const int numblocks = 16; - static const int blocksegments = 20; - static const int sides = 2; - static const int blockspacing = 5; - static const int ticksidle = 50; - static const int tickslevelmul = 5; + static const int bulletsteps = 8; + static const int playerrailwidth = 10; + static const int playerspeed = 10; + static const int bulletspeed = 5; + static const int numblocks = 16; + static const int blocksegments = 20; + static const int sides = 2; + static const int blockspacing = 5; + static const int ticksidle = 50; + static const int tickslevelmul = 5; - int SfxShoot, SfxHit, SfxDie, SfxSucces, MusMusic; - int speed, speedcount, playerdx, playerdeath, riblocksize, riblocksizespacing, segmentwidth; + int SfxShoot, SfxHit, SfxDie, SfxSucces, MusMusic; + int speed, speedcount, playerdx, playerdeath, riblocksize, riblocksizespacing, segmentwidth; SDL_Point playerpos; SDL_Point bulletpos; SDL_Point bulletvel; bool bulletalive = false; - ramitblock playfield[sides][numblocks]; + ramitblock playfield[sides][numblocks]; - bool createbullet(); - void updatebullet(); - void drawbullet(); + bool createbullet(); + void updatebullet(); + void drawbullet(); - void createplayer(); - void drawplayer(); - void updateplayer(); + void createplayer(); + void drawplayer(); + void updateplayer(); - void createplayfield(); - void updateplayfield(bool force); - void drawplayfield(); + void createplayfield(); + void updateplayfield(bool force); + void drawplayfield(); public: - CGameRamIt(CGame* aGame, bool aScreenshotMode = false); - ~CGameRamIt(); - - SDL_Texture* screenshot() override; - void init() override; - void deinit() override; - void LoadSound() override; - void UnLoadSound() override; - void UpdateObjects(bool IsGameState) override; - bool DrawObjects() override; - void DrawBackground(bool motionblur); + CGameRamIt(CGame* aGame, bool aScreenshotMode = false); + ~CGameRamIt(); + + SDL_Texture* screenshot() override; + void init() override; + void deinit() override; + void LoadSound() override; + void UnLoadSound() override; + void UpdateObjects(bool IsGameState) override; + bool DrawObjects() override; + void DrawBackground(bool motionblur); }; \ No newline at end of file diff --git a/src/games/CGameSnake.cpp b/src/games/CGameSnake.cpp index 055030d..c8bfa09 100644 --- a/src/games/CGameSnake.cpp +++ b/src/games/CGameSnake.cpp @@ -3,16 +3,16 @@ CGameSnake::CGameSnake(CGame* aGame, bool aScreenshotMode) : CGameBase(aGame, GSSnake, false, aScreenshotMode) { - Game = aGame; - MusMusic = -1; - SfxFood = -1; - SfxDie = -1; - playfieldwidth = (cols) * snakesize; - playfieldheight = (rows) * snakesize; - screenleft = (ScreenWidth - playfieldwidth) / 2; - screenright = screenleft + playfieldwidth; - screentop = (ScreenHeight - playfieldheight) / 2; - screenbottom = screentop + playfieldheight; + Game = aGame; + MusMusic = -1; + SfxFood = -1; + SfxDie = -1; + playfieldwidth = (cols) * snakesize; + playfieldheight = (rows) * snakesize; + screenleft = (ScreenWidth - playfieldwidth) / 2; + screenright = screenleft + playfieldwidth; + screentop = (ScreenHeight - playfieldheight) / 2; + screenbottom = screentop + playfieldheight; } CGameSnake::~CGameSnake() @@ -20,23 +20,23 @@ CGameSnake::~CGameSnake() } -//food ---------------------------------------------------------------------------------------------------------------- +//food ---------------------------------------------------------------------------------------------------------------- void CGameSnake::createfood() { bool bok = false; - while (!bok) - { + while (!bok) + { food = {screenleft + int((rand() % cols) *snakesize),screentop + int((rand() % rows) * snakesize)}; bok = ((food.x != head.x) && (food.y != head.y)); for (int i = 0; i < snakelength; i++) bok = bok && ((food.x != body[i].x) && (food.y != body[i].y)); - } + } } void CGameSnake::drawfood() { - SDL_SetRenderDrawColor(Game->Renderer, snakefoodcolor.r, snakefoodcolor.g, snakefoodcolor.b, snakefoodcolor.a); + SDL_SetRenderDrawColor(Game->Renderer, snakefoodcolor.r, snakefoodcolor.g, snakefoodcolor.b, snakefoodcolor.a); SDL_Rect r = {food.x, food.y, snakesize, snakesize}; SDL_RenderFillRect(Game->Renderer, &r); } @@ -44,16 +44,16 @@ void CGameSnake::drawfood() void CGameSnake::updatefood() { if ((head.x == food.x) && (head.y == food.y)) - { + { Game->Audio->PlaySound(SfxFood, 0); snakelength += 1; createfood(); - if(!ScreenshotMode) - Game->AddToScore(snakelength*2); + if(!ScreenshotMode) + Game->AddToScore(snakelength*2); } } -//snake ---------------------------------------------------------------------------------------------------------------- +//snake ---------------------------------------------------------------------------------------------------------------- void CGameSnake::createsnake() { @@ -66,84 +66,84 @@ void CGameSnake::createsnake() void CGameSnake::drawsnake() { - SDL_Rect r; - SDL_SetRenderDrawColor(Game->Renderer, snakebodycolor.r, snakebodycolor.g, snakebodycolor.b, snakebodycolor.a); + SDL_Rect r; + SDL_SetRenderDrawColor(Game->Renderer, snakebodycolor.r, snakebodycolor.g, snakebodycolor.b, snakebodycolor.a); for (int i = 0; i < snakelength; i++) - { - r = {body[i].x, body[i].y, snakesize, snakesize}; - SDL_RenderFillRect(Game->Renderer, &r); - } - SDL_SetRenderDrawColor(Game->Renderer, snakeheadcolor.r, snakeheadcolor.g, snakeheadcolor.b, snakeheadcolor.a); + { + r = {body[i].x, body[i].y, snakesize, snakesize}; + SDL_RenderFillRect(Game->Renderer, &r); + } + SDL_SetRenderDrawColor(Game->Renderer, snakeheadcolor.r, snakeheadcolor.g, snakeheadcolor.b, snakeheadcolor.a); r = {head.x, head.y, snakesize, snakesize}; - SDL_RenderFillRect(Game->Renderer, &r); + SDL_RenderFillRect(Game->Renderer, &r); } void CGameSnake::updatesnake() { if(!ScreenshotMode) - { + { if ((Game->Input->Buttons.ButLeft) || - (Game->Input->Buttons.ButLeft2) || - (Game->Input->Buttons.ButDpadLeft)) - { + (Game->Input->Buttons.ButLeft2) || + (Game->Input->Buttons.ButDpadLeft)) + { if(movedone && dir.x == 0) - { + { movedone = false; dir = {-1,0}; - } - } + } + } else - { + { if ((Game->Input->Buttons.ButRight) || - (Game->Input->Buttons.ButRight2) || - (Game->Input->Buttons.ButDpadRight)) - { + (Game->Input->Buttons.ButRight2) || + (Game->Input->Buttons.ButDpadRight)) + { if(movedone && dir.x == 0) - { + { movedone = false; dir = {1,0}; - } - } - else - { + } + } + else + { if ((Game->Input->Buttons.ButUp) || - (Game->Input->Buttons.ButUp2) || - (Game->Input->Buttons.ButDpadUp)) - { + (Game->Input->Buttons.ButUp2) || + (Game->Input->Buttons.ButDpadUp)) + { if(movedone && dir.y == 0) - { + { movedone = false; dir = {0,-1}; - } - } + } + } else - { + { if ((Game->Input->Buttons.ButDown) || - (Game->Input->Buttons.ButDown2) || - (Game->Input->Buttons.ButDpadDown)) - { + (Game->Input->Buttons.ButDown2) || + (Game->Input->Buttons.ButDpadDown)) + { if(movedone && dir.y == 0) - { - movedone = false; + { + movedone = false; dir = {0,1}; - } - } - } - } - } - } + } + } + } + } + } + } - ticks += 1; + ticks += 1; if(ScreenshotMode || (ticks >= updateticks)) - { + { movedone = true; ticks = 0; int i = snakelength; while (i >= 1) - { + { body[i] = body[i-1]; i -= 1; - } + } body[0] = head; head.x += dir.x * snakesize; head.y += dir.y * snakesize; @@ -154,7 +154,6 @@ void CGameSnake::updatesnake() for (int i = 0; i < snakelength; i++) if ((head.x == body[i].x) && (head.y == body[i].y)) playerdeath = true; - } } @@ -162,35 +161,35 @@ void CGameSnake::updatesnake() void CGameSnake::DrawBackground(bool motionblur) { - SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 255, 255); + SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 255, 255); SDL_RenderClear(Game->Renderer); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); SDL_Rect r = {screenleft, screentop, playfieldwidth, playfieldheight}; - SDL_RenderFillRect(Game->Renderer, &r); + SDL_RenderFillRect(Game->Renderer, &r); } - + SDL_Texture* CGameSnake::screenshot() { - SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); - SDL_Texture* image = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); - SDL_SetRenderTarget(Game->Renderer, image); + SDL_Texture* prev = SDL_GetRenderTarget(Game->Renderer); + SDL_Texture* image = SDL_CreateTexture(Game->Renderer, PixelFormat, SDL_TEXTUREACCESS_TARGET, ScreenWidth, ScreenHeight); + SDL_SetRenderTarget(Game->Renderer, image); SDL_SetRenderDrawColor(Game->Renderer, 0, 0, 0, 255); - SDL_RenderClear(Game->Renderer); - init(); + SDL_RenderClear(Game->Renderer); + init(); for (int i = 0; i < 7; i++) - { + { updatesnake(); snakelength += 1; - } + } food = {screenleft + (int(cols / 2)-2) * snakesize, screentop + (int(rows / 2) -2) * snakesize}; Draw(); - SDL_RenderPresent(Game->Renderer); - SDL_SetRenderTarget(Game->Renderer, prev); - deinit(); - return image; + SDL_RenderPresent(Game->Renderer); + SDL_SetRenderTarget(Game->Renderer, prev); + deinit(); + return image; } //init - deinit ---------------------------------------------------------------------------------------------------------------- @@ -198,82 +197,82 @@ SDL_Texture* CGameSnake::screenshot() void CGameSnake::init() { - createsnake(); - createfood(); + createsnake(); + createfood(); - movedone = true; - if (!ScreenshotMode) - { - HealthPoints = 2; - LoadSound(); - Game->CurrentGameMusicID = MusMusic; - Game->Audio->PlayMusic(MusMusic, -1); - } + movedone = true; + if (!ScreenshotMode) + { + HealthPoints = 2; + LoadSound(); + Game->CurrentGameMusicID = MusMusic; + Game->Audio->PlayMusic(MusMusic, -1); + } } void CGameSnake::deinit() { - if (!ScreenshotMode) - { - UnLoadSound(); - Game->SubStateCounter = 0; - Game->SubGameState = SGNone; - Game->CurrentGameMusicID = -1; - } + if (!ScreenshotMode) + { + UnLoadSound(); + Game->SubStateCounter = 0; + Game->SubGameState = SGNone; + Game->CurrentGameMusicID = -1; + } } void CGameSnake::LoadSound() { - SfxFood = Game->Audio->LoadSound("snakey/food.wav"); - SfxDie = Game->Audio->LoadSound("common/die.wav"); - MusMusic = Game->Audio->LoadMusic("snakey/music.ogg"); + SfxFood = Game->Audio->LoadSound("snakey/food.wav"); + SfxDie = Game->Audio->LoadSound("common/die.wav"); + MusMusic = Game->Audio->LoadMusic("snakey/music.ogg"); } void CGameSnake::UnLoadSound() { - Game->Audio->StopMusic(); - Game->Audio->StopSound(); - Game->Audio->UnLoadMusic(MusMusic); - Game->Audio->UnLoadSound(SfxFood); - Game->Audio->UnLoadSound(SfxDie); + Game->Audio->StopMusic(); + Game->Audio->StopSound(); + Game->Audio->UnLoadMusic(MusMusic); + Game->Audio->UnLoadSound(SfxFood); + Game->Audio->UnLoadSound(SfxDie); } //Update ---------------------------------------------------------------------------------------------------------------- void CGameSnake::UpdateObjects(bool IsGameState) { - if (IsGameState) - { - updatesnake(); - updatefood(); - } + if (IsGameState) + { + updatesnake(); + updatefood(); + } - if (IsGameState && playerdeath) - { - Game->Audio->PlaySound(SfxDie, 0); - if(!ScreenshotMode) - Game->AddToScore(-50); + if (IsGameState && playerdeath) + { + Game->Audio->PlaySound(SfxDie, 0); + if(!ScreenshotMode) + Game->AddToScore(-50); - if (HealthPoints > 1) - { - createsnake(); - createfood(); - if (Game->GameMode == GMGame) - HealthPoints -= 1; - Game->SubGameState = SGReadyGo; - Game->SubStateTime = SDL_GetTicks() + 500; - } - else - if(Game->GameMode == GMGame) - if (!ScreenshotMode) - HealthPoints -= 1; - } + if (HealthPoints > 1) + { + createsnake(); + createfood(); + if (Game->GameMode == GMGame) + HealthPoints -= 1; + Game->SubGameState = SGReadyGo; + Game->SubStateTime = SDL_GetTicks() + 500; + } + else + if(Game->GameMode == GMGame) + if (!ScreenshotMode) + HealthPoints -= 1; + } } bool CGameSnake::DrawObjects() { - drawfood(); - drawsnake(); - //don't call drawsprites in base object + drawfood(); + drawsnake(); + //don't call drawsprites in base object return false; } \ No newline at end of file diff --git a/src/games/CGameSnake.h b/src/games/CGameSnake.h index 098a57c..05735a4 100644 --- a/src/games/CGameSnake.h +++ b/src/games/CGameSnake.h @@ -13,41 +13,41 @@ using namespace std; class CGameSnake: public CGameBase { private: - static const int snakesize = 35; - static const int rows = int(ScreenHeight / snakesize) -1; - static const int cols = int(ScreenWidth / snakesize) -1; - static const int updateticks = 8; - - const SDL_Color snakeheadcolor = {255, 0, 0, 255}; - const SDL_Color snakebodycolor = {255, 255, 255, 255}; - const SDL_Color snakefoodcolor = {0, 255 ,0, 255}; - - bool movedone = true; + static const int snakesize = 35; + static const int rows = int(ScreenHeight / snakesize) -1; + static const int cols = int(ScreenWidth / snakesize) -1; + static const int updateticks = 8; + + const SDL_Color snakeheadcolor = {255, 0, 0, 255}; + const SDL_Color snakebodycolor = {255, 255, 255, 255}; + const SDL_Color snakefoodcolor = {0, 255 ,0, 255}; + + bool movedone = true; int snakelength; int ticks; SDL_Point head; SDL_Point body[rows*cols+1]; SDL_Point dir; - SDL_Point food; + SDL_Point food; int playerdeath; - int MusMusic, SfxFood, SfxDie; - - void createfood(); - void drawfood(); - void updatefood(); - - void createsnake(); - void drawsnake(); - void updatesnake(); + int MusMusic, SfxFood, SfxDie; + + void createfood(); + void drawfood(); + void updatefood(); + + void createsnake(); + void drawsnake(); + void updatesnake(); public: - CGameSnake(CGame* aGame, bool aScreenshotMode = false); - ~CGameSnake(); - SDL_Texture* screenshot() override; - void init() override; - void deinit() override; - void LoadSound() override; - void UnLoadSound() override; - void UpdateObjects(bool IsGameState) override; - bool DrawObjects() override; - void DrawBackground(bool motionblur); + CGameSnake(CGame* aGame, bool aScreenshotMode = false); + ~CGameSnake(); + SDL_Texture* screenshot() override; + void init() override; + void deinit() override; + void LoadSound() override; + void UnLoadSound() override; + void UpdateObjects(bool IsGameState) override; + bool DrawObjects() override; + void DrawBackground(bool motionblur); }; \ No newline at end of file diff --git a/src/games/CSpriteObject.h b/src/games/CSpriteObject.h index 98ae6a8..5bbd4ff 100644 --- a/src/games/CSpriteObject.h +++ b/src/games/CSpriteObject.h @@ -7,25 +7,25 @@ class CSpriteObject { public: - bool alive = false; - Vec2F vel = {0,0}; - Vec2F pos = {0,0}; - SDL_Point tz = {0,0}; - CSprite* spr = nullptr; - int healthpoints = 0; - int freeze = 0; - int state = 0; - int stateticks = 0; - //used in toad - int rowtype; - int id; - //used in pang - float force; - float speed; - float curforce; - //used in fast eddy - int floory; - int jumpdown; - int group; - int row; + bool alive = false; + Vec2F vel = {0,0}; + Vec2F pos = {0,0}; + SDL_Point tz = {0,0}; + CSprite* spr = nullptr; + int healthpoints = 0; + int freeze = 0; + int state = 0; + int stateticks = 0; + //used in toad + int rowtype; + int id; + //used in pang + float force; + float speed; + float curforce; + //used in fast eddy + int floory; + int jumpdown; + int group; + int row; };