JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
renamed shape files to sprite, added todo list to svn.
authorJoshua Grams <josh@qualdan.com>
Tue, 21 Mar 2006 13:21:50 +0000 (13:21 +0000)
committerJoshua Grams <josh@qualdan.com>
Tue, 21 Mar 2006 13:21:50 +0000 (13:21 +0000)
Makefile
globals.h
main.c
rocks.c
rocks.h
shape.c [deleted file]
shape.h [deleted file]
sprite.c [new file with mode: 0644]
sprite.h [new file with mode: 0644]
todo [new file with mode: 0644]

index f8f4dd7..b3d8333 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ sdl-ldflags := $(shell sdl-config --libs)
 ldflags := $(sdl-ldflags) -lSDL_image -lSDL_mixer $(LDFLAGS)
 cflags := $(sdl-cflags) $(paths) $(CFLAGS)
 
 ldflags := $(sdl-ldflags) -lSDL_image -lSDL_mixer $(LDFLAGS)
 cflags := $(sdl-cflags) $(paths) $(CFLAGS)
 
-my_objects := args.o dust.o file.o mt.o rocks.o score.o shape.o sound.o
+my_objects := args.o dust.o file.o mt.o rocks.o score.o sprite.o sound.o
 my_objects += main.o
 libs := SFont.o
 objects := $(libs) $(my_objects)
 my_objects += main.o
 libs := SFont.o
 objects := $(libs) $(my_objects)
index bf5e1da..11ae5c4 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -2,7 +2,6 @@
 #define VOR_GLOBALS_H
 
 #include <SDL.h>
 #define VOR_GLOBALS_H
 
 #include <SDL.h>
