📄 g16-02.cpp
字号:
g_currenttile = -1;
g_currentlayer = 2;
}
void Clear3()
{
g_currenttile = -1;
g_currentlayer = 3;
}
// ============================================================================
// Main
// ============================================================================
int main( int argc, char* argv[] )
{
int x;
int y;
int z;
//initialize systems
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
SDL_EnableUNICODE( true );
SDL_WM_SetCaption( PROGRAM_NAME, 0);
TTF_Init();
g_gui = new SDLGUI( WIDTH, HEIGHT, ITEMS, BLACK );
g_gui->SetFont( "arial.ttf", ARIAL, 18, TTF_STYLE_NORMAL );
g_gui->AddCheckbox( 512, 440, "checkboxup.bmp", "checkboxdown.bmp",
"Highlight Current", ARIAL, WHITE, BLACK, Highlight );
g_gui->AddTextBox( 512, 568, 159, 31, g_filename, 63,
ARIAL, WHITE, BLACK, true, 0 );
g_gui->AddLabel( 512, 472, "red map:", ARIAL, WHITE, BLACK );
g_gui->AddTextBox( 610, 472, 189, 31, g_exits[0], 63,
ARIAL, WHITE, BLACK, true, 0 );
g_gui->AddLabel( 512, 504, "green map:", ARIAL, WHITE, BLACK );
g_gui->AddTextBox( 610, 504, 189, 31, g_exits[1], 63,
ARIAL, WHITE, BLACK, true, 0 );
g_gui->AddLabel( 512, 536, "blue map:", ARIAL, WHITE, BLACK );
g_gui->AddTextBox( 610, 536, 189, 31, g_exits[2], 63,
ARIAL, WHITE, BLACK, true, 0 );
g_gui->AddButton( 672, 568, "gbup2.bmp", "gbdown2.bmp", "Save",
ARIAL, BLACK, WHITE, Save );
g_gui->AddButton( 736, 568, "gbup2.bmp", "gbdown2.bmp", "Load",
ARIAL, BLACK, WHITE, Load );
g_gui->AddButton( 512, 0, "gbup.bmp", "gbdown.bmp", "Grass",
ARIAL, BLACK, WHITE, Grass1 );
g_gui->AddButton( 512, 32, "gbup.bmp", "gbdown.bmp", "Snow1",
ARIAL, BLACK, WHITE, Snow1 );
g_gui->AddButton( 512, 64, "gbup.bmp", "gbdown.bmp", "Road",
ARIAL, BLACK, WHITE, Road1 );
g_gui->AddButton( 512, 96, "gbup.bmp", "gbdown.bmp", "Snow2",
ARIAL, BLACK, WHITE, Snow2 );
g_gui->AddButton( 512, 128, "gbup.bmp", "gbdown.bmp", "Snow3",
ARIAL, BLACK, WHITE, Snow3 );
g_gui->AddButton( 512, 160, "gbup.bmp", "gbdown.bmp", "Wall",
ARIAL, BLACK, WHITE, Wall1 );
g_gui->AddButton( 512, 192, "gbup.bmp", "gbdown.bmp", "Items",
ARIAL, BLACK, WHITE, Items );
g_gui->AddButton( 512, 224, "gbup.bmp", "gbdown.bmp", "Players",
ARIAL, BLACK, WHITE, Players );
g_gui->AddButton( 512, 256, "gbup.bmp", "gbdown.bmp", "Exit",
ARIAL, BLACK, WHITE, Exit );
g_gui->AddButton( 512, 288, "gbup.bmp", "gbdown.bmp", "del tile",
ARIAL, BLACK, WHITE, Clear1 );
g_gui->AddButton( 512, 320, "gbup.bmp", "gbdown.bmp", "del item",
ARIAL, BLACK, WHITE, Clear2 );
g_gui->AddButton( 512, 352, "gbup.bmp", "gbdown.bmp", "del player",
ARIAL, BLACK, WHITE, Clear3 );
// load the bmps
// layer 0 bmps:
// grass1
g_groupstarts[0] = 0;
g_groupcounts[0] = 4;
g_grouplayers[0] = 0;
g_bmps[0][0][0] = SDL_LoadBMP( "grass1.bmp" );
g_bmps[0][1][0] = SDL_LoadBMP( "grass2.bmp" );
g_bmps[0][2][0] = SDL_LoadBMP( "grass3.bmp" );
g_bmps[0][3][0] = SDL_LoadBMP( "grass4.bmp" );
g_bmps[0][0][1] = SDL_LoadBMP( "sgrass1.bmp" );
g_bmps[0][1][1] = SDL_LoadBMP( "sgrass2.bmp" );
g_bmps[0][2][1] = SDL_LoadBMP( "sgrass3.bmp" );
g_bmps[0][3][1] = SDL_LoadBMP( "sgrass4.bmp" );
// snow1
g_groupstarts[1] = 4;
g_groupcounts[1] = 2;
g_grouplayers[1] = 0;
g_bmps[0][4][0] = SDL_LoadBMP( "snow1.bmp" );
g_bmps[0][5][0] = SDL_LoadBMP( "snow2.bmp" );
g_bmps[0][4][1] = SDL_LoadBMP( "ssnow1.bmp" );
g_bmps[0][5][1] = SDL_LoadBMP( "ssnow2.bmp" );
// road1
g_groupstarts[2] = 6;
g_groupcounts[2] = 6;
g_grouplayers[2] = 0;
g_bmps[0][6][0] = SDL_LoadBMP( "roadh.bmp" );
g_bmps[0][7][0] = SDL_LoadBMP( "roadv.bmp" );
g_bmps[0][8][0] = SDL_LoadBMP( "roadtopleft.bmp" );
g_bmps[0][9][0] = SDL_LoadBMP( "roadtopright.bmp" );
g_bmps[0][10][0] = SDL_LoadBMP( "roadbottomleft.bmp" );
g_bmps[0][11][0] = SDL_LoadBMP( "roadbottomright.bmp" );
g_bmps[0][6][1] = SDL_LoadBMP( "sroadh.bmp" );
g_bmps[0][7][1] = SDL_LoadBMP( "sroadv.bmp" );
g_bmps[0][8][1] = SDL_LoadBMP( "sroadtopleft.bmp" );
g_bmps[0][9][1] = SDL_LoadBMP( "sroadtopright.bmp" );
g_bmps[0][10][1] = SDL_LoadBMP( "sroadbottomleft.bmp" );
g_bmps[0][11][1] = SDL_LoadBMP( "sroadbottomright.bmp" );
// layer 1 bmps:
// snow2
g_groupstarts[3] = 12;
g_groupcounts[3] = 4;
g_grouplayers[3] = 1;
g_bmps[0][12][0] = SDL_LoadBMP( "snowtop.bmp" );
g_bmps[0][13][0] = SDL_LoadBMP( "snowbottom.bmp" );
g_bmps[0][14][0] = SDL_LoadBMP( "snowleft.bmp" );
g_bmps[0][15][0] = SDL_LoadBMP( "snowright.bmp" );
g_bmps[0][12][1] = SDL_LoadBMP( "ssnowtop.bmp" );
g_bmps[0][13][1] = SDL_LoadBMP( "ssnowbottom.bmp" );
g_bmps[0][14][1] = SDL_LoadBMP( "ssnowleft.bmp" );
g_bmps[0][15][1] = SDL_LoadBMP( "ssnowright.bmp" );
// snow 3
g_groupstarts[4] = 16;
g_groupcounts[4] = 8;
g_grouplayers[4] = 1;
g_bmps[0][16][0] = SDL_LoadBMP( "snowotl.bmp" );
g_bmps[0][17][0] = SDL_LoadBMP( "snowotr.bmp" );
g_bmps[0][18][0] = SDL_LoadBMP( "snowobl.bmp" );
g_bmps[0][19][0] = SDL_LoadBMP( "snowobr.bmp" );
g_bmps[0][20][0] = SDL_LoadBMP( "snowitl.bmp" );
g_bmps[0][21][0] = SDL_LoadBMP( "snowitr.bmp" );
g_bmps[0][22][0] = SDL_LoadBMP( "snowibl.bmp" );
g_bmps[0][23][0] = SDL_LoadBMP( "snowibr.bmp" );
g_bmps[0][16][1] = SDL_LoadBMP( "ssnowotl.bmp" );
g_bmps[0][17][1] = SDL_LoadBMP( "ssnowotr.bmp" );
g_bmps[0][18][1] = SDL_LoadBMP( "ssnowobl.bmp" );
g_bmps[0][19][1] = SDL_LoadBMP( "ssnowobr.bmp" );
g_bmps[0][20][1] = SDL_LoadBMP( "ssnowitl.bmp" );
g_bmps[0][21][1] = SDL_LoadBMP( "ssnowitr.bmp" );
g_bmps[0][22][1] = SDL_LoadBMP( "ssnowibl.bmp" );
g_bmps[0][23][1] = SDL_LoadBMP( "ssnowibr.bmp" );
// wall 1
g_groupstarts[5] = 0;
g_groupcounts[5] = 6;
g_grouplayers[5] = 2;
g_bmps[1][0][0] = SDL_LoadBMP( "wallh.bmp" );
g_bmps[1][1][0] = SDL_LoadBMP( "wallv.bmp" );
g_bmps[1][2][0] = SDL_LoadBMP( "walltl.bmp" );
g_bmps[1][3][0] = SDL_LoadBMP( "walltr.bmp" );
g_bmps[1][4][0] = SDL_LoadBMP( "wallbl.bmp" );
g_bmps[1][5][0] = SDL_LoadBMP( "wallbr.bmp" );
g_bmps[1][0][1] = SDL_LoadBMP( "swallh.bmp" );
g_bmps[1][1][1] = SDL_LoadBMP( "swallv.bmp" );
g_bmps[1][2][1] = SDL_LoadBMP( "swalltl.bmp" );
g_bmps[1][3][1] = SDL_LoadBMP( "swalltr.bmp" );
g_bmps[1][4][1] = SDL_LoadBMP( "swallbl.bmp" );
g_bmps[1][5][1] = SDL_LoadBMP( "swallbr.bmp" );
// items
g_groupstarts[6] = 6;
g_groupcounts[6] = 8;
g_grouplayers[6] = 2;
g_bmps[1][6][0] = SDL_LoadBMP( "wepicon-axe.bmp" );
g_bmps[1][7][0] = SDL_LoadBMP( "wepicon-bow.bmp" );
g_bmps[1][8][0] = SDL_LoadBMP( "wepicon-knife.bmp" );
g_bmps[1][9][0] = SDL_LoadBMP( "wepicon-mace.bmp" );
g_bmps[1][10][0] = SDL_LoadBMP( "wepicon-spear.bmp" );
g_bmps[1][11][0] = SDL_LoadBMP( "wepicon-sword.bmp" );
g_bmps[1][12][0] = SDL_LoadBMP( "wepicon-helm.bmp" );
g_bmps[1][13][0] = SDL_LoadBMP( "wepicon-shield.bmp" );
g_bmps[1][6][1] = SDL_LoadBMP( "swepicon-axe.bmp" );
g_bmps[1][7][1] = SDL_LoadBMP( "swepicon-bow.bmp" );
g_bmps[1][8][1] = SDL_LoadBMP( "swepicon-knife.bmp" );
g_bmps[1][9][1] = SDL_LoadBMP( "swepicon-mace.bmp" );
g_bmps[1][10][1] = SDL_LoadBMP( "swepicon-spear.bmp" );
g_bmps[1][11][1] = SDL_LoadBMP( "swepicon-sword.bmp" );
g_bmps[1][12][1] = SDL_LoadBMP( "swepicon-helm.bmp" );
g_bmps[1][13][1] = SDL_LoadBMP( "swepicon-shield.bmp" );
// players
g_groupstarts[7] = 0;
g_groupcounts[7] = 3;
g_grouplayers[7] = 3;
g_bmps[2][0][0] = SDL_LoadBMP( "hero1.bmp" );
g_bmps[2][1][0] = SDL_LoadBMP( "hero2.bmp" );
g_bmps[2][2][0] = SDL_LoadBMP( "hero3.bmp" );
g_bmps[2][0][1] = SDL_LoadBMP( "shero1.bmp" );
g_bmps[2][1][1] = SDL_LoadBMP( "shero2.bmp" );
g_bmps[2][2][1] = SDL_LoadBMP( "shero3.bmp" );
g_groupstarts[8] = 14;
g_groupcounts[8] = 3;
g_grouplayers[8] = 2;
g_bmps[1][14][0] = SDL_LoadBMP( "rvortex.bmp" );
g_bmps[1][15][0] = SDL_LoadBMP( "gvortex.bmp" );
g_bmps[1][16][0] = SDL_LoadBMP( "bvortex.bmp" );
g_bmps[1][14][1] = SDL_LoadBMP( "srvortex.bmp" );
g_bmps[1][15][1] = SDL_LoadBMP( "sgvortex.bmp" );
g_bmps[1][16][1] = SDL_LoadBMP( "sbvortex.bmp" );
for( y = 0; y < g_map.Height(); y++ )
{
for( x = 0; x < g_map.Width(); x++ )
{
g_map.Get( x, y, 0 ) = rand() % 4;
g_map.Get( x, y, 1 ) = -1;
g_map.Get( x, y, 2 ) = -1;
g_map.Get( x, y, 3 ) = -1;
}
}
// set the color keys of the BMPs
for( y = 0; y < 3; y++ )
{
for( x = 0; x < 41; x++ )
{
if( g_bmps[y][x][0] != 0 )
{
SDL_SetColorKey( g_bmps[y][x][0], SDL_SRCCOLORKEY,
SDL_MapRGB( g_bmps[y][x][0]->format,
255, 0, 255 ) );
SDL_SetColorKey( g_bmps[y][x][1], SDL_SRCCOLORKEY,
SDL_MapRGB( g_bmps[y][x][1]->format,
255, 0, 255 ) );
}
}
}
// set our at exit function
atexit( SDL_Quit ) ;
// declare event variable
SDL_Event event;
g_gui->Draw();
g_gui->Update();
// loop until we get a quit message.
while( 1 )
{
//look for an event
if( SDL_PollEvent( &event ) )
{
//an event was found
if( event.type == SDL_QUIT )
break;
// mouse button was pressed
if( event.type == SDL_MOUSEBUTTONDOWN )
{
// get the mouse g_state.
SDL_GetMouseState( &x, &y );
// tell the GUI that a button has been pressed
g_gui->MouseDown( x, y );
// check to see if the user clicked on a new tile in
// the palette
if( y >= 536 && x <= 512 )
{
z = x / 64;
// make sure that the user actually clicked
// on a tile, instead of a blank.
if( z < g_groupcounts[g_currentgroup] )
{
g_currenttile = g_groupstarts[g_currentgroup] + z;
g_currentlayer = g_grouplayers[g_currentgroup];
}
}
g_mousedown = true;
}
// mouse button was released
if( event.type == SDL_MOUSEBUTTONUP )
{
// get the mouse state.
SDL_GetMouseState( &x, &y );
// tell the GUI that a button has been released
g_gui->MouseUp( x, y );
g_mousedown = false;
// see if the user clicked on a square
x = x / 8;
y = y / 8;
if( x < g_map.Width() && y < g_map.Height() )
{
// draw the tile, in case the user didn't
// move the mouse around.
g_map.Get( x, y, g_currentlayer ) = g_currenttile;
}
}
if( event.type == SDL_MOUSEMOTION )
{
// get the mouse state.
SDL_GetMouseState( &x, &y );
// see if the user clicked on a square
x = x / 8;
y = y / 8;
if( x < g_map.Width() && y < g_map.Height()
&& g_mousedown == true )
{
// draw the tile on the map
g_map.Get( x, y, g_currentlayer ) = g_currenttile;
}
}
if( event.type == SDL_KEYDOWN )
{
// get the mouse state.
SDL_GetMouseState( &x, &y );
// a key was pressed.
if( event.key.keysym.sym == SDLK_ESCAPE )
{
// if ESC was pressed, quit the program.
SDL_Event quit;
quit.type = SDL_QUIT;
SDL_PushEvent( &quit );
}
// tell the GUI that a key was pressed.
g_gui->KeyDown( event.key.keysym.sym,
event.key.keysym.mod,
event.key.keysym.unicode );
}
}
// draw the g_gui at the end of each loop.
g_gui->Draw();
DrawMap();
DrawMiniMap();
DrawPalette();
g_gui->Update();
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -