mirror of
https://github.com/zoriya/ForecastingVillage.git
synced 2026-05-25 23:58:47 +00:00
Smoothing player movements
This commit is contained in:
@@ -15,7 +15,6 @@ struct controllable_component
|
||||
gc_component base;
|
||||
int movement_x;
|
||||
int movement_y;
|
||||
float move_callback;
|
||||
bool can_move;
|
||||
};
|
||||
|
||||
|
||||
+1
-1
Submodule lib/gamacon updated: d1a8a904a4...8d091a9575
@@ -18,7 +18,6 @@ component;
|
||||
|
||||
cmp->movement_x = 0;
|
||||
cmp->movement_y = 0;
|
||||
cmp->move_callback = 0;
|
||||
cmp->can_move = true;
|
||||
(void)args;
|
||||
}
|
||||
@@ -31,7 +30,6 @@ component;
|
||||
|
||||
cmp->movement_x = 0;
|
||||
cmp->movement_y = 0;
|
||||
cmp->move_callback = 0;
|
||||
(void)scene;
|
||||
(void)entity;
|
||||
(void)n;
|
||||
|
||||
@@ -14,22 +14,33 @@
|
||||
#include <utility.h>
|
||||
#include <components/renderer.h>
|
||||
#include <stddef.h>
|
||||
#include <components/transform_component.h>
|
||||
|
||||
static gc_vector2i get_new_map_pos(struct map_linker *link, \
|
||||
struct controllable_component *ctl)
|
||||
{
|
||||
if (!link->tile)
|
||||
return ((gc_vector2i){0, 0});
|
||||
gc_vector2i pos = (gc_vector2i) {
|
||||
link->tile->corners[0]->x,
|
||||
link->tile->corners[0]->y
|
||||
};
|
||||
gc_vector2i move = (gc_vector2i){
|
||||
round(cos(-45) * -ctl->movement_x - sin(-45) * ctl->movement_y),
|
||||
round(sin(-45) * -ctl->movement_x + cos(-45) * ctl->movement_y),
|
||||
};
|
||||
gc_vector2i moves = (gc_vector2i){0, 0};
|
||||
|
||||
return (gc_vector2i_add(pos, move));
|
||||
link->offset = gc_vector2i_add(link->offset, (gc_vector2i){
|
||||
round(cos(-45) * -ctl->movement_x - sin(-45) * -ctl->movement_y),
|
||||
round(sin(-45) * -ctl->movement_x + cos(-45) * -ctl->movement_y)
|
||||
});
|
||||
moves.x = (link->offset.x / 9) % 9;
|
||||
moves.y = -(link->offset.y / 9) % 9;
|
||||
// if (moves.x != 0 || moves.y != 0)
|
||||
// printf("Moves: %d, %d, Offsets: %d, %d\n", moves[0], moves[1], link->offset.x, link->offset.y);
|
||||
if (link->offset.x > 8)
|
||||
link->offset.x = -8;
|
||||
if (link->offset.x < -8)
|
||||
link->offset.x = 8;
|
||||
if (link->offset.y > 8)
|
||||
link->offset.y = -8;
|
||||
if (link->offset.y < -8)
|
||||
link->offset.y = 8;
|
||||
return (gc_vector2i_add((gc_vector2i){
|
||||
link->tile->corners[0]->x, link->tile->corners[0]->y}, (gc_vector2i){moves.y, -moves.x}));
|
||||
}
|
||||
|
||||
void set_animation(gc_entity *entity, struct controllable_component *ctl)
|
||||
@@ -62,25 +73,22 @@ float dtime)
|
||||
{
|
||||
struct controllable_component *ctl = GETCMP(entity, controllable_component);
|
||||
struct map_linker *link = GETCMP(entity, map_linker);
|
||||
gc_vector2i map_pos = get_new_map_pos(link, ctl);
|
||||
gc_scene *scene = engine->scene;
|
||||
gc_list *maps = scene->get_entity_by_cmp(scene, "vertex_component");
|
||||
struct vertex_component *map;
|
||||
gc_vector2i map_pos = get_new_map_pos(link, ctl);
|
||||
struct tile *new_tile;
|
||||
|
||||
if (!maps || !ctl->can_move)
|
||||
return;
|
||||
set_animation(entity, ctl);
|
||||
map = GETCMP(maps->data, vertex_component);
|
||||
new_tile = get_tile_at(map, map_pos);
|
||||
set_animation(entity, ctl);
|
||||
if (new_tile && !new_tile->solid && ctl->move_callback <= 0 \
|
||||
&& new_tile != link->tile) {
|
||||
if (new_tile && !new_tile->solid && new_tile != link->tile) { //CHECK FOR OVERFLOW
|
||||
link->tile->entity = NULL;
|
||||
new_tile->entity = entity;
|
||||
engine->trigger_event(engine, "entity_moved", entity, link->tile);
|
||||
ctl->move_callback = .2f;
|
||||
}
|
||||
ctl->move_callback -= dtime;
|
||||
}
|
||||
|
||||
static void ctr(void *system, va_list list)
|
||||
|
||||
Reference in New Issue
Block a user