Ejemplo n.º 1
0
int msg_mines (int n, int msg, int z) {		// space mines
	int sh, x, y;
	switch (msg) {
		case msg_update:
			objs[n].count = (objs[n].count + 1)&3; return (1);
		case msg_draw:
			sh = 0xf00 + 18 + objs[n].count/2;
			drawshape (&gamevp, sh, objs[n].x, objs[n].y); break;
		case msg_touch:
			switch (objs[z].kind) {
				case obj_player:
					if (class_cnt(class_shield)==0) {
						p_hit (2); snd_play (1,5);
						x = objs[n].x - 11; y = objs[n].y - 9;
						addobj (obj_explode3, x, y, 0, 0);
						explosion (objs[n].x, objs[n].y, 5);
						text ("You hit an enemy space mine!",0);
						killobj (n);
						}; break;
				case obj_shield:
					addobj (obj_explode2, objs[n].x, objs[n].y, 0, 0);
					explosion (objs[n].x, objs[n].y, 5);
					text ("Your shield was destroyed by a space mine",0);
					killobj (n); killobj (z); snd_play (1,5);
				};
		}; return (0);
	};
Ejemplo n.º 2
0
int msg_drop (int n, int msg, int z) {
	int sh=kindtable[obj_drop]*256;
	int c;
	objtype *pobj; pobj=&(objs[n]);

	switch (msg) {
		case msg_update:
			if (pobj->state==0) {
				if (++pobj->counter>=60) {
					pobj->counter=0;
					addobj (obj_drop,pobj->x,pobj->y+2,0,2);
					objs[numobjs-1].state=1;
					};
				}
			else {
				if (!justmove(n,pobj->x,pobj->y+pobj->yd+2)) {
					c=((pobj->y+pobj->yd+2)&0xfff0)+16-pobj->yl;
					if ((c==pobj->y)||(!justmove(n,pobj->x,c))) {
						addobj (obj_splash,pobj->x-11,pobj->y+2,0,0);
						killobj (n);
						};
					};
				if ((pobj->yd+=2)>12) pobj->yd=12;
				}; return (1);
		case msg_draw:
			if (pobj->state==0) {
				drawshape (&gamevp,sh+12+pobj->counter/20,pobj->x,pobj->y);
				}
			else drawshape (&gamevp,sh+11,pobj->x,pobj->y); break;
		case msg_touch: if (z==0) hitplayer (n,0);
		}; return (0);
	};
Ejemplo n.º 3
0
void explosion (int x, int y, int num) {
	int c;
	for (c = 0; c < num; c++) {
		addobj (obj_explode4, x, y, 0, 0);
		objs[num_objs-1].xd = random (7) - 3;
		objs[num_objs-1].yd = random (11) - 8;
		};
	};
Ejemplo n.º 4
0
void eject (int x, int y, int num) {
	int c;
	for (c = 0; c < num; c++) {
		addobj (obj_ejected, x, y, 0, 0);
		objs[num_objs-1].xd = random (7) - 3;
		objs[num_objs-1].yd = random (11) - 8;
		};
	};
