mirror of
https://github.com/zoriya/Gamacon.git
synced 2026-05-29 18:03:52 +00:00
Adding % to the fixed to cam component
This commit is contained in:
@@ -13,7 +13,9 @@
|
||||
struct fixed_to_cam
|
||||
{
|
||||
gc_component base;
|
||||
gc_vector2 offset;
|
||||
gc_vector2 pos;
|
||||
bool per_x;
|
||||
bool per_y;
|
||||
};
|
||||
|
||||
extern const struct fixed_to_cam fixed_to_cam;
|
||||
@@ -15,16 +15,21 @@ static void ctr(void *component, va_list args)
|
||||
{
|
||||
struct fixed_to_cam *cmp = (struct fixed_to_cam *)component;
|
||||
|
||||
cmp->offset = va_arg(args, gc_vector2);
|
||||
cmp->pos = va_arg(args, gc_vector2);
|
||||
}
|
||||
|
||||
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
|
||||
{
|
||||
struct fixed_to_cam *cmp = (struct fixed_to_cam *)component;
|
||||
char *tmp;
|
||||
|
||||
n = xml_getnode(n, "Position");
|
||||
cmp->offset.x = xml_getintprop(n, "x");
|
||||
cmp->offset.y = xml_getintprop(n, "y");
|
||||
cmp->pos.x = xml_getintprop(n, "x");
|
||||
cmp->pos.y = xml_getintprop(n, "y");
|
||||
tmp = xml_gettempprop(n, "x");
|
||||
cmp->per_x = tmp && my_strchr(tmp, '%');
|
||||
tmp = xml_gettempprop(n, "y");
|
||||
cmp->per_y = tmp && my_strchr(tmp, '%');
|
||||
(void)scene;
|
||||
(void)entity;
|
||||
}
|
||||
@@ -49,5 +54,5 @@ const struct fixed_to_cam fixed_to_cam = {
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
},
|
||||
offset: (gc_vector2){0, 0}
|
||||
pos: (gc_vector2){0, 0}
|
||||
};
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "text.h"
|
||||
#include "components/transform_component.h"
|
||||
#include "systems/sfml_renderer_system.h"
|
||||
#include "my.h"
|
||||
#include <SFML/Graphics.h>
|
||||
|
||||
void sfmlrenderer_draw_texture(struct sfml_renderer_system *renderer, \
|
||||
@@ -59,11 +60,16 @@ struct transform_component *tra, gc_animholder *holder, float dtime)
|
||||
void sfmlrenderer_draw_txt(struct sfml_renderer_system *renderer, \
|
||||
struct transform_component *tra, gc_text *txt)
|
||||
{
|
||||
sfText_setString(renderer->text, txt->text);
|
||||
sfFloatRect bounds;
|
||||
|
||||
sfText_setString(renderer->text, txt->text);
|
||||
if (!txt->font)
|
||||
my_printf("%s has a font not loaded. Rendering impossible.", txt->font);
|
||||
sfText_setFont(renderer->text, txt->font);
|
||||
bounds = sfText_getLocalBounds(renderer->text);
|
||||
sfText_setPosition(renderer->text, (sfVector2f){
|
||||
tra->position.x,
|
||||
-tra->position.y
|
||||
tra->position.x - bounds.width / 2,
|
||||
-tra->position.y - bounds.height / 2
|
||||
});
|
||||
sfRenderWindow_drawText(renderer->window, renderer->text, NULL);
|
||||
}
|
||||
@@ -21,20 +21,20 @@ struct sfml_renderer_system *renderer, struct camerafollow_system *cam)
|
||||
gc_list *list;
|
||||
gc_entity *entity;
|
||||
sfVector2f size;
|
||||
gc_vector2 offset;
|
||||
struct transform_component *tra;
|
||||
struct fixed_to_cam *fc;
|
||||
|
||||
list = scene->get_entity_by_cmp(scene, "fixed_to_cam");
|
||||
for (gc_list *li = list; li; li = li->next) {
|
||||
entity = (gc_entity *)li->data;
|
||||
tra = GETCMP(transform_component);
|
||||
if (!tra)
|
||||
fc = GETCMP(fixed_to_cam);
|
||||
if (!tra)
|
||||
continue;
|
||||
size = sfView_getSize(renderer->view);
|
||||
offset = GETCMP(fixed_to_cam)->offset;
|
||||
tra->position = (gc_vector2) {
|
||||
cam->cam_pos.x - size.x / 2 + offset.x,
|
||||
cam->cam_pos.y + size.y / 2 - offset.y,
|
||||
(cam->cam_pos.x - size.x / 2 + fc->pos.x) * fc->per_x ? size.x / 100 : 1,
|
||||
(cam->cam_pos.y + size.y / 2 - fc->pos.y) * fc->per_y ? size.y / 100 : 1
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user