Merge branch 'master' of ssh.marcbarbier.fr:Marc/gamejam-polytech
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ static Mix_Music * music;
|
||||
float accu = 0;
|
||||
|
||||
void cinematic_staticRender(void) {
|
||||
RenderObject_t AdamesLegend;
|
||||
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.");
|
||||
|
||||
+48
-34
@@ -3,13 +3,12 @@
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <SDL2/SDL_surface.h>
|
||||
#include "scaller.h"
|
||||
#include "scene.h"
|
||||
#include "text.h"
|
||||
|
||||
#define SPEED 1.f/10000000000
|
||||
#define GRAVITY 10000.f
|
||||
|
||||
static RenderId_t menuObjects[10];
|
||||
static unsigned menuObjectsSize = 0;
|
||||
static Mix_Music * music;
|
||||
|
||||
Scene_t gameScene;
|
||||
@@ -27,6 +26,10 @@ static float personVelocityY = 0;
|
||||
|
||||
float jetons = 0.f;
|
||||
|
||||
static RenderObject_t person;
|
||||
static RenderId_t personId;
|
||||
RenderObject_t scoreText;
|
||||
static RenderId_t scoreTextId = -1;
|
||||
|
||||
static void playMusic(){
|
||||
music = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
||||
@@ -56,46 +59,53 @@ int game_staticRender(void){
|
||||
}
|
||||
|
||||
|
||||
RenderObject_t gameBackground;
|
||||
RenderObject_t gameBackground = EMPTY_RENDER_OBJECT;
|
||||
strcpy(gameBackground.name, "gameBackground");
|
||||
gameBackground.z = 0;
|
||||
gameBackground.surface = gameBackgroundSurface;
|
||||
scaller(gameBackground.surface, 1, &gameBackground.width, &gameBackground.height);
|
||||
gameBackground.height = 1;
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&gameScene, gameBackground, 0, 0);
|
||||
renderer_setScene(&gameScene);
|
||||
++menuObjectsSize;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int game_render([[maybe_unused]] float delta){
|
||||
for(unsigned i = 2; i < menuObjectsSize; ++i){
|
||||
scene_removeRenderObject(&gameScene, menuObjects[i]);
|
||||
}
|
||||
menuObjectsSize = 2;
|
||||
|
||||
deltaAccu += delta;
|
||||
scene_addRenderObject(&gameScene, gameBackground, 0, 0);
|
||||
|
||||
SDL_Surface* buildingSurface = IMG_Load("./assets/img/building.png");
|
||||
RenderObject_t building;
|
||||
RenderObject_t building = EMPTY_RENDER_OBJECT;
|
||||
strcpy(building.name, "building");
|
||||
building.z = 9;
|
||||
building.surface = buildingSurface;
|
||||
building.width = 0.25;
|
||||
building.height = 1;
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&gameScene, building, 0, 0);
|
||||
++menuObjectsSize;
|
||||
|
||||
|
||||
scene_addRenderObject(&gameScene, building, 0, 0);
|
||||
|
||||
SDL_Surface* personSurface = IMG_Load("./assets/img/person.png");
|
||||
RenderObject_t person;
|
||||
strcpy(person.name, "person");
|
||||
person.z = 9;
|
||||
person.surface = personSurface;
|
||||
person.width = 0.25f;
|
||||
scaller(person.surface, 0.05f, &person.width, &person.height);
|
||||
personId = scene_addRenderObject(&gameScene, person, personPositionX, personPositionY);
|
||||
|
||||
scoreText = EMPTY_RENDER_OBJECT;
|
||||
strcpy(scoreText.name, "scoreText");
|
||||
SDL_Color black = {0, 0, 0, 255};
|
||||
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %d", (unsigned)jetons);
|
||||
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int game_render([[maybe_unused]] float delta){
|
||||
//for(unsigned i = 0; i < menuObjectsSize; ++i){
|
||||
// scene_removeRenderObject(&gameScene, menuObjects[i]);
|
||||
//}
|
||||
// if(scoreTextId > 0)
|
||||
// scene_removeRenderObject(&gameScene, scoreTextId);
|
||||
|
||||
|
||||
deltaAccu += delta;
|
||||
|
||||
|
||||
// if(!crashed && deltaAccu >= SPEED && isSpaceKeypressed){
|
||||
if(!crashed && isSpaceKeypressed){
|
||||
const float distance = personVelocityX * delta;
|
||||
personPositionX += distance;
|
||||
@@ -104,20 +114,24 @@ int game_render([[maybe_unused]] float delta){
|
||||
personVelocityY += GRAVITY * delta;
|
||||
|
||||
personPositionY += personVelocityY * delta;
|
||||
if(personPositionY + CAMERA_HEIGHT * person.height >= CAMERA_HEIGHT - 2) crashed = true;
|
||||
|
||||
jetons += distance;
|
||||
scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0);
|
||||
|
||||
if(personPositionY + CAMERA_HEIGHT * person.height >= CAMERA_HEIGHT - 2){
|
||||
crashed = true;
|
||||
scene_removeRenderObject(&gameScene, scoreTextId);
|
||||
SDL_Color black = {0, 0, 0, 255};
|
||||
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %d", (unsigned)jetons);
|
||||
scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&gameScene, person, personPositionX, personPositionY);
|
||||
++menuObjectsSize;
|
||||
|
||||
scene_moveRenderObject(&gameScene, personId, personPositionX, personPositionY);
|
||||
|
||||
|
||||
RenderObject_t scoreText;
|
||||
strcpy(scoreText.name, "scoreText");
|
||||
SDL_Color black = {0, 0, 0, 255};
|
||||
text_renderText(&scoreText, 50, 0.5f, black, "./assets/fonts/Quinquefive.ttf", 40, "jetons: %d", (unsigned)jetons);
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||
++menuObjectsSize;
|
||||
// scoreTextId = scene_addRenderObject(&gameScene, scoreText, gameScene.x + 2, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -125,7 +139,6 @@ int game_render([[maybe_unused]] float delta){
|
||||
void game_remove(void){
|
||||
scene_free(&gameScene);
|
||||
Mix_FreeMusic(music);
|
||||
menuObjectsSize = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,6 +151,7 @@ void game_handleSpaceKeyInput(void){
|
||||
isSpaceKeypressed = false;
|
||||
gameScene.x = 0;
|
||||
gameScene.y = 0;
|
||||
scene_moveRenderObject(&gameScene, scoreTextId, gameScene.x + 2, 0);
|
||||
}
|
||||
else{
|
||||
isSpaceKeypressed = true;
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ Scene_t demo;
|
||||
|
||||
static void game_setup(void) {
|
||||
menu_staticRender();
|
||||
RenderObject_t text;
|
||||
RenderObject_t text = EMPTY_RENDER_OBJECT;
|
||||
SDL_Color white = {255, 255, 255, 255};
|
||||
TTF_Init();
|
||||
if(text_renderText(&text, 1000, 1, white, "./assets/fonts/arial.ttf", 25, "Hello World") < 0){
|
||||
|
||||
+5
-5
@@ -45,7 +45,7 @@ int menu_staticRender(void){
|
||||
running = false;
|
||||
}
|
||||
|
||||
RenderObject_t backgroundImage;
|
||||
RenderObject_t backgroundImage = EMPTY_RENDER_OBJECT;
|
||||
strcpy(backgroundImage.name, "BackgroundImg");
|
||||
backgroundImage.z = 0;
|
||||
backgroundImage.surface = backgroundImageSurface;
|
||||
@@ -54,14 +54,14 @@ int menu_staticRender(void){
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&menuScene, backgroundImage, 0, 0);
|
||||
++menuObjectsSize;
|
||||
|
||||
RenderObject_t legendOfAdam;
|
||||
RenderObject_t legendOfAdam = EMPTY_RENDER_OBJECT;
|
||||
strcpy(legendOfAdam.name, "TheLegendOfA");
|
||||
SDL_Color white = {255, 255, 255, 255};
|
||||
text_renderText(&legendOfAdam, 9, 1.f, white, "./assets/fonts/Quinquefive.ttf", 48, "The legend of adame");
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&menuScene, legendOfAdam, CAMERA_WIDTH * 0.095f, CAMERA_HEIGHT * 0.2f);
|
||||
++menuObjectsSize;
|
||||
|
||||
RenderObject_t shadowOfAdam;
|
||||
RenderObject_t shadowOfAdam = EMPTY_RENDER_OBJECT;
|
||||
strcpy(legendOfAdam.name, "shadowOfAdam");
|
||||
SDL_Color black = {0, 0, 0, 255};
|
||||
text_renderText(&legendOfAdam, 8, 1.f, black, "./assets/fonts/Quinquefive.ttf", 48, "The legend of adame");
|
||||
@@ -91,14 +91,14 @@ int menu_render(float delta){
|
||||
blinkDelta = 0;
|
||||
}
|
||||
|
||||
RenderObject_t startTextShadow;
|
||||
RenderObject_t startTextShadow = EMPTY_RENDER_OBJECT;
|
||||
strcpy(startTextShadow.name, "StartTextShadow");
|
||||
SDL_Color black = {0, 0, 0, textOpacity};
|
||||
text_renderText(&startTextShadow, 9, 1.f, black, "./assets/fonts/Quinquefive.ttf", 28, "Press space to start");
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&menuScene, startTextShadow, CAMERA_WIDTH * 0.245f, CAMERA_HEIGHT * 0.855f);
|
||||
++menuObjectsSize;
|
||||
|
||||
RenderObject_t startText;
|
||||
RenderObject_t startText = EMPTY_RENDER_OBJECT;
|
||||
strcpy(startText.name, "StartText");
|
||||
SDL_Color orange = {255,165,0, textOpacity};
|
||||
text_renderText(&startText, 10, 1.f, orange, "./assets/fonts/Quinquefive.ttf", 28, "Press space to start");
|
||||
|
||||
+30
-2
@@ -1,5 +1,6 @@
|
||||
#include "renderer.h"
|
||||
#include "scene.h"
|
||||
#include <SDL2/SDL_blendmode.h>
|
||||
#include <SDL2/SDL_error.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
@@ -7,6 +8,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
const RenderObject_t EMPTY_RENDER_OBJECT = { 0, 0, 0, 0, NULL, "Undefined" };
|
||||
|
||||
static int compartSort(const SceneObject_t * a, const SceneObject_t * b) {
|
||||
return a->renderObj.z - b->renderObj.z;
|
||||
}
|
||||
@@ -15,6 +18,7 @@ void scene_render(const Scene_t * scene) {
|
||||
MonitorSize_t monitorSize = renderer_getMonitorSize();
|
||||
|
||||
for(int i = 0; i < scene->objectCount; i++) {
|
||||
printf("Rendering %d, %s\n", scene->objects[i].id, scene->objects[i].renderObj.name);
|
||||
const SceneObject_t * object = &scene->objects[i];
|
||||
float x = (object->x - scene->x) / CAMERA_WIDTH;
|
||||
float y = (object->y - scene->y) / CAMERA_HEIGHT;
|
||||
@@ -49,6 +53,8 @@ RenderId_t scene_addRenderObject(Scene_t * scene, RenderObject_t object, int x,
|
||||
scene->objectCount++;
|
||||
RenderId_t itemId = scene->lastId++;
|
||||
|
||||
printf("adding item: %s: %d\n", object.name, itemId);
|
||||
|
||||
if(scene->objectCount * sizeof(SceneObject_t) > scene->objectArraySize) {
|
||||
scene->objectArraySize = scene->objectCount * sizeof(SceneObject_t);
|
||||
scene->objects = realloc(scene->objects, scene->objectArraySize);
|
||||
@@ -73,7 +79,7 @@ RenderId_t scene_addRenderObject(Scene_t * scene, RenderObject_t object, int x,
|
||||
return itemId;
|
||||
}
|
||||
|
||||
void scene_removeRenderObject(Scene_t * scene, RenderId_t id) {
|
||||
static int indexof(Scene_t * scene, RenderId_t id) {
|
||||
bool found = false;
|
||||
int index = 0;
|
||||
for(int i = 0; i < scene->objectCount; i++) {
|
||||
@@ -85,8 +91,30 @@ void scene_removeRenderObject(Scene_t * scene, RenderId_t id) {
|
||||
}
|
||||
if(!found){
|
||||
printf("object %d not found\n", id);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
void scene_moveRenderObject(Scene_t * scene, RenderId_t id, float x, float y) {
|
||||
int index = indexof(scene, id);
|
||||
if(index < 0)
|
||||
return;
|
||||
|
||||
SceneObject_t * object = &scene->objects[index];
|
||||
object->x = x;
|
||||
object->y = y;
|
||||
}
|
||||
|
||||
void scene_removeRenderObject(Scene_t * scene, RenderId_t id) {
|
||||
int index = indexof(scene, id);
|
||||
if(index < 0)
|
||||
return;
|
||||
|
||||
printf("removing item: %s: %d\n", scene->objects[index].renderObj.name, id);
|
||||
|
||||
|
||||
scene->objectCount--;
|
||||
|
||||
for(int i = index; i < scene->objectCount; i++) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#define CAMERA_WIDTH 160
|
||||
#define CAMERA_HEIGHT 90
|
||||
|
||||
|
||||
typedef int RenderId_t;
|
||||
|
||||
typedef struct RenderObject {
|
||||
@@ -31,8 +32,11 @@ typedef struct Scene {
|
||||
float x,y;
|
||||
} Scene_t;
|
||||
|
||||
extern const RenderObject_t EMPTY_RENDER_OBJECT;
|
||||
|
||||
void scene_render(const Scene_t * scene);
|
||||
void scene_removeRenderObject(Scene_t * scene, RenderId_t id);
|
||||
void scene_moveRenderObject(Scene_t * scene, RenderId_t id, float x, float y);
|
||||
RenderId_t scene_addRenderObject(Scene_t * scene, RenderObject_t object, int x, int y);
|
||||
void scene_free(Scene_t * scene);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user