fixed nan issue in player
parent
1034fff697
commit
1021d04013
|
@ -15,10 +15,11 @@ object_t* player_instance = NULL;
|
|||
void player_update(object_t *object) {
|
||||
float m = sqrtf(player_move_x*player_move_x + player_move_y*player_move_y);
|
||||
if(m == FP_NAN) m = 1;
|
||||
player_xv = player_move_x * 10.f / m,
|
||||
player_yv = player_move_y * 10.f / m;
|
||||
object->sprite.x += player_xv* delta_time();
|
||||
object->sprite.y += player_yv* delta_time();
|
||||
m = 1.f/m;
|
||||
player_xv = player_move_x * 3.f * m,
|
||||
player_yv = player_move_y * 3.f * m;
|
||||
object->sprite.x += player_xv * delta_time();
|
||||
object->sprite.y += player_yv * delta_time();
|
||||
}
|
||||
|
||||
object_t* create_player() {
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
|
||||
struct object_t;
|
||||
|
||||
extern float player_move_x;
|
||||
extern float player_move_y;
|
||||
extern float player_xv;
|
||||
extern float player_yv;
|
||||
extern float player_move_x, player_move_y,
|
||||
player_xv, player_yv;
|
||||
extern struct object_t* player_instance;
|
||||
|
||||
void player_update(struct object_t* object);
|
||||
|
|
Loading…
Reference in New Issue