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