Sa marche !!!!
This commit is contained in:
+8
-4
@@ -15,7 +15,7 @@ static bool increaseTextBrightness = false;
|
||||
static Uint8 textOpacity = 255;
|
||||
|
||||
|
||||
Scene_t menuScene;
|
||||
Scene_t menuScene = { NULL, 0, 0, 0 };
|
||||
|
||||
int menu_staticRender(void){
|
||||
MonitorSize_t size = renderer_getMonitorSize();
|
||||
@@ -29,11 +29,12 @@ int menu_staticRender(void){
|
||||
}
|
||||
|
||||
RenderObject_t backgroundImage;
|
||||
strcpy(backgroundImage.name, "BackgroundImg");
|
||||
backgroundImage.z = 0;
|
||||
backgroundImage.surface = backgroundImageSurface;
|
||||
backgroundImage.width = 1;
|
||||
backgroundImage.height = 1;
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&menuScene, backgroundImage, CAMERA_WIDTH/2, CAMERA_HEIGHT/2);
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&menuScene, backgroundImage, 0, 0);
|
||||
renderer_setScene(&menuScene);
|
||||
++menuObjectsSize;
|
||||
return 0;
|
||||
@@ -58,16 +59,19 @@ int menu_render(float delta){
|
||||
if(textOpacity == 1) increaseTextBrightness = true;
|
||||
blinkDelta = 0;
|
||||
}
|
||||
|
||||
RenderObject_t startTextShadow;
|
||||
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.495f, CAMERA_HEIGHT * 0.855f);
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&menuScene, startTextShadow, CAMERA_WIDTH * 0.245f, CAMERA_HEIGHT * 0.855f);
|
||||
++menuObjectsSize;
|
||||
|
||||
RenderObject_t startText;
|
||||
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");
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&menuScene, startText, CAMERA_WIDTH * 0.5f, CAMERA_HEIGHT * 0.85f);
|
||||
menuObjects[menuObjectsSize] = scene_addRenderObject(&menuScene, startText, CAMERA_WIDTH * 0.25f, CAMERA_HEIGHT * 0.85f);
|
||||
++menuObjectsSize;
|
||||
return 0;
|
||||
}
|
||||
|
||||
+17
-8
@@ -1,5 +1,9 @@
|
||||
#include "renderer.h"
|
||||
#include "scene.h"
|
||||
#include <SDL2/SDL_error.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_surface.h>
|
||||
|
||||
static int compartSort(const SceneObject_t * a, const SceneObject_t * b) {
|
||||
return a->renderObj.z - b->renderObj.z;
|
||||
@@ -7,18 +11,22 @@ static int compartSort(const SceneObject_t * a, const SceneObject_t * b) {
|
||||
|
||||
void scene_render(Scene_t * scene) {
|
||||
MonitorSize_t monitorSize = renderer_getMonitorSize();
|
||||
int minX = scene->x - CAMERA_WIDTH/2;
|
||||
int minY = scene->y - CAMERA_HEIGHT/2;
|
||||
int maxX = scene->x - CAMERA_WIDTH/2;
|
||||
int maxY = scene->y - CAMERA_HEIGHT/2;
|
||||
int minScanX = scene->x - CAMERA_WIDTH;
|
||||
int minScanY = scene->y - CAMERA_HEIGHT;
|
||||
int maxScanX = scene->x + CAMERA_WIDTH;
|
||||
int maxScanY = scene->y + CAMERA_HEIGHT;
|
||||
|
||||
printf("camera: %d %d %d %d\n", minScanX, minScanY, maxScanX, maxScanY);
|
||||
|
||||
for(int i = 0; i < scene->objectCount; i++) {
|
||||
SceneObject_t * object = &scene->objects[i];
|
||||
if(object->x > minX && object->x < maxX && object->y > minY && object->y < maxY) {
|
||||
int x = (object->x - minX) / CAMERA_WIDTH;
|
||||
int y = (object->y - minY) / CAMERA_HEIGHT;
|
||||
if(object->x > minScanX && object->x < maxScanX && object->y > minScanY && object->y < maxScanY) {
|
||||
float x = (object->x) / CAMERA_WIDTH;
|
||||
float y = (object->y) / CAMERA_HEIGHT;
|
||||
//the object is to be rendered
|
||||
|
||||
printf("%f %f\n", x, y);
|
||||
|
||||
SDL_Rect rect = {
|
||||
round(x * monitorSize.width) ,
|
||||
round(y * monitorSize.height),
|
||||
@@ -47,6 +55,7 @@ static void buildCache(SceneObject_t * object) {
|
||||
|
||||
RenderId_t scene_addRenderObject(Scene_t * scene, RenderObject_t object, int x, int y) {
|
||||
RenderId_t itemId = scene->objectCount++;
|
||||
printf("Adding: %s\n", object.name);
|
||||
scene->objects = realloc(scene->objects, scene->objectCount * sizeof(SceneObject_t));
|
||||
|
||||
SceneObject_t item = {
|
||||
@@ -60,7 +69,7 @@ RenderId_t scene_addRenderObject(Scene_t * scene, RenderObject_t object, int x,
|
||||
|
||||
scene->objects[itemId] = item;
|
||||
//the objects are sorted
|
||||
qsort(scene->objects, scene->objectCount, sizeof(RenderObject_t), (__compar_fn_t)compartSort);
|
||||
qsort(scene->objects, scene->objectCount, sizeof(SceneObject_t), (__compar_fn_t)compartSort);
|
||||
return itemId;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ typedef struct RenderObject {
|
||||
float width, height; //ratio between 0 & 1 of the monitor resolution
|
||||
float angle_degre;
|
||||
SDL_Surface * surface;
|
||||
char name[40];
|
||||
} RenderObject_t;
|
||||
|
||||
typedef struct SceneObject {
|
||||
|
||||
Reference in New Issue
Block a user