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

📄 test.cpp

📁 用FREE BASIC做的演示程序
💻 CPP
字号:
#include"..\bdi.h"
#include"..\gscreen.h"
#include"..\GFileLoader.h"
#include"..\font.h"
#include"..\GPacker.h"
#include"..\gppIniFile.h"
#include<windows.h>
GBDI* bdi3=new GBDI();
GBDI *bdi=new GBDI();
GBDI*bdi2=new GBDI();
GBDI*bdi4=new GBDI();
HWND hWnd;
BOOL bActive;
GScreen s;
GLayerManager LayerMan;
#ifdef _DEBUG
#pragma comment(lib,"..\\debug\\gppGameLib3")
#else
#pragma comment(lib,"..\\release\\gppGameLib3")
#endif
#pragma comment(lib,"ddraw")
#pragma comment(lib,"dxguid")
int method=0;
unsigned short**ppPal;
static LRESULT WINAPI AppDefaultWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_ACTIVATEAPP:
		{
			bActive=wParam;	
		}
		break;
	case WM_KEYDOWN:
		switch(wParam)
		{
		case VK_ESCAPE:
			PostQuitMessage(0);
			break;
		}
		break;
	case WM_CHAR:
		switch(wParam)
		{
		case '1':
			LayerMan.EnableLayer(0,!LayerMan.IsLayerEnabled(0));
			break;
		case '2':
			LayerMan.EnableLayer(1,!LayerMan.IsLayerEnabled(1));
			break;
		case '3':
			LayerMan.EnableLayer(2,!LayerMan.IsLayerEnabled(2));
			break;
		case '4':
			LayerMan.EnableLayer(3,!LayerMan.IsLayerEnabled(3));
			break;
		}
		break;
	case WM_TIMER:
		{

			switch(wParam)
			{
			case 1:
				{
					static int n=0;
					RECT rt={n*32,0,n*32+32,128};
					n++;
					if(n>7)
						n=0;
					bdi3->SetShowArea(&rt);
					
//					unsigned short *pPal=s.GetPal();
/*					static int m=0;
					s.SetPal(ppPal[m]);
					m++;
					if(m>=32)
					{
						m=0;
						s.UseDefaultPal(true);
					}
//					for(int i=0;i<256;i++)
//						pPal[i]+=8;
*/				} 
				break;
			case 2:
				{
					method++;
					if(method>2)
						method=0;
				}
				break;
			}
		}
		break;
	case WM_DESTROY:
		{
			PostQuitMessage(0);
		}
		break;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);
}
bool GameCreateMainWindow(HINSTANCE hInst)
{

	
	WNDCLASS WndClass;
	
	WndClass.style=CS_HREDRAW|CS_VREDRAW;
	WndClass.lpfnWndProc=AppDefaultWndProc;
	WndClass.cbClsExtra=0;
	WndClass.cbWndExtra=0;
	WndClass.hInstance=hInst;
	WndClass.hIcon=0;
	WndClass.hCursor=0;
	WndClass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
	WndClass.lpszMenuName=0;
	WndClass.lpszClassName="test";
	RegisterClass(&WndClass);
	
	
	 hWnd=CreateWindowEx(
		NULL,
		"test",
		"test",
		WS_POPUP,
		(GetSystemMetrics(SM_CXSCREEN)-640)/2,
		(GetSystemMetrics(SM_CYSCREEN)-480)/2,
		640,
		480,
		NULL,
		NULL,
		hInst,
		NULL);
	
	if(!hWnd)
	{
		return false;
	}
	ShowWindow(hWnd,SW_SHOW);
	UpdateWindow(hWnd);
	  
	return true;
}
#include<fstream>
using namespace std;
#include<time.h>
#define To565(r,g,b) (((r)<<11)|((g)<<5)|(b))

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
/*	ppPal=new unsigned short*[32];
	for(int i=0;i<32;i++)
	{
		ppPal[i]=new unsigned short[256];
		for(int j=0;j<256;j++)
		{
			ppPal[i][j]=(i)|(j<<8);
		}
	}
*/	
	
	GameCreateMainWindow(hInstance);
	GIniFile *ini=new GIniFile();
	bool b;
	int Width=640;
	int Height=480;
	if(!ini->LoadIniFileName("setting.ini",NULL))
	{
		b=s.CreateWindowed(hWnd,640,480);
		delete ini;
	}
	else
	{
		ini->SetSegment("Window");
		unsigned long bFullScreen=ini->ReadDword("FullScreen",0);
		Width=ini->ReadDword("Width",640);
		Height=ini->ReadDword("Height",480);
		if(bFullScreen)
			b=s.CreateFullScreen(hWnd,Width,Height);
		else
   			b=s.CreateWindowed(hWnd,Width,Height);
		delete ini;
	}
	if(!b)
		return 1;
	GVPacker*pPacker=new GBinarySearchPacker();
	if(!pPacker->OpenPackFile("data.pak"))
	{
		MessageBox(hWnd,"open pack file fail","",0);
		return 1;
	}
	  
	GFont font;	
	srand(unsigned(time(0)));
	MSG msg;
	srand(unsigned(time(0)));  
	GFileLoader fl(pPacker);
	

 	if(!bdi->LoadBDI(&fl,"data\\tile02.bdi"))
	{
		MessageBox(hWnd,"1","",0);
		return 1;
	}
	if(!bdi2->LoadBDI(&fl,"data\\role.bdi"))
	{
		MessageBox(hWnd,"2","",0);
		return 1;
	}
	if(!bdi3->LoadBDI(&fl,"data\\fire.bdi"))
	{
		MessageBox(hWnd,"3","",0);
		return 1;
	}
	if(!bdi4->LoadBDI(&fl,"data\\tile04.bdi"))
	{
		MessageBox(hWnd,"4","",0);
		return 1;
	}
	if(!font.LoadFontFile(&fl,"data\\songti16x16.font"))
	{
		MessageBox(hWnd,"font","",0);
		return 1;
	} 

 	s.UseDefaultPal(false);
	bdi2->SetColorKeyRGB(0,0,0);
    
	s.ClearPrimary();
	s.TextOutDC(200,200,0xffff,20,"正在初始化BDI数据...");
	GBDI::LoadBDITable(&fl,"data\\bdi.dat");

  	s.ClearPrimary();
	s.TextOutDC(200,200,0xffff,20,"初始化BDI数据完成!");

 	SetTimer(hWnd,1,100,NULL);
	SetTimer(hWnd,2,1000,NULL);
	POINT p1={0,0},p2={0,0},p3={0,150};
	SendMessage(hWnd,WM_TIMER,1,0); 
 
	bdi4->SetColorKeyRGB(255,0,255);
 //	bdi4->EnableTrans(true); 
              
	LayerMan.AddObject(bdi,0);
	LayerMan.AddObject(bdi2,1);
	LayerMan.AddObject(bdi3,2);
	LayerMan.AddObject(bdi4,3);
	while(1) 
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
		{       
			if(!GetMessage(&msg, NULL,0,0)) 
				break;
			TranslateMessage(&msg); 
			DispatchMessage(&msg);
		}
		else if(bActive)
		{ 
			s.ClearBuffer(); 
			
			
			static float alpha=8.0f;
			static float k=0.2f;
			alpha+=k;
			if(alpha>15.0f)
			{
				alpha=15.0f;
				k=-k;
			}
			else if(alpha<0.0f)
			{
				alpha=0.0f;
				k=-k;
			}
			p1.x+=1;
			if(p1.x>Width)
				p1.x=-bdi4->GetWidth();
			p2.x+=2;
			p2.y++;
			if(p2.x>Width)
				p2.x=-bdi->GetWidth();
			if(p2.y>Height)
				p2.y=-bdi->GetHeight();
			p3.x-=2;
			if(p3.x<-bdi2->GetWidth())
				p3.x=Width;

			bdi->SetPosition(p2);
			bdi->SetDrawMethod(BDI_ALPHA,alpha);

			bdi2->SetPosition(p3);
			bdi2->SetDrawMethod(BDI_SRCCKADDITIVE,0);
			 
			bdi3->SetPosition(100,100);
			bdi3->SetDrawMethod(BDI_ADDITIVE,0);
			
			bdi4->SetPosition(p1);
			
			if(method==2)
				bdi4->SetDrawMethod(BDI_SRCCKADDITIVE,0);
			else if(method==1)
				bdi4->SetDrawMethod(BDI_SRCCOLORKEY,0);
			else
				bdi4->SetDrawMethod(BDI_SRCCKGRAY,0);



			LayerMan.RenderToScreen(&s);
			
			font.DrawTextFormatToScreen(&s,560,10,10,255,"FPS=%d",s.GetFPS());
	 		s.Present();
		}
		else
			WaitMessage();
	}
	KillTimer(hWnd,2);
	KillTimer(hWnd,1);
	return 1;
}

⌨️ 快捷键说明

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