ratcatcher/edit.c

1171 lines
25 KiB
C

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <math.h>
#include <SDL.h>
#include <SDL_keysym.h>
#include <SDL_rotozoom.h>
#include <SDL_ttf.h>
#include <SDL_framerate.h>
#include "defs.h"
#include "shared.h"
#include "edit.h"
/* these hold the currently selected sprite/tile types */
tiletype_t *seltile = NULL;
int selsprite = -1;
int modified = B_FALSE; // has the current level been modified since last save?
int curworld = 1;
int curlevelnum;
int skipto = -1;
int layer = 1; // which layer we are editting, either 1 or 2
int layertransparent = B_TRUE;
SDL_Surface *whitebox;
SDL_Color red = {255, 0, 0, 0};
SDL_Color black = {0, 0, 0, 0};
SDL_Color blue = {0, 0, 255, 0};
SDL_Color cyan = {0, 255, 255, 0};
SDL_Color white = {255, 255, 255, 0};
SDL_Color grey = {210, 210, 210, 0};
SDL_Color grey2 = {70, 70, 70, 0};
SDL_Color green = {0, 255, 0, 0};
SDL_Color yellow = {255, 255, 0, 0};
int state;
char tempm[BUFLEN];
char statustext[BUFLEN];
SDL_Color *statustextcol = &white;
// for level list mode
int oldy = -1;
int main (int argc, char **argv) {
Uint8 *keys;
char filename[BUFLEN];
int i;
int mb,mx,my;
curlevelnum = 1;
levelbg = NULL;
/* handle arguments */
if (argc >= 2) {
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-fs")) {
printf("Fullscreen mode enabled.\n");
vidargs |= SDL_FULLSCREEN;
} else if (!strcmp(argv[i], "-l")) {
if (++i >= argc) {
printf("Missing level number.\n");
usage();
exit(1);
}
skipto = atoi(argv[i]);
printf("Skipping to level %d.\n",skipto);
} else {
usage();
exit(1);
}
}
}
if (loadlevellist()) {
printf("Error loading level list from levels.dat.\n");
return 1;
}
// is we're skipping to a level, do so now
if (skipto >= 0) {
for (i = 0; i < numlevels; i++) {
if (levelentry[i].id == skipto) {
curlevelnum = i;
}
}
}
/* initialise */
initglobals();
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)==-1) {
printf("SDL_Init: %s\n", SDL_GetError());
exit(1);
}
atexit(cleanup);
#ifdef OPENGL
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
screen = SDL_SetVideoMode(EDITORW,EDITORH,16,SDL_OPENGLBLIT|vidargs);
#else
screen = SDL_SetVideoMode(EDITORW,EDITORH,16,SDL_SWSURFACE|SDL_DOUBLEBUF|vidargs);
#endif
/* init tiles */
if (loadtiletypes("green.tiles")) {
printf("Cannot initialise tiles\n");
exit(1);
}
if (loadimagesets()) {
return 1;
}
strcpy(statustext, "");
statustextcol = &white;
fakeblock.id = T_LAND;
strcpy(fakeblock.name,"Fake");
for (i = 0; i < TILEW; i++) {
fakeblock.lowness[i] = 0;
}
fakeblock.solid = S_SOLID;
fakeblock.img[0] = IMG_Load("newtiles/land.png");
fakeblock.numframes = 1;
fakeblock.next = NULL;
fakeblock.prev = NULL;
// coloured box surface (for tiles on non-active layer)
whitebox = SDL_CreateRGBSurface(SDL_SWSURFACE,
TILEW,TILEH,
screen->format->BitsPerPixel, screen->format->Rmask,
screen->format->Gmask,screen->format->Bmask, 0);
SDL_FillRect(whitebox, NULL, SDL_MapRGB(whitebox->format, 0, 0, 255));
SDL_SetAlpha(whitebox, SDL_SRCALPHA,100);
/* load fonts */
TTF_Init();
sprintf(filename, "editfont.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;
}
}
state = LS_EDIT;
if (loadlevel(curworld,curlevelnum)) {
return 1;
}
modified = B_FALSE;
seltile = tiletype;
draweditorlevel();
drawpalette();
drawsprites();
flip();
timer = 0;
//player->invuln = INVULNTIME;
//player->score = 0;
while (1) {
/* check for mouse actions */
mb = SDL_GetMouseState(&mx,&my);
if (mb & SDL_BUTTON(1)) { // lmb
if (state == LS_EDIT) {
if ((mx >= PALX) && (my < SPALY)) { // over tile palette
tiletype_t *tt;
int x = PALX,y = PALY;
seltile = NULL;
/* get tile number */
for (tt = tiletype; tt != NULL; tt = tt->next) {
if (isplacabletile(tt->id)) {
// is mouse over this one?
if ((mx >= x) && (my >= y) && (mx <= x+TILEW-1) && (my <= y+TILEH-1)) {
seltile = tt;
selsprite = -1;
break;
} else {
// check next one
x += TILEW;
if (x >= EDITORW) {
x = PALX;
y += TILEH;
}
}
}
}
// redraw palette with new selection
drawpalette();
setstatustext("", &white);
} else if ((mx >= PALX) && (my > SPALY)) { // over sprite palette
int p;
int x = SPALX, y = SPALY;
int maxh = 0;
/* get sprite id */
selsprite = -1;
for (p = 0; p < MAXPTYPES; p++) {
if (isplacablesprite(p)) {
SDL_Surface *firstimg;
int w,h;
/* select images */
firstimg = imageset[p].img[F_WALK1];
w = firstimg->w;
h = firstimg->h;
if (h > maxh) maxh = h;
// is mouse over it?
if ((mx >= x) && (my >= y) && (mx <= x+w-1) && (my <= y+h-1)) {
selsprite = p;
seltile = NULL;
break;
} else {
// check next one
x += w;
if (x >= EDITORW-TILEW) {
x = SPALX;
y += maxh;
maxh = 0;
}
}
}
}
// redraw palette with new selection
drawpalette();
setstatustext("", &white);
} else if (mx < PALX) { // over map
int x,y;
if (seltile != NULL) {
/* place selected tile at mouse pos */
x = (mx / TILEW);
y = (my / TILEH);
if (layer == 1) {
curlevel->map[y*LEVELW+x] = seltile->uniqid;
curlevel->tileframe[y*LEVELW+x] = 0;
} else {
// if there's nothing at layer1, it goes there
//if (curlevel->map[y*LEVELW+x] == T_BLANK) {
// printf("falling to layer 1\n");
// curlevel->map[y*LEVELW+x] = seltile->uniqid;
// curlevel->tileframe[y*LEVELW+x] = 0;
//} else {
curlevel->map2[y*LEVELW+x] = seltile->uniqid;
//}
}
// redraw tile and sprites
draweditortile(screen,x,y);
drawsprites();
setmod(B_TRUE);
setstatustext("", &white);
} else if (selsprite >= 0) {
int placed = B_FALSE;
x = (mx / TILEW);
y = (my / TILEH);
/* checks */
// can only have one player/powerup pos
if ((selsprite == P_PLAYER) || (selsprite == P_POWERUPPOS)) {
/* does a player start pos already exist? */
sprite_t *s;
for (s = sprite ; s ; s = s->next) {
if (s->id == selsprite) {
// if so, just move it
s->x = x*TILEW+(TILEW/2);
s->y = y*TILEH+TILEH;
placed = B_TRUE;
setmod(B_TRUE);
// get rid of old sprite
draweditorlevel();
drawsprites();
}
}
} else { // is there a monster already there?
sprite_t *s;
for (s = sprite ; s ; s = s->next) {
if (s->id == selsprite) {
if ((s->x == x*TILEW+(TILEW/2)) && (s->y == y*TILEH+TILEH)) {
/* don't place it */
placed = B_TRUE;
}
}
}
}
if (!placed) {
if (toggletimer == 0) {
/* place selected sprite at mouse position
(locked to a tile) */
if (selsprite == P_HELP) {
addsprite(selsprite, x*TILEW+(TILEW/2),y*TILEH+TILEH,"FILL ME IN" );
} else {
addsprite(selsprite, x*TILEW+(TILEW/2),y*TILEH+TILEH,"something" );
}
toggletimer = 30;
setmod(B_TRUE);
drawsprites();
sprintf(tempm, "Sprite added at %d,%d",x,y);
setstatustext(tempm, &white);
}
}
}
}
} else if (state == LS_SAVE) {
// get pos
int i;
int lev;
// get level # at mouse posj
lev = (my / (EDITTEXT + LLISTPADY));
if (curlevelnum != lev) {
// REMOVE CURRENT LEVEL FROM LIST
for (i = curlevelnum; i < (numlevels-1); i++) {
levelentry[i] = levelentry[i+1];
}
numlevels--;
if (lev > curlevelnum) {
lev--;
}
// shuffle
for (i = numlevels; i > lev+1; i--) {
levelentry[i] = levelentry[i-1];
}
// insert current level at correct position (after where we clicked)
levelentry[lev+1].id = curlevel->id;
strncpy(levelentry[lev+1].desc, curlevel->name, MIDBUFLEN);
strncpy(levelentry[lev+1].filename, curlevel->filename, MIDBUFLEN);
numlevels++;
curlevelnum = lev + 1;
/* save out level list */
savelevellist();
// redraw
drawlevellist();
sprintf(tempm, "Level moved to position %d",curlevelnum);
setstatustext(tempm, &white);
}
}// end if LS_EDIT/LS_SAVE etc
} // end if LMB
/* check for keys */
SDL_PumpEvents();
keys = SDL_GetKeyState(NULL);
if (state == LS_EDIT) {
if (keys[SDLK_1] || keys[SDLK_2]) { // toggle layer
if (toggletimer == 0) {
layer = 3 - layer;
draweditorlevel();
drawsprites();
sprintf(tempm, "Now editting layer %d",layer);
setstatustext(tempm, &green);
toggletimer = 30;
}
}
if (keys[SDLK_t]) {
if (toggletimer == 0) {
if (layertransparent) layertransparent = B_FALSE;
else layertransparent = B_TRUE;
draweditorlevel();
drawsprites();
sprintf(tempm, "Transparent layers now %s",layertransparent ? "ON" : "OFF");
setstatustext(tempm, &green);
toggletimer = 15;
}
}
if (keys[SDLK_x]) { // delete monster
int donesomething = B_FALSE;
sprite_t *s, *nextone;
for (s = sprite ; s ; s = nextone) {
nextone = s->next;
/* if mouse is over this sprite */
if ( (mx >= s->x - (s->img->w/2)) &&
(mx <= s->x + (s->img->w/2)) &&
(my >= s->y - s->img->h) &&
(my <= s->y )) {
// kill it
killsprite(s);
donesomething = B_TRUE;
}
}
if (donesomething) {
draweditorlevel();
drawsprites();
setmod(B_TRUE);
}
}
if (keys[SDLK_c]) {
if (toggletimer == 0) {
clearlevel();
toggletimer = 30;
}
}
/* exit direction */
if (toggletimer == 0) {
if (keys[SDLK_h]) {
curlevel->exitdir = D_LEFT;
toggletimer = 30;
setmod(B_TRUE);
sprintf(tempm, "Exit direction set to DOWN");
setstatustext(tempm, &white);
}
if (keys[SDLK_j]) {
curlevel->exitdir = D_DOWN;
toggletimer = 30;
setmod(B_TRUE);
sprintf(tempm, "Exit direction set to DOWN");
setstatustext(tempm, &white);
}
if (keys[SDLK_k]) {
curlevel->exitdir = D_UP;
toggletimer = 30;
setmod(B_TRUE);
sprintf(tempm, "Exit direction set to DOWN");
setstatustext(tempm, &white);
}
if (keys[SDLK_l]) {
curlevel->exitdir = D_RIGHT;
toggletimer = 30;
setmod(B_TRUE);
sprintf(tempm, "Exit direction set to DOWN");
setstatustext(tempm, &white);
}
}
/* new level */
if (keys[SDLK_n]) {
if (toggletimer == 0) {
newlevel();
draweditorlevel();
drawsprites();
toggletimer = 30;
setmod(B_FALSE);
setstatustext("Created new level.", &white);
}
}
/* next level */
if (keys[SDLK_RIGHT]) {
if (toggletimer == 0) {
if (curlevelnum < (numlevels-1)) {
curlevelnum++;
loadlevel(curworld, curlevelnum);
draweditorlevel();
drawsprites();
toggletimer = 30;
setmod(B_FALSE);
setstatustext("Skipping to next level.", &white);
}
}
}
/* prev level */
if (keys[SDLK_LEFT]) {
if (toggletimer == 0) {
if (curlevelnum > 1) {
curlevelnum--;
loadlevel(curworld, curlevelnum);
draweditorlevel();
drawsprites();
toggletimer = 30;
setmod(B_FALSE);
setstatustext("Skipping to previous level.", &white);
}
}
}
if (keys[SDLK_RETURN]) {
if (toggletimer == 0) {
SDL_WM_ToggleFullScreen(screen);
toggletimer = 50;
}
}
if (keys[SDLK_q]) {
return 1;
}
} else if (state == LS_SAVE) {
if (keys[SDLK_ESCAPE]) {
state = LS_EDIT;
draweditorlevel();
drawsprites();
}
}
/* levellist */
if (keys[SDLK_z]) {
state = LS_SAVE;
drawlevellist();
}
/* SAVE LEVEL */
if (keys[SDLK_s]) {
if (modified) {
savelevel(curworld,curlevelnum);
setmod(B_FALSE);
}
}
// line to selected position
if (state == LS_SAVE) {
char temps[MIDBUFLEN];
int lev, ypos;
// get level # at mouse posj
lev = my / (EDITTEXT + LLISTPADY);
ypos = lev * (EDITTEXT + LLISTPADY);
if (oldy != ypos) {
int textx = EDITMAPW - 200;
sprintf(temps, "Insert level here");
// clear old line
if (oldy != -1) {
drawline16(screen, LLISTX, oldy, EDITMAPW-LLISTX, oldy, black );
}
// clear old text
writetext(screen, textx, oldy-EDITTEXT, temps, EDITTEXT, &black);
// draw new line
drawline16(screen, LLISTX, ypos, EDITMAPW-LLISTX, ypos, green );
oldy = ypos;
// draw new text
writetext(screen, textx, ypos-EDITTEXT, temps, EDITTEXT, &green);
}
}
flip();
if (++timer == 100) timer = 0;
if (toggletimer > 0) toggletimer--;
}
return 0;
}
void cleanup(void) {
int i;
for (i = 1; i < MAXLETTERHEIGHT; i++) {
TTF_CloseFont(font[i]);
}
TTF_Quit();
SDL_Quit();
}
void drawstatus(void) {
char temps[MIDBUFLEN];
SDL_Rect area;
int wid;
SDL_Color *col;
// clear status
area.x = STATUSX;
area.y = STATUSY;
area.w = EDITORW;
area.h = EDITORH-STATUSY;
SDL_FillRect(screen, &area, SDL_MapRGB(screen->format, 0, 0, 0));
// show level num
sprintf(temps, "Level %d",curlevelnum);
wid = writetext(screen, area.x, area.y, temps, EDITTEXT, &white);
area.x += (wid + STATUSPAD);
// show level name
sprintf(temps, "%s",curlevel->filename);
wid = writetext(screen, area.x, area.y, temps, EDITTEXT, &white);
area.x += (wid + STATUSPAD);
// show level desc
sprintf(temps, "\"%s\"",curlevel->name);
wid = writetext(screen, area.x, area.y, temps, EDITTEXT, &blue);
area.x += (wid + STATUSPAD);
// show bg file
sprintf(temps, "bgfile: %s",curlevel->bgfile);
wid = writetext(screen, area.x, area.y, temps, EDITTEXT, &white);
area.x += (wid + STATUSPAD);
// show exit dir
sprintf(temps, "Exit dir: ");
switch (curlevel->exitdir) {
case D_RIGHT: strcat(temps, "RIGHT"); break;
case D_LEFT: strcat(temps, "LEFT"); break;
case D_UP: strcat(temps, "UP"); break;
case D_DOWN: strcat(temps, "DOWN"); break;
default: strcat(temps, "???"); break;
}
wid = writetext(screen, area.x, area.y, temps, EDITTEXT, &white);
area.x += (wid + STATUSPAD);
// show layer
///area.x = (EDITMAPW/4)*3; // 3/4 across
area.x = 0;
area.y += (EDITTEXT );
if (layer == 1) {
col = &green;
} else {
if (layertransparent) {
col = &grey2;
} else {
col = &white;
}
}
sprintf(temps, "Layer 1");
wid = writetext(screen, area.x, area.y, temps, EDITTEXT, col);
if (layer == 2) {
col = &green;
} else {
if (layertransparent) {
col = &grey2;
} else {
col = &white;
}
}
area.x += (wid + STATUSPAD);
sprintf(temps, "Layer 2");
wid = writetext(screen, area.x, area.y, temps, EDITTEXT, col);
// show modified status
area.x = EDITMAPW - 50;
sprintf(temps, "MODIFIED");
if (modified) {
col = &red;
} else {
col = &grey2;
}
wid = writetext(screen, area.x, area.y, temps, EDITTEXT, col);
// Move down
area.y += (EDITTEXT);
area.x = 0;
// status text
wid = writetext(screen, area.x, area.y, statustext, EDITTEXT, statustextcol);
}
void draweditorlevel(void) {
int x,y;
if (temps) {
SDL_FreeSurface(temps);
temps = NULL;
}
temps = SDL_CreateRGBSurface(SDL_SWSURFACE,
640, 480 + EDITTEXT*4,
screen->format->BitsPerPixel, screen->format->Rmask,
screen->format->Gmask,screen->format->Bmask,
screen->format->Amask);
for (x = 0; x < LEVELW; x++) {
for (y = 0; y < LEVELH; y++) {
draweditortile(screen,x,y);
}
}
drawstatus();
SDL_UpdateRect(screen, 0, 0, EDITORW, EDITORH);
}
void drawsprites(void) {
sprite_t *s;
for (s = sprite; s != NULL; s = s->next) {
drawsprite(s);
}
}
/*
char tiletochar(int id) {
switch (id) {
case T_BLANK: return '0';
case T_LAND: return '~';
case T_SLOPEUP: return '/';
case T_SLOPEDOWN: return '\\';
case T_FULL: return '*';
case T_SKY: return '0';
case T_LADDER: return '=';
case T_LADDERTOP: return '-';
case T_RIGHT: return '>';
case T_LEFT: return '<';
case T_SPIKES: return '^';
case T_TELEPORT: return ';';
case T_TELEPORT2: return ':';
case T_TELEPORTDEST: return '.';
case T_WATER: return '}';
case T_WATERTOP: return '{';
case T_WATERSPIKES: return '|';
}
return '0';
}
*/
void usage(void) {
printf("usage: edit [-fs] [-l xx]\n");
printf(" -fs Start in full-screen mode.\n");
printf(" -l xx Edit level xx.\n");
printf("\n");
}
void drawpalette(void) {
tiletype_t *tt;
SDL_Rect area;
tiletype_t *bg = gettile(curlevel->bgtileid);
int p;
int maxheight;
/* draw all tiles */
area.x = PALX;
area.y = PALY;
area.w = TILEW;
area.h = TILEH;
for (tt = tiletype; tt != NULL; tt = tt->next) {
if (isplacabletile(tt->id)) {
/* draw background */
SDL_BlitSurface(bg->img[0], NULL, screen, &area);
/* draw tile */
SDL_BlitSurface(tt->img[0], NULL, screen, &area);
/* draw selector box */
if (seltile == tt) {
drawbox16(screen,area.x,area.y,area.x+area.w-1,area.y+area.h-1,&red,NULL);
drawbox16(screen,area.x+1,area.y+1,area.x+area.w-2,area.y+area.h-2,&red,NULL);
}
/* move on to next position */
area.x += TILEW;
if (area.x >= EDITORW) {
area.x = PALX;
area.y += TILEH;
}
}
}
SDL_UpdateRect(screen, PALX,PALY,PALW,PALH);
/* draw all sprites */
maxheight = 0;
area.x = SPALX;
area.y = SPALY;
for (p = 0; p < MAXPTYPES; p++) {
SDL_Surface *firstimg;
if (isplacablesprite(p)) {
/* select images */
firstimg = imageset[p].img[F_WALK1];
area.w = firstimg->w;
area.h = firstimg->h;
if (area.h > maxheight) maxheight = area.h;
/* clear bg */
drawbox16(screen,area.x,area.y,area.x+area.w,area.y+area.h,&black,&black);
/* draw sprite */
SDL_BlitSurface(firstimg, NULL, screen, &area);
/* draw selector box */
if (selsprite == p) {
drawbox16(screen,area.x,area.y, area.x+area.w-1,area.y+area.h-1,&red,NULL);
drawbox16(screen,area.x+1,area.y+1, area.x+area.w-2,area.y+area.h-2,&red,NULL);
}
/* move to next position */
area.x += area.w;
if (area.x >= EDITORW-TILEW) {
area.x = SPALX;
area.y += maxheight;
maxheight = 0;
}
}
}
SDL_UpdateRect(screen, SPALX,SPALY,SPALW,SPALH);
}
int savelevel(int wnum, int lnum) {
FILE *f;
int x,y;
char filename[BUFLEN];
sprite_t *s;
sprintf(filename,"world%d/%s",wnum,levelentry[lnum].filename);
f = fopen(filename,"wt");
if (!f) {
printf("can't open level file '%s'\n",filename);
return B_TRUE;
}
fprintf(f, "bgfile %s\n",level->bgfile);
fprintf(f, "bg %d\n",level->bgtileid);
fprintf(f, "hurryup %d\n",level->hurryuptime);
/* no mappings */
//fprintf(f, "endmaps\n");
/* help text */
fprintf(f, "help\n");
for (s = sprite; s ; s = s->next) {
if (s->id == P_HELP) {
fprintf(f,"%s\n",s->name);
}
}
fprintf(f, "endhelp\n");
/* monster defs */
fprintf(f, "monsters\n");
for (s = sprite; s ; s = s->next) {
int mx,my;
char mid;
//mid = monstertochar(s->id);
mid = s->id;
mx = (s->x - (TILEW/2)) / TILEW;
my = (s->y - TILEH/2) / TILEH;
fprintf(f,"%d %d %d\n",mid,mx,my);
}
fprintf(f, "endmonsters\n");
/* exit dir */
fprintf(f, "exitdir %d\n",curlevel->exitdir);
/* level data */
for (y = 0; y < LEVELH; y++) {
for (x = 0; x < LEVELW; x++) {
fprintf(f, "%d,",level->map[y*LEVELW+x]);
}
fprintf(f, "\n");
}
fprintf(f, "layer2\n");
/* 2nd layer data - only where needed */
for (y = 0; y < LEVELH; y++) {
for (x = 0; x < LEVELW; x++) {
if (level->map2[y*LEVELW+x] != T_BLANK) {
// x,y,tileid
fprintf(f, "%d,%d,%d\n",x,y,level->map2[y*LEVELW+x]);
}
}
}
fclose(f);
sprintf(tempm,"Level saved to '%s'",filename);
setstatustext(tempm, &green);
return 0;
}
void clearlevel(void) {
int offset,x,y;
/* clear all sprites */
while (sprite) {
killsprite(sprite);
}
/* clear level */
for (x = 0; x < LEVELW; x++) {
for (y = 0; y < LEVELH; y++) {
offset = y*LEVELW+x;
if ((x == 0) || (x == LEVELW-1)) {
curlevel->map[offset] = T_FULL;
} else if (y == LEVELH-1) {
curlevel->map[offset] = T_LAND;
} else {
curlevel->map[offset] = T_BLANK;
}
curlevel->map2[offset] = T_BLANK;
draweditortile(screen,x,y);
}
}
modified = B_TRUE;
}
int isplacabletile(int tid) {
switch (tid) {
case T_TRAMPDOWN:
return B_FALSE;
}
return B_TRUE;
}
int isplacablesprite(int sid) {
switch (sid) {
case P_SPEED:
case P_NUMNETS:
case P_BIGNET:
case P_BLACKCLOUD:
case P_PINKCLOUD:
case P_SPIT:
case P_PUFF:
case P_SMASH:
case P_BOXING:
case P_GLOVE:
case P_DIAMOND:
case P_FTODIAMOND:
case P_FTOGEM:
case P_BOMB:
case P_SHIELD:
case P_MACEPOWERUP:
case P_MACE:
case P_GEMRED:
case P_GEMYELLOW:
case P_GEMPURPLE:
case P_SPRAY:
case P_CANNONPOWERUP:
case P_CANNON:
return B_FALSE;
}
return B_TRUE;
}
// like drawtile but adjusts transparncy based on current layer
void draweditortile(SDL_Surface *where, int x, int y) {
SDL_Rect area;
tiletype_t *tt;
int frame;
int offset;
SDL_Surface *greyim, *temps;
if ((x < 0) || (y < 0) || (x >= LEVELW) || (y >= LEVELH)) {
return;
}
area.x = x * TILEW;
area.y = y * TILEH;
area.w = TILEW;
area.h = TILEH;
/* draw blank tile first */
tt = gettile(curlevel->bgtileid);
SDL_BlitSurface(levelbg, &area, where, &area);
/* figure out what the layer1 tile is */
offset = y*LEVELW+x;
tt = gettile(curlevel->map[offset]);
frame = curlevel->tileframe[offset];
// get greyimnal layer1 image
temps = rotozoomSurfaceXY(tt->img[frame], 0, 1, 1, 0);
// paste grey one on top
//SDL_BlitSurface(whitebox, NULL, greyim, NULL);
SDL_SetAlpha(temps, SDL_SRCALPHA, 50);
greyim = SDL_DisplayFormat(temps);
SDL_FreeSurface(temps);
/* now draw real one */
if (tt->id != curlevel->bgtileid) {
if (layertransparent && (layer == 2)) { // greyed one
SDL_BlitSurface(greyim, NULL, where, &area);
} else {
SDL_BlitSurface(tt->img[frame], NULL, where, &area);
}
}
SDL_FreeSurface(greyim);
/* now draw layer2 if it exists */
if (curlevel->map2[offset] != T_BLANK) {
tt = gettile(curlevel->map2[offset]);
if (tt->id != curlevel->bgtileid) {
// there is a second layer.
// generate greyed version...
// get greyimnal layer2 image
temps = rotozoomSurfaceXY(tt->img[frame], 0, 1, 1, 0);
// paste grey one on top
//SDL_BlitSurface(whitebox, NULL, greyim, NULL);
SDL_SetAlpha(temps, SDL_SRCALPHA, 50);
greyim = SDL_DisplayFormat(temps);
SDL_FreeSurface(temps);
if (layertransparent && (layer == 1)) { // greyed one
SDL_BlitSurface(greyim, NULL, where, &area);
} else {
SDL_BlitSurface(tt->img[frame], NULL, where, &area);
}
}
SDL_FreeSurface(greyim);
}
}
int writetext(SDL_Surface *where, int x, int y, char *text, int size, SDL_Color *col) {
SDL_Surface *temps;
SDL_Rect area;
int wid;
if (strlen(text) <= 0) {
return 0;
}
temps = TTF_RenderText_Solid(font[size], text, *col);
area.x = x;
area.y = y;
area.w = 0;
area.h = 0;
SDL_BlitSurface(temps, NULL, where, &area);
wid = temps->w;
SDL_FreeSurface(temps);
return wid;
}
void setmod(int yesno) {
int oldmod;
oldmod = modified;
if (yesno) {
modified = B_TRUE;
} else {
modified = B_FALSE;
}
// update status bar
if (oldmod != modified) {
drawstatus();
}
}
void drawlevellist(void) {
int i;
char temps[MIDBUFLEN];
SDL_Rect area;
SDL_Color *col;
// clear map
area.x = 0;
area.y = 0;
area.w = EDITMAPW;
area.h = EDITMAPH;
SDL_FillRect(screen, &area, SDL_MapRGB(screen->format, 0, 0, 0));
// draw level list
area.x = LLISTX;
area.y = 0;
area.w = 0;
area.h = 0;
for (i =1; i < numlevels; i++) {
if (i == curlevelnum) {
col = &green;
} else {
col = &white;
}
sprintf(temps, "%d. %s (%s)",levelentry[i].id, levelentry[i].desc, levelentry[i].filename);
writetext(screen, area.x, area.y, temps, EDITTEXT, col);
area.y += (EDITTEXT + LLISTPADY);
}
}
void newlevel(void) {
char tempbuf[BUFLEN];
curlevelnum = numlevels;
clearlevel();
maxlevid++;
sprintf(tempbuf,"level%d.dat",maxlevid);
sprintf(curlevel->filename, tempbuf);
strncpy(levelentry[curlevelnum].filename, tempbuf, MIDBUFLEN);
sprintf(tempbuf,"NEW LEVEL");
sprintf(curlevel->name, tempbuf);
strncpy(levelentry[curlevelnum].desc, tempbuf, MIDBUFLEN);
curlevel->id = maxlevid;
levelentry[curlevelnum].id = maxlevid;
sprintf(tempm,"Made new level '%s'\n",levelentry[curlevelnum].filename);
setstatustext(tempm, &green);
numlevels++;
// save list
savelevellist();
}
void setstatustext(char *text, SDL_Color *col) {
strncpy(statustext, text, BUFLEN);
statustextcol = col;
drawstatus();
}