⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 一个RPG术语查询器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
					textbox.prompt = 2;
					do
					{
					}
					while(key[KEY_SPACE]);
					break;

				case '/':
					if(textbox.message[textbox.currchar+1]=='n')
					{
						TextAddChar(10);
						textbox.currchar+=2;

					}
					else
					{
						TextAddChar(textbox.message[textbox.currchar]);
						++textbox.currchar;
					}

					break;
				case '.':
				case '!':
				case ',':
					TextAddChar(textbox.message[textbox.currchar]);
					++textbox.currchar;
					textbox.delay+=30;
				break;
				
				default:
					TextAddChar(textbox.message[textbox.currchar]);
					++textbox.currchar;
					break;
					
			}
			break;
		case 3:
			ShrinkMessageBox();
			break;
	}

	


}


void CleanUp()
{
	
	//Write the map to disk at close (will be taken out in beta release)
	//Destroy the rest of our bitmaps
    flush_scenario();

	gamelog.write("Destroying surfaces...");
	if( FastTile != NULL ) destroy_bitmap( FastTile );
	if( SolidTile != NULL ) destroy_bitmap( SolidTile );
	if( FastFont != NULL ) destroy_bitmap( FastFont );
	if( FastSFont != NULL ) destroy_bitmap( FastSFont );
	if( SolidObject != NULL ) destroy_bitmap( SolidObject );
	if( gfxmessage != NULL ) destroy_bitmap( gfxmessage );
	if( dirtytiles != NULL ) destroy_bitmap( dirtytiles );
	if( vidbuffer[0] != NULL ) destroy_bitmap( vidbuffer[0] );
	if( vidbuffer[1] != NULL ) destroy_bitmap( vidbuffer[1] );
	
	gamelog.write("Destroyed bitmaps and midi stuff and saved map.  Gulp.");
	gamelog.end();
}

//JOONARBEEN WAS HERE

void ExecEngine()
{ 
	for(int i=0;i<objectmax;++i) if(OBJECTS[i].operational==OPERATE) OBJECTS[i].Execute();
	oframes++;
	
	
}


void CloseHook()
{
	DIE = 1;
}

void InitGame()
{

    //TODO:  ALL GRAPHICS IN SYSTEM RAM - OR ALL GRAPHICS IN VIDEO
    
	swapper.swapnow=0;
  
    gamelog.write("Setting up audio driver...");
	detect_digi_driver(DIGI_AUTODETECT);
	gamelog.write("Done!");
	
    gamelog.write("Setting up midi driver..."); 
    detect_midi_driver(MIDI_AUTODETECT);
    gamelog.write("Done!");
    
    gamelog.write("Setting Window Title...");
	set_window_title("gRPG/Allegro WINDOWED MODE");
	gamelog.write("Done!");

	gamelog.write("Installing sound driver...");
	install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL);
    gamelog.write("Done!");

	set_window_close_hook(&CloseHook);
	
 	gamelog.write("Installing keyboard and mouse...");
    install_mouse();
	position_mouse_z(0);
	install_keyboard();
	gamelog.write("Done!");

 	gamelog.write("Setting color depth...");
	gamelog.write("Done!");	

 	gamelog.write("Starting up graphics mode...");
    int GraphicsFlag;
    if(fullscreen==0)
    {
        set_color_depth(desktop_color_depth());
        GraphicsFlag=set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
    }
    else
    {
        set_color_depth(16);
        GraphicsFlag=set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
    }
    if(GraphicsFlag!=0)
    {
        gamelog.write("Unable to set mode! Trying Safe!");
        GraphicsFlag=set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);
    }
	set_color_conversion(COLORCONV_TOTAL);
	gamelog.write("Done!");		


	

    if(!(gfx_capabilities & GFX_HW_VRAM_BLIT)) gravyhack=1;


	srand(time(NULL));

