mirror of
https://github.com/zoriya/Gamacon.git
synced 2026-06-03 04:02:35 +00:00
Adding a scaler
This commit is contained in:
@@ -23,7 +23,9 @@ SRC = src/engine/engine.c \
|
||||
src/utility/tostr.c \
|
||||
src/utility/atoi.c \
|
||||
src/utility/my_strchr.c \
|
||||
src/utility/intparser.c \
|
||||
src/utility/parsers/intparser.c \
|
||||
src/utility/parsers/floatparser.c \
|
||||
src/utility/parsers/stringparser.c \
|
||||
src/utility/my_strcmp.c \
|
||||
src/utility/pow.c \
|
||||
src/utility/read_line.c \
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
|
||||
#include "component.h"
|
||||
#include "texture.h"
|
||||
#include "vector2.h"
|
||||
|
||||
struct texture_renderer
|
||||
{
|
||||
gc_component base;
|
||||
gc_texture *texture;
|
||||
gc_vector2 scale;
|
||||
};
|
||||
|
||||
extern const struct texture_renderer texture_renderer;
|
||||
+1
-1
@@ -20,7 +20,7 @@ struct gc_engine
|
||||
bool (*is_open)(gc_engine *engine);
|
||||
int (*game_loop)(gc_engine *engine);
|
||||
int (*change_scene)(gc_engine *engine, gc_scene *scene);
|
||||
void (*draw_texture)(gc_engine *, gc_texture *, gc_vector2);
|
||||
void (*draw_texture)(gc_engine *, gc_texture *, gc_vector2, gc_vector2);
|
||||
|
||||
sfRenderWindow *window;
|
||||
sfSprite *sprite;
|
||||
|
||||
+1
-1
@@ -11,4 +11,4 @@
|
||||
|
||||
void renderer_draw(gc_engine *engine);
|
||||
gc_texture *texture_create(const char *path);
|
||||
void renderer_draw_texture(gc_engine *engine, gc_texture *text, gc_vector2 pos);
|
||||
void renderer_draw_texture(gc_engine *, gc_texture *, gc_vector2, gc_vector2);
|
||||
+3
-1
@@ -15,5 +15,7 @@ int my_atoi(const char *str);
|
||||
int my_strcmp(const char *str1, const char *str2);
|
||||
int my_strncmp(const char *str1, const char *str2, int n);
|
||||
char *my_strchr(const char *str, char c);
|
||||
int parse_int(char **str);
|
||||
int parse_arg_int(char **str);
|
||||
float parse_arg_float(char **str);
|
||||
char *parse_arg_str(char **str);
|
||||
int my_pow(int nb, int p);
|
||||
@@ -23,9 +23,9 @@ static void movable_fdctr(gc_engine *engine, void *component, char *args)
|
||||
{
|
||||
struct movable_component *cmp = (struct movable_component *)component;
|
||||
|
||||
cmp->left_key = parse_int(&args);
|
||||
cmp->right_key = parse_int(&args);
|
||||
cmp->jump_key = parse_int(&args);
|
||||
cmp->left_key = parse_arg_int(&args);
|
||||
cmp->right_key = parse_arg_int(&args);
|
||||
cmp->jump_key = parse_arg_int(&args);
|
||||
(void)engine;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ void position_fdctr(gc_engine *engine, void *component, char *args)
|
||||
{
|
||||
struct position_component *cmp = (struct position_component *)component;
|
||||
|
||||
cmp->position.x = parse_int(&args);
|
||||
cmp->position.y = parse_int(&args);
|
||||
cmp->position.x = parse_arg_int(&args);
|
||||
cmp->position.y = parse_arg_int(&args);
|
||||
(void)engine;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include "utility.h"
|
||||
#include "components/position_component.h"
|
||||
#include "components/texture_renderer.h"
|
||||
|
||||
@@ -14,13 +15,17 @@ static void texture_rend_ctr(void *component, va_list args)
|
||||
struct texture_renderer *cmp = (struct texture_renderer *)component;
|
||||
|
||||
cmp->texture = va_arg(args, gc_texture *);
|
||||
cmp->scale.x = va_arg(args, double);
|
||||
cmp->scale.y = va_arg(args, double);
|
||||
}
|
||||
|
||||
static void texture_rend_fdctr(gc_engine *engine, void *component, char *args)
|
||||
{
|
||||
struct texture_renderer *cmp = (struct texture_renderer *)component;
|
||||
|
||||
cmp->texture = get_texture(engine, args);
|
||||
cmp->texture = get_texture(engine, parse_arg_str(&args));
|
||||
cmp->scale.x = parse_arg_float(&args);
|
||||
cmp->scale.y = parse_arg_float(&args);
|
||||
}
|
||||
|
||||
static void texture_rend_dtr(void *component)
|
||||
@@ -48,4 +53,5 @@ const struct texture_renderer texture_renderer = {
|
||||
prev: NULL
|
||||
},
|
||||
texture: NULL,
|
||||
scale: {0, 0}
|
||||
};
|
||||
@@ -16,6 +16,8 @@ gc_entity *prefab_load(gc_engine *engine, const char *path)
|
||||
gc_entity *entity;
|
||||
int fd = open(path, O_RDONLY);
|
||||
|
||||
if (fd == -1)
|
||||
return (NULL);
|
||||
entity = deserialize_entity(engine, fd);
|
||||
close(fd);
|
||||
return (entity);
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
#include <SFML/Graphics.h>
|
||||
|
||||
|
||||
void renderer_draw_texture(gc_engine *engine, gc_texture *text, gc_vector2 pos)
|
||||
void renderer_draw_texture(gc_engine *engine, gc_texture *text, \
|
||||
gc_vector2 pos, gc_vector2 scale)
|
||||
{
|
||||
if (!text)
|
||||
return;
|
||||
sfSprite_setTexture(engine->sprite, text->texture, true);
|
||||
sfSprite_setPosition(engine->sprite, (sfVector2f){pos.x, pos.y});
|
||||
sfSprite_setScale(engine->sprite, (sfVector2f){scale.x, scale.y});
|
||||
sfRenderWindow_drawSprite(engine->window, engine->sprite, NULL);
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -32,14 +32,16 @@ int scene_add_entity(gc_scene *scene, gc_entity *entity)
|
||||
int scene_load_textures(gc_scene *scene, const char **textures)
|
||||
{
|
||||
gc_texture *texture;
|
||||
int len = arraylen(textures) + 1;
|
||||
|
||||
scene->textures = malloc(sizeof(gc_texture) * (arraylen(textures)));
|
||||
scene->textures = malloc(sizeof(gc_texture) * len);
|
||||
for (int i = 0; textures[i]; i++) {
|
||||
texture = texture_create(textures[i]);
|
||||
if (!texture)
|
||||
return (-1);
|
||||
scene->textures[i] = texture;
|
||||
}
|
||||
scene->textures[len - 1] = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -49,7 +51,8 @@ gc_scene *scene_create(const char **textures)
|
||||
|
||||
if (!scene)
|
||||
return (NULL);
|
||||
if (scene_load_textures(scene, textures) < 0)
|
||||
scene->textures = NULL;
|
||||
if (textures && scene_load_textures(scene, textures) < 0)
|
||||
return (NULL);
|
||||
scene->entities = NULL;
|
||||
scene->add_entity = &scene_add_entity;
|
||||
|
||||
@@ -20,7 +20,7 @@ void tex_rend_update_entity(gc_engine *engine, gc_entity *entity)
|
||||
struct texture_renderer *text = (\
|
||||
struct texture_renderer *)entity->get_component(entity, "TextureRenderer");
|
||||
|
||||
engine->draw_texture(engine, text->texture, pos->position);
|
||||
engine->draw_texture(engine, text->texture, pos->position, text->scale);
|
||||
}
|
||||
|
||||
const gc_system texture_renderer_system = {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** floatparser
|
||||
*/
|
||||
|
||||
#include "utility.h"
|
||||
|
||||
int get_int_size(int n)
|
||||
{
|
||||
int base_size = my_strlen("0123456789");
|
||||
int i = 1;
|
||||
|
||||
while (n >= base_size) {
|
||||
n /= base_size;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
float parse_arg_float(char **str)
|
||||
{
|
||||
int i = parse_arg_int(str);
|
||||
int decimal = 0;
|
||||
|
||||
if ((*str)[-1] == '.') {
|
||||
decimal = parse_arg_int(str);
|
||||
return i + ((float)decimal / (get_int_size(decimal) * 10));
|
||||
}
|
||||
return ((float)i);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ int parse_end(char **str, int strlen, int start, int mult)
|
||||
return (nbr);
|
||||
}
|
||||
|
||||
int parse_int(char **str)
|
||||
int parse_arg_int(char **str)
|
||||
{
|
||||
int strlen = 0;
|
||||
int start = -1;
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** stringparser
|
||||
*/
|
||||
|
||||
#include "utility.h"
|
||||
|
||||
char *parse_arg_str(char **str)
|
||||
{
|
||||
char *p = my_strchr(*str, ' ');
|
||||
char *tmp = *str;
|
||||
|
||||
if (!p)
|
||||
return (*str);
|
||||
*p = '\0';
|
||||
*str = p + 1;
|
||||
return (tmp);
|
||||
}
|
||||
Reference in New Issue
Block a user