-#include "shape.h"
 #include "SFont.h"
 
 struct bangdots {
 #include "SFont.h"
 
 struct bangdots {
@@ -40,8 +39,6 @@ extern SDL_Surface
 
 extern SFont_Font *g_font;
 
 
 extern SFont_Font *g_font;
 
-extern uint32_t area;
-
 // Structure global variables
 extern struct enginedots edot[MAXENGINEDOTS], *dotptr;
 extern struct bangdots bdot[MAXBANGDOTS], *bdotptr;
 // Structure global variables
 extern struct enginedots edot[MAXENGINEDOTS], *dotptr;
 extern struct bangdots bdot[MAXBANGDOTS], *bdotptr;
@@ -50,9 +47,6 @@ extern struct bangdots bdot[MAXBANGDOTS], *bdotptr;
 extern char topline[1024];
 extern char *initerror;
 
 extern char topline[1024];
 extern char *initerror;
 
-extern struct shape shipshape;
-extern float shipx,shipy;      // ship position on screen
-extern float shipdx,shipdy;    // ship speed (pixels/tick)
 extern float screendx, screendy;
 extern float xscroll, yscroll;
 extern float yscroll;
 extern float screendx, screendy;
 extern float xscroll, yscroll;
 extern float yscroll;
@@ -62,7 +56,7 @@ extern float scrollvel;
 // All speeds are pixels/tick, with 20 ticks per second.
 extern float t_frame;  // length of this frame (in ticks = 1/20th second)
 
 // All speeds are pixels/tick, with 20 ticks per second.
 extern float t_frame;  // length of this frame (in ticks = 1/20th second)
 
-extern int nships,score;
+extern int score;
 extern float fadetimer, faderate;
 
 extern int pausedown, paused;
 extern float fadetimer, faderate;
 
 extern int pausedown, paused;
diff --git a/main.c b/main.c
index 3f66ce0..ae52bd7 100644 (file)
--- a/main.c
+++ b/main.c
@@ -39,7 +39,7 @@
 #include "mt.h"
 #include "rocks.h"
 #include "score.h"
 #include "mt.h"
 #include "rocks.h"
 #include "score.h"
-#include "shape.h"
+#include "sprite.h"
 #include "sound.h"
 
 // ************************************* VARS
 #include "sound.h"
 
 // ************************************* VARS
diff --git a/rocks.c b/rocks.c
index 82f29bf..8cb7987 100644 (file)
--- a/rocks.c
+++ b/rocks.c
@@ -9,7 +9,6 @@
 #include "globals.h"
 #include "mt.h"
 #include "rocks.h"
 #include "globals.h"
 #include "mt.h"
 #include "rocks.h"
-#include "shape.h"
 
 SDL_Surface *load_image(char *filename);
 
 
 SDL_Surface *load_image(char *filename);
 
diff --git a/rocks.h b/rocks.h
index 52c8cab..40f26bd 100644 (file)
--- a/rocks.h
+++ b/rocks.h
@@ -1,4 +1,4 @@
-#include "shape.h"
+#include "sprite.h"
 
 int init_rocks(void);
 void reset_rocks(void);
 
 int init_rocks(void);
 void reset_rocks(void);
diff --git a/shape.c b/shape.c
deleted file mode 100644 (file)
index f29bd6e..0000000
--- a/shape.c
+++ /dev/null
@@ -1,121 +0,0 @@
-#include <stdlib.h>
-#include "common.h"
-#include "shape.h"
-
-void
-get_shape(SDL_Surface *img, struct shape *s)
-{
-       int x, y;
-       uint16_t *px, transp;
-       uint32_t bits = 0, bit, *p;
-
-       if(img->format->BytesPerPixel != 2) {
-               fprintf(stderr, "get_shape(): not a 16-bit image!\n");
-               exit(1);
-       }
-
-       s->area = 0;
-       s->w = img->w; s->h = img->h;
-       s->mw = ((img->w+31)>>5);
-       s->mask = malloc(4*s->mw*s->h);
-       if(!s->mask) {
-               fprintf(stderr, "can't malloc bitmask");
-               exit(1);
-       }
-
-       SDL_LockSurface(img);
-       px = img->pixels;
-       transp = img->format->colorkey;
-       p = s->mask;
-       for(y=0; y<img->h; y++) {
-               bit = 0;
-               for(x=0; x<img->w; x++) {
-                       if(!bit) { bits = 0; bit = 0x80000000; }
-                       if(*px++ != transp) { bits |= bit; s->area++; }
-                       bit >>= 1;
-                       if(!bit || x == img->w - 1) { *(p++) = bits; }
-               }
-               px = (uint16_t *) ((uint8_t *) px + img->pitch - 2*img->w);
-       }
-       SDL_UnlockSurface(img);
-}
-
-int
-line_collide(int xov, struct shape *r, uint32_t *rbits, struct shape *s, uint32_t *sbits)
-{
-       int lshift, n, i, ret = 0;
-       uint32_t lbits;
-       struct shape *st;
-       uint32_t *bt;
-
-
-       if(xov < 0) {
-               st = r; r = s; s = st;
-               bt = rbits; rbits = sbits; sbits = bt;
-               xov = -xov;
-       }
-
-
-       lshift = (r->w - xov) & 31; 
-       rbits += (r->w - xov) >> 5;
-       n = (xov + 31) >> 5;
-       for(i=0; i<n-1; i++) {
-               lbits = *rbits++ << lshift;
-               lbits |= *rbits >> (32 - lshift);
-               if(lbits & *sbits++) ret = 1;
-       }
-       lbits = *rbits << lshift;
-       if(lbits & *sbits) ret = 1;
-
-       return ret;
-}
-
-int
-mask_collide(int xov, int yov, struct shape *r, struct shape *s)
-{
-       int y, ry, sy;
-       uint32_t *rbits, *sbits;
-
-       if(yov > 0) {
-               ry = r->h - yov; sy = 0;
-               rbits = r->mask + (r->h - yov) * r->mw;
-               sbits = s->mask;
-       } else {
-               ry = 0; sy = s->h + yov;
-               rbits = r->mask;
-               sbits = s->mask + (s->h + yov) * s->mw;
-       }
-
-       for(y=0; y<abs(yov); y++) {
-               if(line_collide(xov, r, rbits, s, sbits)) return 1;
-               rbits += r->mw; sbits += s->mw;
-       }
-
-       return 0;
-}
-
-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 = min(-min(s->w+xdiff, r->w), 0);
-
-       if(ydiff >= 0) yov = max(min(r->h-ydiff, s->h), 0);
-       else yov = min(-min(s->h+ydiff, r->h), 0);
-
-       if(xov == 0 || yov == 0) return 0;  // bboxes hit?
-       else return mask_collide(xov, yov, r, s);
-}
-
-int
-pixel_collide(unsigned int xoff, unsigned int yoff, struct shape *r)
-{
-       uint32_t pmask;
-       
-       if(xoff >= r->w || yoff >= r->h) return 0;
-
-       pmask = 0x80000000 >> (xoff&0x1f);
-       return r->mask[(yoff*r->mw) + (xoff>>5)] & pmask;
-}
diff --git a/shape.h b/shape.h
deleted file mode 100644 (file)
index c2d0a8e..0000000
--- a/shape.h
+++ /dev/null
@@ -1,74 +0,0 @@
-#ifndef VOR_SHAPE_H
-#define VOR_SHAPE_H
-
-#include <SDL/SDL.h>
-#include <inttypes.h>
-
-
-// Shape stuff
-
-struct shape {
-       int w, h;
-       int mw; // mask width (number of uint32's)
-       uint32_t *mask;
-       uint32_t area;
-};
-
-void get_shape(SDL_Surface *img, struct shape *s);
-int collide(int xdiff, int ydiff, struct shape *r, struct shape *s);
-int pixel_collide(unsigned int xoff, unsigned int yoff, struct shape *r);
-
-
-
-// Sprite stuff
-
-typedef union sprite Sprite;
-
-#define SPRITE(x) ((Sprite *) (x))
-
-struct base_sprite {
-       uint8_t type;
-       Sprite *next;
-       float x, y;
-       float dx, dy;
-       SDL_Surface *image;
-       struct shape *shape;
-};
-
-struct rock {
-       // core sprite fields
-       uint8_t sprite_type;
-       Sprite *next;
-       float x, y;
-       float dx, dy;
-       SDL_Surface *image;
-       struct shape *shape;
-       // ROCK extras
-       int type;
-};
-
-struct ship {
-       // core sprite fields
-       uint8_t sprite_type;
-       Sprite *next;
-       float x, y;
-       float dx, dy;
-       SDL_Surface *image;
-       struct shape *shape;
-       // SHIP extras
-       int lives;
-       int jets;
-};
-
-union sprite {
-       uint8_t type;
-       struct base_sprite sprite;
-       struct rock rock;
-       struct ship ship;
-};
-
-#define BASE_SPRITE 0
-#define SHIP_SPRITE 1
-#define ROCK_SPRITE 2
-
-#endif // VOR_SHAPE_H
diff --git a/sprite.c b/sprite.c
new file mode 100644 (file)
index 0000000..ca3e937
--- /dev/null
+++ b/sprite.c
@@ -0,0 +1,121 @@
+#include <stdlib.h>
+#include "common.h"
+#include "sprite.h"
+
+void
+get_shape(SDL_Surface *img, struct shape *s)
+{
+       int x, y;
+       uint16_t *px, transp;
+       uint32_t bits = 0, bit, *p;
+
+       if(img->format->BytesPerPixel != 2) {
+               fprintf(stderr, "get_shape(): not a 16-bit image!\n");
+               exit(1);
+       }
+
+       s->area = 0;
+       s->w = img->w; s->h = img->h;
+       s->mw = ((img->w+31)>>5);
+       s->mask = malloc(4*s->mw*s->h);
+       if(!s->mask) {
+               fprintf(stderr, "can't malloc bitmask");
+               exit(1);
+       }
+
+       SDL_LockSurface(img);
+       px = img->pixels;
+       transp = img->format->colorkey;
+       p = s->mask;
+       for(y=0; y<img->h; y++) {
+               bit = 0;
+               for(x=0; x<img->w; x++) {
+                       if(!bit) { bits = 0; bit = 0x80000000; }
+                       if(*px++ != transp) { bits |= bit; s->area++; }
+                       bit >>= 1;
+                       if(!bit || x == img->w - 1) { *(p++) = bits; }
+               }
+               px = (uint16_t *) ((uint8_t *) px + img->pitch - 2*img->w);
+       }
+       SDL_UnlockSurface(img);
+}
+
+int
+line_collide(int xov, struct shape *r, uint32_t *rbits, struct shape *s, uint32_t *sbits)
+{
+       int lshift, n, i, ret = 0;
+       uint32_t lbits;
+       struct shape *st;
+       uint32_t *bt;
+
+
+       if(xov < 0) {
+               st = r; r = s; s = st;
+               bt = rbits; rbits = sbits; sbits = bt;
+               xov = -xov;
+       }
+
+
+       lshift = (r->w - xov) & 31; 
+       rbits += (r->w - xov) >> 5;
+       n = (xov + 31) >> 5;
+       for(i=0; i<n-1; i++) {
+               lbits = *rbits++ << lshift;
+               lbits |= *rbits >> (32 - lshift);
+               if(lbits & *sbits++) ret = 1;
+       }
+       lbits = *rbits << lshift;
+       if(lbits & *sbits) ret = 1;
+
+       return ret;
+}
+
+int
+mask_collide(int xov, int yov, struct shape *r, struct shape *s)
+{
+       int y, ry, sy;
+       uint32_t *rbits, *sbits;
+
+       if(yov > 0) {
+               ry = r->h - yov; sy = 0;
+               rbits = r->mask + (r->h - yov) * r->mw;
+               sbits = s->mask;
+       } else {
+               ry = 0; sy = s->h + yov;
+               rbits = r->mask;
+               sbits = s->mask + (s->h + yov) * s->mw;
+       }
+
+       for(y=0; y<abs(yov); y++) {
+               if(line_collide(xov, r, rbits, s, sbits)) return 1;
+               rbits += r->mw; sbits += s->mw;
+       }
+
+       return 0;
+}
+
+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 = min(-min(s->w+xdiff, r->w), 0);
+
+       if(ydiff >= 0) yov = max(min(r->h-ydiff, s->h), 0);
+       else yov = min(-min(s->h+ydiff, r->h), 0);
+
+       if(xov == 0 || yov == 0) return 0;  // bboxes hit?
+       else return mask_collide(xov, yov, r, s);
+}
+
+int
+pixel_collide(unsigned int xoff, unsigned int yoff, struct shape *r)
+{
+       uint32_t pmask;
+       
+       if(xoff >= r->w || yoff >= r->h) return 0;
+
+       pmask = 0x80000000 >> (xoff&0x1f);
+       return r->mask[(yoff*r->mw) + (xoff>>5)] & pmask;
+}
diff --git a/sprite.h b/sprite.h
new file mode 100644 (file)
index 0000000..c2d0a8e
--- /dev/null
+++ b/sprite.h
@@ -0,0 +1,74 @@
+#ifndef VOR_SHAPE_H
+#define VOR_SHAPE_H
+
+#include <SDL/SDL.h>
+#include <inttypes.h>
+
+
+// Shape stuff
+
+struct shape {
+       int w, h;
+       int mw; // mask width (number of uint32's)
+       uint32_t *mask;
+       uint32_t area;
+};
+
+void get_shape(SDL_Surface *img, struct shape *s);
+int collide(int xdiff, int ydiff, struct shape *r, struct shape *s);
+int pixel_collide(unsigned int xoff, unsigned int yoff, struct shape *r);
+
+
+
+// Sprite stuff
+
+typedef union sprite Sprite;
+
+#define SPRITE(x) ((Sprite *) (x))
+
+struct base_sprite {
+       uint8_t type;
+       Sprite *next;
+       float x, y;
+       float dx, dy;
+       SDL_Surface *image;
+       struct shape *shape;
+};
+
+struct rock {
+       // core sprite fields
+       uint8_t sprite_type;
+       Sprite *next;
+       float x, y;
+       float dx, dy;
+       SDL_Surface *image;
+       struct shape *shape;
+       // ROCK extras
+       int type;
+};
+
+struct ship {
+       // core sprite fields
+       uint8_t sprite_type;
+       Sprite *next;
+       float x, y;
+       float dx, dy;
+       SDL_Surface *image;
+       struct shape *shape;
+       // SHIP extras
+       int lives;
+       int jets;
+};
+
+union sprite {
+       uint8_t type;
+       struct base_sprite sprite;
+       struct rock rock;
+       struct ship ship;
+};
+
+#define BASE_SPRITE 0
+#define SHIP_SPRITE 1
+#define ROCK_SPRITE 2
+
+#endif // VOR_SHAPE_H
diff --git a/todo b/todo
new file mode 100644 (file)
index 0000000..d1b9de2
--- /dev/null
+++ b/todo
@@ -0,0 +1,12 @@
+****   Finish porting to Windows (should be only file.c and args.c, I think)
+
+***    Switch over to sprites rather than totally separate structures.
+*      Rocks collide with each other?
+
+***    Add a scripting language and separate game logic from the engine.
+       Forth?  Scheme?  Lua?
+
+**     Switch to a TTF font and all ray-traced graphics
+*      Then we can run at the native screen size
+
+*      Deltas on high score display?