From 8193e09e49bc571f9c61e6e3adf45010271c08d5 Mon Sep 17 00:00:00 2001 From: Joshua Grams Date: Thu, 7 Apr 2005 00:47:13 +0000 Subject: [PATCH] data/indicators/life.png: now built by povray from ship graphic. shape.c: generates bitmasks for graphics, no collision detection yet though. --- Makefile | 2 +- data/indicators/life.png | Bin 1230 -> 0 bytes gfx.mk | 3 +++ main.c | 7 +++++- shape.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++ shape.h | 11 ++++++++ 6 files changed, 84 insertions(+), 2 deletions(-) delete mode 100644 data/indicators/life.png create mode 100644 shape.c create mode 100644 shape.h 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 269ebade7772fc62840e34933d0eae2da8e2d047..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1230 zcmWktacmP+7%xwF;6onrqL*-tLr=Mo121sGffsk+rQFy-4pv9W&ZKCU44I)ogU!~3 zBdMlpjYDVBKuwNNVG@XiEV^ltk`&V5kWB~7QR0AUMx1zrf<@NIy#4XL?|XUQm*4OA ze(!y>$*7ryXyoyDX4S6q`rN$0jX5)(a90xjpv~g}4>oP6Upp}|0U-pBL4iRw02Tl& zn|1O`XC&?ifToiJ?Z5|s?GIRi6hdZS0Hic4tOJGP(yD=wl4ltO0UxGHDYYb8f)I`I zhSM%IabcQf@)F1}Bp;4KC}|8V7bE4QtSY&npqZLk=p5kr@Sw;GLaJ!cEQEz*vrpv- z0x^#2rlBeoa>+cyxM-1KMKK{5v#e5+f{@^dktBqsVHX2UhMMXQC&B;_f(o(Ju%?wl zy3X@9rbM1+*&IbB5aI~YMj}=*-9^)EJd_-D+mbO?<>NuoGMmS>WJvM%N)n=Enhx?5 z=+kt=Fc~6sTkVqMiuDa7yHci^XXp`G=D55hW;22$Ff>L`5;GiUV@#sFsmTf=l5K=X zRrNSVCEefY4vU&X0LOJoQk23PP0LX|VEZFEhU94C7)F5-C_=_$EdinJngS?}E0i=9 z<0hJscs?5wbp|1x&tXgq?FgD(wPOdM`&O1UmK6~q2+0_`j6_FuPiYH6j?4NWP~~2X`7m_Fx>Pv`-JU>t5{|OXKwl7u zqRp_1p>=42FdU7Rj6i`F;|P>=oyBCNvrAXA95;}HP?ijykB$$@HpGsqQbfZDBSgh{ z->57(vL1sl0wF?vjA=rc$r1%^;4*QY^ray31NRm6j%z85n<>h0RAt#E`vvzKOxfcz zUiYjS9cr4~1lQMiJs(b+zs{}OYQ3-3w-g)y-8FL4s(Wr|^~3+-wND+m>HW6<_OlP2 z-`-eO*V8ngn)cQGYvSsYp7$~<{=$tHb{@NbX+V&%gpR=xV+TJo-C{T10#CP0@2GgDR;otdIe0Yt%Jfx< zx9jO+adYeMI~INaY2;n;!rs|OZ@*M`_Vn2OqMps%^-^t*`Q4?vS5F?fQ;hs@WtpA#gok^}l_iIqeS7b$Xfz7X zH$=`{3SJC-b7UnS+OmDx>AQ1hFP?d^@X5UX&3BrExeH(Kx;!?t(m2sLvU}6nD#;u# zFfZ=QeEE}i&9P>6%G3?9M>jTGJKE33uGIt%?fIp@dOvNo?R!-D`;XO?$kofm^VR)J z&uy$Mn)hq}{%w!??drwjRqKZumON~5uAiHb7OtJU{%3J1bE>*!*WkfZr}~T~*|{Ec WtLI1i$@ 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); -- 1.7.10.4