Font::Font (const char* fileName){

	File* file;
	//unsigned char* blank;
	int fileSize;
	int count, size;
	unsigned short width, height;
	// Load font from a font file

	try {

		file = new File(fileName, false);

	} catch (int e) {
		#ifdef CASIO
			casioQuit(fileName);
		#endif
		throw e;

	}

	fileSize = file->getSize();

	nCharacters = 128;


	file->seek(20, true);
	lineHeight = file->loadChar() << 1;


	// Create blank character data

	//blank = new unsigned char[3];
	//memset(blank, 0, 3);
	// Load characters
	addobj(0,&ramid);
	for (count = 0; count < 128;++count){
		//characters[count].palette=paletteF;
		if (file->tell() >= fileSize) {
			nCharacters = count;
			break;
		}
		size = file->loadShort();
		if (size > 4) {
			unsigned char* pixels=(unsigned char *)alloca(size);
			file->loadRLE(size,pixels);
			width = pixels[0];
			width |= pixels[1] << 8;
			height = pixels[2];
			height |= pixels[3] << 8;
			if ((size - 4) >= (width * height)){
				//characters[count] = createSurface(pixels + 4, width, height);
				characters[count].pix=(unsigned char *)objs[ramid].ptr+objs[ramid].size;
				resizeobj(ramid,objs[ramid].size+(width*height));
				memcpy(characters[count].pix,pixels+4,width*height);
				characters[count].w=width;
				characters[count].h=height;
			}else{
				//characters[count] = createSurface(blank, 3, 1);
				characters[count].w=3;
				characters[count].h=1;
				characters[count].pix=(unsigned char *)blankFont;
			}
			//delete[] pixels;
		}else{
			//characters[count] = createSurface(blank, 3, 1);
			characters[count].w=3;
			characters[count].h=1;
			characters[count].pix=(unsigned char *)blankFont;
		}

		//SDL_SetColorKey(characters[count], SDL_SRCCOLORKEY, 0);
		characters[count].flags=miniS_COLKEY;
		characters[count].colkey=0;
	}
	//delete[] blank;
	delete file;
	// Create ASCII->font map
	for (count = 0; count < 33; count++) map[count] = 0;
	map[33] = 107; // !
	map[34] = 116; // "
	map[35] = 0; // #
	map[36] = 63; // $
	map[37] = 0; // %
	map[38] = 0; // &
	map[39] = 115; // '
	map[40] = 111; // (
	map[41] = 112; // )
	map[42] = 0; // *
	map[43] = 105; // +
	map[44] = 101; // ,
	map[45] = 104; // -
	map[46] = 102; // .
	map[47] = 108; // /
	for (count = 48; count < 58; count++) map[count] = count + 5;  // Numbers
	map[58] = 114; // :
	map[59] = 113; // ;
	map[60] = 0; // <
	map[61] = 106; // =
	map[62] = 0; // >
	map[63] = 103; // ?
	map[64] = 0; // @
	for (count = 65; count < 91; count++) map[count] = count - 38; // Upper-case letters
	for (; count < 97; count++) map[count] = 0;
	for (; count < 123; count++) map[count] = count - 96; // Lower-case letters
	for (; count < 128; count++) map[count] = 0;

	for (count = 0; count < 128; count++) {

		if (map[count] >= nCharacters) map[count] = 0;

	}
	restorePalette();

}
/**
 * Load a font from a .000 file.
 *
 * @param bonus whether to use FONTS.000 or BONUS.000
 */
Font::Font (bool bonus) {

	File* file;
	//unsigned char* pixels;
	int fileSize;
	int count, width, height;

	// Load font from FONTS.000 or BONUS.000

	try {

		file = new File(bonus? F_BONUS: F_FONTS, false);

	} catch (int e) {

		throw e;

	}


	fileSize = file->getSize();

	nCharacters = file->loadShort(256);

	if (bonus) {

		count = file->loadShort();
		nCharacters -= count;

		// Skip sprites

		for (; count > 0; count--) {

			file->seek(4, false);

			width = file->loadShort();
			if (width == 0xFFFF) width = 0;

			file->seek((width << 2) + file->loadShort(), false);

		}

	}

	// Load characters
	addobj(0,&ramid);
	for (count = 0; count < nCharacters; count++) {

		if (file->tell() >= fileSize) {

			nCharacters = count;

			break;

		}

		width = file->loadShort(SW);
		height = file->loadShort(SH);

		if (bonus) width = (width + 3) & ~3;
		else width <<= 2;

		file->seek(4, false);
		unsigned char * pixels=(unsigned char *)objs[ramid].ptr+objs[ramid].size;
		resizeobj(ramid,objs[ramid].size+(width*height));
		file->loadPixels(width * height,pixels);

		//characters[count] = createSurface(pixels, width, height);
		characters[count].w=width;
		characters[count].h=height;
		characters[count].pix=pixels;
		//SDL_SetColorKey(characters[count], SDL_SRCCOLORKEY, 254);
		characters[count].colkey=254;
		characters[count].flags=miniS_COLKEY;
		//characters[count].palette=paletteF;
		//delete[] pixels;
	}
	delete file;
	lineHeight = characters[0].h;
	// Create blank character data
	//pixels = new unsigned char[3];
	//memset(pixels, 254, 3);
	//characters[nCharacters] = createSurface(pixels, 3, 1);
	characters[nCharacters].w=3;
	characters[nCharacters].h=1;
	characters[nCharacters].pix=(unsigned char *)blankFont;
	//SDL_SetColorKey(characters[nCharacters], SDL_SRCCOLORKEY, 254);
	characters[nCharacters].colkey=0;
	characters[nCharacters].flags=0;//miniS_COLKEY;
	//characters[nCharacters].palette=paletteF;
	//delete[] pixels;
	// Create ASCII->font map
	count = 0;
	if (bonus) {
		for (; count < 42; count++) map[count] = nCharacters;
		map[count++] = 37; // *
		for (; count < 46; count++) map[count] = nCharacters;
		map[count++] = 39; // .
		map[count++] = 38; // /
		for (; count < 59; count++) map[count] = count - 22; // Numbers and :

	} else {

		for (; count < 37; count++) map[count] = nCharacters;
		map[count++] = 36; // %
		for (; count < 48; count++) map[count] = nCharacters;
		for (; count < 58; count++) map[count] = count - 22; // Numbers

	}

	for (; count < 65; count++) map[count] = nCharacters;
	for (; count < 91; count++) map[count] = count - 65; // Upper-case letters
	for (; count < 97; count++) map[count] = nCharacters;
	for (; count < 123; count++) map[count] = count - 97; // Lower-case letters
	for (; count < 128; count++) map[count] = nCharacters;

	nCharacters++;

	for (count = 0; count < 128; count++) {

		if (map[count] >= nCharacters) map[count] = 0;

	}

	restorePalette();

}
/**
 * Create a font from the panel pixel data.
 *
 * @param pixels Panel pixel data
 * @param big Whether to use the small or the big font
 */