//JOONARBEEN WAS HERE
	//Set up video bitmaps
	if (gravyhack==0)
	{
		vidbuffer[0]=create_video_bitmap(SCREEN_W,SCREEN_H);
		if(vidbuffer[0]==NULL)
		{
			//MessageBox(win_get_window(),"HW primary buffer init failed, setting up software","ouch",MB_OK);
			vidbuffer[0]=create_system_bitmap(SCREEN_W,SCREEN_H);
			gravyhack=1;
		}
	   
        vidbuffer[1]=create_video_bitmap(SCREEN_W,SCREEN_H);
		if(vidbuffer[1]==NULL)
		{
			//MessageBox(win_get_window(),"HW primary buffer init failed, setting up software","ouch",MB_OK);
			vidbuffer[1]=create_system_bitmap(SCREEN_W,SCREEN_H);
			gravyhack=1;
		}	
   
    	
		dirtytiles=create_video_bitmap(SCREEN_W+32,SCREEN_W+32);
		if(dirtytiles==NULL)
		{
			//MessageBox(win_get_window(),"tile draw buffer init failed, setting up software","ouch",MB_OK);
			dirtytiles=create_system_bitmap(SCREEN_W+32,SCREEN_W+32);
		}
		
		FastTile=create_video_bitmap(512, 512);
		if(FastTile==NULL)
		{
			//MessageBox(win_get_window(),"HW tiles for layer 1 failed, setting up software","ouch",MB_OK);
			FastTile=create_system_bitmap(512, 512);
		}
		
		FastFont=create_video_bitmap(16, 2048);
		if(FastFont==NULL)
		{
			FastFont=create_system_bitmap(16, 2048);
		}
		
		FastSFont=create_video_bitmap(8, 1024);
		if(FastSFont==NULL)
		{
			FastSFont=create_system_bitmap(8, 1024);
		}


		SolidTile=create_video_bitmap(32,32);
		if(SolidTile==NULL)
		{
			//MessageBox(win_get_window(),"HW generic editor tiles failed, setting up software","ouch",MB_OK);
			SolidTile=create_system_bitmap(32,32);
		}
		BITMAP *mytest2=load_bmp("misc/edit.bmp",pal);
		blit(mytest2,SolidTile,0,0,0,0,32,32);
		destroy_bitmap(mytest2);
	
		mytest2=load_bmp("misc/font.bmp",pal);
		blit(mytest2,FastFont,0,0,0,0,16,2048);
		destroy_bitmap(mytest2);
		
		mytest2=load_bmp("misc/sfont.bmp",pal);
		blit(mytest2,FastSFont,0,0,0,0,8,1024);
		destroy_bitmap(mytest2);

		
		SolidObject=create_video_bitmap(32,32);
		if(SolidObject==NULL)
		{
			//MessageBox(win_get_window(),"HW generic object tiles failed, setting up software","ouch",MB_OK);
			SolidObject=create_system_bitmap(32,32);
		}
		
		mytest2=load_bmp("misc/object.bmp",pal);
		blit(mytest2,SolidObject,0,0,0,0,32,32);
		destroy_bitmap(mytest2);
	}
	else
	{
		vidbuffer[0]=create_system_bitmap(SCREEN_W,SCREEN_H);
        vidbuffer[1]=create_system_bitmap(SCREEN_W,SCREEN_H);
		dirtytiles=create_system_bitmap(SCREEN_W+32,SCREEN_W+32);
		FastTile=create_system_bitmap(512, 512);
		SolidTile=create_system_bitmap(32,32);
		
		BITMAP *mytest2=load_bmp("misc/edit.bmp",pal);
		blit(mytest2,SolidTile,0,0,0,0,32,32);
		destroy_bitmap(mytest2);
		
		FastFont=create_system_bitmap(16, 2048);
		mytest2=load_bmp("misc/font.bmp",pal);
		blit(mytest2,FastFont,0,0,0,0,16,2048);
		destroy_bitmap(mytest2);

		FastSFont=create_system_bitmap(8, 1024);
		mytest2=load_bmp("misc/sfont.bmp",pal);
		blit(mytest2,FastSFont,0,0,0,0,8,1024);
		destroy_bitmap(mytest2);
		
		SolidObject=create_system_bitmap(32,32);
		mytest2=load_bmp("misc/object.bmp",pal);
		blit(mytest2,SolidObject,0,0,0,0,32,32);
		destroy_bitmap(mytest2);
	}
	//JOONARBEEN WAS HERE
	int i;
	int ofail=0;


	if(gravyhack == 0)
	{
		gfxmessage=create_video_bitmap(64,64);
		if(gfxmessage==NULL)
		{
			//MessageBox(win_get_window(),"HW message box failed, setting up software","ouch",MB_OK);
			gfxmessage=create_system_bitmap(64,64);
		}
	}
	else
	{
		gfxmessage=create_system_bitmap(64,64);

	}
	
	BITMAP *boxload=load_bmp("misc/box.bmp",pal);
	blit(boxload,gfxmessage,0,0,0,0,64,64);
	destroy_bitmap(boxload);
	
	
//	if(gravyhack==1) MessageBox(win_get_window(),"Not all surfaces created in video ram, performance may suffer","Doh!",MB_OK);
	
	//Generate sprite offsets for various face directions
	faceway[0][1]=3;
	faceway[2][1]=2;
	faceway[1][0]=1;
	faceway[1][2]=0;
	
	BITMAP *title = load_bmp("title/title.bmp",pal);
	blit(title,vidbuffer[page_num],0,0,0,0,640,480);
    destroy_bitmap(title);
    PrintMessageText("PRESS SPACE BAR",0,460,0);
    blit(vidbuffer[page_num],screen,0,0,0,0,640,480);
    while(readkey()>>8!=KEY_SPACE);
	
	
} 

void Editor()
{


  	if (mouse_z!=currmousez)
	{
		currtile+=mouse_z-currmousez;
		if(currtile>255) currtile=255;
		if(currtile<0) currtile=0;
		if(mouse_z<0) position_mouse_z(0);
		if(mouse_z>255) position_mouse_z(255);
		currmousez=mouse_z;
	}
	
	if (osynchframes>tilechangedelay)
	{
		if(key[KEY_T])
		{
			topdraw=1;
			tilechangedelay=osynchframes+25;
		}
		
		if(key[KEY_B])
		{
			topdraw=0;
			tilechangedelay=osynchframes+25;
		}
//JOONARBEEN WAS HERE
		if(key[KEY_1])
		{
			currlayer=1;
			tilechangedelay=osynchframes+25;
		}
		if(key[KEY_2])
		{
			currlayer=2;
			tilechangedelay=osynchframes+25;
		}

		if(key[KEY_3])
		{
			drawlayer[0]=1-drawlayer[0];
			tilechangedelay=osynchframes+25;
			int x,y;
	
			for(y=0;y<16;y++)
			{
				for(x=0;x<21;x++)
				{
					drawn[x][y]=-1;
						drawn2[x][y]=-1;
				}
			}

		}
		
		if(key[KEY_4])
		{
			int x,y;
	
			for(y=0;y<16;y++)
			{
				for(x=0;x<21;x++)
				{
					drawn[x][y]=-1;
						drawn2[x][y]=-1;
				}
			}
			drawlayer[1]=1-drawlayer[1];
			tilechangedelay=osynchframes+25;
		}
		
		if(key[KEY_EQUALS])
		{
			currtile++;
			if(currtile>255) currtile=255;
			tilechangedelay=osynchframes+25;
		}
        if(key[KEY_S])
        {
            char mad_deleter[512];
            sprintf(mad_deleter,"scenario/%s/%s.map",current_physical_scenario,current_physical_scenario);
        	gamelog.write(mad_deleter);
            PACKFILE *mapload;
        	mapload = pack_fopen(mad_deleter, "w" );
        	if(mapload!=NULL)
        	{
                for(int i=0;i<90;++i)
                {
                        for(int j=0;j<90;++j)
                        {
                                pack_iputl((long)map.map[j][i], mapload);
                                pack_iputl((long)map.map2[j][i], mapload);
                        }
                }
    		pack_fclose( mapload );	
            }
            tilechangedelay=osynchframes+25;
        
        }


		if(key[KEY_MINUS])
		{
	
			currtile--;
			if(currtile<0) currtile=0;
			tilechangedelay=osynchframes+25;
		}
		
	}
 
   
	if(currlayer==1)
	{
		if (mouse_b & 1)
		{
			if(topdraw==1)
			{
				map.map[(camera.y+mouse_y+16)/32][(camera.x+mouse_x+16)/32]=currtile+512;
			}
			else
			{
				map.map[(camera.y+mouse_y+16)/32][(camera.x+mouse_x+16)/32]=currtile;
			}
		}
		if (mouse_b & 2) 
		{
			if(topdraw==1)
			{
				map.map[(camera.y+mouse_y+16)/32][(camera.x+mouse_x+16)/32]=currtile+768;
			}
			else
			{
				map.map[(camera.y+mouse_y+16)/32][(camera.x+mouse_x+16)/32]=currtile+256;
			}
		}
	}
	else
	{
		//Change THIS to make it do solid tiles on the top layer (will implement objects up there soon)
		if (mouse_b & 1) 
		{
			if(topdraw==1)
			{
				map.map2[(camera.y+mouse_y+16)/32][(camera.x+mouse_x+16)/32]=currtile+512;
			}
			else
			{
				map.map2[(camera.y+mouse_y+16)/32][(camera.x+mouse_x+16)/32]=currtile;
			}
			
		}
		
		if (mouse_b & 2) 
		{
			if(topdraw==1)
			{
				map.map2[(camera.y+mouse_y+16)/32][(camera.x+mouse_x+16)/32]=currtile+512;
			}
			else
			{
				map.map2[(camera.y+mouse_y+16)/32][(camera.x+mouse_x+16)/32]=currtile;
			}
			
		}
		//if (mouse_b & 2) {map2[(camera.y+mouse_y+16)/32][(camera.x+mouse_x+16)/32]=currtile+256;}
	}
	
	int til,til2;
	til=currtile;
	til2=til&15;

    blit(FastTile, vidbuffer[page_num], til2*32, (til/16)*32,mouse_x,mouse_y, 32, 32);	
    
    char editormessage[256];
    
    sprintf(editormessage,"Tile %i",map.map2[(camera.y+mouse_y+16)/32][(camera.x+mouse_x+16)/32]);
    PrintMessageText(editormessage,0,410,1);
   	sprintf(editormessage,"Top Drawing: %i",topdraw);
    PrintMessageText(editormessage,0,420,1);
    sprintf(editormessage,"Layer toggles: Bottom %i  Top %i",drawlayer[0],drawlayer[1]);
    PrintMessageText(editormessage,0,430,1);
    sprintf(editormessage,"Currlayer: %i",currlayer);
    PrintMessageText(editormessage,0,440,1);
    sprintf(editormessage,"Mouse Pos: %i,%i  Coords: %i,%i",(camera.x+mouse_x+16)/32,(camera.y+mouse_y+16)/32,((camera.x+mouse_x+16)/32)*32,((camera.y+mouse_y+16)/32)*32);
    PrintMessageText(editormessage,0,450,1);
    sprintf(editormessage,"Tile %i",currtile);
    PrintMessageText(editormessage,0,460,1);

	
	
	

}

