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)
#define VOR_GLOBALS_H
#include <SDL.h>
-#include "shape.h"
#include "SFont.h"
struct bangdots {
extern SFont_Font *g_font;
-extern uint32_t area;
-
// Structure global variables
extern struct enginedots edot[MAXENGINEDOTS], *dotptr;
extern struct bangdots bdot[MAXBANGDOTS], *bdotptr;
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;
// 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;
#include "mt.h"
#include "rocks.h"
#include "score.h"
-#include "shape.h"
+#include "sprite.h"
#include "sound.h"
// ************************************* VARS
#include "globals.h"
#include "mt.h"
#include "rocks.h"
-#include "shape.h"
SDL_Surface *load_image(char *filename);
-#include "shape.h"
+#include "sprite.h"
int init_rocks(void);
void reset_rocks(void);
+++ /dev/null
-#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;
-}
+++ /dev/null
-#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
--- /dev/null
+#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;
+}
--- /dev/null
+#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
--- /dev/null
+**** 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?