From: Joshua Grams Date: Thu, 7 Apr 2005 01:07:53 +0000 (+0000) Subject: bbox collision detection. X-Git-Tag: 0.1~4 X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=commitdiff_plain;h=2bea0659b8edff14f1554d2540780f54ccdc21c9;hp=8193e09e49bc571f9c61e6e3adf45010271c08d5 bbox collision detection. --- diff --git a/Makefile b/Makefile index 7a2fde7..bc7c6ad 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ debug := $(if $(DEBUG),1,0) ldflags := $(shell sdl-config --libs) -lSDL_image -lSDL_mixer -cflags := $(shell sdl-config --cflags) -Wall -DDEBUG=$(debug) +cflags := $(shell sdl-config --cflags) -Wall -DDEBUG=$(debug) -ggdb my_objects := file.o score.o shape.o sound.o main.o $(if $(DEBUG),debug.o) libs := SFont.o diff --git a/main.c b/main.c index aab0d71..ad3ab56 100644 --- a/main.c +++ b/main.c @@ -113,6 +113,7 @@ struct spacedot sdot[MAXSPACEDOTS]; char topline[1024]; char *initerror = ""; +struct shape shipshape; float shipx,shipy = 240.0; // X position, 0..XSIZE float shipdx,shipdy; // Change in X position per tick. float rockrate,rockspeed; @@ -543,6 +544,7 @@ init(int fullscreen) { // Load the spaceship graphic. NULLERROR(temp = IMG_Load(add_path("sprites/ship.png"))); NULLERROR(surf_ship = SDL_DisplayFormat(temp)); + get_shape(surf_ship, &shipshape); // Load the life indicator (small ship) graphic. NULLERROR(temp = IMG_Load(add_path("indicators/life.png"))); @@ -734,6 +736,13 @@ draw() { } if(!gameover && state == GAMEPLAY) { + for(i=0; ipixels; // Check that the black points on the ship are @@ -746,6 +755,7 @@ draw() { } } SDL_UnlockSurface(surf_screen); + */ } // Draw all the little ships @@ -886,6 +896,7 @@ gameloop() { rockptr->dy = rnd()-0.5; rockptr->type_number = random() % NROCKS; rockptr->image = surf_rock[rockptr->type_number];// [random()%NROCKS]; + rockptr->shape = &rock_shapes[rockptr->type_number]; rockptr->active = 1; rockptr->y = rnd()*(YSIZE + rockptr->image->h); } diff --git a/shape.c b/shape.c index 9d0501c..92914cb 100644 --- a/shape.c +++ b/shape.c @@ -52,12 +52,11 @@ collide(int xdiff, int ydiff, struct shape *r, struct shape *s) int xov, yov; if(xdiff >= 0) xov = max(min(r->w-xdiff, s->w), 0); - else xov = -max(min(s->w+xdiff, r->w), 0); + else xov = min(-min(s->w+xdiff, r->w), 0); if(ydiff >= 0) yov = max(min(r->h-ydiff, s->h), 0); - else yov = -max(min(s->h+ydiff, r->h), 0); + else yov = min(-min(s->h+ydiff, r->h), 0); - if(xov == 0 && yov == 0) return 0; - - return 0; + if(xov == 0 || yov == 0) return 0; // bboxes hit? + else return 1; } diff --git a/shape.h b/shape.h index c9a43fa..a76951d 100644 --- a/shape.h +++ b/shape.h @@ -2,8 +2,8 @@ #include struct shape { - uint32_t w, h; - uint32_t mw; + int w, h; + int mw; uint32_t *mask; };