本文整理汇总了C++中Map::Get方法的典型用法代码示例。如果您正苦于以下问题:C++ Map::Get方法的具体用法?C++ Map::Get怎么用?C++ Map::Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map::Get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mouseClick
void mouseClick(MOUSE_EVENT event) {
if (event == MOUSE_LEFT) {
if (inEditorBar()) {
std::cout << "editor!\n";
int editorTileIndex = getTileEditor(mouse_x, mouse_y);
if(editorTileIndex >= 0 && editorTileIndex < NB_TILES_EDITOR) {
std::cout << "id= " << editorTileIndex << "\n";
selectedTileEditor = editorTileIndex;
}
}
else {
//write tile to map
int mapX; int mapY;
getSelectedTileXY(mouse_x, mouse_y, mapX, mapY);
if (mapX >= 0 && mapX < worldMap.GetWidth() &&
mapY >= 0 && mapY < worldMap.GetHeight()) {
int tileId = TILES_EDITOR[selectedTileEditor];
Terrain& terrain = worldMap.Get(mapX, mapY);
if (EDITOR_SELECTED_LAYER == 0) {
terrain.terrainId = tileId;
}
else if (EDITOR_SELECTED_LAYER == 1) {
terrain.objectId = tileId;
}
std::cout << "set tile " << tileId << " at " << mapX << "," << mapY << "\n";
}
}
}
else if (event == MOUSE_RIGHT) {
//erase tile from map
int mapX; int mapY;
getSelectedTileXY(mouse_x, mouse_y, mapX, mapY);
if (mapX >= 0 && mapX <= worldMap.GetWidth() &&
mapY >= 0 && mapY < worldMap.GetHeight()) {
int tileId = TILES_EDITOR[0];
Terrain& terrain = worldMap.Get(mapX, mapY);
if (EDITOR_SELECTED_LAYER == 0) {
terrain.terrainId = -1;
}
else if (EDITOR_SELECTED_LAYER == 1) {
terrain.objectId = -1;
}
std::cout << "set tile " << tileId << " at " << mapX << "," << mapY << "\n";
}
}
}
示例2: Decorate
Map Decorate( Map map )
{
Map newmap(map);
int bounds[4][2] = {
{ 1, 0 },
{ -1, 0 },
{ 0, 1 },
{ 0, -1 }
};
for( int x = 0; x < map.Width(); x++ )
for( int y = 0; y < map.Height(); y++ )
{
int hnb=0,vnb=0;
for( int i = 0; i < 2; i++ )
hnb += (map.GetScroll( x + bounds[i][0], y + bounds[i][1] ) == Map::BLOCK_FREE ? 0 : 1);
for( int i = 2; i < 4; i++ )
vnb += (map.GetScroll( x + bounds[i][0], y + bounds[i][1] ) == Map::BLOCK_FREE ? 0 : 1);
if( (hnb - vnb == 0 || hnb + vnb == 1 ) && map.Get( x, y ) != Map::BLOCK_FREE ) newmap.Set(x, y, 2);
}
return newmap;
}
示例3: render
void render(SDL_Renderer* renderer)
{
//draw draw space
// if (input_draw_space) {
// SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
//
// SDL_Rect rect;
// rect.x = 0;
// rect.y = 0;
// mapToOrtho(worldMap.GetWidth(), worldMap.GetHeight(), rect.w, rect.h);
// zoom(rect);
// worldToScreen(rect.x, rect.y);
//
// SDL_RenderFillRect(renderer, &rect);
// SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
// }
//draw map
for (int y = 0; y < worldMap.GetHeight(); y++) {
for (int x = 0; x < worldMap.GetWidth(); x++) {
SDL_Rect rect; //in world coords
rect.w = tileSizeX;
rect.h = tileSizeY;
mapToIso(x, y, rect.x, rect.y);
zoom(rect);
rect.y -= (tileSizeY*input_scale - tileWidth*input_scale);
worldToScreen(rect.x, rect.y);
SDL_Rect tileRect; //in tileset coords
tileRect.w = tileSizeX;
tileRect.h = tileSizeY;
//layer terrain
const int tileId = worldMap.Get(x,y).terrainId;
if (tileId != -1) {
int tileX; int tileY; getTileXY(tileId, &tileX, &tileY, TILESET_WIDTH);
tileRect.x = tileX * tileSizeX;
tileRect.y = tileY * tileSizeY;
SDL_RenderCopy(renderer, tileset, &tileRect, &rect);
}
//layer object
const int tileId2 = worldMap.Get(x, y).objectId;
if (tileId2 != -1) {
int tileObjX; int tileObjY; getTileXY(tileId2, &tileObjX, &tileObjY, TILESET_WIDTH);
tileRect.x = tileObjX * tileSizeX;
tileRect.y = tileObjY * tileSizeY;
SDL_RenderCopy(renderer, tileset, &tileRect, &rect);
}
}
}
// //draw debug rect
// if (input_show_debug_rect) {
// SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
// for (int y = 0; y < worldMap.GetHeight(); y++) {
// for (int x = 0; x < worldMap.GetWidth(); x++) {
// SDL_Rect rect;
// rect.w = tileSizeX;
// rect.h = tileWidth;
//
// mapToOrtho(x,y,rect.x, rect.y);
// zoom(rect);
// worldToScreen(rect.x, rect.y);
//
// SDL_RenderDrawRect(renderer, &rect);
// }
// }
// SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
// }
//show editor bar
for (int i = 0; i < NB_TILES_EDITOR; i++) {
SDL_Rect tileRect; //in tileset coords
tileRect.w = tileSizeX;
tileRect.h = tileSizeY;
const int tileId = TILES_EDITOR[i];
int tileX; int tileY; getTileXY(tileId, &tileX, &tileY, TILESET_WIDTH);
tileRect.x = tileX * tileSizeX;
tileRect.y = tileY * tileSizeY;
SDL_Rect rect; //in world coords
rect.w = tileSizeX;
rect.h = tileSizeY;
rect.x = i * tileSizeX;
rect.y = WIN_HEIGHT - tileSizeY;
SDL_RenderCopy(renderer, tileset, &tileRect, &rect);
}
if (input_show_debug_rect) {
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
for (int x = 0; x < worldMap.GetWidth() + 1; x++) {
int x1 = x;
int y1 = 0;
int x2 = x;
int y2 = worldMap.GetHeight();
//.........这里部分代码省略.........