perfection
This commit is contained in:
@@ -28,6 +28,7 @@ set(SRC
|
|||||||
src/scaller.c
|
src/scaller.c
|
||||||
src/scene.c
|
src/scene.c
|
||||||
src/game.c
|
src/game.c
|
||||||
|
src/cinematic.c
|
||||||
)
|
)
|
||||||
|
|
||||||
# add the executable
|
# add the executable
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#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;
|
||||||
|
strcpy(AdamesLegend.name, "Adame's Legend");
|
||||||
|
SDL_Color black = {255, 255, 255, 255};
|
||||||
|
text_renderText(&AdamesLegend, 8, 0.8f, black, "./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.");
|
||||||
|
scene_addRenderObject(&cinematicScene, AdamesLegend, 10, 80);
|
||||||
|
|
||||||
|
music = Mix_LoadMUS("./assets/music/chinese rap.mp3");
|
||||||
|
if(music == NULL) {
|
||||||
|
fprintf(stderr, "Prout 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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#ifndef __CINEMATIC_H__
|
||||||
|
#define __CINEMATIC_H__
|
||||||
|
#include "scene.h"
|
||||||
|
|
||||||
|
extern Scene_t cinematicScene;
|
||||||
|
|
||||||
|
void cinematic_render(float delta);
|
||||||
|
void cinematic_remove(void);
|
||||||
|
void cinematic_staticRender(void);
|
||||||
|
|
||||||
|
#endif
|
||||||
+16
-1
@@ -1,10 +1,11 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
|
#include <SDL2/SDL_mixer.h>
|
||||||
#include "scaller.h"
|
#include "scaller.h"
|
||||||
|
|
||||||
static RenderId_t menuObjects[10];
|
static RenderId_t menuObjects[10];
|
||||||
static unsigned menuObjectsSize = 0;
|
static unsigned menuObjectsSize = 0;
|
||||||
|
static Mix_Music * music;
|
||||||
|
|
||||||
Scene_t gameScene;
|
Scene_t gameScene;
|
||||||
|
|
||||||
@@ -18,6 +19,19 @@ int game_staticRender(void){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
music = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
||||||
|
if(music == NULL) {
|
||||||
|
fprintf(stderr, "Prout 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;
|
||||||
|
}
|
||||||
|
|
||||||
RenderObject_t pp;
|
RenderObject_t pp;
|
||||||
strcpy(pp.name, "pp");
|
strcpy(pp.name, "pp");
|
||||||
pp.z = 10;
|
pp.z = 10;
|
||||||
@@ -37,5 +51,6 @@ int game_render([[maybe_unused]] float delta){
|
|||||||
|
|
||||||
void game_remove(void){
|
void game_remove(void){
|
||||||
scene_free(&gameScene);
|
scene_free(&gameScene);
|
||||||
|
Mix_FreeMusic(music);
|
||||||
menuObjectsSize = 0;
|
menuObjectsSize = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-17
@@ -10,25 +10,23 @@
|
|||||||
#include <SDL2/SDL_surface.h>
|
#include <SDL2/SDL_surface.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "cinematic.h"
|
||||||
#include "scaller.h"
|
#include "scaller.h"
|
||||||
|
|
||||||
clock_t timecode;
|
clock_t timecode;
|
||||||
long iter;
|
long iter;
|
||||||
Mix_Music *prout;
|
|
||||||
|
|
||||||
|
|
||||||
static void space(void) {
|
static void space(void) {
|
||||||
printf("space!\n");
|
printf("space!\n");
|
||||||
if(Mix_PlayMusic(prout, 0) != 0){
|
|
||||||
printf("Music sound could not be played!\n"
|
|
||||||
"SDL_Error: %s\n", Mix_GetError());
|
|
||||||
Mix_FreeMusic(prout);
|
|
||||||
running = false;
|
|
||||||
}
|
|
||||||
if(renderer_getScene() == &menuScene){
|
if(renderer_getScene() == &menuScene){
|
||||||
menu_remove();
|
menu_remove();
|
||||||
renderer_setScene(&gameScene);
|
cinematic_staticRender();
|
||||||
|
renderer_setScene(&cinematicScene);
|
||||||
|
} else if(renderer_getScene() == &cinematicScene) {
|
||||||
|
cinematic_remove();
|
||||||
game_staticRender();
|
game_staticRender();
|
||||||
|
renderer_setScene(&gameScene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +51,9 @@ static void game_loop(void) {
|
|||||||
if(renderer_getScene() == &menuScene){
|
if(renderer_getScene() == &menuScene){
|
||||||
menu_render(delta);
|
menu_render(delta);
|
||||||
}
|
}
|
||||||
else{
|
else if(renderer_getScene() == &cinematicScene){
|
||||||
|
cinematic_render(delta);
|
||||||
|
} else {
|
||||||
game_render(delta);
|
game_render(delta);
|
||||||
}
|
}
|
||||||
timecode = clock();
|
timecode = clock();
|
||||||
@@ -68,20 +68,12 @@ int main(void) {
|
|||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
prout = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
|
||||||
if(prout == NULL) {
|
|
||||||
fprintf(stderr, "Prout not found!\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
iter = 0;
|
iter = 0;
|
||||||
timecode = clock();
|
timecode = clock();
|
||||||
|
|
||||||
Mix_Init(MIX_INIT_MP3);
|
Mix_Init(MIX_INIT_MP3);
|
||||||
renderer_main(game_setup, game_loop);
|
renderer_main(game_setup, game_loop);
|
||||||
|
|
||||||
Mix_FreeMusic(prout);
|
|
||||||
|
|
||||||
Mix_CloseAudio();
|
Mix_CloseAudio();
|
||||||
text_freeFontCache();
|
text_freeFontCache();
|
||||||
}
|
}
|
||||||
|
|||||||
+17
@@ -1,5 +1,6 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
|
#include <SDL2/SDL_mixer.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "scaller.h"
|
#include "scaller.h"
|
||||||
@@ -15,6 +16,7 @@ static float blinkDelta = 0;
|
|||||||
static bool increaseTextBrightness = false;
|
static bool increaseTextBrightness = false;
|
||||||
static Uint8 textOpacity = 255;
|
static Uint8 textOpacity = 255;
|
||||||
|
|
||||||
|
static Mix_Music * music;
|
||||||
|
|
||||||
Scene_t menuScene = { NULL, 0, 0, 0, 0, 0 };
|
Scene_t menuScene = { NULL, 0, 0, 0, 0, 0 };
|
||||||
|
|
||||||
@@ -30,6 +32,19 @@ int menu_staticRender(void){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
music = Mix_LoadMUS("./assets/music/pet.mp3");
|
||||||
|
if(music == NULL) {
|
||||||
|
fprintf(stderr, "Prout 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;
|
||||||
|
}
|
||||||
|
|
||||||
RenderObject_t backgroundImage;
|
RenderObject_t backgroundImage;
|
||||||
strcpy(backgroundImage.name, "BackgroundImg");
|
strcpy(backgroundImage.name, "BackgroundImg");
|
||||||
backgroundImage.z = 0;
|
backgroundImage.z = 0;
|
||||||
@@ -94,5 +109,7 @@ int menu_render(float delta){
|
|||||||
|
|
||||||
void menu_remove(void){
|
void menu_remove(void){
|
||||||
//scene_free(&menuScene);
|
//scene_free(&menuScene);
|
||||||
|
Mix_FreeMusic(music);
|
||||||
|
|
||||||
menuObjectsSize = 0;
|
menuObjectsSize = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-8
@@ -13,16 +13,11 @@ static int compartSort(const SceneObject_t * a, const SceneObject_t * b) {
|
|||||||
|
|
||||||
void scene_render(const Scene_t * scene) {
|
void scene_render(const Scene_t * scene) {
|
||||||
MonitorSize_t monitorSize = renderer_getMonitorSize();
|
MonitorSize_t monitorSize = renderer_getMonitorSize();
|
||||||
int minScanX = scene->x - CAMERA_WIDTH;
|
|
||||||
int minScanY = scene->y - CAMERA_HEIGHT;
|
|
||||||
int maxScanX = scene->x + CAMERA_WIDTH;
|
|
||||||
int maxScanY = scene->y + CAMERA_HEIGHT;
|
|
||||||
|
|
||||||
for(int i = 0; i < scene->objectCount; i++) {
|
for(int i = 0; i < scene->objectCount; i++) {
|
||||||
const SceneObject_t * object = &scene->objects[i];
|
const SceneObject_t * object = &scene->objects[i];
|
||||||
if(object->x > minScanX && object->x < maxScanX && object->y > minScanY && object->y < maxScanY) {
|
float x = (object->x - scene->x) / CAMERA_WIDTH;
|
||||||
float x = (object->x) / CAMERA_WIDTH;
|
float y = (object->y - scene->y) / CAMERA_HEIGHT;
|
||||||
float y = (object->y) / CAMERA_HEIGHT;
|
|
||||||
//the object is to be rendered
|
//the object is to be rendered
|
||||||
|
|
||||||
SDL_Rect rect = {
|
SDL_Rect rect = {
|
||||||
@@ -38,7 +33,6 @@ void scene_render(const Scene_t * scene) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buildCache(SceneObject_t * object) {
|
static void buildCache(SceneObject_t * object) {
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ typedef struct Scene {
|
|||||||
int objectCount;
|
int objectCount;
|
||||||
unsigned long objectArraySize;
|
unsigned long objectArraySize;
|
||||||
int lastId;
|
int lastId;
|
||||||
int x,y;
|
float x,y;
|
||||||
} Scene_t;
|
} Scene_t;
|
||||||
|
|
||||||
void scene_render(const Scene_t * scene);
|
void scene_render(const Scene_t * scene);
|
||||||
|
|||||||
+3
-3
@@ -6,7 +6,7 @@
|
|||||||
#include <SDL2/SDL_log.h>
|
#include <SDL2/SDL_log.h>
|
||||||
|
|
||||||
#define FONT_CACHE_SIZE 100
|
#define FONT_CACHE_SIZE 100
|
||||||
#define MAX_TEXT_SIZE 100
|
#define MAX_TEXT_SIZE 10000
|
||||||
|
|
||||||
typedef struct FontCacheObject {
|
typedef struct FontCacheObject {
|
||||||
char* file;
|
char* file;
|
||||||
@@ -63,12 +63,12 @@ int text_renderText(RenderObject_t* renderObject, int z, float scale, SDL_Color
|
|||||||
vsprintf(text, format, args);
|
vsprintf(text, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
SDL_Surface* surface = TTF_RenderText_Blended(font, text, color);
|
MonitorSize_t monitor = renderer_getMonitorSize();
|
||||||
|
SDL_Surface* surface = TTF_RenderText_Blended_Wrapped(font, text, color, monitor.width);
|
||||||
|
|
||||||
int h, w;
|
int h, w;
|
||||||
|
|
||||||
TTF_SizeText(font, text, &w, &h);
|
TTF_SizeText(font, text, &w, &h);
|
||||||
MonitorSize_t monitor = renderer_getMonitorSize();
|
|
||||||
|
|
||||||
renderObject->z = z;
|
renderObject->z = z;
|
||||||
renderObject->angle_degre = 0;
|
renderObject->angle_degre = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user