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

📄 refresh.cpp

📁 一个45度角场景RPG游戏程序的demo
💻 CPP
字号:
#include "main.h"

int cursor=0;
static float time;

void RefreshScreen( )
{
//-----------------------------得到刷新开始时时间--------------
	float time1=GetTickCount();
//-------------------------------------------------------------
	static int bb=0;
	bb++;
	if (bb>30000)
		bb=0;
//-----------------------------光照预处理----------------------
	unsigned char *p1=&LightTable[0];
	unsigned char *p2=&BaseLight[0];
//-----------------------------拷贝光照表----------------------
	__asm
	{
		cld;
		mov esi,p2;
		mov edi,p1;
		mov ecx,76800;
		rep movsd;
	}
//-----------------------------放上其它光照--------------------
	for (int i=0;i<MaxBullet;i++)
	{
		if (bullet[i]->status!=-1)
		{
			MakeRect(0,0,100,100);
			int bx=bullet[i]->x-human[main]->x+272;
			int by=bullet[i]->y-human[main]->y+190;
			if (ChangeRect(bx,by)!=-1)
			{
				p1=&LightTable[by*640+bx];
				p1+=4;
				p2=&SmallLight[rect.top*100+rect.left];
				int height=rect.bottom-rect.top;
				int width=(rect.right-rect.left)/4-1;

				if ((height>0)&&(width>0))
				{
					__asm
					{
						pxor mm2,mm2;
						mov edi,p1;
						mov esi,p2;
						mov ebx,height;
_oloop:
						mov ecx,width;
						push edi;
						push esi;
_iloop:
						movq mm0,[edi];
						movq mm1,[esi];
						punpckhbw mm0,mm2;
						punpckhbw mm1,mm2;
						pmullw mm0,mm1;
						psrlw mm0,8;
						packuswb mm0,mm2;
						movd eax,mm0;
						mov [edi+4],eax;
						add esi,4;
						add edi,4;
						dec ecx;
						jnz _iloop;
						pop esi;
						pop edi;
						add esi,100;
						add edi,640;
						dec ebx;
						jnz _oloop;
					}
				}
			}
		}
	}
//-----------------------------显示背景------------------------
	map->show( );
//-----------------------------将人物和障碍按Y轴显示-----------
	int last_thing=MaxHuman+MaxBlock;
	int *all_y;
	all_y=new int[last_thing];
	int *all_y_order;
	all_y_order=new int[last_thing];
	for (i=0;i<MaxHuman;i++)
	{
		all_y[i]=human[i]->y;
		all_y_order[i]=i;
	}
	for (i=MaxHuman;i<last_thing;i++)
	{
		all_y[i]=block[i-MaxHuman]->y;
		all_y_order[i]=i;
	}
	int temp;
	for (i=0;i<last_thing;i++)//冒泡排序
		for (int j=i;j<last_thing;j++)
			if (all_y[i]>all_y[j])
			{
				temp=all_y[j];
				all_y[j]=all_y[i];
				all_y[i]=temp;//交换元素
				temp=all_y_order[j];
				all_y_order[j]=all_y_order[i];
				all_y_order[i]=temp;
			}
	for (i=0;i<last_thing;i++)
	{
		if (all_y_order[i]<MaxHuman)
			human[all_y_order[i]]->show();
		else
			block[all_y_order[i]-MaxHuman]->show();
	}
//-----------------------------放光照--------------------------
	BYTE *pb=(BYTE *)pS[SBuffer];
	BYTE *pl=(BYTE *)&LightTable[0];
	__asm
	{
		mov ecx,153600;
		mov edi,pb;
		mov esi,pl;
_loop:
		movq mm0,[edi];
		movq mm1,[esi];
		punpckhbw mm1,mm1;
		punpckhbw mm1,mm1;
		psubusb mm0,mm1;
		movq [edi],mm0;
		add edi,8;
		add esi,2;
		dec ecx;
		jnz _loop;
		emms;
	}
//-----------------------------将离鼠标近的人变亮--------------
//-----------------------------先找到离鼠标近的人--------------
	POINT	curpos;
	GetCursorPos(&curpos);
	int mini=FoundHuman(curpos.x,curpos.y);
//-----------------------------如找到则将其变亮----------------
	if ((mini>0)&&(human[main]->MainStatus!=talking))
	{
		BYTE *Bitmap = (BYTE*)pS[SBuffer];
		BYTE *Bitmap2 = (BYTE*)pS[SHuman];
		int sm=human[mini]->FootStatus*64+human[mini]->type*256;
		int fa=human[mini]->face*64;
		if ((sm==192)&&(human[mini]->type==TEnemy))
			sm=256;
		if (sm==-64)
			sm=0;
		int pos,pos1;
		int posx,posy;
		for (int y=fa;y<fa+64;y++)
		{
			posy=human[mini]->y-human[main]->y+192+y-fa;
			posx=human[mini]->x-human[main]->x+288;
			if ((posy>=0)&&(posy<480))
			{
				__int64 mask=0x3c3c3c3c3c3c3c3c;
				pos=posy*SP[SBuffer]+4*posx;
				pos1=y*SP[SHuman]+sm*4;
				for (int x=sm;x<sm+64;x++)
				{
					if ((posx+x-sm>0)&&(posx+x-sm<640)&&((Bitmap2[pos1]!=0)||(Bitmap2[pos1+1]!=0)||(Bitmap2[pos1+2]!=0)))
					{
						BYTE *p1=&Bitmap2[pos1];
						BYTE *p2=&Bitmap[pos];
						__asm
						{
							mov esi,p1;
							mov edi,p2;
							movq mm0,[esi];
							paddusb mm0,mask;
							movq [edi],mm0;
						}
						pos1+=4;
						pos+=4;
					}
					else
					{
						pos+=4;
						pos1+=4;
					}
				}
			}
		}
//-----------------------------画血条--------------------------	
		MakeRect(8,0,170,20);
		FastBlt(240,20,SBuffer,SOther,NoKey);
		MakeRect(240+human[mini]->health*8/5+1,21,401,39);
		DDBLTFX ddBltFx;
		ddBltFx.dwSize=sizeof(DDBLTFX);
		ddBltFx.dwFillColor=0;
		DDS[SBuffer]->Blt(&rect,NULL,&rect,DDBLT_WAIT|DDBLT_COLORFILL,&ddBltFx);
	}
	for (i=0;i<MaxBullet;i++)
		if (bullet[i]->status!=-1)
			bullet[i]->show();
//-----------------------------画对话框------------------------
	__int64 mask=0x4040404040404040;
	if (human[main]->MainStatus==talking)
	{
		unsigned char *Bitmap=(unsigned char *)pS[SBuffer];
		int tt=135*SP[SBuffer]+1040;
		int uu=SP[SBuffer];
		__asm
		{
			movq mm1,mask;
			mov eax,Bitmap;
			add eax,tt;
			mov ecx,70;
outloop:
			push eax;
			mov ebx,60;
innloop:
			movq mm0,[eax];
			psubusb mm0,mm1;
			movq [eax],mm0;
			add eax,8;
			dec ebx;
			jnz innloop;
			pop eax;
			add eax,uu;
			dec ecx;
			jnz outloop;
			emms;
		}
		HDC hdc;
		if (DDS[SBuffer]->GetDC(&hdc) == DD_OK)
		{ 
			SetBkMode(hdc,TRANSPARENT);
			SetTextColor(hdc, RGB(255, 255, 255));
			TextOut(hdc,266,140, DialogText, strlen(DialogText));
			DDS[SBuffer]->ReleaseDC(hdc);
		}
	}
//-----------------------------放标题--------------------------
	HDC hdc;
	char *text="RPG DEMO II Beta Build 0922";
	char *text2="By Kane_Peng@netease.com  http://kanepeng.myetang.com";
	char *text3="LEFT MOUSE: TALK / ATTACK   RIGHT MOUSE: ATTACK";
	char *text4="OICQ:4982526";
	if (DDS[SBuffer]->GetDC(&hdc) == DD_OK)
	{ 
		SetBkMode(hdc,TRANSPARENT);
		SetTextColor(hdc, RGB(255, 255, 255));
		TextOut(hdc,0,0, text, strlen(text));
		SetTextColor(hdc, RGB(0, 255, 0));
		TextOut(hdc,0,20, text2, strlen(text2));
		SetTextColor(hdc, RGB(0, 255, 0));
		TextOut(hdc,0,40, text4, strlen(text4));
		SetTextColor(hdc, RGB(255, 0, 0));
		TextOut(hdc,201,0, text3, strlen(text3));
        DDS[SBuffer]->ReleaseDC(hdc);
	}
//-----------------------------放界面--------------------------
		
//-----------------------------放鼠标--------------------------
	MakeRect(cursor*32,0,cursor*32+32,26);
	MyBlt(curpos.x,curpos.y,SMouse,SBuffer,SrcKey);
//-----------------------------放刷新一次所需机器周期----------
	if (DDS[SBuffer]->GetDC(&hdc) == DD_OK)
	{ 
		static char timestr[9];
		if (bb%15==0)
			time=GetTickCount()-time1;
		gcvt(1000/time,4,timestr);
		strcat(timestr," FPS");
		SetBkMode(hdc,TRANSPARENT);
		SetTextColor(hdc, RGB(255, 255, 255));
		TextOut(hdc,570,0,timestr, strlen(timestr));
		DDS[SBuffer]->ReleaseDC(hdc);
	}
//-----------------------------完成刷新------------------------
	FlipSurface( );
}

⌨️ 快捷键说明

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