summaryrefslogtreecommitdiffstats
path: root/main_old.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main_old.cpp')
-rwxr-xr-xmain_old.cpp200
1 files changed, 200 insertions, 0 deletions
diff --git a/main_old.cpp b/main_old.cpp
new file mode 100755
index 0000000..5ee6a25
--- /dev/null
+++ b/main_old.cpp
@@ -0,0 +1,200 @@
+#include <SDL2/SDL.h>
+
+#include "logging.h"
+#include "files.h"
+#include "display.h"
+#include "music.h"
+
+int main(int argc, char** argv){
+ if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
+ logSDLError(std::cout, "SDL_Init");
+ return 1;
+ }
+
+ SDL_Window *window = SDL_CreateWindow(WINDOW_NAME, 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT,
+ SDL_WINDOW_SHOWN);
+ if (window == nullptr){
+ logSDLError(std::cout, "CreateWindow");
+ return 2;
+ }
+ SDL_Renderer *renderer = SDL_CreateRenderer(window, -1,
+ SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
+ if(renderer == nullptr)
+ renderer = SDL_CreateRenderer(window, -1, 0);
+
+ if (renderer == nullptr){
+ logSDLError(std::cout, "CreateRenderer");
+ return 3;
+ }
+
+ if(Mix_OpenAudio(MIX_SAMPLERATE, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) //Initialisation de l'API Mixer
+ logMixError(std::cout, "OpenAudio");
+
+
+ Mix_Music *musique;
+
+ SDL_Texture *background;
+ SDL_Texture *image;
+
+ std::vector<music> songs = loadSongs();
+ for(std::vector<music>::iterator songData = songs.begin(); songData != songs.end(); ++songData) {
+ std::string path = songData->path + songData->background;
+ background = loadTexture(path, renderer);
+ path = songData->path + songData->banner;
+ image = loadTexture(path, renderer);
+ path = songData->path + songData->music;
+
+ if (background == nullptr || image == nullptr)
+ return 4;
+
+ SDL_RenderClear(renderer);
+
+ int bW, bH;
+ SDL_QueryTexture(background, NULL, NULL, &bW, &bH);
+ renderTexture(background, renderer, 0, 0);
+ renderTexture(background, renderer, bW, 0);
+ renderTexture(background, renderer, 0, bH);
+ renderTexture(background, renderer, bW, bH);
+
+ int iW, iH;
+ SDL_QueryTexture(image, NULL, NULL, &iW, &iH);
+ int x = SCREEN_WIDTH / 2 - iW / 2;
+ int y = SCREEN_HEIGHT / 2 - iH / 2;
+ renderTexture(image, renderer, x, y);
+
+ SDL_RenderPresent(renderer);
+
+ SDL_Event e;
+ bool quit = false;
+ bool playing = false;
+ unsigned int last_tick = SDL_GetTicks();
+ unsigned int last_update = 0;
+ int difficulty = 0;
+ int current_note = 0;
+ int current_line = 0;
+ int current_mes = 0;
+ std::vector<displaynote> displayednotes;
+ displaynote currentNote;
+
+ SDL_Texture *left;
+ SDL_Texture *right;
+ SDL_Texture *up;
+ SDL_Texture *down;
+
+ musique = Mix_LoadMUS(path.c_str());
+ if(musique == nullptr)
+ logMixError(std::cout, "LoadMUS");
+
+ left = loadTexture("left_arrow.png", renderer);
+ right = loadTexture("right_arrow.png", renderer);
+ up = loadTexture("up_arrow.png", renderer);
+ down = loadTexture("down_arrow.png", renderer);
+ unsigned int first_tick = SDL_GetTicks();
+ while (!quit)
+ {
+ while (SDL_PollEvent(&e)){
+ if (e.type == SDL_QUIT)
+ quit = true;
+ if (e.type == SDL_KEYDOWN)
+ quit = true;
+ if (e.type == SDL_MOUSEBUTTONDOWN)
+ quit = true;
+ }
+
+ if((SDL_GetTicks() - first_tick >= (SCREEN_HEIGHT-128*2)/5+songData->offset) && !playing)
+ {
+
+ if((musique != nullptr) && (Mix_PlayMusic(musique, -1) == -1))
+ logMixError(std::cout, "PlayMusic");
+ playing = true;
+ }
+
+
+ std::vector<Note> note = songData->songNotes[difficulty].noteData[current_mes][current_line];
+
+ int time = (1000/(songData->bpms[0].bpm/60))-60;
+
+ if(SDL_GetTicks() - last_tick >= time)
+ {
+ last_tick = SDL_GetTicks();
+
+ if(note[0] == Tap)
+ {
+ currentNote.texture = left;
+ currentNote.x = 10;
+ currentNote.y = SCREEN_HEIGHT;
+ displayednotes.push_back(currentNote);
+ }
+ if(note[1] == Tap)
+ {
+ currentNote.texture = up;
+ currentNote.x = 90;
+ currentNote.y = SCREEN_HEIGHT;
+ displayednotes.push_back(currentNote);
+ }
+ if(note[2] == Tap)
+ {
+ currentNote.texture = down;
+ currentNote.x = 170;
+ currentNote.y = SCREEN_HEIGHT;
+ displayednotes.push_back(currentNote);
+ }
+ if(note[3] == Tap)
+ {
+ currentNote.texture = right;
+ currentNote.x = 250;
+ currentNote.y = SCREEN_HEIGHT;
+ displayednotes.push_back(currentNote);
+ }
+ current_line += 1;
+ }
+
+/* renderTexture(background, renderer, 0, 0);
+ renderTexture(background, renderer, bW, 0);
+ renderTexture(background, renderer, 0, bH);
+ renderTexture(background, renderer, bW, bH);
+
+ renderTexture(image, renderer, x, y);
+*/
+ if(SDL_GetTicks() - last_tick >= 20)
+{
+ SDL_RenderClear(renderer);
+
+ renderTexture(background, renderer, 0, 0);
+ renderTexture(background, renderer, bW, 0);
+ renderTexture(background, renderer, 0, bH);
+ renderTexture(background, renderer, bW, bH);
+
+ renderTexture(image, renderer, x, y);
+
+ for(std::vector<displaynote>::iterator show_note = displayednotes.begin(); show_note != displayednotes.end(); ++show_note) {
+ renderTexture(show_note->texture, renderer, show_note->x, show_note->y);
+ if(SDL_GetTicks() - last_tick >= 1)
+ {
+ last_update = SDL_GetTicks();
+ show_note->y -= 5;
+ }
+ }
+ SDL_RenderPresent(renderer);
+}
+
+ if(songData->songNotes[difficulty].noteData[current_mes].size() <= current_line)
+ {
+ current_line = 0;
+ current_mes +=1;
+ }
+
+ }
+
+ SDL_DestroyTexture(background);
+ SDL_DestroyTexture(image);
+ if(musique) Mix_FreeMusic(musique);
+}
+
+ Mix_CloseAudio();
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+
+ return 0;
+}