Merge branch 'master' of ssh.marcbarbier.fr:Marc/gamejam-polytech

This commit is contained in:
Marc
2023-01-21 15:01:37 +01:00
6 changed files with 69 additions and 41 deletions
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

+10 -25
View File
@@ -11,13 +11,13 @@
#include <unistd.h>
#include "scaller.h"
long timecode;
clock_t timecode;
long iter;
Mix_Music *prout;
static void space(void) {
printf("space!\n");
if(Mix_PlayMusic(prout, -1) != 0){
if(Mix_PlayMusic(prout, 0) != 0){
printf("Music sound could not be played!\n"
"SDL_Error: %s\n", Mix_GetError());
Mix_FreeMusic(prout);
@@ -28,7 +28,7 @@ static void space(void) {
Scene_t demo;
static void game_setup(void) {
menu_render();
menu_staticRender();
RenderObject_t text;
SDL_Color white = {255, 255, 255, 255};
TTF_Init();
@@ -36,50 +36,35 @@ static void game_setup(void) {
printf("error");
exit(1);
}
SDL_Surface* img = IMG_Load("./assets/img/pp.png");
RenderObject_t duck = {
1,
0.5,
0.5,
0,
img
};
scaller(duck.surface, 1, &duck.width, &duck.height);
scene_addRenderObject(&demo, duck, CAMERA_WIDTH/2, CAMERA_HEIGHT/2);
scene_addRenderObject(&demo, text, CAMERA_WIDTH/2, CAMERA_HEIGHT/2);
input_listen(SDL_SCANCODE_SPACE, space);
}
static void game_loop(void) {
long delta = time(NULL) - timecode;
//main game code
float delta = ((float)(clock() - timecode)) / CLOCKS_PER_SEC;
//update time
timecode = time(NULL);
iter++;
menu_render(delta);
timecode = clock();
}
int main(void) {
TTF_Init();
if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) != 0){
printf("Music sound could not be open!\n"
"SDL_Error: %s\n", Mix_GetError());
running = false;
}
prout = Mix_LoadMUS("./assets/music/pet.mp3");
prout = Mix_LoadMUS("./assets/music/jojo arab.mp3");
if(prout == NULL) {
fprintf(stderr, "Prout not found!\n");
exit(1);
}
iter = 0;
timecode = time(NULL);
timecode = clock();
Mix_Init(MIX_INIT_MP3);
renderer_main(game_setup, game_loop);
+55 -14
View File
@@ -2,30 +2,71 @@
#include <SDL2/SDL_image.h>
#include "renderer.h"
#include "scaller.h"
#include "text.h"
#define BLINK_FREQUENCY 0.00005
static RenderId_t menuObjects[10];
static unsigned menuObjectsSize = 0;
int menu_render(void){
SDL_Surface* buttonImageSurface = IMG_Load("./assets/img/start.png");
if(buttonImageSurface == NULL){
printf("cannot load");
return -1;
}
RenderObject_t buttonImage;
float buttonScale = 0.3f;
static float blinkDelta = 0;
static bool increaseTextBrightness = false;
static Uint8 textOpacity = 255;
int menu_staticRender(void){
MonitorSize_t size = renderer_getMonitorSize();
float aspectRatio = (float)size.width / size.height;
buttonImage.x = 0.5f;
buttonImage.y = 0.5f;
scaller(buttonImageSurface, buttonScale, &buttonImage.width, &buttonImage.height);
placer(buttonImageSurface, buttonScale, &buttonImage.x, &buttonImage.y);
SDL_Surface* backgroundImageSurface = IMG_Load("./assets/img/menu_bg.png");
if(backgroundImageSurface == NULL){
printf("cannot load background");
return -1;
}
buttonImage.surface = buttonImageSurface;
menuObjects[menuObjectsSize] = renderer_renderObject(buttonImage);
RenderObject_t backgroundImage;
backgroundImage.x = 0;
backgroundImage.y = 0;
backgroundImage.z = 0;
backgroundImage.surface = backgroundImageSurface;
backgroundImage.width = 1;
backgroundImage.height = 1;
menuObjects[menuObjectsSize] = renderer_renderObject(backgroundImage);
++menuObjectsSize;
return 0;
}
int menu_render(float delta){
for(unsigned i = 1; i < menuObjectsSize; ++i){
renderer_removeObject(menuObjects[i]);
}
menuObjectsSize = 1;
blinkDelta += delta;
if(increaseTextBrightness && blinkDelta >= BLINK_FREQUENCY){
textOpacity += 1;
if(textOpacity == 255) increaseTextBrightness = false;
blinkDelta = 0;
}
else if(!increaseTextBrightness && blinkDelta >= BLINK_FREQUENCY){
textOpacity -= 1;
if(textOpacity == 1) increaseTextBrightness = true;
blinkDelta = 0;
}
RenderObject_t startTextShadow;
SDL_Color black = {0, 0, 0, textOpacity};
text_renderText(&startTextShadow, 0.495f, 0.855f, 9, 1.f, black, "./assets/fonts/Quinquefive.ttf", 28, "Press space to start");
menuObjects[menuObjectsSize] = renderer_renderObject(startTextShadow);
++menuObjectsSize;
RenderObject_t startText;
SDL_Color orange = {255,165,0, textOpacity};
text_renderText(&startText, 0.5f, 0.85f, 10, 1.f, orange, "./assets/fonts/Quinquefive.ttf", 28, "Press space to start");
menuObjects[menuObjectsSize] = renderer_renderObject(startText);
++menuObjectsSize;
return 0;
}
+3 -1
View File
@@ -3,7 +3,9 @@
#include "renderer.h"
int menu_render(void);
int menu_staticRender(void);
int menu_render(float delta);
void menu_remove(void);
+1 -1
View File
@@ -33,7 +33,7 @@ int text_renderText(RenderObject_t* renderObject, int z, float scale, SDL_Color
TTF_Font* font = NULL;
for(unsigned i = 0; i < fontCacheSize; ++i){
if(strcmp(fontCache[i].file, fontFilename) && fontCache[i].size == fontSize){
if(strcmp(fontCache[i].file, fontFilename) == 0 && fontCache[i].size == fontSize){
font = fontCache[i].font;
break;
}