35 lines
734 B
C
35 lines
734 B
C
#include "entity.h"
|
|
#include "layers.h"
|
|
#include "player.h"
|
|
#include <gint/keyboard.h>
|
|
|
|
void
|
|
player_update(struct Player *p)
|
|
{
|
|
int collided;
|
|
const int dir_x = keydown(KEY_RIGHT) - keydown(KEY_LEFT);
|
|
const int dir_y = keydown(KEY_DOWN) - keydown(KEY_UP);
|
|
|
|
p->spd_x += dir_x * 0.1;
|
|
p->spd_y += dir_y * 0.1;
|
|
|
|
/* rem */
|
|
const float spd_n_rem_x = p->spd_x + p->rem_x;
|
|
const int spd_x = spd_n_rem_x;
|
|
p->rem_x = spd_n_rem_x - spd_x;
|
|
const float spd_n_rem_y = p->spd_y + p->rem_y;
|
|
const int spd_y = spd_n_rem_y;
|
|
p->rem_y = spd_n_rem_y - spd_y;
|
|
|
|
/* move */
|
|
collided = entity_move(p, L_SOLID, spd_x, spd_y);
|
|
if (collided & 1) {
|
|
p->spd_x = 0.0;
|
|
p->rem_x = 0.0;
|
|
}
|
|
if (collided & 2) {
|
|
p->spd_y = 0.0;
|
|
p->rem_y = 0.0;
|
|
}
|
|
}
|