Font::Font (unsigned char* pixels, bool big) {

	//unsigned char* chrPixels;
	int count, y;

	if (big) lineHeight = 8;
	else lineHeight = 7;

	//chrPixels =(unsigned char *)alloca(8*lineHeight);//new unsigned char[8 * lineHeight];
	addobj(40*8*lineHeight,&ramid);
	for (count = 0; count < 40; count++) {

		for (y = 0; y < lineHeight; y++)
			memcpy(objs[ramid].ptr + (y * 8)+(count*8*lineHeight), pixels + (count * 8) + (y * SW), 8);

		//characters[count] = createSurface(chrPixels, 8, lineHeight);
		characters[count].w=8;
		characters[count].h=lineHeight;
		characters[count].pix=(unsigned char*)objs[ramid].ptr+(count*8*lineHeight);
		//characters[count].palette=paletteF;
		if (big){
			//SDL_SetColorKey(characters[count], SDL_SRCCOLORKEY, 31);
			characters[count].flags=miniS_COLKEY;
			characters[count].colkey=31;
		}else{
			characters[count].flags=0;
		}

	}

	nCharacters= 40;

	//delete[] chrPixels;


	// Create ASCII->font map

	if (big) {

		// Goes " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-:."

		for (count = 0; count < 45; count++) map[count] = 0;
		map[count++] = 37;
		map[count++] = 39;
		for (; count < 48; count++) map[count] = 0;
		for (; count < 58; count++) map[count] = count - 47; // Numbers
		map[count++] = 38;
		for (; count < 65; count++) map[count] = 0;
		for (; count < 91; count++) map[count] = count - 54; // Upper-case letters
		for (; count < 97; count++) map[count] = 0;
		for (; count < 123; count++) map[count] = count - 86; // Lower-case letters
		for (; count < 128; count++) map[count] = 0;

	} else {

		// Goes " 0123456789oo" (where oo = infinity)
		// Use :; to represent the infinity symbol

		for (count = 0; count < 48; count++) map[count] = 0;
		for (; count < 60; count++) map[count] = count - 47; // Numbers and :;
		for (; count < 128; count++) map[count] = 0;

	}

	restorePalette();

}
Ejemplo n.º 8
0
int objdesign (int dx, int dy) {				// Returns 1 if need redraw
	static int lastobj=0;
	int n;
	int fontnum;
	int objnum=-1;
	int editobj=0;
	char *ourobjname;
	char tempstr[64];

	dx = dx*16; dy = dy*16+disy;

	for (n=0; n<numobjs; n++) {
		if ((objs[n].x==dx)&&(objs[n].y==dy)) {
			objnum=n;
			ourobjname=kindname[objs[n].objkind];
			};
		};
	if (objnum==-1) ourobjname="NONE";

	fontcolor (&statvp,6,0);
	clearvp (&statvp);
	wprint (&statvp,2,1,2,  "Obj: Add Oov");
	wprint (&statvp,2,11,2, "     Del Paste");
	wprint (&statvp,2,21,2, "     Kopy Mod");
	wprint (&statvp,102,1,2,"Kind: ");
	fontcolor (&statvp,3,0);
	wprint (&statvp,102,11,2,ourobjname);
	fontcolor (&statvp,6,0);
	key=toupper (wgetkey(&statvp,102,21,2));
	clearvp (&statvp);
	switch (key) {
		case 'A':
			objnum=numobjs;
			addobj (obj_killme,dx,dy,0,0);
			editobj=1; break;
		case 'D':
			if (objnum>0) objs[objnum].objkind=obj_killme;
			return (1);
		case 'P':
			addobj (objs[lastobj].objkind,dx,dy,0,0);
			memcpy (&(objs[numobjs-1]),&(objs[lastobj]),
				sizeof(objs[lastobj]));
			objs[numobjs-1].x=dx;
			objs[numobjs-1].y=dy;
			return (1);
		case 'O':										// mOov object
			objs[lastobj].x=dx;
			objs[lastobj].y=dy;
			drawboard();
			return (1);
		case 'K':
			if (objnum>=0) lastobj=objnum; break;
		case 'M':
			if (objnum>=0) editobj=1; break;
		};

	if (editobj) {
		printobjinfo (objnum);
		strcpy (tempstr,kindname[objs[objnum].objkind]);
		winput (&statvp,38,1,2,tempstr,12);
		strupr (tempstr);
		for (n=0; n<numobjkinds; n++) {
			if (strcmp (tempstr,kindname[n])==0) {
				objs[objnum].objkind=n;	break;
				};
			};

		printobjinfo (objnum);
		itoa (objs[objnum].state,tempstr,10);
		winput (&statvp,38,11,2,tempstr,12);
		if (tempstr[0]!='\0') objs[objnum].state=atoi(tempstr);

		printobjinfo (objnum);
		itoa (objs[objnum].xd,tempstr,10);
		winput (&statvp,38,21,2,tempstr, 12);
		if (tempstr[0]!='\0') objs[objnum].xd=atoi(tempstr);

		printobjinfo (objnum);
		itoa (objs[objnum].yd,tempstr,10);
		winput (&statvp,140,1,2,tempstr, 12);
		if (tempstr[0]!='\0') objs[objnum].yd=atoi(tempstr);

		printobjinfo (objnum);
		itoa (objs[objnum].counter,tempstr,10);
		winput (&statvp,140,11,2,tempstr, 12);
		if (tempstr[0]!='\0') objs[objnum].counter=atoi(tempstr);

		objs[objnum].xl=kindxl[objs[objnum].objkind];
		objs[objnum].yl=kindyl[objs[objnum].objkind];

		if (kindflags[objs[objnum].objkind]&f_inside) {
			printobjinfo (objnum);
			if (objs[objnum].objkind==obj_text8) fontnum=1;
			else fontnum=2;
		if (objs[objnum].inside==NULL) tempstr[0]='\0';
		else strcpy (tempstr,(char*)objs[objnum].inside);

		fontcolor (&gamevp,objs[objnum].xd,objs[objnum].yd);
		winput (&gamevp,objs[objnum].x,objs[objnum].y,fontnum,tempstr, 64);

		if (objs[objnum].inside!=NULL) free (objs[objnum].inside);
		objs[objnum].inside=malloc (strlen(tempstr)+1);
		strcpy (objs[objnum].inside, tempstr);
		setobjsize (objnum);
		};
		printobjinfo (objnum);

		shm_want[kindtable[objs[objnum].objkind]]=1;
		shm_do();
		return (1);
		};
	return (0);
	};