commit de53477a49520ec2e7c2c0cd908923c3ed22bbeb Author: Dennis Gunia Date: Fri Jul 5 18:24:10 2019 +0200 Initial commit diff --git a/.cproject b/.cproject new file mode 100644 index 0000000..3b3cd2a --- /dev/null +++ b/.cproject @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..69552ce --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + sdl2 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + + + SDL2 + file:/usr/include/SDL2 + + + diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml new file mode 100644 index 0000000..75d34c3 --- /dev/null +++ b/.settings/language.settings.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..726ff15 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/SnakeGame.cpp=UTF-8 diff --git a/.userdata b/.userdata new file mode 100644 index 0000000..cb2ed58 --- /dev/null +++ b/.userdata @@ -0,0 +1,11 @@ +der Boss; +9305,krasser typ; +660,der Boss; +560,der Boss; +250,dennisgunia; +20,dennisgunia; +0,player; +0,player; +0,player; +0,player; +0,player; diff --git a/AnimatedTexture.cpp b/AnimatedTexture.cpp new file mode 100644 index 0000000..eab21dd --- /dev/null +++ b/AnimatedTexture.cpp @@ -0,0 +1,57 @@ +/* + * AnimatedTexture.cpp + * + * Created on: Apr 12, 2019 + * Author: dennisgunia + */ + +#include "AnimatedTexture.h" + +void AnimatedTexture::setupAnimatedTexture( std::string file, int frames, SDL_Renderer *render ) { + // TODO Auto-generated constructor stub + this->frames = frames; + + this->tx_frames = new FramePointer[frames]; + if (frames > 1){ + this->animatedSequence = true; + }else{ + this->animatedSequence = false; + } + // load textures + + for (int i_frame = 0; i_frame < frames ; i_frame++){ + std::stringstream tx_filenameStream; + tx_filenameStream << file << "/frame" << i_frame << ".png"; + std::string tx_filenameString = tx_filenameStream.str(); + char * tx_filename = new char [tx_filenameString.length()+1]; + strcpy (tx_filename, tx_filenameString.c_str()); + + printf("Loading texture : %s \n", tx_filename); + this->tx_frames[i_frame] = IMG_LoadTexture(render, tx_filename); + if (this->tx_frames[i_frame] == NULL ){ + printf("[ERROR] Loading texture : %s failed \n", tx_filename); + } + } +} +AnimatedTexture::AnimatedTexture() { + // TODO Auto-generated destructor stub +} +AnimatedTexture::~AnimatedTexture() { + // TODO Auto-generated destructor stub +} + +void AnimatedTexture::doAnimationStep(){ + this->frame ++; + if(this->frame >= this->frames){ + this->frame = 0; + } +}; + +int AnimatedTexture::getOffset() { + return this->frame; +} + +SDL_Texture *AnimatedTexture::getTexture(int offset) { + + return this->tx_frames[(offset+(this->frame))%(this->frames)]; +} diff --git a/AnimatedTexture.h b/AnimatedTexture.h new file mode 100644 index 0000000..eaaeb0c --- /dev/null +++ b/AnimatedTexture.h @@ -0,0 +1,41 @@ +/* + * AnimatedTexture.h + * + * Created on: Apr 12, 2019 + * Author: dennisgunia + */ + +#ifndef ANIMATEDTEXTURE_H_ +#define ANIMATEDTEXTURE_H_ +#include +#include +#include +#include +#include +#include +#include + +#include + +typedef SDL_Texture* FramePointer; + +class AnimatedTexture { +private: + bool animatedSequence; + int frames; + int frame; + + FramePointer *tx_frames; + +public: + AnimatedTexture( ); + void setupAnimatedTexture( std::string file, int frames ,SDL_Renderer *render ); + void doAnimationStep(); + virtual ~AnimatedTexture(); + + int getOffset(); + SDL_Texture *getTexture(int offest); + +}; + +#endif /* ANIMATEDTEXTURE_H_ */ diff --git a/AssetLoader.cpp b/AssetLoader.cpp new file mode 100644 index 0000000..87f2fba --- /dev/null +++ b/AssetLoader.cpp @@ -0,0 +1,80 @@ +/* + * AssetLoader.cpp + * + * Created on: Apr 13, 2019 + * Author: dennisgunia + */ + + +#include "AssetLoader.hpp" + +namespace AssetLoader { + +rootPath AL_DefineRootPath(std::string path) +{ + return path; +} + +TTF_Font *AL_LoadFont(rootPath root,std::string assetName, int fontSize) +{ + std::string url = AL_AssetURL(root,assetName); + std::cout << "Load asset @ " << url << "\n"; + char * temp = new char [url.length()+1]; + strcpy (temp, url.c_str()); + TTF_Font *font = TTF_OpenFont(temp, fontSize); + if(!font) { + printf("Cannot load asset @ %s\n", url); + printf("SDL Error: %s\n", TTF_GetError()); + } + return font; +} + +Mix_Music *AL_LoadMusic(rootPath root,std::string assetName) +{ + std::string url = AL_AssetURL(root,assetName); + std::cout << "Load asset @ " << url << "\n"; + char * temp = new char [url.length()+1]; + strcpy (temp, url.c_str()); + Mix_Music *music = Mix_LoadMUS(temp); + if(!music) { + printf("Cannot load asset @ %s\n", url); + printf("SDL Error: %s\n", TTF_GetError()); + } + return music; +} +Mix_Chunk *AL_LoadChunk(rootPath root,std::string assetName) +{ + std::string url = AL_AssetURL(root,assetName); + std::cout << "Load asset @ " << url << "\n"; + char * temp = new char [url.length()+1]; + strcpy (temp, url.c_str()); + Mix_Chunk *music = Mix_LoadWAV(temp); + if(!music) { + printf("Cannot load asset @ %s\n", url); + printf("SDL Error: %s\n", TTF_GetError()); + } + return music; +} + +SDL_Texture *AL_LoadTexture(rootPath root,std::string assetName , SDL_Renderer * renderer) +{ + std::string url = AL_AssetURL(root,assetName); + std::cout << "Load asset @ " << url << "\n"; + char * temp = new char [url.length()+1]; + strcpy (temp, url.c_str()); + SDL_Texture *tx = IMG_LoadTexture(renderer, temp); + if(!tx) { + printf("Cannot load asset @ %s\n", url); + printf("SDL Error: %s\n", TTF_GetError()); + } + return tx; +} + +std::string AL_AssetURL(rootPath root,std::string assetName) +{ + std::stringstream ss; + ss << root << "/" << assetName; + return ss.str(); +} + +} /* namespace AssetLoader */ diff --git a/AssetLoader.hpp b/AssetLoader.hpp new file mode 100644 index 0000000..624e97a --- /dev/null +++ b/AssetLoader.hpp @@ -0,0 +1,37 @@ +/* + * AssetLoader.hpp + * + * Created on: Apr 13, 2019 + * Author: dennisgunia + */ + + + +#ifndef ASSETLOADER_HPP_ +#define ASSETLOADER_HPP_ + +#include +#include +#include +#include +#include +#include +#include +#include + + + +namespace AssetLoader { +typedef std::string rootPath; +rootPath AL_DefineRootPath(std::string path); + +TTF_Font *AL_LoadFont(rootPath root,std::string assetName, int fontSize); +Mix_Music *AL_LoadMusic(rootPath root,std::string assetName); +SDL_Texture *AL_LoadTexture(rootPath root,std::string assetName , SDL_Renderer * renderer); +Mix_Chunk *AL_LoadChunk(rootPath root,std::string assetName); + +std::string AL_AssetURL(rootPath root,std::string assetName); +} + + +#endif /* ASSETLOADER_HPP_ */ diff --git a/Assets/.~lock.hackintosh.ods# b/Assets/.~lock.hackintosh.ods# new file mode 100644 index 0000000..a7fdf80 --- /dev/null +++ b/Assets/.~lock.hackintosh.ods# @@ -0,0 +1 @@ +,dennisgunia,dennisgunia-MacBookPro,03.11.2018 12:25,file:///home/dennisgunia/.config/libreoffice/4; \ No newline at end of file diff --git a/Assets/8bit Stage1 Intro.wav b/Assets/8bit Stage1 Intro.wav new file mode 100644 index 0000000..7b4e8b9 Binary files /dev/null and b/Assets/8bit Stage1 Intro.wav differ diff --git a/Assets/8bit Stage1 Loop.wav b/Assets/8bit Stage1 Loop.wav new file mode 100644 index 0000000..efb84fb Binary files /dev/null and b/Assets/8bit Stage1 Loop.wav differ diff --git a/Assets/8bit Stage4 Loop.wav b/Assets/8bit Stage4 Loop.wav new file mode 100644 index 0000000..0314174 Binary files /dev/null and b/Assets/8bit Stage4 Loop.wav differ diff --git a/Assets/ARCADECLASSIC.TTF b/Assets/ARCADECLASSIC.TTF new file mode 100644 index 0000000..394a9f7 Binary files /dev/null and b/Assets/ARCADECLASSIC.TTF differ diff --git a/Assets/CHAR_astronaut_00000.png b/Assets/CHAR_astronaut_00000.png new file mode 100644 index 0000000..f34b07d Binary files /dev/null and b/Assets/CHAR_astronaut_00000.png differ diff --git a/Assets/Death02.wav b/Assets/Death02.wav new file mode 100644 index 0000000..cfc7934 Binary files /dev/null and b/Assets/Death02.wav differ diff --git a/Assets/Misc01.wav b/Assets/Misc01.wav new file mode 100644 index 0000000..d9335db Binary files /dev/null and b/Assets/Misc01.wav differ diff --git a/Assets/Misc05.wav b/Assets/Misc05.wav new file mode 100644 index 0000000..4adb43c Binary files /dev/null and b/Assets/Misc05.wav differ diff --git a/Assets/Retro_8-Bit_Game-Interface_UI_20.wav b/Assets/Retro_8-Bit_Game-Interface_UI_20.wav new file mode 100644 index 0000000..52c932c Binary files /dev/null and b/Assets/Retro_8-Bit_Game-Interface_UI_20.wav differ diff --git a/Assets/Seven Oh Ess 8x8 Monospaced.ttf b/Assets/Seven Oh Ess 8x8 Monospaced.ttf new file mode 100644 index 0000000..c2ce221 Binary files /dev/null and b/Assets/Seven Oh Ess 8x8 Monospaced.ttf differ diff --git a/Assets/coin/.directory b/Assets/coin/.directory new file mode 100644 index 0000000..a5294fa --- /dev/null +++ b/Assets/coin/.directory @@ -0,0 +1,4 @@ +[Dolphin] +Timestamp=2019,4,12,17,14,53 +Version=4 +ViewMode=1 diff --git a/Assets/coin/frame0.png b/Assets/coin/frame0.png new file mode 100644 index 0000000..5fff45a Binary files /dev/null and b/Assets/coin/frame0.png differ diff --git a/Assets/coin/frame1.png b/Assets/coin/frame1.png new file mode 100644 index 0000000..2926b80 Binary files /dev/null and b/Assets/coin/frame1.png differ diff --git a/Assets/coin/frame10.png b/Assets/coin/frame10.png new file mode 100644 index 0000000..15cc1a2 Binary files /dev/null and b/Assets/coin/frame10.png differ diff --git a/Assets/coin/frame11.png b/Assets/coin/frame11.png new file mode 100644 index 0000000..8a39bb3 Binary files /dev/null and b/Assets/coin/frame11.png differ diff --git a/Assets/coin/frame12.png b/Assets/coin/frame12.png new file mode 100644 index 0000000..be79154 Binary files /dev/null and b/Assets/coin/frame12.png differ diff --git a/Assets/coin/frame13.png b/Assets/coin/frame13.png new file mode 100644 index 0000000..8a45af4 Binary files /dev/null and b/Assets/coin/frame13.png differ diff --git a/Assets/coin/frame2.png b/Assets/coin/frame2.png new file mode 100644 index 0000000..c87b5df Binary files /dev/null and b/Assets/coin/frame2.png differ diff --git a/Assets/coin/frame3.png b/Assets/coin/frame3.png new file mode 100644 index 0000000..4cefb45 Binary files /dev/null and b/Assets/coin/frame3.png differ diff --git a/Assets/coin/frame4.png b/Assets/coin/frame4.png new file mode 100644 index 0000000..a588b2e Binary files /dev/null and b/Assets/coin/frame4.png differ diff --git a/Assets/coin/frame5.png b/Assets/coin/frame5.png new file mode 100644 index 0000000..73e8faf Binary files /dev/null and b/Assets/coin/frame5.png differ diff --git a/Assets/coin/frame6.png b/Assets/coin/frame6.png new file mode 100644 index 0000000..abb3366 Binary files /dev/null and b/Assets/coin/frame6.png differ diff --git a/Assets/coin/frame7.png b/Assets/coin/frame7.png new file mode 100644 index 0000000..1b6a4cf Binary files /dev/null and b/Assets/coin/frame7.png differ diff --git a/Assets/coin/frame8.png b/Assets/coin/frame8.png new file mode 100644 index 0000000..2e8de77 Binary files /dev/null and b/Assets/coin/frame8.png differ diff --git a/Assets/coin/frame9.png b/Assets/coin/frame9.png new file mode 100644 index 0000000..1d4f7be Binary files /dev/null and b/Assets/coin/frame9.png differ diff --git a/Assets/coinDeath/.directory b/Assets/coinDeath/.directory new file mode 100644 index 0000000..04f2bfd --- /dev/null +++ b/Assets/coinDeath/.directory @@ -0,0 +1,4 @@ +[Dolphin] +Timestamp=2019,4,12,19,22,35 +Version=4 +ViewMode=1 diff --git a/Assets/coinDeath/frame0.png b/Assets/coinDeath/frame0.png new file mode 100644 index 0000000..2d103a3 Binary files /dev/null and b/Assets/coinDeath/frame0.png differ diff --git a/Assets/coinDeath/frame1.png b/Assets/coinDeath/frame1.png new file mode 100644 index 0000000..867ee33 Binary files /dev/null and b/Assets/coinDeath/frame1.png differ diff --git a/Assets/coinDeath/frame10.png b/Assets/coinDeath/frame10.png new file mode 100644 index 0000000..103ddcb Binary files /dev/null and b/Assets/coinDeath/frame10.png differ diff --git a/Assets/coinDeath/frame11.png b/Assets/coinDeath/frame11.png new file mode 100644 index 0000000..df3ece9 Binary files /dev/null and b/Assets/coinDeath/frame11.png differ diff --git a/Assets/coinDeath/frame12.png b/Assets/coinDeath/frame12.png new file mode 100644 index 0000000..785ab20 Binary files /dev/null and b/Assets/coinDeath/frame12.png differ diff --git a/Assets/coinDeath/frame13.png b/Assets/coinDeath/frame13.png new file mode 100644 index 0000000..8933676 Binary files /dev/null and b/Assets/coinDeath/frame13.png differ diff --git a/Assets/coinDeath/frame2.png b/Assets/coinDeath/frame2.png new file mode 100644 index 0000000..f9a5800 Binary files /dev/null and b/Assets/coinDeath/frame2.png differ diff --git a/Assets/coinDeath/frame3.png b/Assets/coinDeath/frame3.png new file mode 100644 index 0000000..3236ba9 Binary files /dev/null and b/Assets/coinDeath/frame3.png differ diff --git a/Assets/coinDeath/frame4.png b/Assets/coinDeath/frame4.png new file mode 100644 index 0000000..e600ed0 Binary files /dev/null and b/Assets/coinDeath/frame4.png differ diff --git a/Assets/coinDeath/frame5.png b/Assets/coinDeath/frame5.png new file mode 100644 index 0000000..1f67672 Binary files /dev/null and b/Assets/coinDeath/frame5.png differ diff --git a/Assets/coinDeath/frame6.png b/Assets/coinDeath/frame6.png new file mode 100644 index 0000000..f91dadc Binary files /dev/null and b/Assets/coinDeath/frame6.png differ diff --git a/Assets/coinDeath/frame7.png b/Assets/coinDeath/frame7.png new file mode 100644 index 0000000..1872a71 Binary files /dev/null and b/Assets/coinDeath/frame7.png differ diff --git a/Assets/coinDeath/frame8.png b/Assets/coinDeath/frame8.png new file mode 100644 index 0000000..e111a35 Binary files /dev/null and b/Assets/coinDeath/frame8.png differ diff --git a/Assets/coinDeath/frame9.png b/Assets/coinDeath/frame9.png new file mode 100644 index 0000000..38046a6 Binary files /dev/null and b/Assets/coinDeath/frame9.png differ diff --git a/Assets/earth.png b/Assets/earth.png new file mode 100644 index 0000000..a893142 Binary files /dev/null and b/Assets/earth.png differ diff --git a/Assets/filtered-9445449A-6C14-4C25-8477-19A23121B9AB.MP4 b/Assets/filtered-9445449A-6C14-4C25-8477-19A23121B9AB.MP4 new file mode 100644 index 0000000..a44b1f3 Binary files /dev/null and b/Assets/filtered-9445449A-6C14-4C25-8477-19A23121B9AB.MP4 differ diff --git a/Assets/moon_surface.png b/Assets/moon_surface.png new file mode 100644 index 0000000..e490e2c Binary files /dev/null and b/Assets/moon_surface.png differ diff --git a/Assets/music/Title.wav b/Assets/music/Title.wav new file mode 100644 index 0000000..c3c2c6b Binary files /dev/null and b/Assets/music/Title.wav differ diff --git a/Assets/music/UI03.wav b/Assets/music/UI03.wav new file mode 100644 index 0000000..1a34368 Binary files /dev/null and b/Assets/music/UI03.wav differ diff --git a/Assets/music/UI04.wav b/Assets/music/UI04.wav new file mode 100644 index 0000000..380f755 Binary files /dev/null and b/Assets/music/UI04.wav differ diff --git a/Assets/potion_A_green_full.png b/Assets/potion_A_green_full.png new file mode 100644 index 0000000..37653f4 Binary files /dev/null and b/Assets/potion_A_green_full.png differ diff --git a/Assets/sparkle/.directory b/Assets/sparkle/.directory new file mode 100644 index 0000000..7039f7d --- /dev/null +++ b/Assets/sparkle/.directory @@ -0,0 +1,4 @@ +[Dolphin] +Timestamp=2019,4,12,19,32,53 +Version=4 +ViewMode=1 diff --git a/Assets/sparkle/frame0.png b/Assets/sparkle/frame0.png new file mode 100644 index 0000000..a089855 Binary files /dev/null and b/Assets/sparkle/frame0.png differ diff --git a/Assets/sparkle/frame1.png b/Assets/sparkle/frame1.png new file mode 100644 index 0000000..9e3cc46 Binary files /dev/null and b/Assets/sparkle/frame1.png differ diff --git a/Assets/sparkle/frame10.png b/Assets/sparkle/frame10.png new file mode 100644 index 0000000..c1d899c Binary files /dev/null and b/Assets/sparkle/frame10.png differ diff --git a/Assets/sparkle/frame11.png b/Assets/sparkle/frame11.png new file mode 100644 index 0000000..278ab22 Binary files /dev/null and b/Assets/sparkle/frame11.png differ diff --git a/Assets/sparkle/frame12.png b/Assets/sparkle/frame12.png new file mode 100644 index 0000000..72751a9 Binary files /dev/null and b/Assets/sparkle/frame12.png differ diff --git a/Assets/sparkle/frame13.png b/Assets/sparkle/frame13.png new file mode 100644 index 0000000..5ccad53 Binary files /dev/null and b/Assets/sparkle/frame13.png differ diff --git a/Assets/sparkle/frame14.png b/Assets/sparkle/frame14.png new file mode 100644 index 0000000..a4c192d Binary files /dev/null and b/Assets/sparkle/frame14.png differ diff --git a/Assets/sparkle/frame15.png b/Assets/sparkle/frame15.png new file mode 100644 index 0000000..f507ec7 Binary files /dev/null and b/Assets/sparkle/frame15.png differ diff --git a/Assets/sparkle/frame16.png b/Assets/sparkle/frame16.png new file mode 100644 index 0000000..a6f8191 Binary files /dev/null and b/Assets/sparkle/frame16.png differ diff --git a/Assets/sparkle/frame17.png b/Assets/sparkle/frame17.png new file mode 100644 index 0000000..0843cdf Binary files /dev/null and b/Assets/sparkle/frame17.png differ diff --git a/Assets/sparkle/frame18.png b/Assets/sparkle/frame18.png new file mode 100644 index 0000000..5202934 Binary files /dev/null and b/Assets/sparkle/frame18.png differ diff --git a/Assets/sparkle/frame19.png b/Assets/sparkle/frame19.png new file mode 100644 index 0000000..eea7427 Binary files /dev/null and b/Assets/sparkle/frame19.png differ diff --git a/Assets/sparkle/frame2.png b/Assets/sparkle/frame2.png new file mode 100644 index 0000000..defca6d Binary files /dev/null and b/Assets/sparkle/frame2.png differ diff --git a/Assets/sparkle/frame20.png b/Assets/sparkle/frame20.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame20.png differ diff --git a/Assets/sparkle/frame21.png b/Assets/sparkle/frame21.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame21.png differ diff --git a/Assets/sparkle/frame22.png b/Assets/sparkle/frame22.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame22.png differ diff --git a/Assets/sparkle/frame23.png b/Assets/sparkle/frame23.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame23.png differ diff --git a/Assets/sparkle/frame24.png b/Assets/sparkle/frame24.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame24.png differ diff --git a/Assets/sparkle/frame25.png b/Assets/sparkle/frame25.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame25.png differ diff --git a/Assets/sparkle/frame26.png b/Assets/sparkle/frame26.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame26.png differ diff --git a/Assets/sparkle/frame27.png b/Assets/sparkle/frame27.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame27.png differ diff --git a/Assets/sparkle/frame28.png b/Assets/sparkle/frame28.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame28.png differ diff --git a/Assets/sparkle/frame29.png b/Assets/sparkle/frame29.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame29.png differ diff --git a/Assets/sparkle/frame3.png b/Assets/sparkle/frame3.png new file mode 100644 index 0000000..5832134 Binary files /dev/null and b/Assets/sparkle/frame3.png differ diff --git a/Assets/sparkle/frame30.png b/Assets/sparkle/frame30.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame30.png differ diff --git a/Assets/sparkle/frame31.png b/Assets/sparkle/frame31.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame31.png differ diff --git a/Assets/sparkle/frame32.png b/Assets/sparkle/frame32.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame32.png differ diff --git a/Assets/sparkle/frame33.png b/Assets/sparkle/frame33.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/Assets/sparkle/frame33.png differ diff --git a/Assets/sparkle/frame4.png b/Assets/sparkle/frame4.png new file mode 100644 index 0000000..3e30d02 Binary files /dev/null and b/Assets/sparkle/frame4.png differ diff --git a/Assets/sparkle/frame5.png b/Assets/sparkle/frame5.png new file mode 100644 index 0000000..8e072c1 Binary files /dev/null and b/Assets/sparkle/frame5.png differ diff --git a/Assets/sparkle/frame6.png b/Assets/sparkle/frame6.png new file mode 100644 index 0000000..1997e05 Binary files /dev/null and b/Assets/sparkle/frame6.png differ diff --git a/Assets/sparkle/frame7.png b/Assets/sparkle/frame7.png new file mode 100644 index 0000000..ce8bc4d Binary files /dev/null and b/Assets/sparkle/frame7.png differ diff --git a/Assets/sparkle/frame8.png b/Assets/sparkle/frame8.png new file mode 100644 index 0000000..cda11a7 Binary files /dev/null and b/Assets/sparkle/frame8.png differ diff --git a/Assets/sparkle/frame9.png b/Assets/sparkle/frame9.png new file mode 100644 index 0000000..7b5a6ac Binary files /dev/null and b/Assets/sparkle/frame9.png differ diff --git a/Assets/splash.png b/Assets/splash.png new file mode 100644 index 0000000..aff18a0 Binary files /dev/null and b/Assets/splash.png differ diff --git a/Assets/splash.xcf b/Assets/splash.xcf new file mode 100644 index 0000000..a08ed97 Binary files /dev/null and b/Assets/splash.xcf differ diff --git a/Assets/stars.png b/Assets/stars.png new file mode 100644 index 0000000..d04c746 Binary files /dev/null and b/Assets/stars.png differ diff --git a/Debug/AnimatedTexture.d b/Debug/AnimatedTexture.d new file mode 100644 index 0000000..131061e --- /dev/null +++ b/Debug/AnimatedTexture.d @@ -0,0 +1,3 @@ +AnimatedTexture.o: ../AnimatedTexture.cpp ../AnimatedTexture.h + +../AnimatedTexture.h: diff --git a/Debug/AnimatedTexture.o b/Debug/AnimatedTexture.o new file mode 100644 index 0000000..6226f71 Binary files /dev/null and b/Debug/AnimatedTexture.o differ diff --git a/Debug/AssetLoader.d b/Debug/AssetLoader.d new file mode 100644 index 0000000..0b0ab34 --- /dev/null +++ b/Debug/AssetLoader.d @@ -0,0 +1,3 @@ +AssetLoader.o: ../AssetLoader.cpp ../AssetLoader.hpp + +../AssetLoader.hpp: diff --git a/Debug/AssetLoader.o b/Debug/AssetLoader.o new file mode 100644 index 0000000..2a44061 Binary files /dev/null and b/Debug/AssetLoader.o differ diff --git a/Debug/SnakeGame.d b/Debug/SnakeGame.d new file mode 100644 index 0000000..8934429 --- /dev/null +++ b/Debug/SnakeGame.d @@ -0,0 +1,15 @@ +SnakeGame.o: ../SnakeGame.cpp ../SnakeGame.hpp ../global.h \ + ../AssetLoader.hpp ../AnimatedTexture.h ../SnakeTextAnimation.h \ + ../SnakeTextAnimationHelper.h + +../SnakeGame.hpp: + +../global.h: + +../AssetLoader.hpp: + +../AnimatedTexture.h: + +../SnakeTextAnimation.h: + +../SnakeTextAnimationHelper.h: diff --git a/Debug/SnakeGame.o b/Debug/SnakeGame.o new file mode 100644 index 0000000..81100d2 Binary files /dev/null and b/Debug/SnakeGame.o differ diff --git a/Debug/SnakeMenu.d b/Debug/SnakeMenu.d new file mode 100644 index 0000000..f942649 --- /dev/null +++ b/Debug/SnakeMenu.d @@ -0,0 +1,8 @@ +SnakeMenu.o: ../SnakeMenu.cpp ../SnakeMenu.h ../global.h \ + ../AssetLoader.hpp + +../SnakeMenu.h: + +../global.h: + +../AssetLoader.hpp: diff --git a/Debug/SnakeMenu.o b/Debug/SnakeMenu.o new file mode 100644 index 0000000..fa06995 Binary files /dev/null and b/Debug/SnakeMenu.o differ diff --git a/Debug/SnakeTextAnimation.d b/Debug/SnakeTextAnimation.d new file mode 100644 index 0000000..858e4fb --- /dev/null +++ b/Debug/SnakeTextAnimation.d @@ -0,0 +1,3 @@ +SnakeTextAnimation.o: ../SnakeTextAnimation.cpp ../SnakeTextAnimation.h + +../SnakeTextAnimation.h: diff --git a/Debug/SnakeTextAnimation.o b/Debug/SnakeTextAnimation.o new file mode 100644 index 0000000..983947e Binary files /dev/null and b/Debug/SnakeTextAnimation.o differ diff --git a/Debug/SnakeTextAnimationHelper.d b/Debug/SnakeTextAnimationHelper.d new file mode 100644 index 0000000..ad12d0d --- /dev/null +++ b/Debug/SnakeTextAnimationHelper.d @@ -0,0 +1,6 @@ +SnakeTextAnimationHelper.o: ../SnakeTextAnimationHelper.cpp \ + ../SnakeTextAnimationHelper.h ../SnakeTextAnimation.h + +../SnakeTextAnimationHelper.h: + +../SnakeTextAnimation.h: diff --git a/Debug/SnakeTextAnimationHelper.o b/Debug/SnakeTextAnimationHelper.o new file mode 100644 index 0000000..bcde609 Binary files /dev/null and b/Debug/SnakeTextAnimationHelper.o differ diff --git a/Debug/global.d b/Debug/global.d new file mode 100644 index 0000000..ac6ad29 --- /dev/null +++ b/Debug/global.d @@ -0,0 +1,5 @@ +global.o: ../global.cpp ../global.h ../AssetLoader.hpp + +../global.h: + +../AssetLoader.hpp: diff --git a/Debug/global.o b/Debug/global.o new file mode 100644 index 0000000..43c4cf2 Binary files /dev/null and b/Debug/global.o differ diff --git a/Debug/main.d b/Debug/main.d new file mode 100644 index 0000000..64b18f8 --- /dev/null +++ b/Debug/main.d @@ -0,0 +1,17 @@ +main.o: ../main.cpp ../SnakeGame.hpp ../global.h ../AssetLoader.hpp \ + ../AnimatedTexture.h ../SnakeTextAnimation.h \ + ../SnakeTextAnimationHelper.h ../SnakeMenu.h + +../SnakeGame.hpp: + +../global.h: + +../AssetLoader.hpp: + +../AnimatedTexture.h: + +../SnakeTextAnimation.h: + +../SnakeTextAnimationHelper.h: + +../SnakeMenu.h: diff --git a/Debug/main.o b/Debug/main.o new file mode 100644 index 0000000..69da27c Binary files /dev/null and b/Debug/main.o differ diff --git a/Debug/makefile b/Debug/makefile new file mode 100644 index 0000000..b56ba8d --- /dev/null +++ b/Debug/makefile @@ -0,0 +1,63 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +-include ../makefile.init + +RM := rm -rf + +# All of the sources participating in the build are defined here +-include sources.mk +-include subdir.mk +-include objects.mk + +ifneq ($(MAKECMDGOALS),clean) +ifneq ($(strip $(CC_DEPS)),) +-include $(CC_DEPS) +endif +ifneq ($(strip $(C++_DEPS)),) +-include $(C++_DEPS) +endif +ifneq ($(strip $(C_UPPER_DEPS)),) +-include $(C_UPPER_DEPS) +endif +ifneq ($(strip $(CXX_DEPS)),) +-include $(CXX_DEPS) +endif +ifneq ($(strip $(INO_DEPS)),) +-include $(INO_DEPS) +endif +ifneq ($(strip $(PDE_DEPS)),) +-include $(PDE_DEPS) +endif +ifneq ($(strip $(CPP_DEPS)),) +-include $(CPP_DEPS) +endif +ifneq ($(strip $(C_DEPS)),) +-include $(C_DEPS) +endif +endif + +-include ../makefile.defs + +# Add inputs and outputs from these tool invocations to the build variables + +# All Target +all: sdl2 + +# Tool invocations +sdl2: $(OBJS) $(USER_OBJS) + @echo 'Building target: $@' + @echo 'Invoking: GCC C++ Linker' + g++ -L/usr/include/SDL2 -o "sdl2" $(OBJS) $(USER_OBJS) $(LIBS) `sdl2-config --libs` -lSDL2_image -lSDL2_ttf -lSDL2_mixer -lSDL2_gfx -lm + @echo 'Finished building target: $@' + @echo ' ' + +# Other Targets +clean: + -$(RM) $(CC_DEPS)$(C++_DEPS)$(EXECUTABLES)$(C_UPPER_DEPS)$(CXX_DEPS)$(OBJS)$(INO_DEPS)$(PDE_DEPS)$(CPP_DEPS)$(C_DEPS) sdl2 + -@echo ' ' + +.PHONY: all clean dependents + +-include ../makefile.targets diff --git a/Debug/objects.mk b/Debug/objects.mk new file mode 100644 index 0000000..1d85790 --- /dev/null +++ b/Debug/objects.mk @@ -0,0 +1,8 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +USER_OBJS := + +LIBS := -lSDL2 + diff --git a/Debug/sdl2 b/Debug/sdl2 new file mode 100755 index 0000000..58f32c9 Binary files /dev/null and b/Debug/sdl2 differ diff --git a/Debug/sources.mk b/Debug/sources.mk new file mode 100644 index 0000000..3666eb8 --- /dev/null +++ b/Debug/sources.mk @@ -0,0 +1,31 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +C_UPPER_SRCS := +CXX_SRCS := +C++_SRCS := +OBJ_SRCS := +INO_SRCS := +PDE_SRCS := +CC_SRCS := +ASM_SRCS := +CPP_SRCS := +C_SRCS := +O_SRCS := +S_UPPER_SRCS := +CC_DEPS := +C++_DEPS := +EXECUTABLES := +C_UPPER_DEPS := +CXX_DEPS := +OBJS := +INO_DEPS := +PDE_DEPS := +CPP_DEPS := +C_DEPS := + +# Every subdirectory with source files must be described here +SUBDIRS := \ +. \ + diff --git a/Debug/subdir.mk b/Debug/subdir.mk new file mode 100644 index 0000000..1d4a4ac --- /dev/null +++ b/Debug/subdir.mk @@ -0,0 +1,45 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +CPP_SRCS += \ +../AnimatedTexture.cpp \ +../AssetLoader.cpp \ +../SnakeGame.cpp \ +../SnakeMenu.cpp \ +../SnakeTextAnimation.cpp \ +../SnakeTextAnimationHelper.cpp \ +../global.cpp \ +../main.cpp + +OBJS += \ +./AnimatedTexture.o \ +./AssetLoader.o \ +./SnakeGame.o \ +./SnakeMenu.o \ +./SnakeTextAnimation.o \ +./SnakeTextAnimationHelper.o \ +./global.o \ +./main.o + +CPP_DEPS += \ +./AnimatedTexture.d \ +./AssetLoader.d \ +./SnakeGame.d \ +./SnakeMenu.d \ +./SnakeTextAnimation.d \ +./SnakeTextAnimationHelper.d \ +./global.d \ +./main.d + + +# Each subdirectory must supply rules for building sources it contributes +%.o: ../%.cpp + @echo 'Building file: $<' + @echo 'Invoking: GCC C++ Compiler' + g++ -I/usr/include/SDL2 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/SnakeGame.cpp b/SnakeGame.cpp new file mode 100644 index 0000000..acb6433 --- /dev/null +++ b/SnakeGame.cpp @@ -0,0 +1,560 @@ +/* + * snakeGame.cpp + * + * Created on: Apr 11, 2019 + * Author: dennisgunia + */ + +#include "SnakeGame.hpp" + + + + + +static void soundPlayloop(){ + Mix_PlayMusic(AssetLoader::AL_LoadMusic(assetPath,"8bit Stage1 Loop.wav"),-1); +} + +SnakeGame::SnakeGame(size Size, SDL_Renderer *render, SDL_Window *window) { + this->Size = Size; + this->render = render; + this->player = {Size.X/2,Size.Y/2,true}; + this->direction = dir_stop; + this->taillen = 0; + this->foodcount = 0; + this->lastWasHit = false; + this->speed = 750; + this->coins = 0; + this->score = 0; + this->highscore = 0; + this->activePowerup = foodtype::powerup_none; + this->tailPhase = -1; + this->countdownPowerup = -1; + this->tmpOffset = {20,20}; + + this->stars = AssetLoader::AL_LoadTexture(assetPath,"stars.png",this->render); + + this->powerup[foodtype::powerup_potion] =AssetLoader::AL_LoadTexture(assetPath,"potion_A_green_full.png",this->render); + + //this->font=TTF_OpenFont("/home/dennisgunia/eclipse-workspace-cpp/Desktop/Seven Oh Ess 8x8 Monospaced.ttf", 29); + this->font=AssetLoader::AL_LoadFont(assetPath,"Seven Oh Ess 8x8 Monospaced.ttf", 29); + + //this->snd_click = Mix_LoadWAV("/home/dennisgunia/eclipse-workspace-cpp/Desktop/Misc01.wav"); + //this->snd_death = Mix_LoadWAV("/home/dennisgunia/eclipse-workspace-cpp/Desktop/Death02.wav"); + //this->snd_powerup = Mix_LoadWAV("/home/dennisgunia/eclipse-workspace-cpp/Desktop/Misc05.wav"); + + this->snd_click = AssetLoader::AL_LoadChunk(assetPath,"Misc01.wav"); + this->snd_death = AssetLoader::AL_LoadChunk(assetPath,"Death02.wav"); + this->snd_powerup = AssetLoader::AL_LoadChunk(assetPath,"Misc05.wav"); + + SDL_SetWindowSize(window,this->Size.scale * this->Size.X + offset_left + offset_right,this->Size.scale * this->Size.Y + offset_top + offset_bottom); + + Mix_VolumeChunk(snd_click, 35); + + + + //this->tx_food[foodtype::type_coin_std].setupAnimatedTexture("/home/dennisgunia/eclipse-workspace-cpp/Desktop/coin", 14,this->render ); + //this->tx_food[foodtype::type_coin_death].setupAnimatedTexture("/home/dennisgunia/eclipse-workspace-cpp/Desktop/coinDeath", 14, this->render ); + //this->tx_food[foodtype::type_powerup].setupAnimatedTexture("/home/dennisgunia/eclipse-workspace-cpp/Desktop/sparkle", 34, this->render ); + + + this->tx_food[foodtype::type_coin_std].setupAnimatedTexture(AssetLoader::AL_AssetURL(assetPath,"coin"), 14,this->render ); + this->tx_food[foodtype::type_coin_death].setupAnimatedTexture(AssetLoader::AL_AssetURL(assetPath,"coinDeath"), 14, this->render ); + this->tx_food[foodtype::type_powerup].setupAnimatedTexture(AssetLoader::AL_AssetURL(assetPath,"sparkle"), 34, this->render ); + + + this->Music_normal = AssetLoader::AL_LoadMusic(assetPath,"8bit Stage1 Loop.wav"); + this->Music_powerup1 = AssetLoader::AL_LoadMusic(assetPath,"8bit Stage4 Loop.wav"); + + text_animations = SnakeTextAnimationHelper(); + text_animations.setRenderer(this->render); + +} + + + + + +void SnakeGame::doAnimation(){ + this->text_animations.doAnimations(); + this->tx_food[0].doAnimationStep(); + this->tx_food[1].doAnimationStep(); + this->tx_food[2].doAnimationStep(); + + if (this->tailPhase >= 0){ + this->tailPhase += 20; + if (this->tailPhase >= 180){ + this->tailPhase = 0; + } + } + if (this->countdownPowerup > 0){ + this->countdownPowerup --; + }else if (this->countdownPowerup == 0){ + this->countdownPowerup --; + this->activePowerup = foodtype::powerup_none; + this->tailPhase = -1; + this->countdownPowerup = -1; + Mix_PlayMusic(this->Music_normal, -1); + } + + + +} + +SnakeGame::~SnakeGame() { + // TODO Auto-generated destructor stub +} + +void SnakeGame::shiftTailArray () { + if (this->taillen > 0){ + // aktuelle länge bestimmen + int len =this->taillen; + // array verschieben + if (this->lastWasHit ){ + //len++; + this->lastWasHit = false; + } + for ( int index = len ; index > 0; index--){ + this->tail[index] = this->tail[index - 1]; + } + // aktuelle position hinzufügen + this->tail[0] = this->player; + + this->tail[0].enabled = true; + + } +} + +void SnakeGame::addTailArray(){ + + this->taillen++; + this->lastWasHit = true; + this->speed = this->speed - (this->speed * 0.10); + + if (this->speed < 50){ + this->speed = 50; + } + Mix_PlayChannel(-1, snd_click, 0); +} + +void SnakeGame::setDirection(int direction){ + this->direction = direction; + if (direction == dir_stop){ + Mix_PlayChannel(-1, snd_death, 0); + } +} + +void SnakeGame::convertToCoins(){ + for ( int index3 = 0 ; index3 < 500 ; index3++){ + this->food[index3].X = 0; + this->food[index3].Y = 0; + this->food[index3].enabled = false; + this->food[index3].type = foodtype::type_coin_std; + this->food[index3].offset = 0; + } + int arrayLen = this->taillen; + for ( int index = 0 ; index < arrayLen ; index++){ + if (this->tail[index].enabled){ + this->foodcount++; + for ( int index2 = 0 ; index2 < 50 ; index2++){ + if (this->food[index2].enabled == false){ + this->food[index2].X = this->tail[index].X; + this->food[index2].Y = this->tail[index].Y; + this->food[index2].enabled = true; + this->food[index2].type = foodtype::type_coin_death; + //this->food[index2].offset = this->tx_food[foodtype::type_coin_death].getOffset(); + this->food[index2].powerupType = foodtype::powerup_none; + this->tail[index].enabled = false; + break; + } + } + } + else + { + break; + } + } + +} + +bool SnakeGame::doSnakeStep(){ + + switch(this->direction){ + case dir_up: + this->shiftTailArray(); + this->player.Y -= 1; + break; + case dir_down: + this->shiftTailArray(); + this->player.Y += 1; + break; + case dir_left: + this->shiftTailArray(); + this->player.X -= 1; + break; + case dir_right: + this->shiftTailArray(); + this->player.X += 1; + break; + default: + return true; + } + + for ( int index = 0 ; index < 500 ; index++){ + if (this->food[index].enabled && (this->food[index].X == this->player.X)&& (this->food[index].Y == this->player.Y)) { + + std::stringstream popup; + int tx = this->food[index].X * this->Size.scale + 2 + offset_left; + int ty = (this->food[index].Y - 1) * this->Size.scale + 2 + offset_top; + + if (this->food[index].powerupType == foodtype::powerup_none){ + + this->addTailArray(); + if (this->food[index].type == foodtype::type_coin_std){ + this->score += 20; + popup << "+20" ; + }else{ + this->score += 5; + popup << "+5" ; + } + if (this->highscore < this->score){ + this->highscore = this->score; + } + this->coins++; + + this->food[index].enabled = false; + + this->text_animations.startAnimation(tx + this->tmpOffset.X,ty+ this->tmpOffset.Y,popup.str(),{64,255,64,0},this->font); + + }else{ + if (this->activePowerup == foodtype::powerup_none){ + this->score += 150; + popup << "+150" ; + this->text_animations.startAnimation(tx + this->tmpOffset.X,ty+ this->tmpOffset.Y,popup.str(),{64,255,64,0},this->font); + + this->food[index].enabled = false; + this->activePowerup = this->food[index].powerupType; + Mix_PlayChannel(-1, snd_powerup, 0); + this->tailPhase = 0; + this->countdownPowerup = 500; + Mix_PlayMusic(this->Music_powerup1, -1); + + + } + } + } + } + + + if (this->player.X < 0){ + this->player.X = this->Size.X - 1; + if (this->tailPhase < 0){return false;}; + + } + if (this->player.Y < 0){ + this->player.Y = this->Size.Y - 1; + if (this->tailPhase < 0){return false;}; + } + if (this->player.X > this->Size.X - 1){ + this->player.X = 0; + if (this->tailPhase < 0){return false;}; + } + if (this->player.Y > this->Size.Y - 1){ + this->player.Y = 0; + if (this->tailPhase < 0){return false;}; + } + + for ( int index = 0 ; index < this->taillen + 1 ; index++){ + if (this->tail[index].enabled && (this->tail[index].X == this->player.X)&& (this->tail[index].Y == this->player.Y)){ + if (this->tailPhase < 0){return false;}; + } + } + return true; +} + +void SnakeGame::generateFood () { + + int foodtype = rand()%40; + if (foodtype < 30) + { + this->foodcount++; + for ( int index = 0 ; index < 500 ; index++){ + if (this->food[index].enabled == false){ + this->food[index].X = rand()%this->Size.X; + this->food[index].Y = rand()%this->Size.Y; + this->food[index].enabled = true; + this->food[index].type = foodtype::type_coin_std; + this->food[index].offset = this->tx_food[foodtype::type_coin_std].getOffset(); + this->food[index].powerupType = foodtype::powerup_none; + break; + } + } + } + else if (foodtype < 40) + { + this->foodcount++; + for ( int index = 0 ; index < 500 ; index++){ + if (this->food[index].enabled == false){ + this->food[index].X = rand()%this->Size.X; + this->food[index].Y = rand()%this->Size.Y; + this->food[index].enabled = true; + this->food[index].type = foodtype::type_powerup; + this->food[index].offset = this->tx_food[foodtype::type_powerup].getOffset(); + this->food[index].powerupType = foodtype::powerup_potion; + + break; + } + } + } +} + +int SnakeGame::getTimeOut(){ + return this->speed; +} + + +void SnakeGame::drawHud(){ + + +} + + +void SnakeGame::drawGame(){ + + + coordinate playerInRender = {20,20}; + SDL_Rect cell; + SDL_GetRendererOutputSize(this->render,&cell.w,&cell.h); + + + playerInRender.X = this->player.X * this->Size.scale + 2 + offset_left + this->tmpOffset.X; + playerInRender.Y = this->player.Y * this->Size.scale + 2 + offset_top + this->tmpOffset.Y; + + int steps = 4; + + + if(playerInRender.X < cell.w * 0.2){ + this->tmpOffset.X += this->Size.scale /steps; + } + if(playerInRender.X > cell.w * 0.8){ + this->tmpOffset.X -= this->Size.scale /steps; + } + + if(playerInRender.Y < cell.h * 0.2){ + this->tmpOffset.Y += this->Size.scale /steps; + } + if(playerInRender.Y > cell.h * 0.8){ + this->tmpOffset.Y -= this->Size.scale/steps; + } + + SDL_SetRenderDrawColor(this->render, SNAKE_BACKGROUND); + SDL_RenderClear(this->render); + + + + this->drawStarfield(this->tmpOffset.X / 8,this->tmpOffset.Y / 8); + + + for (int posY = 0 ; posY < this->Size.Y + 1;posY++){ + SDL_Rect cell; + cell.x = offset_left - 32 + offset_left - 32 + this->tmpOffset.X; + cell.y = posY * this->Size.scale+ offset_top - 32 + this->tmpOffset.Y; + cell.h = this->Size.scale; + cell.w = this->Size.scale; + SDL_SetRenderDrawColor(this->render, SNAKE_BORDER); + SDL_RenderDrawRects(this->render,&cell,1); + cell.x = (this->Size.X + 1) * this->Size.scale + offset_left - 32 + this->tmpOffset.X; + cell.y = posY * this->Size.scale+ offset_top - 32 + this->tmpOffset.Y; + SDL_RenderDrawRects(this->render,&cell,1); + } + for (int posX = 0 ; posX < this->Size.X + 1;posX++){ + SDL_Rect cell; + cell.x = posX * this->Size.scale + offset_left - 32 + this->tmpOffset.X; + cell.y = offset_top - 32 + this->tmpOffset.Y; + cell.h = this->Size.scale; + cell.w = this->Size.scale; + SDL_SetRenderDrawColor(this->render, SNAKE_BORDER); + SDL_RenderDrawRects(this->render,&cell,1); + + cell.x = posX * this->Size.scale + offset_left - 32 + this->tmpOffset.X; + cell.y = (this->Size.Y +1) * this->Size.scale + offset_top - 32 + this->tmpOffset.Y; + SDL_RenderDrawRects(this->render,&cell,1); + } + + + SDL_SetRenderDrawColor(this->render, SNAKE_PLAYER); + + cell.x = this->player.X * this->Size.scale + 2 + offset_left + this->tmpOffset.X; + cell.y = this->player.Y * this->Size.scale + 2 + offset_top + this->tmpOffset.Y; + cell.h = this->Size.scale - 4; + cell.w = this->Size.scale - 4; + + + if (this->tailPhase >= 0){ + int phase = (this->tailPhase)%180; + SDL_SetRenderDrawColor(this->render, 255,128,000,(sin(phase*PI/180)*255)); + } + SDL_RenderFillRects(this->render,&cell,1); + + int arrayLen = taillen; + + SDL_SetRenderDrawColor(this->render, SNAKE_TAIL); + SDL_Rect cell1; + cell1.h = this->Size.scale - 4; + cell1.w = this->Size.scale - 4; + SDL_SetRenderDrawColor(this->render, SNAKE_TAIL); + for ( int index = 0 ; index < arrayLen ; index++){ + if (this->tail[index].enabled){ + cell1.x = this->tail[index].X * this->Size.scale + 2 + offset_left + this->tmpOffset.X; + cell1.y = this->tail[index].Y * this->Size.scale + 2 + offset_top + this->tmpOffset.Y; + + if (this->tailPhase >= 0){ + int offset = (index + 1) * 20; + int phase = (offset + this->tailPhase)%180; + SDL_SetRenderDrawColor(this->render, 255,255,255,(sin(phase*PI/180)*255)); + } + + + SDL_RenderFillRects(this->render,&cell1,1); + } + else + { + break; + } + } + + //SDL_SetRenderDrawColor(this->render, SNAKE_FOOD); + for ( int index = 0 ; index < 500 ; index++){ + if (this->food[index].enabled){ + //SDL_Rect cell1; + cell1.x = this->food[index].X * this->Size.scale + 2 + offset_left + this->tmpOffset.X; + cell1.y = this->food[index].Y * this->Size.scale + 2 + offset_top + this->tmpOffset.Y; + cell1.h = this->Size.scale - 4; + cell1.w = this->Size.scale - 4; + + //SDL_RenderFillRects(this->render,&cell1,1); + + if(this->food[index].type == foodtype::type_powerup){ + switch(this->food[index].powerupType) { + case foodtype::powerup_potion: + SDL_RenderCopy(this->render, this->powerup[this->food[index].powerupType], NULL, &cell1); + + break; + default: + break; + } + } + //SDL_RenderCopy(this->render, this->coin[(this->coinStep + this->food[index].offset)%14][this->food[index].type -1], NULL, &cell1); + + //printf("[debug] getting texture for %i with animIndex %i - pointer to %i\n",index,this->food[index].offset,this->tx_food[this->food[index].type].getTexture(this->food[index].offset)); + + SDL_RenderCopy(this->render, this->tx_food[this->food[index].type].getTexture(this->food[index].offset), NULL, &cell1); + + } + } + + SDL_Color color={255,255,255,255}, bgcolor={0,0,0,0}; + std::stringstream ss; + ss << "score:" << this->score; + std::string s = ss.str(); + char * tab2 = new char [s.length()+1]; + strcpy (tab2, s.c_str()); + // text score + SDL_Surface *temp_surface = TTF_RenderText_Blended(this->font,tab2,color); + SDL_Texture *tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + SDL_Rect txt_score_dest; + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = 10; + txt_score_dest.y = 1; + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); + + // text highscore + std::stringstream ss2; + ss2 << "highscore:" << this->highscore; + std::string s2 = ss2.str(); + char * tab3 = new char [s2.length()+1]; + strcpy (tab3, s2.c_str()); + temp_surface = TTF_RenderText_Blended(this->font,tab3,color); + SDL_Texture *tx_highscore = SDL_CreateTextureFromSurface(this->render, temp_surface); + txt_score_dest.x = txt_score_dest.w + 50; + SDL_QueryTexture(tx_highscore, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + SDL_RenderCopy(this->render, tx_highscore, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_highscore); + SDL_FreeSurface(temp_surface); + // text coins + std::stringstream ss3; + ss3 << "coins:" << this->coins; + std::string s3 = ss3.str(); + char * tab4 = new char [s3.length()+1]; + strcpy (tab4, s3.c_str()); + temp_surface = TTF_RenderText_Blended(this->font,tab4,color); + SDL_Texture *tx_coins = SDL_CreateTextureFromSurface(this->render, temp_surface); + txt_score_dest.x =txt_score_dest.x + txt_score_dest.w + 50; + SDL_QueryTexture(tx_coins, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + SDL_RenderCopy(this->render, tx_coins, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_coins); + SDL_FreeSurface(temp_surface); + this->text_animations.renderAnimations(); + SDL_RenderPresent(this->render); + + +} + +int SnakeGame::getScore(){ + return this->score; +} + +void SnakeGame::startGame(){ + + Mix_PlayMusic(AssetLoader::AL_LoadMusic(assetPath,"8bit Stage1 Intro.wav"), 1); + Mix_HookMusicFinished(soundPlayloop); + this->taillen = 0; + this->speed = 300;// 750; + this->player = {this->Size.X/2,this->Size.Y/2,true}; + this->score = 0; + this->coins = 0; + this->activePowerup = foodtype::powerup_none; + this->tailPhase = -1; + SDL_Rect cell; + SDL_GetRendererOutputSize(this->render,&cell.w,&cell.h); + this->tmpOffset.X = (cell.w/2) - (((this->player.X)+2) * this->Size.scale); + this->tmpOffset.Y = (cell.h/2) - (((this->player.Y)+2) * this->Size.scale); +} + +void SnakeGame::drawStarfield(int x, int y){ + SDL_Rect cell; + + + SDL_GetRendererOutputSize(this->render,&cell.w,&cell.h); + x = x%cell.w; + y = y%cell.h; + cell.x = x; + cell.y = y; + SDL_RenderCopy(this->render, this->stars, NULL, &cell); + cell.x = x; + cell.y = y - cell.h; + SDL_RenderCopy(this->render, this->stars, NULL, &cell); + cell.x = x; + cell.y = y + cell.h; + SDL_RenderCopy(this->render, this->stars, NULL, &cell); + cell.x = x + cell.w; + cell.y = y - cell.h; + SDL_RenderCopy(this->render, this->stars, NULL, &cell); + cell.x = x+ cell.w; + cell.y = y + cell.h; + SDL_RenderCopy(this->render, this->stars, NULL, &cell); + cell.x = x - cell.w; + cell.y = y - cell.h; + SDL_RenderCopy(this->render, this->stars, NULL, &cell); + cell.x = x - cell.w; + cell.y = y + cell.h; + SDL_RenderCopy(this->render, this->stars, NULL, &cell); + cell.x = x + cell.w; + cell.y = y; + SDL_RenderCopy(this->render, this->stars, NULL, &cell); + cell.x = x - cell.w; + cell.y = y; + SDL_RenderCopy(this->render, this->stars, NULL, &cell); +} diff --git a/SnakeGame.hpp b/SnakeGame.hpp new file mode 100644 index 0000000..21dc6c1 --- /dev/null +++ b/SnakeGame.hpp @@ -0,0 +1,145 @@ +/* + * snakeGame.hpp + * + * Created on: Apr 11, 2019 + * Author: dennisgunia + */ + +#ifndef SNAKEGAME_HPP_ +#define SNAKEGAME_HPP_ + +#include "global.h" + +#include "AnimatedTexture.h" +#include "SnakeTextAnimation.h" +#include "SnakeTextAnimationHelper.h" + +#define offset_top 96 +#define offset_bottom 32 +#define offset_left 32 +#define offset_right 32 + +#define PI 3.14159265 + +enum { + dir_up = 0x00, + dir_down = 0x02, + dir_left = 0x04, + dir_right = 0x08, + dir_stop = 0x10 +}; + +struct foodtype { + enum { + type_tail = -1, + type_coin_std = 0, + type_coin_death = 1, + type_powerup = 2 + }; + enum { + powerup_potion = 0, + powerup_none = -1 + }; +}; +struct size { + int X; + int Y; + int scale; +}; + +struct coordinate { + int X; + int Y; + bool enabled = false; +}; + + + + +struct food_item { + int X; + int Y; + bool enabled = false; + int type = foodtype::type_coin_std; + int offset = 0; + int ttl = -1; + int powerupType = -1; +}; + +#define SNAKE_BACKGROUND 0,0,0,255 +#define SNAKE_BORDER 128,128,128,255 +#define SNAKE_PLAYER 255,128,0,255 +#define SNAKE_TAIL 255,0,0,255 +#define SNAKE_FOOD 0,0,255,255 + +#define amount_foodtypes 3 +#define amount_powerups 1 + +class SnakeGame { +private: + size Size; + SDL_Renderer *render; + + coordinate player; + int speed; + int score; + int highscore; + int coins; + int direction; + + food_item food[500]; + int foodcount; + coordinate tail[10000]; + int taillen; + + bool lastWasHit; + + Mix_Chunk *snd_click; + Mix_Chunk *snd_death; + Mix_Chunk *snd_powerup; + + SDL_Texture *stars; + + SDL_Texture *powerup[amount_powerups]; + + TTF_Font *font; + Mix_Music *Music_normal = NULL; + Mix_Music *Music_powerup1 = NULL; + + AnimatedTexture tx_food[amount_foodtypes]; + + SnakeTextAnimationHelper text_animations; + int textAnimationStep[1]; + + int activePowerup; + int countdownPowerup; + int tailPhase; + void shiftTailArray(); + void addTailArray(); + void drawHud(); + + coordinate tmpOffset; + + +public: + SnakeGame(size Size, SDL_Renderer *render , SDL_Window *window); + virtual ~SnakeGame(); + + int getTimeOut(); + + void startGame(); + + void setDirection(int direction); + bool doSnakeStep(); + void drawGame(); + void generateFood(); + + void doAnimation(); + void convertToCoins(); + + void drawStarfield(int x, int y); + + int getScore(); +}; + +#endif /* SNAKEGAME_HPP_ */ diff --git a/SnakeMenu.cpp b/SnakeMenu.cpp new file mode 100644 index 0000000..fd2e7b7 --- /dev/null +++ b/SnakeMenu.cpp @@ -0,0 +1,506 @@ +/* + * SnakeMenu.cpp + * + * Created on: Apr 13, 2019 + * Author: dennisgunia + */ + +#include "SnakeMenu.h" +#include "global.h" + +#include +#include + +SnakeMenu::SnakeMenu(SDL_Renderer *render) { + // TODO Auto-generated constructor stub + this->render = render; + + this->font_title = AssetLoader::AL_LoadFont(assetPath,"Seven Oh Ess 8x8 Monospaced.ttf",60); + this->font_subtitle = AssetLoader::AL_LoadFont(assetPath,"Seven Oh Ess 8x8 Monospaced.ttf",29); + this->font_text = AssetLoader::AL_LoadFont(assetPath,"Seven Oh Ess 8x8 Monospaced.ttf",20); + + this->music = AssetLoader::AL_LoadMusic(assetPath,"music/Title.wav"); + this->snd_enter = AssetLoader::AL_LoadChunk(assetPath,"music/UI03.wav"); + this->snd_select = AssetLoader::AL_LoadChunk(assetPath,"music/UI04.wav"); + + this->stars = AssetLoader::AL_LoadTexture(assetPath,"stars.png",this->render); + this->moon = AssetLoader::AL_LoadTexture(assetPath,"moon_surface.png",this->render); + this->earth = AssetLoader::AL_LoadTexture(assetPath,"earth.png",this->render); + this->splash = AssetLoader::AL_LoadTexture(assetPath,"splash.png",this->render); + + this->currentFrame = frame_splash; + this->selectedItem = 0; + + this->splashTimeout = 50; + this->splashFade = 25; + + + + this->name = "dennisgunia"; + + this->curs_char = ' '; + + this->earthPhase = 0.75; + + Mix_PlayMusic(music,-1); + + + + this->readScores(); + + SDL_StopTextInput(); +} + +SnakeMenu::~SnakeMenu() { + // TODO Auto-generated destructor stub +} + +void SnakeMenu::pressKey(Menukey key){ + if (this->currentFrame == frame_title){ + switch (key){ + case menukey_up: + this->selectedItem --; + Mix_PlayChannel(-1, this->snd_select, 0); + break; + case menukey_down: + this->selectedItem ++; + Mix_PlayChannel(-1, this->snd_select, 0); + break; + case menukey_enter: + + switch(this->selectedItem){ + case btn_exit: + + this->currentFrame = frame_title_fadeout_exit; + Mix_PlayChannel(-1, this->snd_enter, 0); + Mix_FadeOutMusic(1000); + break; + case btn_start: + + this->currentFrame = frame_nameinput; + SDL_StartTextInput(); + Mix_PlayChannel(-1, this->snd_enter, 0); + //Mix_FadeOutMusic(1000); + break; + case btn_score: + this->currentFrame = frame_scoreboard; + Mix_PlayChannel(-1, this->snd_enter, 0); + break; + + default: + break; + } + + break; + default: + break; + } + + if (this->selectedItem < 0){ + this->selectedItem += 3; + } + if (this->selectedItem > 2){ + this->selectedItem -= 3; + } + }else if (this->currentFrame == frame_scoreboard){ + switch (key){ + case menukey_enter: + this->currentFrame = frame_title; + Mix_PlayChannel(-1, this->snd_enter, 0); + break; + default: + break; + } + + }else if (this->currentFrame == frame_nameinput){ + switch (key){ + case menukey_up: + this->selectedItem --; + Mix_PlayChannel(-1, this->snd_select, 0); + + + break; + case menukey_down: + this->selectedItem ++; + Mix_PlayChannel(-1, this->snd_select, 0); + break; + case menukey_back: + if((this->name.length() > 0) && (this->currentFrame == frame_nameinput)){ + this->name.pop_back(); + } + break; + case menukey_enter: + + switch(this->selectedItem){ + case 2: + this->currentFrame = frame_title; + Mix_PlayChannel(-1, this->snd_enter, 0); + break; + case 1: + + this->currentFrame = frame_title_fadeout_start; + Mix_PlayChannel(-1, this->snd_enter, 0); + Mix_FadeOutMusic(1000); + break; + + + default: + break; + } + + break; + default: + break; + } + + if (this->selectedItem < 0){ + this->selectedItem += 3; + } + if (this->selectedItem > 2){ + this->selectedItem -= 3; + } + + if(this->selectedItem == 0){ + SDL_StartTextInput(); + }else{ + SDL_StopTextInput(); + this->curs_char = ' '; + } + + } +} + +int SnakeMenu::renderFrame(){ + SDL_RenderClear(this->render); + SDL_Rect cell; + SDL_GetRendererOutputSize(this->render,&cell.w,&cell.h); + + Uint32 now = SDL_GetTicks(); + if (this->lastAnimFrame + 150 < now){ + this->skyBoxPos += 1; + if(this->skyBoxPos >= cell.w){ + this->skyBoxPos = 0; + } + + + + + } + if (this->lastCurs + 400 < now && this->selectedItem == 0){ + if(this->curs_char == ' '){ + this->curs_char = '_'; + }else{ + this->curs_char = ' '; + } + this->lastCurs = now; + } + + + + if (this->lastBlend +30 < now){ + this->lastBlend = now; + this->earthPhase += 0.0005; + if(this->earthPhase >= 2){ + this->earthPhase = 0.00; + } + + if (this->splashFade > -1 ){ + if(this->splashTimeout > 0 ){ + this->splashTimeout --; + }else if(this->splashTimeout == 0 ){ + this->currentFrame = frame_title; + this->splashTimeout --; + }else{ + if(this->splashFade > 0 ){ + this->splashFade --; + }else if (this->splashFade == 0 ){ + + this->splashFade --; + + } + } + } + } + cell.x = + this->skyBoxPos; + cell.y = 0; + + + //calculate earth + + + + + + SDL_RenderCopy(this->render, this->stars, NULL, &cell); + cell.x -= cell.w; + SDL_RenderCopy(this->render, this->stars, NULL, &cell); + cell.x = 0; + SDL_RenderCopy(this->render, this->moon, NULL, &cell); + + + + SDL_Surface *temp_surface = TTF_RenderText_Blended(this->font_title,"SpaceSnake",{255,255,255,255}); + SDL_Texture *tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + SDL_Rect txt_score_dest; + + const int amplitude = cell.h * 1.75; + + SDL_QueryTexture(this->earth, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (cell.w / 2)-(txt_score_dest.w / 2) - (sin(this->earthPhase * PI)*amplitude); + txt_score_dest.y = cell.h * 1.8+ (cos(this->earthPhase * PI)*amplitude); + SDL_RenderCopy(this->render, this->earth, NULL, &txt_score_dest); + + + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (cell.w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 50; + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); + temp_surface = TTF_RenderText_Blended(this->font_subtitle,"(c) 2019 by Dennis Vincent Gunia",{255,255,255,255}); + tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + txt_score_dest; + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (cell.w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 130; + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); + + + + + if(this->currentFrame == frame_title){ + this->renderMenuButtons(); + } + if(this->currentFrame == frame_scoreboard){ + this->renderMenuScore(); + } + if(this->currentFrame == frame_nameinput){ + this->renderNameInput(); + } + + + + if(!Mix_PlayingMusic()){ + if (this->currentFrame == frame_title_fadeout_exit){ + this->currentFrame = frame_can_exit; + } + if (this->currentFrame == frame_title_fadeout_start){ + this->currentFrame = frame_can_start; + } + } + + if(this->splashFade >= 0 ){ + cell.x = 0; + cell.y = 0; + SDL_GetRendererOutputSize(this->render,&cell.w,&cell.h); + SDL_SetTextureAlphaMod( this->splash,this->splashFade*10 + 5); + SDL_RenderCopy(this->render, this->splash, NULL, &cell); + + } + + SDL_RenderPresent(this->render); + return this->currentFrame; + + +} + +void SnakeMenu::renderMenuButtons(){ + + SDL_Color col[3] = {{255,255,255,255},{255,255,255,255},{255,255,255,255}}; + + col[this->selectedItem] = {0,255,255,255}; + int scr_w; + SDL_GetRendererOutputSize(this->render,&scr_w,NULL); + SDL_Surface *temp_surface = TTF_RenderText_Blended(this->font_subtitle,"play game",col[btn_start]); + SDL_Texture *tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + SDL_Rect txt_score_dest; + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (scr_w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 400; + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); + + temp_surface = TTF_RenderText_Blended(this->font_subtitle,"scoreboard",col[btn_score]); + tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + txt_score_dest; + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (scr_w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 450; + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); + + temp_surface = TTF_RenderText_Blended(this->font_subtitle,"exit",col[btn_exit]); + tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + txt_score_dest; + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (scr_w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 600; + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); +} + +void SnakeMenu::renderMenuScore(){ + int scores = this->scoreboard.size(); + int scr_w; + SDL_GetRendererOutputSize(this->render,&scr_w,NULL); + // output score + for (int i = 0 ; i < 10 ; i ++){ + int i_score = this->scoreboard[i].score; + std::string i_name = this->scoreboard[i].name; + + std::stringstream ss; + ss << i_score << " - " << i_name; + std::string s = ss.str(); + char * tab2 = new char [s.length()+1]; + strcpy (tab2, s.c_str()); + + SDL_Surface *temp_surface = TTF_RenderText_Blended(this->font_subtitle,tab2,{255,255,255,255}); + SDL_Texture *tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + SDL_Rect txt_score_dest; + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (scr_w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 300 + (i*40); + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); + } + + SDL_Surface *temp_surface = TTF_RenderText_Blended(this->font_subtitle,"back",{0,255,255,255}); + SDL_Texture *tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + SDL_Rect txt_score_dest; + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (scr_w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 800; + + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); +} + +void SnakeMenu::registerScore(int score){ + Score temp = {score , this->name}; + for (int i = 0 ; i < 10 ; i ++){ + if (this->scoreboard[i].score < temp.score){ + this->scoreboard.insert(this->scoreboard.begin()+i,temp); + break; + } + } + this->writeScores(); + // save score + + + +} + +void SnakeMenu::goToTitle(){ + this->currentFrame = frame_title; + this->selectedItem = 0; + + Mix_PlayMusic(music,-1); +} + +void SnakeMenu::renderNameInput() +{ + int scr_w; + SDL_GetRendererOutputSize(this->render,&scr_w,NULL); + SDL_Surface *temp_surface = TTF_RenderText_Blended(this->font_text,"enter playername:",{255,255,255,255}); + SDL_Texture *tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + SDL_Rect txt_score_dest; + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (scr_w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 400; + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); + + SDL_Color col[3] = {{255,255,255,255},{255,255,255,255},{255,255,255,255}}; + + col[this->selectedItem] = {0,255,255,255}; + + + std::stringstream ss; + ss << this->name << this->curs_char ; + std::string s = ss.str(); + + + char * tempname = new char [s.length()+1]; + strcpy (tempname, s.c_str()); + temp_surface = TTF_RenderText_Blended(this->font_subtitle,tempname,col[0]); + tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (scr_w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 450; + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); + + temp_surface = TTF_RenderText_Blended(this->font_subtitle,"continue",col[1]); + tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (scr_w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 600; + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); + + temp_surface = TTF_RenderText_Blended(this->font_subtitle,"back",col[2]); + tx_score = SDL_CreateTextureFromSurface(this->render, temp_surface); + SDL_QueryTexture(tx_score, NULL, NULL, &txt_score_dest.w, &txt_score_dest.h); + txt_score_dest.x = (scr_w / 2)-(txt_score_dest.w / 2); + txt_score_dest.y = 650; + SDL_RenderCopy(this->render, tx_score, NULL, &txt_score_dest); + SDL_DestroyTexture(tx_score); + SDL_FreeSurface(temp_surface); +} + + +void SnakeMenu::readScores() +{ + std::ifstream openFile; + openFile.open(saveFiles); + std::string line; + if (openFile.is_open()){ + + std::getline (openFile,line) ; + line.pop_back(); + this->name = line; + + while ( std::getline (openFile,line) ) + { + line.pop_back(); + std::size_t found = line.find(","); + std::string tmp_name = line.substr(found + 1); + int tmp_score_int; + std::istringstream iss (line.substr(0,found)); + iss >> tmp_score_int; + + std::cout << tmp_score_int << " - " << tmp_name << '\n'; + Score dummyscore = {tmp_score_int,tmp_name}; + this->scoreboard.push_back(dummyscore); + } + openFile.close(); + } + else{ + Score dummyscore = {0,"player"}; + for (int i = 0 ; i < 10 ; i ++){ + this->scoreboard.push_back(dummyscore); + } + } +} + +void SnakeMenu::writeScores() +{ + std::ofstream saveFile; + saveFile.open(saveFiles, std::ofstream::out | std::ofstream::trunc); + saveFile << this->name << ";\n"; + for (int i = 0 ; i < 10 ; i ++){ + saveFile << this->scoreboard[i].score <<","<< this->scoreboard[i].name << ";\n"; + } + saveFile.close(); +} diff --git a/SnakeMenu.h b/SnakeMenu.h new file mode 100644 index 0000000..b9af1e1 --- /dev/null +++ b/SnakeMenu.h @@ -0,0 +1,110 @@ +/* + * SnakeMenu.h + * + * Created on: Apr 13, 2019 + * Author: dennisgunia + */ + +#ifndef SNAKEMENU_H_ +#define SNAKEMENU_H_ + + +#include +#include +#include +#include +#include +#include +#include +#include +#define PI 3.14159265 +enum { + menukey_up, + menukey_down, + menukey_left, + menukey_right, + menukey_back, + menukey_enter +}; + +enum { + frame_splash, + frame_title, + frame_title_fadeout_exit, + frame_title_fadeout_start, + frame_can_exit, + frame_can_start, + frame_scoreboard, + frame_nameinput +}; + +enum { + btn_start, + btn_score, + btn_exit +}; + +struct Score { + int score; + std::string name; +}; + +typedef Uint8 Menukey; + +class SnakeMenu { +private: + SDL_Renderer *render; + SDL_Texture *stars; + SDL_Texture *moon; + SDL_Texture *earth; + + SDL_Texture *splash; + + Mix_Chunk *snd_select; + Mix_Chunk *snd_enter; + + Mix_Music *music; + + TTF_Font *font_title; + TTF_Font *font_subtitle; + TTF_Font *font_text; + + std::vector scoreboard; + + int currentFrame; + + int selectedItem; + + int splashTimeout; + int splashFade; + + int skyBoxPos = 0; + + double earthPhase; + Uint32 lastAnimFrame = 0; + Uint32 lastCurs = 0; + Uint32 lastBlend = 0; + + char curs_char; + + + void readScores(); + void writeScores(); +public: + std::string name; + + SnakeMenu(SDL_Renderer *render); + virtual ~SnakeMenu(); + + void pressKey(Menukey key); + int renderFrame(); + void registerScore(int score); + void renderMenuButtons(); + void renderMenuScore(); + + void renderNameInput(); + + void goToTitle(); +}; + +#endif /* SNAKEMENU_H_ */ diff --git a/SnakeTextAnimation.cpp b/SnakeTextAnimation.cpp new file mode 100644 index 0000000..13413aa --- /dev/null +++ b/SnakeTextAnimation.cpp @@ -0,0 +1,70 @@ +/* + * SnakeTextAnimation.cpp + * + * Created on: Apr 12, 2019 + * Author: dennisgunia + */ + +#include "SnakeTextAnimation.h" + +SnakeTextAnimation::SnakeTextAnimation() { + // TODO Auto-generated constructor stub + this->frame = -1; + this->frames = 30; + this->x = -1; + this->y = -1; +} + +SnakeTextAnimation::~SnakeTextAnimation() { + // TODO Auto-generated destructor stub +} + +void SnakeTextAnimation::addAnimationStep(int index,textAnimFrame frame){ + this->keyframe[index] = frame; +} + +void SnakeTextAnimation::startAnimation(int x, int y,std::string s,SDL_Color color,TTF_Font *font, SDL_Renderer *render){ + this->x = x; + this->y = y; + this->s = s; + this->frame = 0; + this->color = color; + + printf("start animation at x:%i y:%i\n",this->x,this->y); + + char * temp = new char [this->s.length()+1]; + strcpy (temp, this->s.c_str()); + SDL_Surface *temp_surface = TTF_RenderText_Blended(font,temp,this->color); + this->tx_temp = SDL_CreateTextureFromSurface(render, temp_surface); + SDL_FreeSurface(temp_surface); + + this->dst_temp.x = this->x; + this->dst_temp.y = this->y; + this->color.a = this->keyframe[frame].opacity; + SDL_QueryTexture(this->tx_temp, NULL, NULL, &this->dst_temp.w, &this->dst_temp.h); +} +bool SnakeTextAnimation::doAnimation(){ + if (this->frame >= 0){ + this->frame ++; + if (this->frame >= this->frames){ + this->frame = -1; + SDL_DestroyTexture(this->tx_temp); + return false; + } + return true; + }else{ + return false; + } +} + + +void SnakeTextAnimation::renderAnimation(SDL_Renderer *render){ + if (this->frame >= 0){ + + this->dst_temp.y = this->y + this->keyframe[frame].offset; + SDL_SetTextureAlphaMod( this->tx_temp,this->keyframe[frame].opacity); + SDL_RenderCopy(render, this->tx_temp, NULL, &this->dst_temp); + + } + +} diff --git a/SnakeTextAnimation.h b/SnakeTextAnimation.h new file mode 100644 index 0000000..108e813 --- /dev/null +++ b/SnakeTextAnimation.h @@ -0,0 +1,46 @@ +/* + * SnakeTextAnimation.h + * + * Created on: Apr 12, 2019 + * Author: dennisgunia + */ +#include +#include +#include +#include +#include + +#include + +#ifndef SNAKETEXTANIMATION_H_ +#define SNAKETEXTANIMATION_H_ + +struct textAnimFrame { + int offset; + int opacity; +}; + +#define keyframes 34 +class SnakeTextAnimation { +private: + textAnimFrame keyframe[keyframes]; + int x; + int y; + int frames; + int frame; + std::string s; + SDL_Texture *tx_temp; + SDL_Rect dst_temp; + SDL_Color color; + +public: + SnakeTextAnimation(); + virtual ~SnakeTextAnimation(); + + void addAnimationStep(int index,textAnimFrame frame); + void startAnimation(int x, int y,std::string s,SDL_Color color,TTF_Font *font, SDL_Renderer *render); + bool doAnimation(); + void renderAnimation(SDL_Renderer *render); +}; + +#endif /* SNAKETEXTANIMATION_H_ */ diff --git a/SnakeTextAnimationHelper.cpp b/SnakeTextAnimationHelper.cpp new file mode 100644 index 0000000..947d65e --- /dev/null +++ b/SnakeTextAnimationHelper.cpp @@ -0,0 +1,84 @@ +/* + * SnakeTextAnimationHelper.cpp + * + * Created on: Apr 13, 2019 + * Author: dennisgunia + */ + +#include "SnakeTextAnimationHelper.h" + +SnakeTextAnimationHelper::SnakeTextAnimationHelper() { + // TODO Auto-generated constructor stub + for (int index = 0; index < maxAnimations ; index++){ + this->animation[index].addAnimationStep(33,{-17,16}); + this->animation[index].addAnimationStep(32,{-16,32}); + this->animation[index].addAnimationStep(31,{-15,48}); + this->animation[index].addAnimationStep(30,{-14,64}); + this->animation[index].addAnimationStep(29,{-13,92}); + this->animation[index].addAnimationStep(28,{-12,128}); + this->animation[index].addAnimationStep(27,{-11,144}); + this->animation[index].addAnimationStep(26,{-10,160}); + this->animation[index].addAnimationStep(25,{-9,176}); + this->animation[index].addAnimationStep(24,{-8,192}); + this->animation[index].addAnimationStep(23,{-7,208}); + this->animation[index].addAnimationStep(22,{-6,224}); + this->animation[index].addAnimationStep(21,{-5,240}); + this->animation[index].addAnimationStep(20,{-4,255}); + this->animation[index].addAnimationStep(19,{-3,255}); + this->animation[index].addAnimationStep(18,{-2,255}); + this->animation[index].addAnimationStep(17,{-1,255}); + this->animation[index].addAnimationStep(16,{0,255}); + this->animation[index].addAnimationStep(15,{1,255}); + this->animation[index].addAnimationStep(14,{2,240}); + this->animation[index].addAnimationStep(13,{3,224}); + this->animation[index].addAnimationStep(12,{4,208}); + this->animation[index].addAnimationStep(11,{5,192}); + this->animation[index].addAnimationStep(10,{6,176}); + this->animation[index].addAnimationStep(9,{7,160}); + this->animation[index].addAnimationStep(8,{8,144}); + this->animation[index].addAnimationStep(7,{9,128}); + this->animation[index].addAnimationStep(6,{10,112}); + this->animation[index].addAnimationStep(5,{11,96}); + this->animation[index].addAnimationStep(4,{12,80}); + this->animation[index].addAnimationStep(3,{13,64}); + this->animation[index].addAnimationStep(2,{14,48}); + this->animation[index].addAnimationStep(1,{15,32}); + this->animation[index].addAnimationStep(0,{16,16}); + } + this->render = NULL; +} + +SnakeTextAnimationHelper::~SnakeTextAnimationHelper() { + // TODO Auto-generated destructor stub +} + +bool SnakeTextAnimationHelper::startAnimation(int x, int y,std::string s,SDL_Color color,TTF_Font *font){ + for (int index = 0; index < maxAnimations ; index++){ + if (this->animationActive[index] == false){ + this->animationActive[index] = true; + this->animation[index].startAnimation(x,y,s,color,font,this->render); + return true; + } + } + return false; +} +void SnakeTextAnimationHelper::doAnimations(){ + for (int index = 0; index < maxAnimations ; index++){ + if (this->animationActive[index] == true){ + if(!this->animation[index].doAnimation()){ + this->animationActive[index] = false; + } + } + } +} +void SnakeTextAnimationHelper::renderAnimations(){ + for (int index = 0; index < maxAnimations ; index++){ + if (this->animationActive[index] == true){ + this->animation[index].renderAnimation(this->render); + } + } +} + +void SnakeTextAnimationHelper::setRenderer(SDL_Renderer *render){ + this->render = render; +} diff --git a/SnakeTextAnimationHelper.h b/SnakeTextAnimationHelper.h new file mode 100644 index 0000000..e4fdfb1 --- /dev/null +++ b/SnakeTextAnimationHelper.h @@ -0,0 +1,30 @@ +/* + * SnakeTextAnimationHelper.h + * + * Created on: Apr 13, 2019 + * Author: dennisgunia + */ +#include "SnakeTextAnimation.h" +#ifndef SNAKETEXTANIMATIONHELPER_H_ +#define SNAKETEXTANIMATIONHELPER_H_ + +#define maxAnimations 50 + +class SnakeTextAnimationHelper { +private: + SnakeTextAnimation animation[maxAnimations]; + bool animationActive[maxAnimations]; + SDL_Renderer *render; + +public: + SnakeTextAnimationHelper(); + virtual ~SnakeTextAnimationHelper(); + + + bool startAnimation(int x, int y,std::string s,SDL_Color color,TTF_Font *font); + void doAnimations(); + void renderAnimations(); + void setRenderer( SDL_Renderer *render); +}; + +#endif /* SNAKETEXTANIMATIONHELPER_H_ */ diff --git a/gameBuild/Assets/.~lock.hackintosh.ods# b/gameBuild/Assets/.~lock.hackintosh.ods# new file mode 100644 index 0000000..a7fdf80 --- /dev/null +++ b/gameBuild/Assets/.~lock.hackintosh.ods# @@ -0,0 +1 @@ +,dennisgunia,dennisgunia-MacBookPro,03.11.2018 12:25,file:///home/dennisgunia/.config/libreoffice/4; \ No newline at end of file diff --git a/gameBuild/Assets/8bit Stage1 Intro.wav b/gameBuild/Assets/8bit Stage1 Intro.wav new file mode 100644 index 0000000..7b4e8b9 Binary files /dev/null and b/gameBuild/Assets/8bit Stage1 Intro.wav differ diff --git a/gameBuild/Assets/8bit Stage1 Loop.wav b/gameBuild/Assets/8bit Stage1 Loop.wav new file mode 100644 index 0000000..efb84fb Binary files /dev/null and b/gameBuild/Assets/8bit Stage1 Loop.wav differ diff --git a/gameBuild/Assets/8bit Stage4 Loop.wav b/gameBuild/Assets/8bit Stage4 Loop.wav new file mode 100644 index 0000000..0314174 Binary files /dev/null and b/gameBuild/Assets/8bit Stage4 Loop.wav differ diff --git a/gameBuild/Assets/ARCADECLASSIC.TTF b/gameBuild/Assets/ARCADECLASSIC.TTF new file mode 100644 index 0000000..394a9f7 Binary files /dev/null and b/gameBuild/Assets/ARCADECLASSIC.TTF differ diff --git a/gameBuild/Assets/CHAR_astronaut_00000.png b/gameBuild/Assets/CHAR_astronaut_00000.png new file mode 100644 index 0000000..f34b07d Binary files /dev/null and b/gameBuild/Assets/CHAR_astronaut_00000.png differ diff --git a/gameBuild/Assets/Death02.wav b/gameBuild/Assets/Death02.wav new file mode 100644 index 0000000..cfc7934 Binary files /dev/null and b/gameBuild/Assets/Death02.wav differ diff --git a/gameBuild/Assets/Misc01.wav b/gameBuild/Assets/Misc01.wav new file mode 100644 index 0000000..d9335db Binary files /dev/null and b/gameBuild/Assets/Misc01.wav differ diff --git a/gameBuild/Assets/Misc05.wav b/gameBuild/Assets/Misc05.wav new file mode 100644 index 0000000..4adb43c Binary files /dev/null and b/gameBuild/Assets/Misc05.wav differ diff --git a/gameBuild/Assets/Retro_8-Bit_Game-Interface_UI_20.wav b/gameBuild/Assets/Retro_8-Bit_Game-Interface_UI_20.wav new file mode 100644 index 0000000..52c932c Binary files /dev/null and b/gameBuild/Assets/Retro_8-Bit_Game-Interface_UI_20.wav differ diff --git a/gameBuild/Assets/Seven Oh Ess 8x8 Monospaced.ttf b/gameBuild/Assets/Seven Oh Ess 8x8 Monospaced.ttf new file mode 100644 index 0000000..c2ce221 Binary files /dev/null and b/gameBuild/Assets/Seven Oh Ess 8x8 Monospaced.ttf differ diff --git a/gameBuild/Assets/coin/.directory b/gameBuild/Assets/coin/.directory new file mode 100644 index 0000000..a5294fa --- /dev/null +++ b/gameBuild/Assets/coin/.directory @@ -0,0 +1,4 @@ +[Dolphin] +Timestamp=2019,4,12,17,14,53 +Version=4 +ViewMode=1 diff --git a/gameBuild/Assets/coin/frame0.png b/gameBuild/Assets/coin/frame0.png new file mode 100644 index 0000000..5fff45a Binary files /dev/null and b/gameBuild/Assets/coin/frame0.png differ diff --git a/gameBuild/Assets/coin/frame1.png b/gameBuild/Assets/coin/frame1.png new file mode 100644 index 0000000..2926b80 Binary files /dev/null and b/gameBuild/Assets/coin/frame1.png differ diff --git a/gameBuild/Assets/coin/frame10.png b/gameBuild/Assets/coin/frame10.png new file mode 100644 index 0000000..15cc1a2 Binary files /dev/null and b/gameBuild/Assets/coin/frame10.png differ diff --git a/gameBuild/Assets/coin/frame11.png b/gameBuild/Assets/coin/frame11.png new file mode 100644 index 0000000..8a39bb3 Binary files /dev/null and b/gameBuild/Assets/coin/frame11.png differ diff --git a/gameBuild/Assets/coin/frame12.png b/gameBuild/Assets/coin/frame12.png new file mode 100644 index 0000000..be79154 Binary files /dev/null and b/gameBuild/Assets/coin/frame12.png differ diff --git a/gameBuild/Assets/coin/frame13.png b/gameBuild/Assets/coin/frame13.png new file mode 100644 index 0000000..8a45af4 Binary files /dev/null and b/gameBuild/Assets/coin/frame13.png differ diff --git a/gameBuild/Assets/coin/frame2.png b/gameBuild/Assets/coin/frame2.png new file mode 100644 index 0000000..c87b5df Binary files /dev/null and b/gameBuild/Assets/coin/frame2.png differ diff --git a/gameBuild/Assets/coin/frame3.png b/gameBuild/Assets/coin/frame3.png new file mode 100644 index 0000000..4cefb45 Binary files /dev/null and b/gameBuild/Assets/coin/frame3.png differ diff --git a/gameBuild/Assets/coin/frame4.png b/gameBuild/Assets/coin/frame4.png new file mode 100644 index 0000000..a588b2e Binary files /dev/null and b/gameBuild/Assets/coin/frame4.png differ diff --git a/gameBuild/Assets/coin/frame5.png b/gameBuild/Assets/coin/frame5.png new file mode 100644 index 0000000..73e8faf Binary files /dev/null and b/gameBuild/Assets/coin/frame5.png differ diff --git a/gameBuild/Assets/coin/frame6.png b/gameBuild/Assets/coin/frame6.png new file mode 100644 index 0000000..abb3366 Binary files /dev/null and b/gameBuild/Assets/coin/frame6.png differ diff --git a/gameBuild/Assets/coin/frame7.png b/gameBuild/Assets/coin/frame7.png new file mode 100644 index 0000000..1b6a4cf Binary files /dev/null and b/gameBuild/Assets/coin/frame7.png differ diff --git a/gameBuild/Assets/coin/frame8.png b/gameBuild/Assets/coin/frame8.png new file mode 100644 index 0000000..2e8de77 Binary files /dev/null and b/gameBuild/Assets/coin/frame8.png differ diff --git a/gameBuild/Assets/coin/frame9.png b/gameBuild/Assets/coin/frame9.png new file mode 100644 index 0000000..1d4f7be Binary files /dev/null and b/gameBuild/Assets/coin/frame9.png differ diff --git a/gameBuild/Assets/coinDeath/.directory b/gameBuild/Assets/coinDeath/.directory new file mode 100644 index 0000000..04f2bfd --- /dev/null +++ b/gameBuild/Assets/coinDeath/.directory @@ -0,0 +1,4 @@ +[Dolphin] +Timestamp=2019,4,12,19,22,35 +Version=4 +ViewMode=1 diff --git a/gameBuild/Assets/coinDeath/frame0.png b/gameBuild/Assets/coinDeath/frame0.png new file mode 100644 index 0000000..2d103a3 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame0.png differ diff --git a/gameBuild/Assets/coinDeath/frame1.png b/gameBuild/Assets/coinDeath/frame1.png new file mode 100644 index 0000000..867ee33 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame1.png differ diff --git a/gameBuild/Assets/coinDeath/frame10.png b/gameBuild/Assets/coinDeath/frame10.png new file mode 100644 index 0000000..103ddcb Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame10.png differ diff --git a/gameBuild/Assets/coinDeath/frame11.png b/gameBuild/Assets/coinDeath/frame11.png new file mode 100644 index 0000000..df3ece9 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame11.png differ diff --git a/gameBuild/Assets/coinDeath/frame12.png b/gameBuild/Assets/coinDeath/frame12.png new file mode 100644 index 0000000..785ab20 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame12.png differ diff --git a/gameBuild/Assets/coinDeath/frame13.png b/gameBuild/Assets/coinDeath/frame13.png new file mode 100644 index 0000000..8933676 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame13.png differ diff --git a/gameBuild/Assets/coinDeath/frame2.png b/gameBuild/Assets/coinDeath/frame2.png new file mode 100644 index 0000000..f9a5800 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame2.png differ diff --git a/gameBuild/Assets/coinDeath/frame3.png b/gameBuild/Assets/coinDeath/frame3.png new file mode 100644 index 0000000..3236ba9 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame3.png differ diff --git a/gameBuild/Assets/coinDeath/frame4.png b/gameBuild/Assets/coinDeath/frame4.png new file mode 100644 index 0000000..e600ed0 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame4.png differ diff --git a/gameBuild/Assets/coinDeath/frame5.png b/gameBuild/Assets/coinDeath/frame5.png new file mode 100644 index 0000000..1f67672 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame5.png differ diff --git a/gameBuild/Assets/coinDeath/frame6.png b/gameBuild/Assets/coinDeath/frame6.png new file mode 100644 index 0000000..f91dadc Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame6.png differ diff --git a/gameBuild/Assets/coinDeath/frame7.png b/gameBuild/Assets/coinDeath/frame7.png new file mode 100644 index 0000000..1872a71 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame7.png differ diff --git a/gameBuild/Assets/coinDeath/frame8.png b/gameBuild/Assets/coinDeath/frame8.png new file mode 100644 index 0000000..e111a35 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame8.png differ diff --git a/gameBuild/Assets/coinDeath/frame9.png b/gameBuild/Assets/coinDeath/frame9.png new file mode 100644 index 0000000..38046a6 Binary files /dev/null and b/gameBuild/Assets/coinDeath/frame9.png differ diff --git a/gameBuild/Assets/earth.png b/gameBuild/Assets/earth.png new file mode 100644 index 0000000..a893142 Binary files /dev/null and b/gameBuild/Assets/earth.png differ diff --git a/gameBuild/Assets/filtered-9445449A-6C14-4C25-8477-19A23121B9AB.MP4 b/gameBuild/Assets/filtered-9445449A-6C14-4C25-8477-19A23121B9AB.MP4 new file mode 100644 index 0000000..a44b1f3 Binary files /dev/null and b/gameBuild/Assets/filtered-9445449A-6C14-4C25-8477-19A23121B9AB.MP4 differ diff --git a/gameBuild/Assets/moon_surface.png b/gameBuild/Assets/moon_surface.png new file mode 100644 index 0000000..e490e2c Binary files /dev/null and b/gameBuild/Assets/moon_surface.png differ diff --git a/gameBuild/Assets/music/Title.wav b/gameBuild/Assets/music/Title.wav new file mode 100644 index 0000000..c3c2c6b Binary files /dev/null and b/gameBuild/Assets/music/Title.wav differ diff --git a/gameBuild/Assets/music/UI03.wav b/gameBuild/Assets/music/UI03.wav new file mode 100644 index 0000000..1a34368 Binary files /dev/null and b/gameBuild/Assets/music/UI03.wav differ diff --git a/gameBuild/Assets/music/UI04.wav b/gameBuild/Assets/music/UI04.wav new file mode 100644 index 0000000..380f755 Binary files /dev/null and b/gameBuild/Assets/music/UI04.wav differ diff --git a/gameBuild/Assets/potion_A_green_full.png b/gameBuild/Assets/potion_A_green_full.png new file mode 100644 index 0000000..37653f4 Binary files /dev/null and b/gameBuild/Assets/potion_A_green_full.png differ diff --git a/gameBuild/Assets/sparkle/.directory b/gameBuild/Assets/sparkle/.directory new file mode 100644 index 0000000..7039f7d --- /dev/null +++ b/gameBuild/Assets/sparkle/.directory @@ -0,0 +1,4 @@ +[Dolphin] +Timestamp=2019,4,12,19,32,53 +Version=4 +ViewMode=1 diff --git a/gameBuild/Assets/sparkle/frame0.png b/gameBuild/Assets/sparkle/frame0.png new file mode 100644 index 0000000..a089855 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame0.png differ diff --git a/gameBuild/Assets/sparkle/frame1.png b/gameBuild/Assets/sparkle/frame1.png new file mode 100644 index 0000000..9e3cc46 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame1.png differ diff --git a/gameBuild/Assets/sparkle/frame10.png b/gameBuild/Assets/sparkle/frame10.png new file mode 100644 index 0000000..c1d899c Binary files /dev/null and b/gameBuild/Assets/sparkle/frame10.png differ diff --git a/gameBuild/Assets/sparkle/frame11.png b/gameBuild/Assets/sparkle/frame11.png new file mode 100644 index 0000000..278ab22 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame11.png differ diff --git a/gameBuild/Assets/sparkle/frame12.png b/gameBuild/Assets/sparkle/frame12.png new file mode 100644 index 0000000..72751a9 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame12.png differ diff --git a/gameBuild/Assets/sparkle/frame13.png b/gameBuild/Assets/sparkle/frame13.png new file mode 100644 index 0000000..5ccad53 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame13.png differ diff --git a/gameBuild/Assets/sparkle/frame14.png b/gameBuild/Assets/sparkle/frame14.png new file mode 100644 index 0000000..a4c192d Binary files /dev/null and b/gameBuild/Assets/sparkle/frame14.png differ diff --git a/gameBuild/Assets/sparkle/frame15.png b/gameBuild/Assets/sparkle/frame15.png new file mode 100644 index 0000000..f507ec7 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame15.png differ diff --git a/gameBuild/Assets/sparkle/frame16.png b/gameBuild/Assets/sparkle/frame16.png new file mode 100644 index 0000000..a6f8191 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame16.png differ diff --git a/gameBuild/Assets/sparkle/frame17.png b/gameBuild/Assets/sparkle/frame17.png new file mode 100644 index 0000000..0843cdf Binary files /dev/null and b/gameBuild/Assets/sparkle/frame17.png differ diff --git a/gameBuild/Assets/sparkle/frame18.png b/gameBuild/Assets/sparkle/frame18.png new file mode 100644 index 0000000..5202934 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame18.png differ diff --git a/gameBuild/Assets/sparkle/frame19.png b/gameBuild/Assets/sparkle/frame19.png new file mode 100644 index 0000000..eea7427 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame19.png differ diff --git a/gameBuild/Assets/sparkle/frame2.png b/gameBuild/Assets/sparkle/frame2.png new file mode 100644 index 0000000..defca6d Binary files /dev/null and b/gameBuild/Assets/sparkle/frame2.png differ diff --git a/gameBuild/Assets/sparkle/frame20.png b/gameBuild/Assets/sparkle/frame20.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame20.png differ diff --git a/gameBuild/Assets/sparkle/frame21.png b/gameBuild/Assets/sparkle/frame21.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame21.png differ diff --git a/gameBuild/Assets/sparkle/frame22.png b/gameBuild/Assets/sparkle/frame22.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame22.png differ diff --git a/gameBuild/Assets/sparkle/frame23.png b/gameBuild/Assets/sparkle/frame23.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame23.png differ diff --git a/gameBuild/Assets/sparkle/frame24.png b/gameBuild/Assets/sparkle/frame24.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame24.png differ diff --git a/gameBuild/Assets/sparkle/frame25.png b/gameBuild/Assets/sparkle/frame25.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame25.png differ diff --git a/gameBuild/Assets/sparkle/frame26.png b/gameBuild/Assets/sparkle/frame26.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame26.png differ diff --git a/gameBuild/Assets/sparkle/frame27.png b/gameBuild/Assets/sparkle/frame27.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame27.png differ diff --git a/gameBuild/Assets/sparkle/frame28.png b/gameBuild/Assets/sparkle/frame28.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame28.png differ diff --git a/gameBuild/Assets/sparkle/frame29.png b/gameBuild/Assets/sparkle/frame29.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame29.png differ diff --git a/gameBuild/Assets/sparkle/frame3.png b/gameBuild/Assets/sparkle/frame3.png new file mode 100644 index 0000000..5832134 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame3.png differ diff --git a/gameBuild/Assets/sparkle/frame30.png b/gameBuild/Assets/sparkle/frame30.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame30.png differ diff --git a/gameBuild/Assets/sparkle/frame31.png b/gameBuild/Assets/sparkle/frame31.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame31.png differ diff --git a/gameBuild/Assets/sparkle/frame32.png b/gameBuild/Assets/sparkle/frame32.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame32.png differ diff --git a/gameBuild/Assets/sparkle/frame33.png b/gameBuild/Assets/sparkle/frame33.png new file mode 100644 index 0000000..36c7984 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame33.png differ diff --git a/gameBuild/Assets/sparkle/frame4.png b/gameBuild/Assets/sparkle/frame4.png new file mode 100644 index 0000000..3e30d02 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame4.png differ diff --git a/gameBuild/Assets/sparkle/frame5.png b/gameBuild/Assets/sparkle/frame5.png new file mode 100644 index 0000000..8e072c1 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame5.png differ diff --git a/gameBuild/Assets/sparkle/frame6.png b/gameBuild/Assets/sparkle/frame6.png new file mode 100644 index 0000000..1997e05 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame6.png differ diff --git a/gameBuild/Assets/sparkle/frame7.png b/gameBuild/Assets/sparkle/frame7.png new file mode 100644 index 0000000..ce8bc4d Binary files /dev/null and b/gameBuild/Assets/sparkle/frame7.png differ diff --git a/gameBuild/Assets/sparkle/frame8.png b/gameBuild/Assets/sparkle/frame8.png new file mode 100644 index 0000000..cda11a7 Binary files /dev/null and b/gameBuild/Assets/sparkle/frame8.png differ diff --git a/gameBuild/Assets/sparkle/frame9.png b/gameBuild/Assets/sparkle/frame9.png new file mode 100644 index 0000000..7b5a6ac Binary files /dev/null and b/gameBuild/Assets/sparkle/frame9.png differ diff --git a/gameBuild/Assets/splash.png b/gameBuild/Assets/splash.png new file mode 100644 index 0000000..eaba075 Binary files /dev/null and b/gameBuild/Assets/splash.png differ diff --git a/gameBuild/Assets/splash.xcf b/gameBuild/Assets/splash.xcf new file mode 100644 index 0000000..61ce4d7 Binary files /dev/null and b/gameBuild/Assets/splash.xcf differ diff --git a/gameBuild/Assets/stars.png b/gameBuild/Assets/stars.png new file mode 100644 index 0000000..d04c746 Binary files /dev/null and b/gameBuild/Assets/stars.png differ diff --git a/gameBuild/gameBuild.zip b/gameBuild/gameBuild.zip new file mode 100644 index 0000000..0cee560 Binary files /dev/null and b/gameBuild/gameBuild.zip differ diff --git a/gameBuild/sdl2 b/gameBuild/sdl2 new file mode 100755 index 0000000..9199a34 Binary files /dev/null and b/gameBuild/sdl2 differ diff --git a/global.cpp b/global.cpp new file mode 100644 index 0000000..39b1406 --- /dev/null +++ b/global.cpp @@ -0,0 +1,5 @@ +#include "global.h" + +//extern const AssetLoader::rootPath assetPath = "/home/dennisgunia/eclipse-workspace-cpp/Desktop"; +extern const AssetLoader::rootPath assetPath = "./Assets"; +extern const AssetLoader::rootPath saveFiles = "./.userdata"; diff --git a/global.h b/global.h new file mode 100644 index 0000000..daddfb6 --- /dev/null +++ b/global.h @@ -0,0 +1,13 @@ + +#ifndef GLOBAL__ +#define GLOBAL__ + + +#include "AssetLoader.hpp" + + +extern const AssetLoader::rootPath assetPath; + +extern const AssetLoader::rootPath saveFiles; + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..3a9b469 --- /dev/null +++ b/main.cpp @@ -0,0 +1,217 @@ +#include +#include "SnakeGame.hpp" +#include "SnakeMenu.h" +#include +#include +#include +#include +#include +#include "global.h" + +SDL_Window *Window; +SDL_Renderer *Renderer; +SDL_Surface* screenSurface = NULL; +Mix_Music *Music = NULL; + + +void exit_(void) +{ + + SDL_DestroyRenderer(Renderer); + SDL_DestroyWindow(Window); + + SDL_Quit(); + +} + +void init(void) +{ + + + SDL_Init(SDL_INIT_EVERYTHING); + + Window = SDL_CreateWindow("", 0, 0, 0, 0, SDL_WINDOW_HIDDEN); + if(TTF_Init()==-1) { + printf("TTF_Init: %s\n", TTF_GetError()); + exit(2); + } + SDL_SetWindowPosition(Window,0,0); + SDL_SetWindowSize(Window,200,200); + SDL_SetWindowTitle(Window, "Schlange"); + SDL_ShowWindow(Window); + SDL_SetWindowFullscreen(Window,SDL_WINDOW_FULLSCREEN_DESKTOP); + + Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ); + + Mix_VolumeMusic(60); + + //END ICON + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); + Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ); + SDL_SetRenderDrawBlendMode(Renderer, SDL_BLENDMODE_BLEND); + SDL_ShowCursor(SDL_DISABLE); + //SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); + + +} + + +bool alive = true; + + +Uint32 ticklastFrame = 0; +Uint32 ticklastAnim = 0; +bool running = true; + +int mode = 0; + + + +void doTitle(SnakeGame *sg,SnakeMenu *sm){ + + //BEGIN EVENT LOOP + SDL_Event event; + while(SDL_PollEvent(&event)){ + if(event.type == SDL_QUIT){ + running =false; + } + else if( event.type == SDL_TEXTINPUT ) + { + sm->name += event.text.text; + + } + else if(event.type == SDL_KEYDOWN ){ + switch(event.key.keysym.sym ){ + case SDLK_SPACE: + sm->pressKey(menukey_enter); + break; + case SDLK_UP: + sm->pressKey(menukey_up); + break; + case SDLK_DOWN: + sm->pressKey(menukey_down); + break; + case SDLK_ESCAPE: + running =false; + break; + case SDLK_BACKSPACE: + sm->pressKey(menukey_back); + break; + + default: + break; + } + } + } + + switch(sm->renderFrame()){ + case frame_can_exit: + running =0; + break; + case frame_can_start: + mode = 1; + sg->startGame(); + Mix_VolumeMusic(MIX_MAX_VOLUME/2); + + break; + default: + break; + } + +} + +void doGame(SnakeGame *sg,SnakeMenu *sm){ + Uint32 now = SDL_GetTicks(); + if (ticklastAnim + 30 < now){ + sg->doAnimation(); + ticklastAnim = now; + } + + if (ticklastFrame + sg->getTimeOut() < now){ + if ( !sg->doSnakeStep()){ + // what happens if dead + sm->registerScore(sg->getScore()); + sg->setDirection(dir_stop); + alive = false; + sg->convertToCoins(); + mode = 0; + Mix_HookMusicFinished(NULL); + Mix_HaltMusic(); + sm->goToTitle(); + } + if ((rand()%30 > 22 )&& alive){sg->generateFood();}; + + ticklastFrame=now; + } + + + //BEGIN EVENT LOOP + SDL_Event event; + while(SDL_PollEvent(&event)){ + if(event.type == SDL_QUIT){ + running =0; + } + if(event.type == SDL_KEYDOWN ){ + switch(event.key.keysym.sym ){ + case SDLK_UP: + sg->setDirection(dir_up); + alive = true; + break; + case SDLK_LEFT: + sg->setDirection(dir_left); + alive = true; + break; + case SDLK_DOWN: + sg->setDirection(dir_down); + alive = true; + break; + case SDLK_RIGHT: + sg->setDirection(dir_right); + alive = true; + break; + case SDLK_ESCAPE: + mode = 0; + Mix_HookMusicFinished(NULL); + Mix_HaltMusic(); + sm->goToTitle(); + break; + + default: + break; + } + } + } + + sg->drawGame(); + +} + +int main(int argc, char *argv[]) +{ + init(); + + SDL_RenderClear(Renderer); + + size GameField; + GameField.X = 80; + GameField.Y = 60; + GameField.scale = 32; + SnakeGame sg = SnakeGame(GameField,Renderer, Window); + SnakeMenu sm = SnakeMenu(Renderer); + + + Uint32 ticklastFrame = 0; + Uint32 ticklastAnim = 0; + + mode = 0; + Mix_VolumeMusic(MIX_MAX_VOLUME/2); + + Mix_VolumeMusic(MIX_MAX_VOLUME); + while(running){ + if(mode==0){ + doTitle(&sg,&sm); + }else{ + doGame(&sg,&sm); + } + }; +} diff --git a/sdl2 b/sdl2 new file mode 100755 index 0000000..9199a34 Binary files /dev/null and b/sdl2 differ