From: Joshua Grams Date: Thu, 7 Apr 2005 00:47:13 +0000 (+0000) Subject: data/indicators/life.png: now built by povray from ship graphic. X-Git-Tag: 0.1~5 X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=commitdiff_plain;h=8193e09e49bc571f9c61e6e3adf45010271c08d5 data/indicators/life.png: now built by povray from ship graphic. shape.c: generates bitmasks for graphics, no collision detection yet though. --- diff --git a/Makefile b/Makefile index 31c4214..7a2fde7 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ rocks += 20 21 22 23 24 25 26 27 28 29 rocks += 30 31 32 33 34 35 36 37 38 39 rocks += 40 41 42 43 44 45 46 47 48 49 -graphics := data/sprites/ship.png $(rocks:%=data/sprites/rock%.png) +graphics := data/sprites/ship.png data/indicators/life.png $(rocks:%=data/sprites/rock%.png) INSTALL = install INSTALL_PROGRAM = $(INSTALL) -o games -g games diff --git a/data/indicators/life.png b/data/indicators/life.png deleted file mode 100644 index 269ebad..0000000 Binary files a/data/indicators/life.png and /dev/null differ diff --git a/gfx.mk b/gfx.mk index 2543dfa..ec0202f 100644 --- a/gfx.mk +++ b/gfx.mk @@ -7,6 +7,9 @@ data/sprites/ship.png: ship.pov pnmoutline gfx.mk pnmtopng -transparent =white data/sprites/ship.pnm >$@ rm ship.png ship.pnm data/sprites/ship.pnm +data/indicators/life.png: ship.pov gfx.mk + povray -D +A +UA +W17 +H17 $< -O$@ + data/sprites/rock%.png: rocks.pov gfx.mk povray -Irocks.pov -D +H52 +W52 +K`echo "$@" | grep -o '[0-9][0-9]'` +Fp -O$@.pnm 2>/dev/null pnmcrop < $@.pnm > $@-c.pnm diff --git a/main.c b/main.c index be5ae97..aab0d71 100644 --- a/main.c +++ b/main.c @@ -26,6 +26,7 @@ #include "config.h" #include "file.h" #include "score.h" +#include "shape.h" #include "sound.h" #include @@ -52,6 +53,7 @@ struct rock_struct { int dead; // has been blown out of the way // to make room for a new ship appearing. SDL_Surface *image; + struct shape *shape; int type_number; }; struct black_point_struct { @@ -96,6 +98,8 @@ SDL_Surface *surf_rock[NROCKS], // THE ROCKS *surf_font_big; // The big font +struct shape rock_shapes[NROCKS]; + SFont_Font *g_font; // Structure global variables @@ -467,6 +471,7 @@ drawdots(SDL_Surface *s) { SDL_UnlockSurface(s); } + char a[MAX_PATH_LEN]; int init(int fullscreen) { @@ -563,11 +568,11 @@ init(int fullscreen) { // Load all our lovely rocks for(i = 0; i +#include "shape.h" + +void +get_shape(SDL_Surface *img, struct shape *s) +{ + int x, y; + uint16_t *px, transp; + uint32_t bits; + + if(img->format->BytesPerPixel != 2) { + fprintf(stderr, "get_shape(): not a 16-bit image!\n"); + exit(1); + } + + s->w = img->w; s->h = img->h; + s->mw = ((img->w+31)>>5) * img->h; + s->mask = malloc(4*s->mw); + if(!s->mask) { + fprintf(stderr, "can't malloc bitmask"); + exit(1); + } + + SDL_LockSurface(img); + px = img->pixels; + transp = img->format->colorkey; + bits = 0; + for(y=0; yh; y++) { + for(x=0; xw; x++) { + if(*px++ != transp) bits |= 1; + if(x == img->w-1 || !(x+1)%32) { + *(s->mask++) = bits; + bits = 0; + } else bits = bits << 1; + } + px = (uint16_t *) ((uint8_t *) px + img->pitch - 2*img->w); + } + SDL_UnlockSurface(img); +} + +#ifndef max +#define max(a, b) ((a) > (b) ? (a) : (b)) +#endif + +#ifndef min +#define min(a, b) ((a) < (b) ? (a) : (b)) +#endif + +int +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); + + if(ydiff >= 0) yov = max(min(r->h-ydiff, s->h), 0); + else yov = -max(min(s->h+ydiff, r->h), 0); + + if(xov == 0 && yov == 0) return 0; + + return 0; +} diff --git a/shape.h b/shape.h new file mode 100644 index 0000000..c9a43fa --- /dev/null +++ b/shape.h @@ -0,0 +1,11 @@ +#include +#include + +struct shape { + uint32_t w, h; + uint32_t mw; + uint32_t *mask; +}; + +void get_shape(SDL_Surface *img, struct shape *s); +int collide(int xdiff, int ydiff, struct shape *r, struct shape *s);