From a21ae8219e67783c52ba5f415e1ca4745755adb5 Mon Sep 17 00:00:00 2001 From: esquizo Date: Sat, 9 May 2026 00:29:54 -0300 Subject: iteração de física MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'game.c') diff --git a/game.c b/game.c index a44b0cf..2d64f78 100644 --- a/game.c +++ b/game.c @@ -6,7 +6,7 @@ #include "dat.h" -#define SPEED 250 +#define SPEED 100 static EntityCollisionProc bulletcollproc; static EntityCollisionProc ghostcollproc; @@ -25,6 +25,8 @@ static EntityUpdateProc *updateprocs[LASTEntity] = { [EBULLET] = bulletproc, }; +static void physics(float delta); + Entity entitybuffer[2048]; int ebufi; @@ -57,18 +59,7 @@ entinit() void entupdate(float delta) { - EntityCollision *coll; - while((coll = deqcoll())) { - Entity *self = coll->self; - Entity *target = coll->target; - - if(collisionProcs[self->type]) - collisionProcs[self->type](self, target); - - if(collisionProcs[target->type]) - collisionProcs[target->type](target, self); - } - + physics(delta); for(int ei = 0; ei < ebufi; ei++) { Entity *e = entitybuffer + ei; if(!e->active) @@ -227,3 +218,29 @@ freeentity(Entity *e) { e->active = false; } + +void +physics(float delta) +{ + #define PHYSICS_TIME (1.0 / 480.0) + + EntityCollision *coll; + + static float time = 0; + + time += delta; + while(time >= PHYSICS_TIME) { + entphysics(PHYSICS_TIME); + while((coll = deqcoll())) { + Entity *self = coll->self; + Entity *target = coll->target; + + if(collisionProcs[self->type]) + collisionProcs[self->type](self, target); + + if(collisionProcs[target->type]) + collisionProcs[target->type](target, self); + } + time -= PHYSICS_TIME; + } +} -- cgit v1.2.3