mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
fixed rounding errors in the character core causing it to favour certain directions
This commit is contained in:
parent
c7be15caeb
commit
cff4feea6b
|
@ -19,6 +19,13 @@ inline float sign(float f)
|
|||
return f<0.0f?-1.0f:1.0f;
|
||||
}
|
||||
|
||||
inline int round(float f)
|
||||
{
|
||||
if(f > 0)
|
||||
return (int)(f+0.5f);
|
||||
return (int)(f-0.5f);
|
||||
}
|
||||
|
||||
template<typename T, typename TB>
|
||||
inline T mix(const T a, const T b, TB amount)
|
||||
{
|
||||
|
|
|
@ -186,9 +186,9 @@ void CHARACTER_CORE::tick(bool use_input)
|
|||
|
||||
// get ground state
|
||||
bool grounded = false;
|
||||
if(col_check_point((int)(pos.x+phys_size/2), (int)(pos.y+phys_size/2+5)))
|
||||
if(col_check_point(pos.x+phys_size/2, pos.y+phys_size/2+5))
|
||||
grounded = true;
|
||||
if(col_check_point((int)(pos.x-phys_size/2), (int)(pos.y+phys_size/2+5)))
|
||||
if(col_check_point(pos.x-phys_size/2, pos.y+phys_size/2+5))
|
||||
grounded = true;
|
||||
|
||||
vec2 target_direction = normalize(vec2(input.target_x, input.target_y));
|
||||
|
@ -466,16 +466,17 @@ void CHARACTER_CORE::move()
|
|||
|
||||
void CHARACTER_CORE::write(NETOBJ_CHARACTER_CORE *obj_core)
|
||||
{
|
||||
obj_core->x = (int)pos.x;
|
||||
obj_core->y = (int)pos.y;
|
||||
obj_core->vx = (int)(vel.x*256.0f);
|
||||
obj_core->vy = (int)(vel.y*256.0f);
|
||||
obj_core->x = round(pos.x);
|
||||
obj_core->y = round(pos.y);
|
||||
|
||||
obj_core->vx = round(vel.x*256.0f);
|
||||
obj_core->vy = round(vel.y*256.0f);
|
||||
obj_core->hook_state = hook_state;
|
||||
obj_core->hook_tick = hook_tick;
|
||||
obj_core->hook_x = (int)hook_pos.x;
|
||||
obj_core->hook_y = (int)hook_pos.y;
|
||||
obj_core->hook_dx = (int)(hook_dir.x*256.0f);
|
||||
obj_core->hook_dy = (int)(hook_dir.y*256.0f);
|
||||
obj_core->hook_x = round(hook_pos.x);
|
||||
obj_core->hook_y = round(hook_pos.y);
|
||||
obj_core->hook_dx = round(hook_dir.x*256.0f);
|
||||
obj_core->hook_dy = round(hook_dir.y*256.0f);
|
||||
obj_core->hooked_player = hooked_player;
|
||||
obj_core->jumped = jumped;
|
||||
obj_core->direction = direction;
|
||||
|
|
|
@ -194,7 +194,7 @@ public:
|
|||
#define min(a, b) ( a > b ? b : a)
|
||||
#define max(a, b) ( a > b ? a : b)
|
||||
|
||||
inline bool col_check_point(float x, float y) { return col_is_solid((int)x, (int)y) != 0; }
|
||||
inline bool col_check_point(float x, float y) { return col_is_solid(round(x), round(y)) != 0; }
|
||||
inline bool col_check_point(vec2 p) { return col_check_point(p.x, p.y); }
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue