296 lines
5.4 KiB
C
296 lines
5.4 KiB
C
#include <SDL_image.h>
|
|
|
|
//#define OPENGL
|
|
|
|
|
|
#define EDITORW 800
|
|
#define EDITORH 480
|
|
|
|
// location of tile palette in editor
|
|
#define PALX 640
|
|
#define PALY 0
|
|
#define PALW (EDITORW-PALX)
|
|
#define PALH (EDITORH/2)-1
|
|
|
|
// loc of sprite palette
|
|
#define SPALX 640
|
|
#define SPALY (EDITORH/2)
|
|
#define SPALW (EDITORW-PALX)
|
|
#define SPALH (EDITORH/2)-1
|
|
|
|
// text sizes
|
|
#define TEXTSIZE_HELP 20
|
|
#define TEXTSIZE_POINTS 10
|
|
#define TEXTSIZE_HURRY 50
|
|
|
|
#define INVULNTIME 200
|
|
|
|
#define WANTFPS 75
|
|
|
|
#define TEXTSPEED 2
|
|
#define NETSPEED 9
|
|
|
|
#define POINTSDELAY 40
|
|
#define HURRYDELAY 50
|
|
#define LEVELDELAY 40
|
|
#define HELPDELAY 80
|
|
|
|
#define MAXMAPPINGS 50
|
|
|
|
#define MAXMONSTERSPERLEVEL 20
|
|
|
|
#define MAXLETTERHEIGHT 100
|
|
|
|
#define MAXFRAMES 10
|
|
|
|
#define MAXHELP 5
|
|
|
|
#define TILEH 16
|
|
#define TILEW 16
|
|
|
|
#define LEVELW 40
|
|
#define LEVELH 30
|
|
|
|
#define BUFLEN 512
|
|
#define MIDBUFLEN 64
|
|
#define SMALLBUFLEN 32
|
|
|
|
#define FALLSPEED 4
|
|
|
|
#define B_TRUE -1
|
|
#define B_FALSE 0
|
|
|
|
#define S_NOTSOLID 0
|
|
#define S_SOLID 1
|
|
#define S_SLOPE 2
|
|
|
|
#define MAXPTYPES 15
|
|
#define P_PLAYER 0
|
|
#define P_RAT 1
|
|
#define P_CHEESE 2
|
|
#define P_SPEED 3
|
|
#define P_NUMNETS 4
|
|
#define P_BIGNET 5
|
|
#define P_BEE 6
|
|
#define P_SPIDER 7
|
|
#define P_CLOUD 8
|
|
#define P_ICECREAM 9
|
|
#define P_CHIPS 10
|
|
#define P_BURGER 11
|
|
#define P_SNAKE 12
|
|
#define P_SPIT 13
|
|
#define P_HELP 14
|
|
|
|
#define F_WALK1 0
|
|
#define F_JUMP 1
|
|
#define F_FALL 2
|
|
#define F_CAUGHT 3
|
|
#define F_DEAD 4
|
|
#define F_DEAD2 5
|
|
#define F_DEAD3 6
|
|
#define F_DEAD4 7
|
|
#define F_CLIMB1 8
|
|
#define F_CLIMB2 9
|
|
|
|
#define T_BLANK 0
|
|
#define T_LAND 1
|
|
#define T_SLOPEUP 2
|
|
#define T_SLOPEDOWN 3
|
|
#define T_FULL 4
|
|
#define T_SKY 5
|
|
#define T_LADDER 6
|
|
#define T_LADDERTOP 7
|
|
#define T_RIGHT 8
|
|
#define T_LEFT 9
|
|
#define T_SPIKES 10
|
|
#define T_TELEPORT 11
|
|
#define T_TELEPORT2 12
|
|
#define T_TELEPORTDEST 13
|
|
#define T_WATER 14
|
|
#define T_WATERTOP 15
|
|
#define T_WATERSPIKES 16
|
|
|
|
|
|
|
|
typedef struct mapping_s {
|
|
char ch;
|
|
int tnum;
|
|
} mapping_t;
|
|
|
|
typedef struct tiletype_s {
|
|
int id;
|
|
char name[SMALLBUFLEN];
|
|
int lowness[TILEW];
|
|
int solid;
|
|
int water;
|
|
int spikes;
|
|
SDL_Surface *img;
|
|
struct tiletype_s *next;
|
|
struct tiletype_s *prev;
|
|
} tiletype_t;
|
|
tiletype_t *tiletype;
|
|
|
|
typedef struct initialmonster_s {
|
|
int startx;
|
|
int starty;
|
|
int id;
|
|
char *help;
|
|
} initialmonster_t;
|
|
|
|
typedef struct text_s {
|
|
int x,y;
|
|
int size;
|
|
int maxsize;
|
|
int state;
|
|
int delay; // how long to stay on screen
|
|
char txt[BUFLEN];
|
|
SDL_Rect bgarea;
|
|
SDL_Surface *bg;
|
|
SDL_Surface *img;
|
|
SDL_Color *c;
|
|
struct text_s *next;
|
|
struct text_s *prev;
|
|
} text_t;
|
|
|
|
typedef struct level_s {
|
|
int id;
|
|
int bgtileid;
|
|
char name[SMALLBUFLEN];
|
|
int map[LEVELW*LEVELH];
|
|
struct level_s *next;
|
|
struct level_s *prev;
|
|
int p1x; /* player 1 start pos */
|
|
int p1y;
|
|
int nummonsters;
|
|
initialmonster_t initm[MAXMONSTERSPERLEVEL];
|
|
int hurryuptime;
|
|
} level_t;
|
|
level_t *level;
|
|
|
|
typedef struct sprite_s {
|
|
int id;
|
|
double speed;
|
|
|
|
int score;
|
|
|
|
int falling;
|
|
int fallspeed;
|
|
int jumping;
|
|
int jumpdir;
|
|
|
|
int willbecome;
|
|
|
|
int angry;
|
|
|
|
int teleporting;
|
|
|
|
int dead;
|
|
int invuln;
|
|
int bounces;
|
|
|
|
struct sprite_s *caughtby;
|
|
int caughtstate;
|
|
|
|
int jumpspeed;
|
|
int climbing;
|
|
int slamming;
|
|
double slamangle;
|
|
int netting;
|
|
int netcaught;
|
|
int netmax;
|
|
int netspeed;
|
|
int netdir;
|
|
int netlen;
|
|
int netbig;
|
|
int nety;
|
|
int netxstart;
|
|
int netystart;
|
|
|
|
int timer;
|
|
int jumptimer;
|
|
|
|
int moved;
|
|
|
|
int flies;
|
|
|
|
double xs,ys;
|
|
|
|
struct sprite_s *bullet;
|
|
struct sprite_s *owner;
|
|
|
|
double x,y;
|
|
int dir;
|
|
SDL_Surface *img;
|
|
SDL_Surface *netbg;
|
|
struct sprite_s *next;
|
|
struct sprite_s *prev;
|
|
char name[MIDBUFLEN];
|
|
} sprite_t;
|
|
|
|
typedef struct imageset_s {
|
|
SDL_Surface *img[MAXFRAMES*4];
|
|
int numimages;
|
|
} imageset_t;
|
|
imageset_t imageset[MAXPTYPES];
|
|
|
|
|
|
void cleanup(void);
|
|
int addtext(int x, int y, int size, char *string, SDL_Color *c, int delay);
|
|
void drawscore(void);
|
|
void drawtext(void);
|
|
void movetext(void);
|
|
void killtext(text_t *t);
|
|
void removeall(void);
|
|
void removetext(void);
|
|
sprite_t *addsprite(int id,int x, int y, char *name, int initial);
|
|
int loadtiletypes(char *filename);
|
|
tiletype_t *gettileat(int pixx,int pixy, int *tilex, int *tiley);
|
|
int loadlevel(int wnum, int lnum);
|
|
int loadimagesets(void);
|
|
void drawlevel(void);
|
|
void drawtile(SDL_Surface *s, int x, int y);
|
|
void removesprite(sprite_t *s);
|
|
void removenetting(sprite_t *s);
|
|
void drawsprite(sprite_t *s);
|
|
void drawnetting(sprite_t *s);
|
|
void dogravity(sprite_t *s);
|
|
void dotileeffects(sprite_t *s);
|
|
void flip(void);
|
|
int movex(sprite_t *s,double amt);
|
|
void movesprite(sprite_t *s);
|
|
int isinwater(sprite_t *s);
|
|
int isroofabove(sprite_t *s);
|
|
int isroofnabove(sprite_t *s,int howfar);
|
|
int isonground(sprite_t *s);
|
|
int isongroundpoint(sprite_t *s, int x, int y);
|
|
int isonladder(sprite_t *s);
|
|
int isladderabove(sprite_t *s);
|
|
int isfruit(int id);
|
|
int dofruiteffect(sprite_t *s);
|
|
int ismonster(int id);
|
|
int isbullet(int id);
|
|
void killsprite(sprite_t *s);
|
|
void checkcollide(sprite_t *s);
|
|
void die(sprite_t *s);
|
|
void nextlevel(void);
|
|
void jump(sprite_t *s, int dir);
|
|
double getspeed(sprite_t *s );
|
|
void adjustheight(sprite_t *s);
|
|
void setdefaults(sprite_t *s);
|
|
void tick(void);
|
|
void usage(void);
|
|
|
|
int chartomonster(char ch);
|
|
|
|
|
|
inline void drawpixel16(SDL_Surface *screen, int x, int y, SDL_Color c);
|
|
inline void drawpixel32(SDL_Surface *screen, int x, int y, SDL_Color c);
|
|
inline void drawbox16(SDL_Surface *screen, int x1,int y1,int x2,int y2,SDL_Color *c,SDL_Color *fc);
|
|
void drawline16(SDL_Surface *screen, int x1, int y1, int x2, int y2, SDL_Color c);
|
|
int getcolor(SDL_Surface *dest, int x, int y, SDL_Color *col);
|
|
|
|
|
|
///////////////////////////////////////
|
|
void drawpalette(void);
|
|
void drawsprites(void);
|