parent
d6735eea16
commit
4091b98e58
2
Makefile
2
Makefile
|
@ -1,2 +1,2 @@
|
||||||
rc: rc.c rc.h
|
rc: rc.c rc.h
|
||||||
gcc -mwindows -Wall -orc -g rc.c `sdl-config --cflags --libs` -I/usr/local/include -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx
|
gcc -mwindows -mno-cygwin -Wall -orc.exe -DWINDOWS -g rc.c `sdl-config --cflags --libs` -I/usr/local/include -lmingw32 -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
rc: rc.c rc.h
|
rc: rc.c rc.h
|
||||||
gcc -mwindows -Wall -orc -g rc.c `sdl-config --cflags --libs` -I/usr/local/include -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx
|
gcc -mwindows -Wall -orc -g rc.c `sdl-config --cflags --libs` -I/usr/local/include -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
rc: rc.c rc.h
|
rc: rc.c rc.h
|
||||||
gcc -mwindows -mno-cygwin -Wall -orc.exe -DWINDOWS -g rc.c `sdl-config --cflags --libs` -I/usr/local/include -lmingw32 -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx
|
gcc -mwindows -mno-cygwin -Wall -orc.exe -DWINDOWS -g rc.c `sdl-config --cflags --libs` -I/usr/local/include -lmingw32 -L/usr/local/lib -lSDLmain -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf
|
||||||
|
|
28
level1.dat
28
level1.dat
|
@ -8,25 +8,25 @@ bg 0
|
||||||
*000000~~~~~~~~~~~~**000000000000000000*
|
*000000~~~~~~~~~~~~**000000000000000000*
|
||||||
*00000000000000000000000000000000000000*
|
*00000000000000000000000000000000000000*
|
||||||
*00000000000000000000000000000000000000*
|
*00000000000000000000000000000000000000*
|
||||||
*00000000000000001000000000000000000000*
|
*0000000000000000000000r000000000000000*
|
||||||
*000000000000~~~~~~~~~~~~~~~00000000000*
|
*000000000000~~~~~~~~~~~~~~~00000000000*
|
||||||
*00000000000000000000000000000000000000*
|
*00000000000000000000000000000000000000*
|
||||||
*00000000000000000000000000000000000000*
|
*00000000000000000000000000000000000000*
|
||||||
*0000000000r000000000000000000000r00000*
|
*00000000000000000000000000000000000000*
|
||||||
*000~~~~~~~~~~~~~~0000~~~~~0000~~~~~000*
|
*00000000000000/~~~~~~~~~\0000000000000*
|
||||||
|
*0000000000000/***********\000000000000*
|
||||||
|
*000000000000/**000000000**\00000000000*
|
||||||
|
*00000000000/***0000000r0***\0000000000*
|
||||||
|
*000~~~~~~~~~~~~~~0000~~~~~~~~~~~~~~000*
|
||||||
|
*00000000000000000000000000000000000000*
|
||||||
|
*00000000000000000000000000000000000000*
|
||||||
|
*00000000000r000000000000000r0000000000*
|
||||||
|
*000000000~~~~0000000000000~~~~00000000*
|
||||||
*00000000000000000000000000000000000000*
|
*00000000000000000000000000000000000000*
|
||||||
*00000000000000000000000000000000000000*
|
*00000000000000000000000000000000000000*
|
||||||
*000000000000000000000000r0000000000000*
|
*000000000000000000000000r0000000000000*
|
||||||
*000~~~~~0000~~~~~0000~~~~~~~~~~~~~~000*
|
*000~~~~~0000~~~~~0000~~~~~~~~~~~~~~000*
|
||||||
*00000000000000000000000000000000000000*
|
*0000000000000000*0000*0000000000000000*
|
||||||
*00000000000000000000000000000000000000*
|
*0000000000000000*0000*0000000000000000*
|
||||||
*00000000000r00000000000000000000000000*
|
*0010000000000000*^^^^*0000000r00000000*
|
||||||
*000~~~~~~~~~~~~~~0000~~~~~0000~~~~~000*
|
|
||||||
*00000000000000000000000000000000000000*
|
|
||||||
*00000000000000000000000000000000000000*
|
|
||||||
*000000000000000000000000r0000000000000*
|
|
||||||
*000~~~~~0000~~~~~0000~~~~~~~~~~~~~~000*
|
|
||||||
*00000000000000000000000000000000000000*
|
|
||||||
*00000000000000000000000000000000000000*
|
|
||||||
*00000000000000000000000000000000000000*
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
BIN
rat.bmp
BIN
rat.bmp
Binary file not shown.
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
374
rc.c
374
rc.c
|
@ -12,10 +12,14 @@
|
||||||
#include <SDL/SDL.h>
|
#include <SDL/SDL.h>
|
||||||
#include <SDL/SDL_keysym.h>
|
#include <SDL/SDL_keysym.h>
|
||||||
#include <SDL/SDL_rotozoom.h>
|
#include <SDL/SDL_rotozoom.h>
|
||||||
|
#include <SDL/SDL_ttf.h>
|
||||||
|
|
||||||
#include "rc.h"
|
#include "rc.h"
|
||||||
|
|
||||||
SDL_Surface *screen;
|
SDL_Surface *screen;
|
||||||
|
TTF_Font *font[MAXLETTERHEIGHT];
|
||||||
|
|
||||||
|
char tempm[BUFLEN];
|
||||||
|
|
||||||
int curlevelnum = 1;
|
int curlevelnum = 1;
|
||||||
level_t *curlevel;
|
level_t *curlevel;
|
||||||
|
@ -24,6 +28,8 @@ sprite_t *sprite = NULL; /* main sprite list */
|
||||||
sprite_t *player;
|
sprite_t *player;
|
||||||
sprite_t *lastsprite;
|
sprite_t *lastsprite;
|
||||||
|
|
||||||
|
text_t *text, *lasttext;
|
||||||
|
|
||||||
SDL_Color red = {255, 0, 0, 0};
|
SDL_Color red = {255, 0, 0, 0};
|
||||||
SDL_Color white = {255, 255, 255, 0};
|
SDL_Color white = {255, 255, 255, 0};
|
||||||
|
|
||||||
|
@ -33,6 +39,8 @@ int toggletimer = 0;
|
||||||
int main (int argc, char **argv) {
|
int main (int argc, char **argv) {
|
||||||
Uint8 *keys;
|
Uint8 *keys;
|
||||||
sprite_t *s,*nextsprite;
|
sprite_t *s,*nextsprite;
|
||||||
|
char filename[BUFLEN];
|
||||||
|
int i;
|
||||||
|
|
||||||
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)==-1) {
|
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)==-1) {
|
||||||
printf("SDL_Init: %s\n", SDL_GetError());
|
printf("SDL_Init: %s\n", SDL_GetError());
|
||||||
|
@ -43,14 +51,26 @@ int main (int argc, char **argv) {
|
||||||
|
|
||||||
screen = SDL_SetVideoMode(640,480,16,SDL_HWSURFACE|SDL_DOUBLEBUF);
|
screen = SDL_SetVideoMode(640,480,16,SDL_HWSURFACE|SDL_DOUBLEBUF);
|
||||||
|
|
||||||
|
|
||||||
if (loadimagesets()) {
|
if (loadimagesets()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* load fonts */
|
||||||
|
TTF_Init();
|
||||||
|
sprintf(filename, "verdana.ttf");
|
||||||
|
for (i = 1; i < MAXLETTERHEIGHT; i++) {
|
||||||
|
font[i] = TTF_OpenFont(filename,i);
|
||||||
|
if (!font[i]) {
|
||||||
|
printf("Error opening font: %s\n", TTF_GetError());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (loadlevel(curlevelnum)) {
|
if (loadlevel(curlevelnum)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
drawlevel();
|
drawlevel();
|
||||||
SDL_Flip(screen);
|
SDL_Flip(screen);
|
||||||
|
|
||||||
|
@ -59,6 +79,7 @@ int main (int argc, char **argv) {
|
||||||
printf("player y is %0.1f\n",player->y);
|
printf("player y is %0.1f\n",player->y);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
while (1) {
|
while (1) {
|
||||||
|
removetext();
|
||||||
/* remove player */
|
/* remove player */
|
||||||
for (s = sprite ; s ; s = s->next) {
|
for (s = sprite ; s ; s = s->next) {
|
||||||
removesprite(s);
|
removesprite(s);
|
||||||
|
@ -85,6 +106,11 @@ fflush(stdout);
|
||||||
toggletimer = 50;
|
toggletimer = 50;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (keys[SDLK_q]) {
|
||||||
|
if (text == NULL) {
|
||||||
|
addtext(100,100,32,"Test");
|
||||||
|
}
|
||||||
|
}
|
||||||
if (keys[SDLK_ESCAPE]) {
|
if (keys[SDLK_ESCAPE]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -137,11 +163,13 @@ fflush(stdout);
|
||||||
player->netystart = player->y;
|
player->netystart = player->y;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* shoot net */
|
if (player->netcaught < player->netmax) {
|
||||||
player->netting = 1;
|
/* shoot net */
|
||||||
player->netspeed = NETSPEED;
|
player->netting = 1;
|
||||||
player->netlen = 0;
|
player->netspeed = NETSPEED;
|
||||||
player->netdir = player->dir;
|
player->netlen = 0;
|
||||||
|
player->netdir = player->dir;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,6 +177,7 @@ fflush(stdout);
|
||||||
for (s = sprite; s ; s = s->next) {
|
for (s = sprite; s ; s = s->next) {
|
||||||
movesprite(s);
|
movesprite(s);
|
||||||
}
|
}
|
||||||
|
movetext();
|
||||||
|
|
||||||
|
|
||||||
/* gravity */
|
/* gravity */
|
||||||
|
@ -166,6 +195,9 @@ fflush(stdout);
|
||||||
checkcollide(s);
|
checkcollide(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* draw text */
|
||||||
|
drawtext();
|
||||||
|
|
||||||
drawnetting(player);
|
drawnetting(player);
|
||||||
|
|
||||||
/* draw player */
|
/* draw player */
|
||||||
|
@ -182,8 +214,12 @@ fflush(stdout);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void cleanup(void) {
|
void cleanup(void) {
|
||||||
|
int i;
|
||||||
|
for (i = 1; i < MAXLETTERHEIGHT; i++) {
|
||||||
|
TTF_CloseFont(font[i]);
|
||||||
|
}
|
||||||
|
TTF_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,14 +236,19 @@ void checkcollide(sprite_t *s) {
|
||||||
if (collide) {
|
if (collide) {
|
||||||
/* check for colission with our net */
|
/* check for colission with our net */
|
||||||
if ((s->netting) && (!s2->caughtby)) {
|
if ((s->netting) && (!s2->caughtby)) {
|
||||||
xdiff = (s->x + s->netlen*s->netdir) - s2->x;
|
if (s->netcaught < s->netmax) {
|
||||||
if (xdiff < 0) xdiff = -xdiff;
|
xdiff = (s->x + s->netlen*s->netdir) - s2->x;
|
||||||
ydiff = s->netystart - s2->y;
|
if (xdiff < 0) xdiff = -xdiff;
|
||||||
if (ydiff < 0) ydiff = -ydiff;
|
ydiff = s->netystart - s2->y;
|
||||||
|
if (ydiff < 0) ydiff = -ydiff;
|
||||||
|
|
||||||
if ((xdiff <= s2->img->w) && (ydiff <= s2->img->h)) {
|
if ((xdiff <= s2->img->w) && (ydiff <= s2->img->h)) {
|
||||||
s2->caughtby = s;
|
s2->caughtby = s;
|
||||||
s2->caughtstate = 1;
|
s2->jumping = 0;
|
||||||
|
s2->falling = 0;
|
||||||
|
s2->caughtstate = 1;
|
||||||
|
s->netcaught++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* check for collision with us */
|
/* check for collision with us */
|
||||||
|
@ -223,7 +264,10 @@ void checkcollide(sprite_t *s) {
|
||||||
if (s == player) {
|
if (s == player) {
|
||||||
/* kill the fruit */
|
/* kill the fruit */
|
||||||
s2->dead = 4;
|
s2->dead = 4;
|
||||||
|
/* draw text */
|
||||||
|
addtext(s2->x,s2->y - s2->img->h/2, 16, "100");
|
||||||
/* give points to the player */
|
/* give points to the player */
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ismonster(s2->id)) {
|
if (ismonster(s2->id)) {
|
||||||
|
@ -313,12 +357,12 @@ void movesprite(sprite_t *s) {
|
||||||
} else if (s->dead == 3) { /* final fall */
|
} else if (s->dead == 3) { /* final fall */
|
||||||
s->x += s->xs;
|
s->x += s->xs;
|
||||||
s->y += s->ys;
|
s->y += s->ys;
|
||||||
if (s->x >= (640-(s->img->w/2))) {
|
if (s->x >= (640-TILEW)) {
|
||||||
if (s->xs > 0) {
|
if (s->xs > 0) {
|
||||||
s->xs = -s->xs;
|
s->xs = -s->xs;
|
||||||
s->bounces++;
|
s->bounces++;
|
||||||
}
|
}
|
||||||
} else if (s->x <= s->img->w/2) {
|
} else if (s->x <= TILEW) {
|
||||||
if (s->xs < 0) {
|
if (s->xs < 0) {
|
||||||
s->xs = -s->xs;
|
s->xs = -s->xs;
|
||||||
s->bounces++;
|
s->bounces++;
|
||||||
|
@ -338,7 +382,6 @@ void movesprite(sprite_t *s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ((s->ys > 0) && (s->y >= TILEH)) {
|
if ((s->ys > 0) && (s->y >= TILEH)) {
|
||||||
if (isonground(s)) {
|
if (isonground(s)) {
|
||||||
int x,y,ty;
|
int x,y,ty;
|
||||||
|
@ -347,6 +390,10 @@ void movesprite(sprite_t *s) {
|
||||||
x = s->x;
|
x = s->x;
|
||||||
gettileat(s->x,s->y-1,NULL,&ty);
|
gettileat(s->x,s->y-1,NULL,&ty);
|
||||||
y = ty*TILEH + TILEH - 2;
|
y = ty*TILEH + TILEH - 2;
|
||||||
|
|
||||||
|
/* make sure it's within the screen */
|
||||||
|
if (x > (640-TILEW)) x = 640-TILEW;
|
||||||
|
if (x < (TILEW)) x = TILEW;
|
||||||
addsprite(P_CHEESE, x, y, "Cheese");
|
addsprite(P_CHEESE, x, y, "Cheese");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -362,16 +409,82 @@ void movesprite(sprite_t *s) {
|
||||||
if (s->id == P_RAT) {
|
if (s->id == P_RAT) {
|
||||||
if (!s->falling) {
|
if (!s->falling) {
|
||||||
tiletype_t *tt;
|
tiletype_t *tt;
|
||||||
/* if there's not a hole in front of us, move */
|
int move = B_FALSE;
|
||||||
|
int xdiff, absxdiff;
|
||||||
|
|
||||||
|
|
||||||
|
/* distance to player */
|
||||||
|
xdiff = player->x - s->x;
|
||||||
|
if (xdiff < 0) absxdiff = -xdiff;
|
||||||
|
else absxdiff = xdiff;
|
||||||
|
|
||||||
tt = gettileat(s->x + s->dir+s->speed,s->y,NULL,NULL);
|
tt = gettileat(s->x + s->dir+s->speed,s->y,NULL,NULL);
|
||||||
if (tt->solid == S_NOTSOLID) {
|
if (tt->solid == S_NOTSOLID) {
|
||||||
s->dir = -s->dir;
|
/* if there's a hole in front of us */
|
||||||
|
if (player->y > s->y) {
|
||||||
|
/* if player is below, fall off */
|
||||||
|
if (xdiff <= (TILEW*8)) {
|
||||||
|
move = B_TRUE;
|
||||||
|
}
|
||||||
|
} else if (player->y == s->y) {
|
||||||
|
/* if player is at same level and close, jump */
|
||||||
|
if ((s->dir == 1) && (xdiff > 0) && (xdiff <= (TILEW*7))) {
|
||||||
|
s->jumping = 1;
|
||||||
|
s->jumpdir = 1;
|
||||||
|
s->jumpspeed = 5;
|
||||||
|
} else if ((s->dir == -1) && (xdiff < 0) && (xdiff >= -(TILEW*7))) {
|
||||||
|
s->jumping = 1;
|
||||||
|
s->jumpdir = -1;
|
||||||
|
s->jumpspeed = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
move = B_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* either move or turn around */
|
||||||
|
if (move) {
|
||||||
rv = movex(s, s->dir*s->speed);
|
rv = movex(s, s->dir*s->speed);
|
||||||
if (rv) {
|
if (rv) {
|
||||||
|
/* if we couldn't move (hit a wall), turn */
|
||||||
s->dir = -s->dir;
|
s->dir = -s->dir;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
s->dir = -s->dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((player->dead == 0) && (!s->jumping)) {
|
||||||
|
/* if player is above us, jump */
|
||||||
|
if (player->y < s->y) {
|
||||||
|
if ((xdiff >= (TILEW*2)) && (xdiff <= (TILEW*3))) {
|
||||||
|
/* jump right */
|
||||||
|
s->jumpdir = 1;
|
||||||
|
s->jumping = 1;
|
||||||
|
s->jumpspeed = 5;
|
||||||
|
} else if ((xdiff <= -(TILEW*2)) && (xdiff >= -(TILEW*3))) {
|
||||||
|
/* jump left */
|
||||||
|
s->jumpdir = -1;
|
||||||
|
s->jumping = 1;
|
||||||
|
s->jumpspeed = 5;
|
||||||
|
} else if (s->y - player->y <= (TILEH*6)) {
|
||||||
|
if ((xdiff >= 0) && (xdiff < (TILEW*2))) {
|
||||||
|
/* jump up */
|
||||||
|
s->jumpdir = 0;
|
||||||
|
s->jumping = 1;
|
||||||
|
s->jumpspeed = 5;
|
||||||
|
} else if ((xdiff <= 0) && (xdiff > -(TILEW*2))) {
|
||||||
|
/* jump up */
|
||||||
|
s->jumpdir = 0;
|
||||||
|
s->jumping = 1;
|
||||||
|
s->jumpspeed = 5;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* jump whichever way we're facing */
|
||||||
|
s->jumpdir = s->dir;
|
||||||
|
s->jumping = 1;
|
||||||
|
s->jumpspeed = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -691,6 +804,8 @@ int loadtiletypes(char *filename) {
|
||||||
|
|
||||||
int loadimagesets(void) {
|
int loadimagesets(void) {
|
||||||
int p,i;
|
int p,i;
|
||||||
|
SDL_Surface *tempimg;
|
||||||
|
|
||||||
imageset[P_PLAYER].img[F_WALK1] = IMG_Load("pdwarf.png");
|
imageset[P_PLAYER].img[F_WALK1] = IMG_Load("pdwarf.png");
|
||||||
imageset[P_PLAYER].img[F_JUMP] = IMG_Load("pdwarfjump.png");
|
imageset[P_PLAYER].img[F_JUMP] = IMG_Load("pdwarfjump.png");
|
||||||
imageset[P_PLAYER].img[F_FALL] = IMG_Load("pdwarffall.png");
|
imageset[P_PLAYER].img[F_FALL] = IMG_Load("pdwarffall.png");
|
||||||
|
@ -700,7 +815,7 @@ int loadimagesets(void) {
|
||||||
imageset[P_PLAYER].numimages = 8;
|
imageset[P_PLAYER].numimages = 8;
|
||||||
|
|
||||||
imageset[P_RAT].img[F_WALK1] = IMG_Load("rat.bmp");
|
imageset[P_RAT].img[F_WALK1] = IMG_Load("rat.bmp");
|
||||||
imageset[P_RAT].img[F_JUMP] = IMG_Load("rat.bmp");
|
imageset[P_RAT].img[F_JUMP] = IMG_Load("ratjump.bmp");
|
||||||
imageset[P_RAT].img[F_FALL] = IMG_Load("rat.bmp");
|
imageset[P_RAT].img[F_FALL] = IMG_Load("rat.bmp");
|
||||||
imageset[P_RAT].img[F_CAUGHT] = IMG_Load("ratcaught.bmp");
|
imageset[P_RAT].img[F_CAUGHT] = IMG_Load("ratcaught.bmp");
|
||||||
imageset[P_RAT].img[F_DEAD] = IMG_Load("ratdead.bmp");
|
imageset[P_RAT].img[F_DEAD] = IMG_Load("ratdead.bmp");
|
||||||
|
@ -708,18 +823,25 @@ int loadimagesets(void) {
|
||||||
imageset[P_RAT].numimages = 8;
|
imageset[P_RAT].numimages = 8;
|
||||||
|
|
||||||
imageset[P_CHEESE].img[F_WALK1] = IMG_Load("cheese.bmp");
|
imageset[P_CHEESE].img[F_WALK1] = IMG_Load("cheese.bmp");
|
||||||
|
imageset[P_CHEESE].img[F_DEAD] = IMG_Load("cheese.bmp");
|
||||||
imageset[P_CHEESE].numimages = 1;
|
imageset[P_CHEESE].numimages = 1;
|
||||||
|
|
||||||
/* generate rotated/flipped images */
|
/* generate rotated/flipped images */
|
||||||
for (p = 0; p < MAXPTYPES; p++) {
|
for (p = 0; p < MAXPTYPES; p++) {
|
||||||
imageset[p].img[F_DEAD2] = rotozoomSurface(imageset[p].img[F_DEAD],90,1,0);
|
tempimg = rotozoomSurface(imageset[p].img[F_DEAD],90,1,0);
|
||||||
imageset[p].img[F_DEAD3] = rotozoomSurface(imageset[p].img[F_DEAD],180,1,0);
|
imageset[p].img[F_DEAD2] = SDL_DisplayFormat(tempimg);
|
||||||
imageset[p].img[F_DEAD4] = rotozoomSurface(imageset[p].img[F_DEAD],270,1,0);
|
|
||||||
|
tempimg = rotozoomSurface(imageset[p].img[F_DEAD],180,1,0);
|
||||||
|
imageset[p].img[F_DEAD3] = SDL_DisplayFormat(tempimg);
|
||||||
|
|
||||||
|
tempimg = rotozoomSurface(imageset[p].img[F_DEAD],270,1,0);
|
||||||
|
imageset[p].img[F_DEAD4] = SDL_DisplayFormat(tempimg);
|
||||||
|
|
||||||
for (i = 0; i < imageset[p].numimages; i++) {
|
for (i = 0; i < imageset[p].numimages; i++) {
|
||||||
SDL_SetColorKey(imageset[p].img[i],
|
SDL_SetColorKey(imageset[p].img[i],
|
||||||
SDL_SRCCOLORKEY, SDL_MapRGB(screen->format, 0, 0, 0));
|
SDL_SRCCOLORKEY, SDL_MapRGB(screen->format, 0, 0, 0));
|
||||||
|
|
||||||
|
|
||||||
imageset[p].img[MAXFRAMES+i] =
|
imageset[p].img[MAXFRAMES+i] =
|
||||||
rotozoomSurfaceXY(imageset[p].img[i], 0, -1,1,0);
|
rotozoomSurfaceXY(imageset[p].img[i], 0, -1,1,0);
|
||||||
}
|
}
|
||||||
|
@ -735,6 +857,141 @@ double getspeed(int id) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int addtext(int x, int y, int size, char *string) {
|
||||||
|
text_t *t;
|
||||||
|
|
||||||
|
if (text == NULL) {
|
||||||
|
text = malloc(sizeof(text_t));
|
||||||
|
t = text;
|
||||||
|
t->prev = NULL;
|
||||||
|
} else {
|
||||||
|
t = lasttext;
|
||||||
|
t->next = malloc(sizeof(text_t));
|
||||||
|
t->next->prev = t;
|
||||||
|
|
||||||
|
t = t->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
t->bg = SDL_CreateRGBSurface(SDL_HWSURFACE,
|
||||||
|
300, 110,
|
||||||
|
screen->format->BitsPerPixel, screen->format->Rmask,
|
||||||
|
screen->format->Gmask,screen->format->Bmask,
|
||||||
|
screen->format->Amask);
|
||||||
|
|
||||||
|
t->x = x;
|
||||||
|
t->y = y;
|
||||||
|
t->maxsize = size;
|
||||||
|
t->size = 3;
|
||||||
|
strcpy(t->txt, string);
|
||||||
|
t->state = 0;
|
||||||
|
|
||||||
|
t->img = TTF_RenderText_Solid(font[t->size], t->txt, white);
|
||||||
|
|
||||||
|
|
||||||
|
t->next = NULL;
|
||||||
|
lasttext = t;
|
||||||
|
|
||||||
|
return B_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void removetext(void) {
|
||||||
|
SDL_Rect sarea;
|
||||||
|
text_t *t;
|
||||||
|
|
||||||
|
for (t = text ; t ; t = t->next) {
|
||||||
|
sarea.x = 0;
|
||||||
|
sarea.y = 0;
|
||||||
|
sarea.w = t->bgarea.w;
|
||||||
|
sarea.h = t->bgarea.h;
|
||||||
|
|
||||||
|
SDL_BlitSurface(t->bg, &sarea, screen, &t->bgarea);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void movetext(void) {
|
||||||
|
text_t *t,*nextt;
|
||||||
|
for (t = text ; t ; t = nextt) {
|
||||||
|
nextt = t->next;
|
||||||
|
if (t->state == 0) {
|
||||||
|
t->size += TEXTSPEED;
|
||||||
|
if (t->size >= t->maxsize) {
|
||||||
|
t->state = 1;
|
||||||
|
}
|
||||||
|
} else if (t->state == TEXTDELAY) {
|
||||||
|
t->size -= TEXTSPEED;
|
||||||
|
if (t->size <= 3) {
|
||||||
|
killtext(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
t->state++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawtext(void) {
|
||||||
|
text_t *t;
|
||||||
|
SDL_Rect area;
|
||||||
|
|
||||||
|
for (t = text ; t ; t = t->next) {
|
||||||
|
|
||||||
|
/* create text */
|
||||||
|
if (t->img) {
|
||||||
|
SDL_FreeSurface(t->img);
|
||||||
|
t->img = NULL;
|
||||||
|
}
|
||||||
|
t->img = TTF_RenderText_Solid(font[t->size], t->txt, white);
|
||||||
|
|
||||||
|
/* get bg */
|
||||||
|
t->bgarea.x = t->x - t->img->w/2;
|
||||||
|
t->bgarea.y = t->y - t->img->h/2;
|
||||||
|
t->bgarea.w = t->img->w;
|
||||||
|
t->bgarea.h = t->img->h;
|
||||||
|
SDL_BlitSurface(screen, &t->bgarea, t->bg, NULL);
|
||||||
|
|
||||||
|
/* draw text */
|
||||||
|
area.x = t->x - t->img->w/2;
|
||||||
|
area.y = t->y - t->img->h/2;
|
||||||
|
area.w = t->img->w;
|
||||||
|
area.h = t->img->h;
|
||||||
|
SDL_BlitSurface(t->img,NULL, screen, &area);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void killtext(text_t *t) {
|
||||||
|
text_t *nextone, *lastone;
|
||||||
|
|
||||||
|
|
||||||
|
if (t->bg) {
|
||||||
|
SDL_FreeSurface(t->bg);
|
||||||
|
t->bg = NULL;
|
||||||
|
}
|
||||||
|
if (t->img) {
|
||||||
|
SDL_FreeSurface(t->img);
|
||||||
|
t->img = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextone = t->next;
|
||||||
|
if (nextone != NULL) {
|
||||||
|
nextone->prev = t->prev;
|
||||||
|
} else { /*last text */
|
||||||
|
lasttext = t->prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t->prev == NULL) {
|
||||||
|
/* first text */
|
||||||
|
nextone = text->next;
|
||||||
|
free(text);
|
||||||
|
text = nextone;
|
||||||
|
} else {
|
||||||
|
lastone = t->prev;
|
||||||
|
free (lastone->next );
|
||||||
|
lastone->next = nextone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int addsprite(int id, int x, int y, char *name ) {
|
int addsprite(int id, int x, int y, char *name ) {
|
||||||
sprite_t *s;
|
sprite_t *s;
|
||||||
|
|
||||||
|
@ -762,7 +1019,7 @@ int addsprite(int id, int x, int y, char *name ) {
|
||||||
|
|
||||||
if (s == sprite) {
|
if (s == sprite) {
|
||||||
s->netbg = SDL_CreateRGBSurface(SDL_HWSURFACE,
|
s->netbg = SDL_CreateRGBSurface(SDL_HWSURFACE,
|
||||||
200, 10,
|
200, 64,
|
||||||
screen->format->BitsPerPixel, screen->format->Rmask,
|
screen->format->BitsPerPixel, screen->format->Rmask,
|
||||||
screen->format->Gmask,screen->format->Bmask,
|
screen->format->Gmask,screen->format->Bmask,
|
||||||
screen->format->Amask);
|
screen->format->Amask);
|
||||||
|
@ -774,6 +1031,8 @@ int addsprite(int id, int x, int y, char *name ) {
|
||||||
s->jumping = 0;
|
s->jumping = 0;
|
||||||
s->jumpdir = 1;
|
s->jumpdir = 1;
|
||||||
s->netting = 0;
|
s->netting = 0;
|
||||||
|
s->netmax = 4;
|
||||||
|
s->netcaught = 0;
|
||||||
s->falling = 0;
|
s->falling = 0;
|
||||||
s->fallspeed = 0;
|
s->fallspeed = 0;
|
||||||
s->dir = 1;
|
s->dir = 1;
|
||||||
|
@ -818,6 +1077,8 @@ void drawnetting(sprite_t *s) {
|
||||||
SDL_Rect area;
|
SDL_Rect area;
|
||||||
|
|
||||||
if (s->netting) {
|
if (s->netting) {
|
||||||
|
int y,yy;
|
||||||
|
int dis;
|
||||||
|
|
||||||
sx = s->x;
|
sx = s->x;
|
||||||
s->nety = s->y - (s->img->h/2);
|
s->nety = s->y - (s->img->h/2);
|
||||||
|
@ -830,14 +1091,23 @@ void drawnetting(sprite_t *s) {
|
||||||
} else {
|
} else {
|
||||||
area.x = s->netxstart - TILEW/2 - s->netlen;
|
area.x = s->netxstart - TILEW/2 - s->netlen;
|
||||||
}
|
}
|
||||||
area.y = s->netystart;
|
//area.y = s->netystart;
|
||||||
|
area.y = s->y - s->img->h-2;
|
||||||
area.w = s->netlen;
|
area.w = s->netlen;
|
||||||
area.h = 7;
|
area.h = s->img->h+2;
|
||||||
SDL_BlitSurface(screen, &area,s->netbg, NULL);
|
SDL_BlitSurface(screen, &area,s->netbg, NULL);
|
||||||
|
|
||||||
drawline16(screen,sx,s->nety,s->x + s->netdir*s->netlen,s->nety-3,white);
|
dis = (int)s->img->h / (int)(s->netmax+1) + 1;
|
||||||
drawline16(screen,sx,s->nety,s->x + s->netdir*s->netlen,s->nety,white);
|
|
||||||
drawline16(screen,sx,s->nety,s->x + s->netdir*s->netlen,s->nety+3,white);
|
for (y = dis; y < s->img->h; y += dis) {
|
||||||
|
yy = s->y - s->img->h;
|
||||||
|
yy += y;
|
||||||
|
drawline16(screen,sx,s->nety,s->x + s->netdir*s->netlen,yy,white);
|
||||||
|
}
|
||||||
|
|
||||||
|
//drawline16(screen,sx,s->nety,s->x + s->netdir*s->netlen,s->nety-3,white);
|
||||||
|
//drawline16(screen,sx,s->nety,s->x + s->netdir*s->netlen,s->nety,white);
|
||||||
|
//drawline16(screen,sx,s->nety,s->x + s->netdir*s->netlen,s->nety+3,white);
|
||||||
} else if (s->slamming) {
|
} else if (s->slamming) {
|
||||||
double dist;
|
double dist;
|
||||||
int x,y;
|
int x,y;
|
||||||
|
@ -878,7 +1148,7 @@ void drawsprite(sprite_t *s) {
|
||||||
frame = F_FALL;
|
frame = F_FALL;
|
||||||
} else {
|
} else {
|
||||||
if (s->moved) {
|
if (s->moved) {
|
||||||
if ((timer/6) % 2 == 0) {
|
if ((timer/12) % 2 == 0) {
|
||||||
frame = F_WALK1;
|
frame = F_WALK1;
|
||||||
} else {
|
} else {
|
||||||
frame = F_JUMP;
|
frame = F_JUMP;
|
||||||
|
@ -920,16 +1190,17 @@ void removenetting(sprite_t *s) {
|
||||||
sarea.x = 0;
|
sarea.x = 0;
|
||||||
sarea.y = 0;
|
sarea.y = 0;
|
||||||
sarea.w = s->netlen;
|
sarea.w = s->netlen;
|
||||||
sarea.h = 7;
|
sarea.h = s->img->h+2;
|
||||||
|
|
||||||
if (s->netdir == 1) {
|
if (s->netdir == 1) {
|
||||||
area.x = s->netxstart + TILEW/2;
|
area.x = s->netxstart + TILEW/2;
|
||||||
} else {
|
} else {
|
||||||
area.x = s->netxstart - TILEW/2 - s->netlen;
|
area.x = s->netxstart - TILEW/2 - s->netlen;
|
||||||
}
|
}
|
||||||
area.y = s->netystart;
|
//area.y = s->netystart;
|
||||||
|
area.y = s->y - s->img->h-2;
|
||||||
area.w = s->netlen;
|
area.w = s->netlen;
|
||||||
area.h = 7;
|
area.h = s->img->h+2;
|
||||||
|
|
||||||
if (s->netbg != NULL) {
|
if (s->netbg != NULL) {
|
||||||
SDL_BlitSurface(s->netbg, &sarea, screen, &area);
|
SDL_BlitSurface(s->netbg, &sarea, screen, &area);
|
||||||
|
@ -1116,18 +1387,53 @@ void dogravity(sprite_t *s) {
|
||||||
if (s->slamming) {
|
if (s->slamming) {
|
||||||
s->slamangle += (10 * (M_PI/180));
|
s->slamangle += (10 * (M_PI/180));
|
||||||
if (s->slamangle >= (190 * (M_PI/180))) {
|
if (s->slamangle >= (190 * (M_PI/180))) {
|
||||||
|
int xdiff,ydiff,xnet = 0,ynet = 0;
|
||||||
|
int pointsinc = 250;
|
||||||
|
int psize = 6;
|
||||||
|
|
||||||
/* if we hit the ground, kill anything we've caught */
|
/* if we hit the ground, kill anything we've caught */
|
||||||
s->slamming = 0;
|
s->slamming = 0;
|
||||||
|
|
||||||
for (s2 = sprite; s2 ; s2 = s2->next) {
|
for (s2 = sprite; s2 ; s2 = s2->next) {
|
||||||
|
/* kill anything we have caught */
|
||||||
if (s2->caughtby == s) {
|
if (s2->caughtby == s) {
|
||||||
if (isongroundpoint(s2,s2->x,s->y)) {
|
if (isongroundpoint(s2,s2->x,s->y)) {
|
||||||
s2->dead = 1;
|
s2->dead = 1;
|
||||||
|
pointsinc *= 2;
|
||||||
|
psize += 10;
|
||||||
}
|
}
|
||||||
s2->caughtby = NULL;
|
s2->caughtby = NULL;
|
||||||
|
xnet = s2->x;
|
||||||
|
ynet = s2->y - s2->img->h/2;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* also kill anything we hit */
|
||||||
|
xdiff = s2->x - xnet;
|
||||||
|
if (xdiff < 0) xdiff =-xdiff;
|
||||||
|
ydiff = (s2->y - s2->img->h/2) - ynet;
|
||||||
|
if (ydiff < 0) ydiff =-ydiff;
|
||||||
|
|
||||||
|
if ((xdiff <= s2->img->w) && (ydiff <= s2->img->h)) {
|
||||||
|
s2->dead = 1;
|
||||||
|
pointsinc *= 2;
|
||||||
|
psize += 10;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s->netcaught = 0;
|
||||||
|
|
||||||
|
/* show points */
|
||||||
|
if (psize >= MAXLETTERHEIGHT) {
|
||||||
|
psize = MAXLETTERHEIGHT-1;
|
||||||
|
}
|
||||||
|
if (pointsinc > 250) {
|
||||||
|
sprintf(tempm, "%d",pointsinc);
|
||||||
|
addtext(xnet,ynet-TILEH, psize, tempm);
|
||||||
|
/* TODO: give points to player */
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
rc.h
25
rc.h
|
@ -1,9 +1,14 @@
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define TEXTSPEED 2
|
||||||
|
#define TEXTDELAY 40
|
||||||
#define NETSPEED 9
|
#define NETSPEED 9
|
||||||
|
|
||||||
#define MAXMONSTERSPERLEVEL 20
|
#define MAXMONSTERSPERLEVEL 20
|
||||||
|
|
||||||
|
#define MAXLETTERHEIGHT 100
|
||||||
|
|
||||||
#define MAXPTYPES 3
|
#define MAXPTYPES 3
|
||||||
#define MAXFRAMES 8
|
#define MAXFRAMES 8
|
||||||
|
|
||||||
|
@ -39,6 +44,19 @@ typedef struct initialmonster_s {
|
||||||
int id;
|
int id;
|
||||||
} initialmonster_t;
|
} initialmonster_t;
|
||||||
|
|
||||||
|
typedef struct text_s {
|
||||||
|
int x,y;
|
||||||
|
int size;
|
||||||
|
int maxsize;
|
||||||
|
int state;
|
||||||
|
char txt[BUFLEN];
|
||||||
|
SDL_Rect bgarea;
|
||||||
|
SDL_Surface *bg;
|
||||||
|
SDL_Surface *img;
|
||||||
|
struct text_s *next;
|
||||||
|
struct text_s *prev;
|
||||||
|
} text_t;
|
||||||
|
|
||||||
typedef struct level_s {
|
typedef struct level_s {
|
||||||
int id;
|
int id;
|
||||||
int bgtileid;
|
int bgtileid;
|
||||||
|
@ -72,6 +90,8 @@ typedef struct sprite_s {
|
||||||
int slamming;
|
int slamming;
|
||||||
double slamangle;
|
double slamangle;
|
||||||
int netting;
|
int netting;
|
||||||
|
int netcaught;
|
||||||
|
int netmax;
|
||||||
int netspeed;
|
int netspeed;
|
||||||
int netdir;
|
int netdir;
|
||||||
int netlen;
|
int netlen;
|
||||||
|
@ -100,6 +120,11 @@ imageset_t imageset[MAXPTYPES];
|
||||||
|
|
||||||
|
|
||||||
void cleanup(void);
|
void cleanup(void);
|
||||||
|
int addtext(int x, int y, int size, char *string);
|
||||||
|
void drawtext(void);
|
||||||
|
void movetext(void);
|
||||||
|
void killtext(text_t *t);
|
||||||
|
void removetext(void);
|
||||||
int addsprite(int id,int x, int y, char *name);
|
int addsprite(int id,int x, int y, char *name);
|
||||||
int loadtiletypes(char *filename);
|
int loadtiletypes(char *filename);
|
||||||
tiletype_t *gettileat(int pixx,int pixy, int *tilex, int *tiley);
|
tiletype_t *gettileat(int pixx,int pixy, int *tilex, int *tiley);
|
||||||
|
|
Loading…
Reference in New Issue