diff options
Diffstat (limited to 'sdl3_main.c')
| -rw-r--r-- | sdl3_main.c | 144 |
1 files changed, 2 insertions, 142 deletions
diff --git a/sdl3_main.c b/sdl3_main.c index 507a64c..b5455ce 100644 --- a/sdl3_main.c +++ b/sdl3_main.c @@ -8,43 +8,6 @@ #include "dat.h" -#define BULLET_SIZE 2 -#define ENTITY_SIZE 16 - -typedef struct { - Body body; -} Player; - -typedef struct { - Body body; - bool active; -} Ghost; - -typedef struct { - Body body; - float time; - bool active; -} Bullet; - -typedef struct { - enum { - EPLAYER, - EGHOST, - EBULLET, - } type; - - bool active; - Body body; - float time; -} Entity; - -typedef struct { - Entity *self; - Entity *target; -} EntityCollision; - -typedef void (EntityCollisionProc)(Entity *self, Entity *other); - static void render(void); static void update(float delta); static void process_events(void); @@ -52,11 +15,6 @@ static void process_events(void); static Entity *allocentity(void); static void freeentity(Entity *); -static void entphysics(float delta); - -static void enqcoll(EntityCollision *c); -static EntityCollision *deqcoll(void); - static EntityCollisionProc bulletcollproc; static EntityCollisionProc *collisionProcs[] = { @@ -70,20 +28,14 @@ static Uint64 old_ticks, new_ticks; static Entity *player; -static Entity entitybuffer[2048]; -static int ebufi; - -static EntityCollision ecoll[2048]; -static int ecollstart, ecollend, ecollsi; +Entity entitybuffer[2048]; +int ebufi; static float camera_x, camera_y; static bool shot; static int shotx, shoty; -extern char map_data[]; -extern int map_width, map_height; - int main() { @@ -368,98 +320,6 @@ freeentity(Entity *e) } void -entphysics(float delta) -{ - for(int i = 0; i < ebufi; i++) { - Entity *e = entitybuffer + i; - if(!e->active) - continue; - - for(int y = 0; y < map_height; y++) - for(int x = 0; x < map_width; x++) { - if(!map_data[x + y * map_width]) - continue; - - Body b = { - .pos = { - x * ENTITY_SIZE * 2.0, - y * ENTITY_SIZE * 2.0, - }, - .size = { ENTITY_SIZE, ENTITY_SIZE }, - }; - - if(checkcollision(&e->body, &b)) { - float p[2]; - resolvecoll(&e->body, &b, p); - - for(int i = 0; i < 2; i++) - e->body.pos[i] -= p[i]; - - if(p[0] != 0.0) { - e->body.vel[0] = 0; - } else { - e->body.vel[1] = 0; - } - } - } - - for(int j = i; j < ebufi; j++) { - Entity *f = entitybuffer + j; - if(!f->active) - break; - - if(checkcollision(&e->body, &f->body)) { - EntityCollision cl; - - cl.self = e; - cl.target = f; - - enqcoll(&cl); - } - } - } - - for(int i = 0; i < ebufi; i++) { - Entity *e = entitybuffer + i; - if(!e->active) - continue; - - for(int j = 0; j < 2; j++) - e->body.pos[j] += e->body.vel[j] * delta; - } -} - -void -enqcoll(EntityCollision *c) -{ - if(ecollsi >= 2048) - return; - - ecollsi++; - - ecoll[ecollend++] = *c; - if(ecollend >= 2048) - ecollend = 0; -} - -EntityCollision * -deqcoll(void) -{ - EntityCollision *c; - if(ecollsi <= 0) - return NULL; - - ecollsi--; - - c = ecoll + ecollstart++; - - if(ecollstart >= 2048) - ecollstart = 0; - - return c; -} - -void bulletcollproc(Entity *self, Entity *target) { if(target->type == EGHOST) { |
