int main() { int i = 0; int index = 0; int numResources = 0; char *resources; loadTiles(); loadResourceList(); while(1) { printf("\nIndex: "); scanf("%d", &index); resources = getResources(index); numResources = resources[0]; printf("Tile: %d\n", getTileType(index)); printf("Resources: "); printf("%d", resources[0]); for(i = 0; i < numResources; i++) { printf("%d", resources[i * 2 + 1] ); printf("%d", resources[(i * 2) + 2]); } } return 0; }
void TileMap::draw() { const DWORD COLOR_BOARD_LINE = 0x55020202; for (int i = 0; i <= CELL_COUNT_Y; ++i) // ºáÏß { g_HGE->Gfx_RenderLine(0, i*CELL_SIZE_Y, CELL_COUNT_X*CELL_SIZE_X, i*CELL_SIZE_Y, COLOR_BOARD_LINE); } for (int i = 0; i <= CELL_COUNT_X; ++i) // ÊúÏß { g_HGE->Gfx_RenderLine(i*CELL_SIZE_X, 0, i*CELL_SIZE_X, CELL_COUNT_Y*CELL_SIZE_Y, COLOR_BOARD_LINE); } for (short x = 0; x < CELL_COUNT_X; ++x) { for (short y = 0; y < CELL_COUNT_Y; ++y) { util::fillCell(CellCoord(x, y), getTileColor(getTileType(fdkgame::navi::CellCoord(x, y))) ); } } }
WorldMap* MapReader::readMap(std::string filename) { std::ifstream infile(filename.c_str()); int cellWidth = 0; int cellHeight = 0; int nextTileVal = 0; std::stringstream lineStream; infile >> cellWidth >> cellHeight; WorldMap* map = new WorldMap(cellWidth, cellHeight, Terrain::getSize()); std::cout << "Loading map [" << filename << "] (" << cellWidth << ", " << cellHeight << ")" << std::endl; // Loop through each row of the map for (int height = 0; height < cellHeight; ++height) { // Loop through each column of the map for (int width = 0; width < cellWidth; ++width) { infile >> nextTileVal; // Special case -- victory condition if (nextTileVal == 2) { Manager::getInstance()->getTarget()->setLocation(width * Terrain::getSize(), height * Terrain::getSize()); } // All other cases. else { Terrain * nextTileType = getTileType(nextTileVal); if (nextTileType != NULL) { map->setCell(width, height, nextTileType); } } } lineStream.str(""); } /* for (int width = 0; width < cellWidth; ++width) { map->setCell(width, cellHeight - 1, getTileType(1)); } */ return map; }
void Map::updateNodes() { for (int x = 0; x < m_worldWidthTiles; ++x) { for (int y = 0; y < m_worldHeightTiles; ++y) { TileNode& tileNode = m_tileNodes[getTileNodeIndex(x, y)]; tileNode.m_type = getTileType(x, y); tileNode.m_pos = PointI(x, y); tileNode.m_transition = TileNode::Transition(); tileNode.m_isWaypoint = false; // TODO - cars, etc... } } for (const auto& waypoint : m_world->getWaypoints()) { TileNode& tileNode = m_tileNodes[getTileNodeIndex(waypoint[0], waypoint[1])]; tileNode.m_isWaypoint = true; } }
int main() { int s = 1; printf("---Program starts---\n"); // checking Tile condition if (getTileType(153) != 'W') printf("153 should return W"); else if (getTileType(65) != 'L') printf("65 should return L"); else if (getTileType(49) != 'G') printf("49 should return G"); else if (getTileType(0) != 'C') printf("0 should return C"); else if (getTileType(105) != 'G') printf("105 should be G"); else if (getTileType(79) != ' ') printf("79 should be space"); else { printf("getTileType test passed!\nEnter board size: "); scanf_s("%d", &s); displayBoard(s); // Calling displayBoard function printf("---End Program---\n"); } return 0; }
void CmdRemoveTile_c::undo() { m_map->addTile( getTileX(), getTileY(), getTileType() ); }
void CmdAddTile_c::redo() { m_map->addTile( getTileX(), getTileY(), getTileType() ); }
int IsoMapTile::getHeight() const { return heights[getTileType()]; }
void displayBoard(unsigned int size, struct Player players[], unsigned int playerCount){ int i, j, k, S, n; char c; S = 4 * size - 5; // tiles are counted in a clockwise order starting from the top left n = size; // Printing for Only size 1 if (size == 1){ for (i = 0; i < size; i++){ printf(" ___ "); } printf("\n"); for (i = 0; i < size; i++){ c = getTileType(i, players, playerCount); printf("| %c |", c); } printf("\n"); for (i = 0; i < size; i++){ printf("|___|"); } printf("\n"); } // Printing for any size else if (size > 1){ for (i = 0; i < size; i++){ printf(" ___ "); } printf("\n"); for (i = 0; i < size; i++){ // printing first row c = getTileType(i, players, playerCount); printf("| %c |", c); } printf("\n"); for (i = 0; i < size; i++){ printf("|___|"); } printf("\n"); for (k = 1; k <= size - 2; k++){ for (j = 1; j <= size; j++){ if ((j == 1) || (j == (size))){ // Printing two Column printf(" ___ "); } else{ printf(" "); } } printf("\n"); c = getTileType(S, players, playerCount); printf("| %c |", c); for (j = 1; j <= size - 2; j++){ printf(" "); } c = getTileType(n, players, playerCount); printf("| %c |", c); printf("\n"); for (i = 1; i <= size; i++){ if ((i == 1) || (i == (size))){ printf("|___|"); } else { printf(" "); } } S = S - 1; // Decrising S by 1 and Incresing tile numer by 1 n = n + 1; printf("\n"); } for (i = 0; i < size; i++){ printf(" ___ "); } printf("\n"); // Printing last row for (i = 0; i < size; i++){ c = getTileType(S, players, playerCount); printf("| %c |", c); S = S - 1; } printf("\n"); for (i = 0; i < size; i++){ printf("|___|"); }printf("\n"); } }
void EditorToolBar::update(float deltaTime) { ASSERT(world!=0, "world was null! Call setWorld first!"); ASSERT(toolBarTools!=0, "toolBarTools was null"); ASSERT(toolBarMisc!=0, "toolBarMisc was null"); ASSERT(toolBarZone!=0, "toolBarZone was null"); ASSERT(mousePosLabel!=0, "mousePosLabel was null"); ASSERT(objectPalette!=0, "objectPalette was null"); ASSERT(tileTypeSelector!=0, "tileTypeSelector was null"); ASSERT(texturePalette_Wall!=0, "texturePalette_Wall was null"); ASSERT(texturePalette_Floor!=0, "texturePalette_Floor was null"); ASSERT(tileHeightSelector!=0, "tileHeightSelector was null"); if(g_Application.getState() == GAME_STATE_EDITOR) { toolBarTools->m_bVisible = true; toolBarMisc->m_bVisible = true; toolBarZone->m_bVisible = true; mousePosLabel->m_bVisible = true; // Hide the object palette (overridden by create tool) objectPalette->m_bVisible = false; // Hide the tile properties panel (overridden in map editor mode) toolBarTilePropreties->m_bVisible = false; // Get the point under the mouse cursor mousePos = getGroundPickPos(0.0f); // update the mouse cursor to show this position mousePosLabel->setLabel(string("Mouse: (") + ftoa(mousePos.x) + string(", ") + ftoa(mousePos.y) + string(", ") + ftoa(mousePos.z) + string(")")); if(g_Keys.isKeyDown(KEY_TEST)) { world->getMap().removeAllMaterials(); } // Update the tool bar widgets switch(toolBarTools->getTool()) { case ToolBarForEditorTools::EDITOR_CREATE_TOOL: // Show the object palette objectPalette->m_bVisible = true; // Decide the selected object { string o = chooseNextObject(); if(!o.empty()) { nextObject = o; } } break; case ToolBarForEditorTools::EDITOR_TILE_PENCIL_TOOL: toolBarTilePropreties->m_bVisible = true; // Update tile properties from the selectors tileEditor_wallTextureFile = chooseTileWallTexture(); tileEditor_floorTextureFile = chooseTileFloorTexture(); tileEditor_type = getTileType(); break; case ToolBarForEditorTools::EDITOR_TILE_BLOCK_TOOL: toolBarTilePropreties->m_bVisible = true; // Update tile properties from the selectors tileEditor_wallTextureFile = chooseTileWallTexture(); tileEditor_floorTextureFile = chooseTileFloorTexture(); tileEditor_type = getTileType(); // Has a drag stopped? if(!g_Input.MouseLeft) { // drag exitted if(drag) { // get a reference to the map Map &map = world->getMap(); // Get the position on the ground plane that the mouse was over vec3 groundPos = getGroundPickPos(0.0f); // Fill a block of tiles if(map.onATile(groundPos.x, groundPos.z) && map.onATile(mouseDownPos.x, mouseDownPos.z)) { map.fillBlock(groundPos.x, groundPos.z, mouseDownPos.x, mouseDownPos.z, tileEditor_type, tileEditor_properties, tileEditor_floorTextureFile, tileEditor_wallTextureFile, tileEditor_height); // Rebuild the map display list map.reaquire(); g_SoundSystem.play("data/sound/activate.wav"); } } drag = false; } break; case ToolBarForEditorTools::EDITOR_DESTROY_TOOL: // (This tool doesn't require updating every tick) break; case ToolBarForEditorTools::EDITOR_ROTATE_TOOL: // (This tool doesn't require updating every tick) break; case ToolBarForEditorTools::EDITOR_ROTATE_X_TOOL: // (This tool doesn't require updating every tick) break; case ToolBarForEditorTools::EDITOR_ROTATE_Z_TOOL: // (This tool doesn't require updating every tick) break; case ToolBarForEditorTools::EDITOR_MOVE_TOOL: // (This tool doesn't require updating every tick) break; case ToolBarForEditorTools::EDITOR_SELECT_TOOL: // (This tool doesn't require updating every tick) break; }; // The tile selectors cannot be opened if the tile properties dialog is not if(toolBarTilePropreties->m_bVisible) { switch(textureSelectorState) { case TEXTURE_SELECTOR_HIDE: texturePalette_Wall->m_bVisible = false; texturePalette_Floor->m_bVisible = false; break; case TEXTURE_SELECTOR_FLOOR: texturePalette_Wall->m_bVisible = false; texturePalette_Floor->m_bVisible = true; break; case TEXTURE_SELECTOR_WALL: texturePalette_Wall->m_bVisible = true; texturePalette_Floor->m_bVisible = false; break; }; } else { tileTypeSelector->m_bVisible = false; tileHeightSelector->m_bVisible = false; textureSelectorState = TEXTURE_SELECTOR_HIDE; texturePalette_Wall->m_bVisible = false; texturePalette_Floor->m_bVisible = false; } // In editor mode, only update the selected object if(selected) selected->updateForEditor(deltaTime); // Call the event handler for left-click if(g_Input.MouseLeft) { onLeftMouseDown(); } else { leftClickDebounce=false; } // Save / Load the game if(shouldSave) { world->saveToFile(); } else if(shouldLoad) { world->loadFromFile(); } else if(shouldNew) { createNewMap(); } } else {// None of these should be visible in game mode toolBarTools->m_bVisible = false; toolBarMisc->m_bVisible = false; mousePosLabel->m_bVisible = false; objectPalette->m_bVisible = false; toolBarZone->m_bVisible = false; // Hide tile properties dialogs toolBarTilePropreties->m_bVisible = false; tileTypeSelector->m_bVisible = false; tileHeightSelector->m_bVisible = false; texturePalette_Wall->m_bVisible = false; texturePalette_Floor->m_bVisible = false; tileHeightSelector->m_bVisible = false; } // reset each tick shouldSave = false; shouldLoad = false; shouldNew = false; }
PointD Map::getTurnOuterCorner(int x, int y, const TilePathNode& turn) const { static const double displacement = m_game->getTrackTileMargin() + std::min(m_game->getCarWidth(), m_game->getCarHeight()) / 2; static const double bigDisplacement = m_game->getTrackTileSize() - displacement; static const std::map<model::TileType, PointD> displacementMap = { { model::LEFT_TOP_CORNER, PointD(displacement, displacement) }, { model::LEFT_BOTTOM_CORNER, PointD(displacement, bigDisplacement) }, { model::RIGHT_TOP_CORNER, PointD(bigDisplacement, displacement) }, { model::RIGHT_BOTTOM_CORNER, PointD(bigDisplacement, bigDisplacement) }, // others not yet implemented }; model::TileType tileType = getTileType(x, y); switch (tileType) { case model::LEFT_HEADED_T: case model::RIGHT_HEADED_T: case model::TOP_HEADED_T: case model::BOTTOM_HEADED_T: case model::CROSSROADS: { // T-turn or crossroads handling is similar to corresponding usual turn struct TurnTuple { TilePathNode::AbsoluteTurn from, to; bool operator==(const TurnTuple&r) const { return from == r.from && to == r.to; } }; typedef std::pair<TurnTuple, model::TileType> TurnsCornerPair; static const TurnsCornerPair turnsToCorner[] = { { { AbsoluteDirection::UP, AbsoluteDirection::RIGHT }, model::LEFT_TOP_CORNER }, { { AbsoluteDirection::LEFT, AbsoluteDirection::DOWN }, model::LEFT_TOP_CORNER }, { { AbsoluteDirection::UP, AbsoluteDirection::LEFT}, model::RIGHT_TOP_CORNER }, { { AbsoluteDirection::RIGHT, AbsoluteDirection::DOWN }, model::RIGHT_TOP_CORNER }, { { AbsoluteDirection::LEFT, AbsoluteDirection::UP }, model::LEFT_BOTTOM_CORNER }, { { AbsoluteDirection::DOWN, AbsoluteDirection::RIGHT }, model::LEFT_BOTTOM_CORNER }, { { AbsoluteDirection::RIGHT, AbsoluteDirection::UP}, model::RIGHT_BOTTOM_CORNER }, { { AbsoluteDirection::DOWN, AbsoluteDirection::LEFT}, model::RIGHT_BOTTOM_CORNER }, }; TurnTuple thisTurn = {turn.m_turnAbsoluteFrom, turn.m_turnAbsolute/*to*/}; auto found = std::find_if(std::begin(turnsToCorner), std::end(turnsToCorner), [&thisTurn](const TurnsCornerPair& tupleCornerPair) { return tupleCornerPair.first == thisTurn; }); if (found != std::end(turnsToCorner)) { tileType = found->second; // assume this crossroad to be usual turn } break; } default: break; } auto displacementIt = displacementMap.find(tileType); return getTileCorner(x, y) + (displacementIt != displacementMap.end() ? displacementIt->second : m_tileCenter); }