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

📄 main.cpp

📁 一个简单的rpg游戏
💻 CPP
字号:
#include "Headers.h"
#include "resource.h"
#include "DriverDialog.h"
#include "MAIN.h"

#include <mmsystem.h>


BEGIN_MESSAGE_MAP(MAIN, DirectDrawWin)
	//{{AFX_MSG_MAP(MAIN)
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()



MAIN::MAIN()
{
	lpdd=0;
	hwnd=0;
	instance=0;

	desiredwidth=640;
	desiredheight=480;
	desireddepth=16;

}

BOOL MAIN::CreateCustomSurfaces()
{
	// create your surfaces here...
	lpdd=(LPDIRECTDRAW)GetDDraw();
	hwnd=GetSafeHwnd();
	instance=AfxGetInstanceHandle();

	Init();

	return TRUE;
}

void MAIN::DrawScene()
{
	Draw();
	primsurf->Flip( 0, DDFLIP_WAIT );

	TranslateInput();
	TranslateNpcInput();

}

void MAIN::RestoreSurfaces()
{
}

int MAIN::SelectDriver()
{
	int numdrivers=GetNumDrivers();
	if (numdrivers==1)
		return 0;

	CArray<CString, CString> drivers;
	for (int i=0;i<numdrivers;i++)
	{
		LPSTR desc, name;
		GetDriverInfo( i, 0, &desc, &name );
		drivers.Add(desc);
	}

	DriverDialog dialog;
	dialog.SetContents( &drivers );
	if (dialog.DoModal()!=IDOK)
		return -1;

	return dialog.GetSelection();
}

int MAIN::SelectInitialDisplayMode()
{
	DWORD curdepth=GetDisplayDepth();
	int i, nummodes=GetNumDisplayModes();
	DWORD w,h,d;

	if (curdepth!=desireddepth)
		ddraw2->SetDisplayMode( 640, 480, curdepth, 0, 0 );

	for (i=0;i<nummodes;i++)
	{
		GetDisplayModeDimensions( i, w, h, d );
		if (w==desiredwidth && h==desiredheight && d==desireddepth)
			return i;
	}

	for (i=0;i<nummodes;i++)
	{
		GetDisplayModeDimensions( i, w, h, d );
		if (d==desireddepth)
			return i;
	}

	return 0;
}



LRESULT MAIN::DefWindowProc( UINT message, WPARAM wParam, LPARAM lParam )
{
	if(hwnd==0)
		hwnd=GetSafeHwnd();

	if( wParam==MCI_NOTIFY_SUCCESSFUL && message==MM_MCINOTIFY )
	{
	}

	return ::DefWindowProc( hwnd,message,wParam,lParam );
}



void MAIN::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (nChar==VK_ESCAPE)
	{
		lpdd->FlipToGDISurface();

		if( MessageBox("退出吗?",NULL,MB_YESNO | MB_ICONQUESTION)==IDYES )
		{
			Deinit();

			PostMessage( WM_CLOSE );
		}
	}

	if(puttext)//begin if
	{

	//music
	if(nChar==VK_F1)
	{
	}

	//step
	if(nChar==VK_F2)
	{
		if(game.step==32)
			game.step=2;
		else
			game.step*=2;
	}

	//kill hit & acc
	if(nChar==VK_F3)
	{
		ZeroMemory(hit, sizeof(BYTE)*MAX_HIT);
		ZeroMemory(acc, sizeof(BYTE)*MAX_ACC);
	}

	//fill hit & acc
	if(nChar==VK_F4)
	{
		map[0]->GetAppend(hit,300,acc,300);
	}

	//save
	if(nChar==VK_F5)
	{
		FILE *file=0;

		file=fopen("h","w+");
		if(file!=0)
		{
			fwrite(hit,sizeof(BYTE),MAX_HIT,file);
		
			fclose(file);
			file=0;

			MessageBox("hit file saved");
		}

		file=fopen("a","w+");
		if(file!=0)
		{
			fwrite(acc,sizeof(BYTE),MAX_HIT,file);
		
			fclose(file);
			file=0;

			MessageBox("acc file saved");
		}
	}

	//game.process
	if(nChar==VK_F6)
	{
		game.process[nproc++]=1;
	}
	}//end if

	if(nChar==VK_F12)
	{
		puttext=!puttext;
	}

}

⌨️ 快捷键说明

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