mirror of https://github.com/bgiraudr/Adoranda.git
player moves separatly from camera
This commit is contained in:
parent
ecb14f5cd2
commit
e8b5b1557a
|
@ -20,6 +20,7 @@ struct Vec2f {
|
|||
struct Vec2 vec2_add(struct Vec2, struct Vec2);
|
||||
struct Vec2f vec2f_add(struct Vec2f, struct Vec2f);
|
||||
struct Vec2 vec2_sub(struct Vec2, struct Vec2);
|
||||
struct Vec2f vec2f_sub(struct Vec2f, struct Vec2f);
|
||||
struct Vec2 vec2_mul(struct Vec2, int scale);
|
||||
struct Vec2f vec2f_mul(struct Vec2f, int scale);
|
||||
struct Vec2 vec2f_vec2(struct Vec2f);
|
||||
|
|
|
@ -11,6 +11,6 @@ struct Camera camera_new(struct Vec2f *target) {
|
|||
}
|
||||
|
||||
void camera_update(struct Camera *c) {
|
||||
c->pos = vec2f_lerp(c->pos, *c->target, 0.2);
|
||||
c->pos = vec2f_lerp(c->pos, *c->target, 0.05);
|
||||
c->offset = vec2f_vec2(c->pos);
|
||||
}
|
||||
|
|
25
src/engine.c
25
src/engine.c
|
@ -58,22 +58,25 @@ void engine_draw_map(struct Game const *game) {
|
|||
}
|
||||
|
||||
/*draw the player*/
|
||||
void engine_draw_player(struct Game const *game) {
|
||||
if(is_map_larger(game->map)) {
|
||||
dframe(game->player->show_x * TILE_SIZE,
|
||||
game->player->show_y * TILE_SIZE - 5,
|
||||
game->player->anim.img); //draw the player 5 pixel up
|
||||
void engine_draw_player(struct Game const *g) {
|
||||
struct Vec2f draw_offset = vec2f_sub(g->player->pos_visual, vec2_vec2f(g->camera.offset));
|
||||
draw_offset.x += g->player->anim.dx * 3;
|
||||
draw_offset.y += g->player->anim.dy * 3;
|
||||
if(is_map_larger(g->map)) {
|
||||
dframe(g->player->show_x * TILE_SIZE + draw_offset.x,
|
||||
g->player->show_y * TILE_SIZE - 5 + draw_offset.y,
|
||||
g->player->anim.img); //draw the player 5 pixel up
|
||||
|
||||
} else {
|
||||
const int offset_map_x = (DWIDTH / TILE_SIZE - game->map->w + 1)/2;
|
||||
const int offset_map_y = (DHEIGHT / TILE_SIZE - game->map->h + 1)/2;
|
||||
const int offset_map_x = (DWIDTH / TILE_SIZE - g->map->w + 1)/2;
|
||||
const int offset_map_y = (DHEIGHT / TILE_SIZE - g->map->h + 1)/2;
|
||||
|
||||
dframe(
|
||||
(game->player->pos.x + offset_map_x) * TILE_SIZE + game->player->anim.dx*3,
|
||||
(game->player->pos.y + offset_map_y) * TILE_SIZE - 5 + game->player->anim.dy*3,
|
||||
game->player->anim.img); //draw the player 5 pixel up
|
||||
(g->player->pos.x + offset_map_x) * TILE_SIZE + g->player->anim.dx*3,
|
||||
(g->player->pos.y + offset_map_y) * TILE_SIZE - 5 + g->player->anim.dy*3,
|
||||
g->player->anim.img); //draw the player 5 pixel up
|
||||
}
|
||||
dprint(1,1,C_BLACK,"%d:%d",game->player->pos.x, game->player->pos.y);
|
||||
dprint(1,1,C_BLACK,"%d:%d",g->player->pos.x, g->player->pos.y);
|
||||
}
|
||||
|
||||
/*move the player to the direction*/
|
||||
|
|
|
@ -18,6 +18,12 @@ vec2_sub(struct Vec2 v1, struct Vec2 v2)
|
|||
return VEC2(v1.x - v2.x, v1.y - v2.y);
|
||||
}
|
||||
|
||||
struct Vec2f
|
||||
vec2f_sub(struct Vec2f v1, struct Vec2f v2)
|
||||
{
|
||||
return VEC2F(v1.x - v2.x, v1.y - v2.y);
|
||||
}
|
||||
|
||||
struct Vec2
|
||||
vec2_mul(struct Vec2 v, int scale)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue