Merge branch 'master' of ssh.marcbarbier.fr:Marc/gamejam-polytech
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
+10
-25
@@ -11,13 +11,13 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "scaller.h"
|
#include "scaller.h"
|
||||||
|
|
||||||
long timecode;
|
clock_t timecode;
|
||||||
long iter;
|
long iter;
|
||||||
Mix_Music *prout;
|
Mix_Music *prout;
|
||||||
|
|
||||||
static void space(void) {
|
static void space(void) {
|
||||||
printf("space!\n");
|
printf("space!\n");
|
||||||
if(Mix_PlayMusic(prout, -1) != 0){
|
if(Mix_PlayMusic(prout, 0) != 0){
|
||||||
printf("Music sound could not be played!\n"
|
printf("Music sound could not be played!\n"
|
||||||
"SDL_Error: %s\n", Mix_GetError());
|
"SDL_Error: %s\n", Mix_GetError());
|
||||||
Mix_FreeMusic(prout);
|
Mix_FreeMusic(prout);
|
||||||
@@ -28,7 +28,7 @@ static void space(void) {
|
|||||||
Scene_t demo;
|
Scene_t demo;
|
||||||
|
|
||||||
static void game_setup(void) {
|
static void game_setup(void) {
|
||||||
menu_render();
|
menu_staticRender();
|
||||||
RenderObject_t text;
|
RenderObject_t text;
|
||||||
SDL_Color white = {255, 255, 255, 255};
|
SDL_Color white = {255, 255, 255, 255};
|
||||||
TTF_Init();
|
TTF_Init();
|
||||||
@@ -36,50 +36,35 @@ static void game_setup(void) {
|
|||||||
printf("error");
|
printf("error");
|
||||||
exit(1);
|
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);
|
input_listen(SDL_SCANCODE_SPACE, space);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void game_loop(void) {
|
static void game_loop(void) {
|
||||||
long delta = time(NULL) - timecode;
|
float delta = ((float)(clock() - timecode)) / CLOCKS_PER_SEC;
|
||||||
//main game code
|
|
||||||
|
|
||||||
//update time
|
//update time
|
||||||
timecode = time(NULL);
|
menu_render(delta);
|
||||||
iter++;
|
|
||||||
|
timecode = clock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
TTF_Init();
|
||||||
if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) != 0){
|
if(Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) != 0){
|
||||||
printf("Music sound could not be open!\n"
|
printf("Music sound could not be open!\n"
|
||||||
"SDL_Error: %s\n", Mix_GetError());
|
"SDL_Error: %s\n", Mix_GetError());
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
prout = Mix_LoadMUS("./assets/music/pet.mp3");
|
prout = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
||||||
if(prout == NULL) {
|
if(prout == NULL) {
|
||||||
fprintf(stderr, "Prout not found!\n");
|
fprintf(stderr, "Prout not found!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
iter = 0;
|
iter = 0;
|
||||||
timecode = time(NULL);
|
timecode = clock();
|
||||||
|
|
||||||
Mix_Init(MIX_INIT_MP3);
|
Mix_Init(MIX_INIT_MP3);
|
||||||
renderer_main(game_setup, game_loop);
|
renderer_main(game_setup, game_loop);
|
||||||
|
|||||||
+55
-14
@@ -2,30 +2,71 @@
|
|||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "scaller.h"
|
#include "scaller.h"
|
||||||
|
#include "text.h"
|
||||||
|
|
||||||
|
#define BLINK_FREQUENCY 0.00005
|
||||||
|
|
||||||
static RenderId_t menuObjects[10];
|
static RenderId_t menuObjects[10];
|
||||||
static unsigned menuObjectsSize = 0;
|
static unsigned menuObjectsSize = 0;
|
||||||
|
|
||||||
int menu_render(void){
|
static float blinkDelta = 0;
|
||||||
SDL_Surface* buttonImageSurface = IMG_Load("./assets/img/start.png");
|
static bool increaseTextBrightness = false;
|
||||||
if(buttonImageSurface == NULL){
|
static Uint8 textOpacity = 255;
|
||||||
printf("cannot load");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
RenderObject_t buttonImage;
|
|
||||||
float buttonScale = 0.3f;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int menu_staticRender(void){
|
||||||
MonitorSize_t size = renderer_getMonitorSize();
|
MonitorSize_t size = renderer_getMonitorSize();
|
||||||
float aspectRatio = (float)size.width / size.height;
|
float aspectRatio = (float)size.width / size.height;
|
||||||
|
|
||||||
buttonImage.x = 0.5f;
|
|
||||||
buttonImage.y = 0.5f;
|
|
||||||
|
|
||||||
scaller(buttonImageSurface, buttonScale, &buttonImage.width, &buttonImage.height);
|
SDL_Surface* backgroundImageSurface = IMG_Load("./assets/img/menu_bg.png");
|
||||||
placer(buttonImageSurface, buttonScale, &buttonImage.x, &buttonImage.y);
|
if(backgroundImageSurface == NULL){
|
||||||
|
printf("cannot load background");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
buttonImage.surface = buttonImageSurface;
|
RenderObject_t backgroundImage;
|
||||||
menuObjects[menuObjectsSize] = renderer_renderObject(buttonImage);
|
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;
|
++menuObjectsSize;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
|
||||||
int menu_render(void);
|
|
||||||
|
int menu_staticRender(void);
|
||||||
|
int menu_render(float delta);
|
||||||
|
|
||||||
void menu_remove(void);
|
void menu_remove(void);
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ int text_renderText(RenderObject_t* renderObject, int z, float scale, SDL_Color
|
|||||||
|
|
||||||
TTF_Font* font = NULL;
|
TTF_Font* font = NULL;
|
||||||
for(unsigned i = 0; i < fontCacheSize; ++i){
|
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;
|
font = fontCache[i].font;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user