void TransIn() 
{

	DrawGame(camera.x,camera.y,dirtytiles,FastTile);
	int x1=318,y1=238,x2=320,y2=240;
	int blitx=(camera.x&31);
	int blity=(camera.y&31);
//JOONARBEEN WAS HERE
	for(x1=318;x1>=0;x1-=4)
	{
		clear_bitmap(vidbuffer[page_num]);
		blit(dirtytiles,vidbuffer[page_num],blitx+x1,blity+y1,x1,y1,x2-x1+1,y2-y1+1);
		blit(vidbuffer[page_num],screen,0,0,0,0,640,480);
        vsync();
		y1-=4;
		if(y1<0) y1=0;
		x2+=4;
		if(x2>639) x2=639;
		y2+=4;
		if(y2>479) y2=479;
	}

}

void TransOut()
{
	int x1=0,y1=0,x2=639,y2=479;
	int blitx=(camera.x&31);
	int blity=(camera.y&31);

	for(x1=0;x1<=318;x1+=4)
	{
		clear_bitmap(vidbuffer[page_num]);
		blit(dirtytiles,vidbuffer[page_num],blitx+x1,blity+y1,x1,y1,x2-x1+1,y2-y1+1);
		blit(vidbuffer[page_num],screen,0,0,0,0,640,480);
        vsync();
		y1+=4;
		if(y1>479) y1=479;
		x2-=4;
		if(x2<0) x2=0;
		y2-=4;
		if(y2<0) y2=0;
	}

}

void MainGameLoop()
{

    if(swapper.swapnow==1)
    {
        TransOut();
        flush_scenario();
        LoadScenario(swapper.name);
        void *jiggle = GetEObject(0);
        ENTITY *jig = (ENTITY *)jiggle;
        if(jig!=NULL)
        {
            jig->MoveTo(swapper.warpx,swapper.warpy);
        }
        swapper.swapnow=0;
        
        camera.x=swapper.warpx-304;
        camera.y=swapper.warpy-224;
	    if (camera.x>2208) camera.x=2208;
    	if (camera.y>2368) camera.y=2368;
    	if (camera.x<0) camera.x=0;
    	if (camera.y<0) camera.y=0;
        
        
        TransIn();
    }



	if(key[KEY_M]) CreateMessageBox("Hello there and welcome to gRPG",-1);
	if(key[KEY_E] && osynchframes>editortime) 
	{
		editortime=osynchframes+25;
		editortoggle=1-editortoggle;
			int x,y;
	
			for(y=0;y<16;y++)
			{
				for(x=0;x<21;x++)
				{
					drawn[x][y]=-1;
					drawn2[x][y]=-1;
				}
			}

	}

	


	
	while(synchobjects>0)
	{
		if(textbox.status==0) ExecEngine();
		else ExecMessageBox();
		--synchobjects;
		++osynchframes;
	}
	
	camera.x=OBJECTS[objectfocus].x-304;
    camera.y=OBJECTS[objectfocus].y-224;
	if (camera.x>2208) camera.x=2208;
	if (camera.y>2368) camera.y=2368;
	if (camera.x<0) camera.x=0;
	if (camera.y<0) camera.y=0;

	acquire_bitmap(vidbuffer[page_num]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -