#include "cinematic.h"
#include "renderer.h"
#include "scene.h"
#include "text.h"
#include <stdio.h>
#include <SDL2/SDL_mixer.h>

Scene_t cinematicScene;

#define SPEED 1.f/1000

static Mix_Music * music;

float accu = 0;

void cinematic_staticRender(void) {
    RenderObject_t AdamesLegend = EMPTY_RENDER_OBJECT;
    strcpy(AdamesLegend.name, "Adame's Legend");
    SDL_Color white = {255, 255, 255, 255};
    text_renderText(&AdamesLegend, 8, 0.8f, white, "./assets/fonts/Quinquefive.ttf", 40, "Adame est l'eleve modele de Polytech,\n Membre de plusieurs associations il est connu de tous.\n Lors de l'edition 21.2 de la Nantarena,\n Adame s'est retrouve a engeuler des joueurs pour leur demander de mettre leur putain de masque.\n\n L'edition finie, Adame a kidnappe l'ensemble des joueurs qui forcaient pour leur apprendre a respecter l'autorite a coup de coup de pied au cul.\n\n Press space to continue");
    scene_addRenderObject(&cinematicScene, AdamesLegend, 10, 80);

    music = Mix_LoadMUS("./assets/music/chinese rap.mp3");
	if(music == NULL) {
		fprintf(stderr, "Chinese rap not found!\n");
		exit(1);
	}

    if(Mix_PlayMusic(music, 0) != 0){
		printf("Music sound could not be played!\n"
			"SDL_Error: %s\n", Mix_GetError());
		Mix_FreeMusic(music);
		running = false;
	}
}RenderId_t id = -1;


void cinematic_render([[maybe_unused]]float delta) {
    accu += delta;

    if(accu >= SPEED && cinematicScene.y < 90){
        printf("Scroll %f\n", cinematicScene.y);
        cinematicScene.y += 0.1;
        accu -= SPEED;
    }

    renderer_setScene(&cinematicScene);
}

void cinematic_remove(void) {
    scene_free(&cinematicScene);
    Mix_FreeMusic(music);
}
