Render fixes + performance boost
This commit is contained in:
+23
-23
@@ -3,6 +3,7 @@
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <SDL2/SDL_surface.h>
|
||||
#include "scaller.h"
|
||||
#include "scene.h"
|
||||
|
||||
#define SPEED 1.f/10000000000
|
||||
#define GRAVITY 10000.f
|
||||
@@ -24,6 +25,8 @@ static float personPositionY = startPersonPositionY;
|
||||
static const float personVelocityX = 200;
|
||||
static float personVelocityY = 0;
|
||||
|
||||
static RenderObject_t person;
|
||||
static RenderId_t personId;
|
||||
|
||||
static void playMusic(){
|
||||
music = Mix_LoadMUS("./assets/music/jojo arab.mp3");
|
||||
@@ -53,46 +56,43 @@ 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);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int game_render([[maybe_unused]] float delta){
|
||||
//for(unsigned i = 0; i < menuObjectsSize; ++i){
|
||||
// scene_removeRenderObject(&gameScene, menuObjects[i]);
|
||||
//}
|
||||
menuObjectsSize = 0;
|
||||
|
||||
deltaAccu += delta;
|
||||
|
||||
|
||||
// if(!crashed && deltaAccu >= SPEED && isSpaceKeypressed){
|
||||
if(!crashed && isSpaceKeypressed){
|
||||
personPositionX += personVelocityX * delta;
|
||||
@@ -103,8 +103,8 @@ int game_render([[maybe_unused]] float delta){
|
||||
personPositionY += personVelocityY * delta;
|
||||
if(personPositionY + CAMERA_HEIGHT * person.height >= CAMERA_HEIGHT - 2) crashed = true;
|
||||
}
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&gameScene, person, personPositionX, personPositionY);
|
||||
++menuObjectsSize;
|
||||
|
||||
scene_moveRenderObject(&gameScene, personId, personPositionX, personPositionY);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user