2008-09-16 12:40:09 +10:00
|
|
|
#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>
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
#include "defs.h"
|
|
|
|
#include "shared.h"
|
|
|
|
#include "edit.h"
|
2008-09-16 12:40:09 +10:00
|
|
|
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
/* these hold the currently selected sprite/tile types */
|
2008-09-16 12:40:09 +10:00
|
|
|
tiletype_t *seltile = NULL;
|
|
|
|
int selsprite = -1;
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
int modified = B_FALSE; // has the current level been modified since last save?
|
2008-09-16 12:40:09 +10:00
|
|
|
|
|
|
|
|
|
|
|
int curworld = 1;
|
|
|
|
int curlevelnum;
|
|
|
|
|
2008-10-01 17:27:44 +10:00
|
|
|
int skipto = -1;
|
|
|
|
|
2008-09-29 18:32:56 +10:00
|
|
|
int layer = 1; // which layer we are editting, either 1 or 2
|
2008-10-07 16:53:06 +11:00
|
|
|
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};
|
2008-10-16 14:16:47 +11:00
|
|
|
SDL_Color green1 = {0, 100, 0, 0};
|
2008-10-07 16:53:06 +11:00
|
|
|
SDL_Color yellow = {255, 255, 0, 0};
|
2008-10-16 14:16:47 +11:00
|
|
|
SDL_Color yellow1 = {100, 100, 0, 0};
|
2008-10-07 16:53:06 +11:00
|
|
|
|
|
|
|
int state;
|
|
|
|
|
|
|
|
char tempm[BUFLEN];
|
|
|
|
|
|
|
|
char statustext[BUFLEN];
|
|
|
|
SDL_Color *statustextcol = &white;
|
|
|
|
|
|
|
|
// for level list mode
|
|
|
|
int oldy = -1;
|
2008-09-29 18:32:56 +10:00
|
|
|
|
2008-09-16 12:40:09 +10:00
|
|
|
int main (int argc, char **argv) {
|
|
|
|
Uint8 *keys;
|
|
|
|
char filename[BUFLEN];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
int mb,mx,my;
|
|
|
|
|
|
|
|
curlevelnum = 1;
|
|
|
|
|
2008-09-30 17:42:09 +10:00
|
|
|
levelbg = NULL;
|
|
|
|
|
2008-10-07 20:18:42 +11:00
|
|
|
setfruitinfo();
|
|
|
|
|
2008-10-10 10:12:51 +11:00
|
|
|
datadir = NULL;
|
|
|
|
|
2008-09-16 12:40:09 +10:00
|
|
|
/* handle arguments */
|
|
|
|
if (argc >= 2) {
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "-fs")) {
|
|
|
|
printf("Fullscreen mode enabled.\n");
|
|
|
|
vidargs |= SDL_FULLSCREEN;
|
2008-10-10 10:12:51 +11:00
|
|
|
} else if (!strcmp(argv[i], "-d")) {
|
|
|
|
if (++i >= argc) {
|
|
|
|
printf("Missing data dir.\n");
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
datadir = strdup(argv[i]);
|
2008-10-07 20:18:42 +11:00
|
|
|
} else if (!strcmp(argv[i], "-dump")) {
|
|
|
|
dumpinfo();
|
|
|
|
exit(1);
|
2008-09-16 12:40:09 +10:00
|
|
|
} else if (!strcmp(argv[i], "-l")) {
|
|
|
|
if (++i >= argc) {
|
|
|
|
printf("Missing level number.\n");
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-10-01 17:27:44 +10:00
|
|
|
skipto = atoi(argv[i]);
|
|
|
|
printf("Skipping to level %d.\n",skipto);
|
2008-09-16 12:40:09 +10:00
|
|
|
} else {
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 10:12:51 +11:00
|
|
|
if (datadir == NULL) {
|
|
|
|
datadir = strdup("data");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-30 17:42:09 +10:00
|
|
|
if (loadlevellist()) {
|
|
|
|
printf("Error loading level list from levels.dat.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-10-01 17:27:44 +10:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
/* initialise */
|
|
|
|
initglobals();
|
|
|
|
|
2008-09-16 12:40:09 +10:00
|
|
|
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE)==-1) {
|
|
|
|
printf("SDL_Init: %s\n", SDL_GetError());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
|
2008-09-16 12:40:09 +10:00
|
|
|
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
|
|
|
|
|
2008-10-31 08:56:50 +11:00
|
|
|
// set title bar
|
|
|
|
sprintf(progname, "Rat Catcher Level Editor v0.%d", REV);
|
|
|
|
SDL_WM_SetCaption(progname, progname);
|
|
|
|
|
2008-10-15 16:20:47 +11:00
|
|
|
/* load fonts */
|
|
|
|
TTF_Init();
|
|
|
|
sprintf(filename, "%s/editfont.ttf",datadir);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-03 17:37:05 +10:00
|
|
|
/* init tiles */
|
|
|
|
if (loadtiletypes("green.tiles")) {
|
|
|
|
printf("Cannot initialise tiles\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-09-16 12:40:09 +10:00
|
|
|
if (loadimagesets()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
strcpy(statustext, "");
|
|
|
|
statustextcol = &white;
|
|
|
|
|
2008-09-16 12:40:09 +10:00
|
|
|
fakeblock.id = T_LAND;
|
|
|
|
strcpy(fakeblock.name,"Fake");
|
|
|
|
for (i = 0; i < TILEW; i++) {
|
|
|
|
fakeblock.lowness[i] = 0;
|
|
|
|
}
|
|
|
|
fakeblock.solid = S_SOLID;
|
2008-10-10 10:12:51 +11:00
|
|
|
|
|
|
|
sprintf(filename, "%s/newtiles/land.png",datadir);
|
|
|
|
fakeblock.img[0] = IMG_Load(filename);
|
2008-09-17 21:16:19 +10:00
|
|
|
fakeblock.numframes = 1;
|
2008-09-16 12:40:09 +10:00
|
|
|
fakeblock.next = NULL;
|
|
|
|
fakeblock.prev = NULL;
|
2008-10-07 16:53:06 +11:00
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2008-09-16 12:40:09 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
state = LS_EDIT;
|
|
|
|
|
2008-10-10 10:49:43 +11:00
|
|
|
if (loadlevel(curworld,curlevelnum, B_TRUE)) {
|
2008-09-16 12:40:09 +10:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
modified = B_FALSE;
|
2008-09-16 12:40:09 +10:00
|
|
|
|
|
|
|
seltile = tiletype;
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
draweditorlevel();
|
2008-09-16 12:40:09 +10:00
|
|
|
drawpalette();
|
|
|
|
drawsprites();
|
|
|
|
flip();
|
|
|
|
|
|
|
|
timer = 0;
|
|
|
|
|
2008-09-26 19:51:17 +10:00
|
|
|
//player->invuln = INVULNTIME;
|
|
|
|
//player->score = 0;
|
2008-09-16 12:40:09 +10:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
|
|
|
|
|
|
|
/* check for mouse actions */
|
|
|
|
mb = SDL_GetMouseState(&mx,&my);
|
|
|
|
if (mb & SDL_BUTTON(1)) { // lmb
|
2008-10-07 16:53:06 +11:00
|
|
|
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;
|
|
|
|
}
|
2008-09-30 17:42:09 +10:00
|
|
|
}
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
// 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;
|
|
|
|
}
|
2008-09-30 17:42:09 +10:00
|
|
|
}
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
// 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;
|
|
|
|
//}
|
2008-09-27 21:35:24 +10:00
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
// 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;
|
2008-09-27 21:35:24 +10:00
|
|
|
placed = B_TRUE;
|
2008-10-07 16:53:06 +11:00
|
|
|
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;
|
|
|
|
}
|
2008-09-17 12:34:39 +10:00
|
|
|
}
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
|
|
|
|
|
|
|
|
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);
|
2008-09-27 21:35:24 +10:00
|
|
|
}
|
2008-09-27 16:02:42 +10:00
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (state == LS_SAVE) {
|
|
|
|
// get pos
|
|
|
|
int i;
|
|
|
|
int lev;
|
|
|
|
// get level # at mouse posj
|
|
|
|
lev = (my / (EDITTEXT + LLISTPADY));
|
2008-10-30 08:54:53 +11:00
|
|
|
// adjust for world offset
|
|
|
|
lev = lev + (getworld(curlevelnum)-1)*20;
|
2008-10-07 16:53:06 +11:00
|
|
|
|
|
|
|
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--;
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
// 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);
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
}// end if LS_EDIT/LS_SAVE etc
|
|
|
|
} // end if LMB
|
|
|
|
|
2008-09-16 12:40:09 +10:00
|
|
|
|
|
|
|
/* check for keys */
|
|
|
|
SDL_PumpEvents();
|
|
|
|
keys = SDL_GetKeyState(NULL);
|
2008-09-17 12:34:39 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
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;
|
2008-09-17 12:34:39 +10:00
|
|
|
}
|
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
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;
|
|
|
|
}
|
2008-09-27 16:02:42 +10:00
|
|
|
}
|
2008-09-28 13:18:36 +10:00
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
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);
|
|
|
|
}
|
2008-09-28 13:18:36 +10:00
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
if (keys[SDLK_c]) {
|
|
|
|
if (toggletimer == 0) {
|
|
|
|
clearlevel();
|
|
|
|
toggletimer = 30;
|
|
|
|
}
|
2008-09-28 13:18:36 +10:00
|
|
|
}
|
2008-10-09 14:32:15 +11:00
|
|
|
if (keys[SDLK_f]) {
|
|
|
|
if (toggletimer == 0) {
|
|
|
|
filllevel();
|
|
|
|
toggletimer = 30;
|
|
|
|
}
|
|
|
|
}
|
2008-09-28 13:18:36 +10:00
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
|
|
|
|
|
|
|
|
/* exit direction */
|
2008-09-26 19:51:17 +10:00
|
|
|
if (toggletimer == 0) {
|
2008-10-07 16:53:06 +11:00
|
|
|
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);
|
2008-09-30 17:42:09 +10:00
|
|
|
}
|
2008-09-26 19:51:17 +10:00
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
|
|
|
|
/* new level */
|
|
|
|
if (keys[SDLK_n]) {
|
|
|
|
if (toggletimer == 0) {
|
|
|
|
newlevel();
|
2008-09-26 19:51:17 +10:00
|
|
|
draweditorlevel();
|
|
|
|
drawsprites();
|
|
|
|
toggletimer = 30;
|
2008-10-07 16:53:06 +11:00
|
|
|
setmod(B_FALSE);
|
|
|
|
setstatustext("Created new level.", &white);
|
2008-09-26 19:51:17 +10:00
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
/* next level */
|
|
|
|
if (keys[SDLK_RIGHT]) {
|
|
|
|
if (toggletimer == 0) {
|
|
|
|
if (curlevelnum < (numlevels-1)) {
|
|
|
|
curlevelnum++;
|
2008-10-10 10:49:43 +11:00
|
|
|
loadlevel(curworld, curlevelnum, B_TRUE);
|
2008-10-07 16:53:06 +11:00
|
|
|
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--;
|
2008-10-10 10:49:43 +11:00
|
|
|
loadlevel(curworld, curlevelnum, B_TRUE);
|
2008-10-07 16:53:06 +11:00
|
|
|
draweditorlevel();
|
|
|
|
drawsprites();
|
|
|
|
toggletimer = 30;
|
|
|
|
setmod(B_FALSE);
|
|
|
|
setstatustext("Skipping to previous level.", &white);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-17 12:34:39 +10:00
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
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();
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
/* SAVE LEVEL */
|
|
|
|
if (keys[SDLK_s]) {
|
|
|
|
if (modified) {
|
|
|
|
savelevel(curworld,curlevelnum);
|
2008-10-07 16:53:06 +11:00
|
|
|
setmod(B_FALSE);
|
2008-09-17 12:34:39 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
// 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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-09-16 12:40:09 +10:00
|
|
|
|
|
|
|
flip();
|
|
|
|
if (++timer == 100) timer = 0;
|
|
|
|
if (toggletimer > 0) toggletimer--;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
void cleanup(void) {
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < MAXLETTERHEIGHT; i++) {
|
|
|
|
TTF_CloseFont(font[i]);
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
2008-09-17 12:34:39 +10:00
|
|
|
TTF_Quit();
|
|
|
|
SDL_Quit();
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
void drawstatus(void) {
|
2008-10-20 07:45:38 +11:00
|
|
|
char temps[BUFLEN];
|
2008-10-07 16:53:06 +11:00
|
|
|
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);
|
2008-10-20 07:45:38 +11:00
|
|
|
// show level filename
|
|
|
|
snprintf(temps, BUFLEN, "%s",curlevel->filename);
|
2008-10-07 16:53:06 +11:00
|
|
|
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);
|
|
|
|
}
|
2008-09-16 12:40:09 +10:00
|
|
|
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
void draweditorlevel(void) {
|
|
|
|
int x,y;
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
if (temps) {
|
|
|
|
SDL_FreeSurface(temps);
|
|
|
|
temps = NULL;
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
2008-09-17 12:34:39 +10:00
|
|
|
temps = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
2008-10-07 16:53:06 +11:00
|
|
|
640, 480 + EDITTEXT*4,
|
2008-09-17 12:34:39 +10:00
|
|
|
screen->format->BitsPerPixel, screen->format->Rmask,
|
|
|
|
screen->format->Gmask,screen->format->Bmask,
|
|
|
|
screen->format->Amask);
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
for (x = 0; x < LEVELW; x++) {
|
|
|
|
for (y = 0; y < LEVELH; y++) {
|
2008-10-07 16:53:06 +11:00
|
|
|
draweditortile(screen,x,y);
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
drawstatus();
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
SDL_UpdateRect(screen, 0, 0, EDITORW, EDITORH);
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void drawsprites(void) {
|
|
|
|
sprite_t *s;
|
|
|
|
for (s = sprite; s != NULL; s = s->next) {
|
|
|
|
drawsprite(s);
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
|
|
|
|
/*
|
|
|
|
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");
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
|
|
|
|
|
|
|
|
void drawpalette(void) {
|
2008-09-16 12:40:09 +10:00
|
|
|
tiletype_t *tt;
|
2008-09-17 12:34:39 +10:00
|
|
|
SDL_Rect area;
|
|
|
|
tiletype_t *bg = gettile(curlevel->bgtileid);
|
|
|
|
int p;
|
|
|
|
int maxheight;
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
/* draw all tiles */
|
|
|
|
area.x = PALX;
|
|
|
|
area.y = PALY;
|
|
|
|
area.w = TILEW;
|
|
|
|
area.h = TILEH;
|
|
|
|
for (tt = tiletype; tt != NULL; tt = tt->next) {
|
2008-09-30 17:42:09 +10:00
|
|
|
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;
|
|
|
|
}
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
SDL_UpdateRect(screen, PALX,PALY,PALW,PALH);
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
/* draw all sprites */
|
|
|
|
maxheight = 0;
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
area.x = SPALX;
|
|
|
|
area.y = SPALY;
|
|
|
|
for (p = 0; p < MAXPTYPES; p++) {
|
|
|
|
SDL_Surface *firstimg;
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-30 17:42:09 +10:00
|
|
|
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);
|
|
|
|
}
|
2008-09-17 12:34:39 +10:00
|
|
|
|
2008-09-30 17:42:09 +10:00
|
|
|
/* move to next position */
|
|
|
|
area.x += area.w;
|
|
|
|
if (area.x >= EDITORW-TILEW) {
|
|
|
|
area.x = SPALX;
|
|
|
|
area.y += maxheight;
|
|
|
|
maxheight = 0;
|
|
|
|
}
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
2008-09-17 12:34:39 +10:00
|
|
|
|
|
|
|
}
|
|
|
|
SDL_UpdateRect(screen, SPALX,SPALY,SPALW,SPALH);
|
|
|
|
}
|
2008-09-16 12:40:09 +10:00
|
|
|
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
int savelevel(int wnum, int lnum) {
|
|
|
|
FILE *f;
|
|
|
|
int x,y;
|
|
|
|
char filename[BUFLEN];
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
sprite_t *s;
|
2008-09-16 12:40:09 +10:00
|
|
|
|
|
|
|
|
2008-10-10 07:51:09 +11:00
|
|
|
sprintf(filename,"%s/world%d/%s",datadir,wnum,levelentry[lnum].filename);
|
2008-09-30 17:42:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
f = fopen(filename,"wt");
|
|
|
|
if (!f) {
|
2008-10-03 17:37:05 +10:00
|
|
|
printf("can't open level file '%s'\n",filename);
|
2008-09-17 12:34:39 +10:00
|
|
|
return B_TRUE;
|
|
|
|
}
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-10-03 17:37:05 +10:00
|
|
|
fprintf(f, "bgfile %s\n",level->bgfile);
|
2008-09-17 12:34:39 +10:00
|
|
|
fprintf(f, "bg %d\n",level->bgtileid);
|
|
|
|
fprintf(f, "hurryup %d\n",level->hurryuptime);
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
/* no mappings */
|
2008-10-07 16:53:06 +11:00
|
|
|
//fprintf(f, "endmaps\n");
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
/* help text */
|
|
|
|
fprintf(f, "help\n");
|
|
|
|
for (s = sprite; s ; s = s->next) {
|
|
|
|
if (s->id == P_HELP) {
|
|
|
|
fprintf(f,"%s\n",s->name);
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
|
|
|
}
|
2008-09-17 12:34:39 +10:00
|
|
|
fprintf(f, "endhelp\n");
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
/* monster defs */
|
|
|
|
fprintf(f, "monsters\n");
|
|
|
|
for (s = sprite; s ; s = s->next) {
|
|
|
|
int mx,my;
|
|
|
|
char mid;
|
2008-10-07 16:53:06 +11:00
|
|
|
//mid = monstertochar(s->id);
|
|
|
|
mid = s->id;
|
2008-09-17 12:34:39 +10:00
|
|
|
mx = (s->x - (TILEW/2)) / TILEW;
|
|
|
|
my = (s->y - TILEH/2) / TILEH;
|
2008-10-07 16:53:06 +11:00
|
|
|
fprintf(f,"%d %d %d\n",mid,mx,my);
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
2008-09-17 12:34:39 +10:00
|
|
|
fprintf(f, "endmonsters\n");
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-28 13:18:36 +10:00
|
|
|
/* exit dir */
|
|
|
|
fprintf(f, "exitdir %d\n",curlevel->exitdir);
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
/* level data */
|
|
|
|
for (y = 0; y < LEVELH; y++) {
|
|
|
|
for (x = 0; x < LEVELW; x++) {
|
|
|
|
fprintf(f, "%d,",level->map[y*LEVELW+x]);
|
2008-09-16 12:40:09 +10:00
|
|
|
}
|
2008-09-17 12:34:39 +10:00
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-29 18:32:56 +10:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
fclose(f);
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
sprintf(tempm,"Level saved to '%s'",filename);
|
|
|
|
setstatustext(tempm, &green);
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-09-17 12:34:39 +10:00
|
|
|
return 0;
|
|
|
|
}
|
2008-09-16 12:40:09 +10:00
|
|
|
|
2008-10-09 14:32:15 +11:00
|
|
|
void filllevel(void) {
|
|
|
|
int offset,x,y;
|
|
|
|
|
|
|
|
if (seltile == NULL) {
|
|
|
|
setstatustext("No tile selected for fill!",&red);
|
|
|
|
} else {
|
|
|
|
/* fill level with current tile*/
|
|
|
|
for (x = 0; x < LEVELW; x++) {
|
|
|
|
for (y = 0; y < LEVELH; y++) {
|
|
|
|
offset = y*LEVELW+x;
|
|
|
|
curlevel->map[offset] = seltile->uniqid;
|
|
|
|
curlevel->map2[offset] = T_BLANK;
|
|
|
|
draweditortile(screen,x,y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
modified = B_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:42:09 +10:00
|
|
|
|
|
|
|
void clearlevel(void) {
|
|
|
|
int offset,x,y;
|
|
|
|
|
|
|
|
/* clear all sprites */
|
|
|
|
while (sprite) {
|
|
|
|
killsprite(sprite);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* clear level */
|
2008-10-30 08:54:53 +11:00
|
|
|
if (curlevel->animtiles) {
|
|
|
|
free(level->animtiles);
|
|
|
|
curlevel->animtiles = NULL;
|
|
|
|
}
|
2008-09-30 17:42:09 +10:00
|
|
|
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;
|
2008-10-30 08:54:53 +11:00
|
|
|
curlevel->tileframe[offset] = 0;
|
2008-10-07 16:53:06 +11:00
|
|
|
draweditortile(screen,x,y);
|
2008-09-30 17:42:09 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-30 08:54:53 +11:00
|
|
|
curlevel->nummonsters = 0;
|
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
|
2008-09-30 17:42:09 +10:00
|
|
|
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:
|
2008-10-07 16:53:06 +11:00
|
|
|
case P_BLACKCLOUD:
|
|
|
|
case P_PINKCLOUD:
|
2008-09-30 17:42:09 +10:00
|
|
|
case P_SPIT:
|
|
|
|
case P_PUFF:
|
2008-10-03 17:37:05 +10:00
|
|
|
case P_SMASH:
|
2008-09-30 17:42:09 +10:00
|
|
|
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:
|
2008-10-07 16:53:06 +11:00
|
|
|
case P_SPRAY:
|
|
|
|
case P_CANNONPOWERUP:
|
|
|
|
case P_CANNON:
|
2008-10-09 14:32:15 +11:00
|
|
|
case P_TROPHY:
|
|
|
|
case P_SNOWMAN:
|
|
|
|
case P_RINGSILVER:
|
|
|
|
case P_RINGGOLD:
|
|
|
|
case P_CLOCK:
|
|
|
|
case P_BELL:
|
2008-10-24 14:31:25 +11:00
|
|
|
case P_ARMOUR:
|
2008-10-09 14:32:15 +11:00
|
|
|
case P_GEMBOOST:
|
|
|
|
case P_HELMET:
|
2008-10-10 21:06:40 +11:00
|
|
|
case P_PHONE:
|
|
|
|
case P_BUBBLE:
|
|
|
|
case P_HONEY:
|
|
|
|
case P_STARPOWERUP:
|
|
|
|
case P_STAR:
|
|
|
|
case P_UFO:
|
|
|
|
case P_METEOR:
|
|
|
|
case P_LIFE:
|
|
|
|
case P_BIGSPEED:
|
2008-10-15 14:20:10 +11:00
|
|
|
case P_MOVINGCARD:
|
|
|
|
case P_FIVECARDS:
|
2008-10-15 16:22:43 +11:00
|
|
|
case P_MASKPOWERUP:
|
|
|
|
case P_MASK:
|
|
|
|
case P_TAP:
|
2008-10-18 14:30:57 +11:00
|
|
|
case P_CLOVER:
|
2008-10-20 07:45:38 +11:00
|
|
|
case P_SKULL:
|
|
|
|
case P_WINGLEFT:
|
|
|
|
case P_WINGRIGHT:
|
2008-10-24 09:06:01 +11:00
|
|
|
case P_WINGBOOTS:
|
|
|
|
case P_ACCORDION:
|
2008-09-30 17:42:09 +10:00
|
|
|
return B_FALSE;
|
|
|
|
}
|
2008-10-15 06:36:51 +11:00
|
|
|
|
2008-10-15 20:00:16 +11:00
|
|
|
if (iseffect(sid) && (sid != P_POWERUPPOS)) {
|
2008-10-15 16:22:43 +11:00
|
|
|
return B_FALSE;
|
|
|
|
}
|
2008-10-15 06:36:51 +11:00
|
|
|
if (iscard(sid)) {
|
|
|
|
return B_FALSE;
|
|
|
|
}
|
2008-09-30 17:42:09 +10:00
|
|
|
return B_TRUE;
|
|
|
|
}
|
2008-10-07 16:53:06 +11:00
|
|
|
|
|
|
|
// 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));
|
|
|
|
|
2008-10-30 08:54:53 +11:00
|
|
|
// draw level list (starting at current world)
|
2008-10-07 16:53:06 +11:00
|
|
|
area.x = LLISTX;
|
|
|
|
area.y = 0;
|
|
|
|
area.w = 0;
|
|
|
|
area.h = 0;
|
2008-10-30 08:54:53 +11:00
|
|
|
for (i = ((getworld(curlevelnum)-1)*20)+1; i < numlevels; i++) {
|
2008-10-07 16:53:06 +11:00
|
|
|
if (i == curlevelnum) {
|
|
|
|
col = &green;
|
2008-10-16 14:16:47 +11:00
|
|
|
} else if (i <= 20) {
|
|
|
|
col = &green1;
|
|
|
|
} else if (i <= 40) {
|
|
|
|
col = &yellow1;
|
2008-10-07 16:53:06 +11:00
|
|
|
} else {
|
|
|
|
col = &white;
|
|
|
|
}
|
2008-10-16 14:16:47 +11:00
|
|
|
sprintf(temps, "%d-%d. %s (id=%d, %s)",getworld(i),getlevel(i),levelentry[i].desc, levelentry[i].id, levelentry[i].filename);
|
2008-10-07 16:53:06 +11:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2008-10-10 12:30:40 +11:00
|
|
|
// default
|
|
|
|
curlevel->hurryuptime = 30;
|
|
|
|
curlevel->exitdir = D_RIGHT;
|
|
|
|
|
2008-10-07 16:53:06 +11:00
|
|
|
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();
|
|
|
|
}
|