📄 main.cpp
字号:
SetActiveWindow( g_hWnd );
// Render toolbar tileset
vRenderTileSet();
}
void vPreviousTile( void )
{
if( g_iCurTileSet > 0 )
g_iCurTileSet--;
vRenderTileSet();
SetActiveWindow( g_hWnd );
}
void vNextTile( void )
{
if( g_iCurTileSet < g_iMaxTileSet )
g_iCurTileSet++;
vRenderTileSet();
SetActiveWindow( g_hWnd );
}
void vRenderTileSet(void)
{
RECT rectDest;
RECT rectSrc;
int iX;
int iY;
int iTile;
// Turn on ambient lighting
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00606060 );
// Clear the backbuffer and the zbuffer
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
// Begin Rendering
g_pd3dDevice->BeginScene();
// Set alpha blending states
// This is used to provide transparency/translucency
g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
// Display active tiles
for( iY = 0; iY < 7; iY++ ) {
for( iX = 0; iX < 3; iX++ ) {
// Calculate tile to render
iTile = (g_iCurTileSet*21)+(iX+(iY*3));
// Render if valid tile
if( iTile < g_iTotalTiles ) {
vDrawInterfaceObject(
iX*g_iTileSize,
iY*g_iTileSize,
(float)g_iTileSize,
(float)g_iTileSize,
iTile );
}
// Draw overlay to show which
// tile is selected
if( iTile == g_iCurTile ) {
vDrawInterfaceObject(
iX*g_iTileSize,
iY*g_iTileSize,
(float)g_iTileSize,
(float)g_iTileSize,
18 );
}
}
}
// Display a red box around the
// current tile selected
vDrawInterfaceObject(
32,
32*7,
(float)g_iTileSize,
(float)g_iTileSize,
g_iCurTile );
// Stop Rendering
g_pd3dDevice->EndScene();
//
// Output the scene
//
// Source rectangle
rectSrc.top = 0;
rectSrc.bottom = g_iTileSize*8;
rectSrc.left = 0;
rectSrc.right = g_iTileSize*3;
// Destination rectangle
rectDest.top = 0;
rectDest.bottom = (g_iTileSize*8);
rectDest.left = 0;
rectDest.right = (g_iTileSize*3);
// Present the results
g_pd3dDevice->Present( &rectSrc, &rectDest, hWndToolBar, NULL );
}
void vCheckMouse( void )
{
RECT rcWindow;
POINT Point;
int iMouseX;
int iMouseY;
int iTileX;
int iTileY;
// Get mouse coordinates
GetCursorPos( &Point );
iMouseX = Point.x;
iMouseY = Point.y;
// Figure out the toolbar work area
GetWindowRect( hWndToolBar, &rcWindow );
// Check if mouse within tool-bar window
if( iMouseX > rcWindow.left &&
iMouseX < rcWindow.right &&
iMouseY > rcWindow.top &&
iMouseY < rcWindow.bottom )
{
// Adjust mouse coords to be local to toolbar
iMouseX -= rcWindow.right;
iMouseY -= rcWindow.top;
// Figure out tile coordinates
iTileX = iMouseX/g_iTileSize;
iTileY = iMouseY/g_iTileSize;
// Figure out picked tile
g_iCurTile = (g_iCurTileSet*21)+(iTileX+(iTileY*3))-1;
// Make sure tile is valid
if( g_iCurTile < 0 || g_iCurTile >= g_iTotalTiles ) {
g_iCurTile = 0;
}
vRenderTileSet();
}
// Check if mouse within edit window
else {
GetWindowRect( g_hWnd, &rcWindow );
if( iMouseX > rcWindow.left &&
iMouseX < rcWindow.right &&
iMouseY > rcWindow.top &&
iMouseY < rcWindow.bottom )
{
// Adjust mouse coords to be local to edit window
iMouseX -= rcWindow.left+g_iXOffset;
iMouseY -= rcWindow.top+g_iYOffset;
// Figure out tile coordinates
iTileX = iMouseX/g_iTileSize;
iTileY = iMouseY/g_iTileSize;
g_iTileMap[ iTileX+g_iXPos+
( (iTileY + g_iYPos)
* g_iMapWidth ) ] = g_iCurTile;
// Render updated minimap
vRenderMinimap();
}
}
}
//-----------------------------------------------------------------------------
//
// Saves the tile map to a binary file.
//
//-----------------------------------------------------------------------------
void vSaveMap( void )
{
FILE *fp;
int iRet;
OPENFILENAME fileStruct;
char szFileName[ 512 ];
char szFilter[ 32 ];
char szExtension[ 32 ];
// Clear buffer to receive file name
memset( szFileName, 0x00, 512 );
// Create file filter
memset( szFilter, 0x00, 32 );
strcpy( szFilter, "*.dat" );
// Create file extension
memset( szExtension, 0x00, 32 );
strcpy( szExtension, "dat" );
//
// Setup the file dialog box
//
// Clear file dialog structure
memset( &fileStruct, 0x00, sizeof( OPENFILENAME ) );
// Initialize structure
fileStruct.hInstance = g_hInstance;
fileStruct.hwndOwner = g_hWnd;
fileStruct.lpstrDefExt = szExtension;
fileStruct.lpstrFileTitle = szFileName;
fileStruct.lpstrFilter = szFilter;
fileStruct.nMaxFileTitle = 512;
fileStruct.lStructSize = sizeof( OPENFILENAME );
// Retrieve the filename
iRet = GetSaveFileName( &fileStruct );
// Exit out on failure
if( !iRet ) {
return;
}
// Open the tile file
fp = fopen( szFileName, "wb" );
// Return if open failed
if( fp == NULL ) {
return;
}
// Save the tile buffer
fwrite( g_iTileMap, 10000, sizeof(int), fp );
// Close the tile file
fclose( fp );
// Play sound to indicate action
PlaySound("bleep.wav",NULL,SND_FILENAME|SND_ASYNC);
}
//-----------------------------------------------------------------------------
//
// Loads the tile map from a binary file.
//
//-----------------------------------------------------------------------------
void vLoadMap( void )
{
FILE *fp;
OPENFILENAME fileStruct;
char szFileName[ 512 ];
char szFilter[ 32 ];
char szExtension[ 32 ];
int iRet;
// Clear buffer to receive file name
memset( szFileName, 0x00, 512 );
// Create file filter
memset( szFilter, 0x00, 32 );
strcpy( szFilter, "*.dat" );
// Create file extension
memset( szExtension, 0x00, 32 );
strcpy( szExtension, "dat" );
//
// Setup the file dialog box
//
// Clear file dialog structure
memset( &fileStruct, 0x00, sizeof( OPENFILENAME ) );
// Initialize structure
fileStruct.hInstance = g_hInstance;
fileStruct.hwndOwner = g_hWnd;
fileStruct.lpstrDefExt = szExtension;
fileStruct.lpstrFileTitle = szFileName;
fileStruct.lpstrFilter = szFilter;
fileStruct.nMaxFileTitle = 512;
fileStruct.lStructSize = sizeof( OPENFILENAME );
// Retrieve the filename
iRet = GetOpenFileName( &fileStruct );
// Exit out on failure
if( !iRet ) {
return;
}
// Open the tile file
fp = fopen( szFileName, "rb" );
// Return if no file to load
if( fp == NULL ) {
return;
}
// Read the tile buffer
fread( g_iTileMap, 10000, sizeof(int), fp );
// Close the tile file
fclose( fp );
// Play sound to indicate action
PlaySound("button.wav",NULL,SND_FILENAME|SND_ASYNC);
}
//-----------------------------------------------------------------------------
//
// Create the minimap window
//
//-----------------------------------------------------------------------------
void vCreateMinimap(HWND hwnd, HINSTANCE hinst)
{
WNDCLASSEX wcMinimap;
RECT rcWindow;
// Set up and register toolbar window class
wcMinimap.cbSize = sizeof(wcMinimap);
wcMinimap.style = CS_HREDRAW | CS_VREDRAW;
wcMinimap.lpfnWndProc = fnMessageProcessor;
wcMinimap.cbClsExtra = 0;
wcMinimap.cbWndExtra = 0;
wcMinimap.hInstance = hinst;
wcMinimap.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wcMinimap.hCursor = LoadCursor( NULL, IDC_ARROW );
wcMinimap.hbrBackground = (HBRUSH) GetStockObject (COLOR_BACKGROUND);
wcMinimap.lpszMenuName = NULL;
wcMinimap.lpszClassName = "Minimap"; // Registered Class Name
wcMinimap.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
RegisterClassEx(&wcMinimap);
// Figure out position
GetWindowRect( g_hWnd, &rcWindow );
// Create mini-map window
hWndMinimap = CreateWindowEx (
WS_EX_LEFT|WS_EX_TOPMOST|WS_EX_TOOLWINDOW,
"Minimap", "Minimap",
WS_BORDER | WS_VISIBLE | WS_MINIMIZEBOX,
rcWindow.left+10, rcWindow.bottom+g_iYOffset-140,
100, 100, hwnd, NULL, hinst, NULL);
// Activate edit area
SetActiveWindow( g_hWnd );
}
//-----------------------------------------------------------------------------
//
// Render the minimap
//
//-----------------------------------------------------------------------------
void vRenderMinimap( void )
{
RECT rectSrc;
RECT rectDest;
int iX;
int iY;
int iCurTile;
int iBufferPos;
// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
// Begin the scene
g_pd3dDevice->BeginScene();
//---------------------
//
// RENDER THE MINIMAP
//
//---------------------
// Top to bottom
for( iY = 0; iY < g_iMapHeight; iY++ ) {
// Left to right
for( iX = 0; iX < g_iMapWidth; iX++ ) {
// Calculate buffer offset
iBufferPos = iX+( iY * g_iMapWidth );
// Get the proper tile
iCurTile = g_iTileMap[ iBufferPos ];
// Display the tile
vDrawInterfaceObject( ( iX ),
( iY ),
(float)1,
(float)1,
iCurTile );
}
}
// End the scene
g_pd3dDevice->EndScene();
//
// Output the scene
//
// Source rectangle
rectSrc.top = 0;
rectSrc.bottom = g_iMapHeight;
rectSrc.left = 0;
rectSrc.right = g_iMapWidth;
// Destination rectangle
rectDest.top = 0;
rectDest.bottom = g_iMapHeight;
rectDest.left = 0;
rectDest.right = g_iMapWidth;
// Present the results
g_pd3dDevice->Present( &rectSrc, &rectDest, hWndMinimap, NULL );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -