This repository has been archived on 2022-01-13. You can view files and clone it, but cannot push or open issues or pull requests.
jtmm2-old/src/player.c
KikooDX 65ceff3971 Lot of bugfixes and improvements :)
- [input] Completely rewrote most of the code
- [input/camera] Renamed `*_draw` functions used in debug section to
`*_draw_debug`
- [main/input] Now use `_Bool` instead of `int` when appropriate
- [input] Added function `input_is_up`
- [player] Added function `player_draw_debug`
- [vec] Use `int` instead of `float`, new macro `VEC_PRECISION`
- [main/camera/player/vec] Updated vector related code to work with the
new system
2020-09-18 11:12:34 +02:00

48 lines
1.3 KiB
C

#include <gint/display.h>
#include "player.h"
#include "camera.h"
#include "input.h"
void player_step(Player *player, Input *input)
{
Vec move = {
(input_is_down(input, K_RIGHT) - input_is_down(input, K_LEFT)) * VEC_PRECISION,
(input_is_down(input, K_DOWN) - input_is_down(input, K_UP)) * VEC_PRECISION
};
#ifdef FX9860G
vec_div(&move, 50);
#endif /* FX9860G */
#ifdef FXCG50
vec_mul(&move, 2);
#endif /* FXCG50 */
vec_add(&player->pos, move);
}
void player_draw(Player *player, Camera *camera)
{
Vec draw_pos_tl;
Vec draw_pos_br;
vec_cpy(&draw_pos_tl, player->pos);
vec_sub(&draw_pos_tl, player->origin);
vec_cpy(&draw_pos_br, draw_pos_tl);
vec_add(&draw_pos_br, player->hbox);
vec_div(&draw_pos_tl, VEC_PRECISION);
vec_div(&draw_pos_br, VEC_PRECISION);
#ifdef FX9860G
drect(draw_pos_tl.x, draw_pos_tl.y, draw_pos_br.x, draw_pos_br.y, C_LIGHT);
#endif /* FX9860G */
#ifdef FXCG50
drect(draw_pos_tl.x, draw_pos_tl.y, draw_pos_br.x, draw_pos_br.y, C_BLACK);
#endif /* FXCG50 */
}
void player_draw_debug(Player *player)
{
dprint(0, 0, C_BLACK, "x: %d", player->pos.x);
dprint(0, 10, C_BLACK, "y: %d", player->pos.y);
dprint(0, 20, C_BLACK, "tx: %d", player->pos.x / VEC_PRECISION);
dprint(0, 30, C_BLACK, "ty: %d", player->pos.y / VEC_PRECISION);
dprint(0, 40, C_BLACK, "vp: %d", VEC_PRECISION);
}