const Surface* Tilemap::find_tile(const std::string& name, Pos pos) const { auto layer = std::find_if(m_layers.begin(), m_layers.end(), [&name](const Layer& layer) { return Utils::tolower(layer.name) == name; }); if (layer == m_layers.end()) return NULL; return find_tile(std::distance(m_layers.begin(), layer), pos); }
tiled_region thread::get_tiled_address(u32 offset, u32 location) { u32 address = get_address(offset, location); GcmTileInfo *tile = find_tile(offset, location); u32 base = 0; if (tile) { base = offset - tile->offset; address = get_address(tile->offset, location); } return{ address, base, tile, (u8*)vm::base(address) }; }
bool move(int tile) { if (find_tile(tile)) { // If true switch it. if (check_move()) { int temp_r = tile_r; int temp_c = tile_c; int temp = board[tile_r][tile_c]; board[tile_r][tile_c] = board[blank_r][blank_c]; board[blank_r][blank_c] = temp; blank_r = temp_r; blank_c = temp_c; return true; } } return false; }
void click_stairs(Map& level, Player& player1, Idevice& input, Viewpoint& camera) { if(!(player_on_or_near(player1, input, camera))) return; int mapvalue = find_tile(level, input, camera); int dest; switch(mapvalue) { case UPSTAIRS: dest = player1.get_floor() - 1; player1.put_stairs(0); break; case DOWNSTAIRS: dest = player1.get_floor() + 1; player1.put_stairs(1); break; } player1.put_destfloor(dest); return; }
bool logic(Map& level, Player& player1, Viewpoint& camera, Idevice& input) { int mapvalue; if (input.get_click() == ON) { mapvalue = find_tile(level, input, camera); if (mapvalue == WARP) click_warp(level, player1, input, camera); if (mapvalue == EXIT) click_door(level, player1, input, camera); if (mapvalue == UPSTAIRS || mapvalue == DOWNSTAIRS) click_stairs(level, player1, input, camera); if (mapvalue == CAVE) click_dungeon(level, player1, input, camera); if (mapvalue == CITY) click_town(level, player1, input, camera); } input.put_click(OFF); if(player1.check_map() | player1.check_floor()) return 0; move_player(level, player1, input); move_camera(level, player1, camera); return 1; }
bool Tilemap::collision(Pos tile) const { return collisions.count(tile) || find_tile("blocks", {tile.x * tilewidth, tile.y * tileheight}); }
//int counter=0; void make_tiles() { //int baseZoom = clamp(round(center.zoom), 0, 18); int baseZoom = clamp((int)floor(center.zoom+0.5), 0, 18); double tl[2]= {0,0}; double tr[2]= {(double)veiwport[0],0}; double bl[2]= {0,(double)veiwport[1]}; double br[2]= {(double)veiwport[0],(double)veiwport[1]}; int minCol; int maxCol; int minRow; int maxRow; int row_count; int col; crd_t ctl; crd_t ctr; crd_t cbl; crd_t cbr; crd_set2(&ctl,¢er,tl,br); crd_zoomto(&ctl,baseZoom); crd_set2(&ctr,¢er,tr,br); crd_zoomto(&ctr,baseZoom); crd_set2(&cbl,¢er,bl,br); crd_zoomto(&cbl,baseZoom); crd_set2(&cbr,¢er,br,br); crd_zoomto(&cbr,baseZoom); minCol = (int)floor(_mind(_mind(ctl.column,ctr.column),_mind(cbl.column,cbr.column))); maxCol = (int)floor(_maxd(_maxd(ctl.column,ctr.column),_maxd(cbl.column,cbr.column))); minRow = (int)floor(_mind(_mind(ctl.row,ctr.row),_mind(cbl.row,cbr.row))); maxRow = (int)floor(_maxd(_maxd(ctl.row,ctr.row),_maxd(cbl.row,cbr.row))); minCol -= 1;//FIXME: calc veiwport area maxCol += 1; row_count = (int)floor(pow(2.0, baseZoom))-1; minCol = _maxi(0,minCol); minRow = _maxi(0,minRow); maxCol = _mini(maxCol,row_count); maxRow = _mini(maxRow,row_count); tiles_draw_count = 0; col = minCol; for (; col <= maxCol; ++col) { int row = minRow; for (; row <= maxRow; ++row) { Tile tile = {baseZoom,col,row}; //print_tile(&tile); Tile* ret = find_tile(tiles,&tile); if (ret==0) { Tile* newtile = (Tile*)malloc(sizeof(Tile)); newtile->z = tile.z; newtile->x = tile.x; newtile->y = tile.y; getImageTile(newtile); push_list(tiles,newtile); //fprintf(stderr,"push tiles count: %ld\n",tiles->count); ret = newtile; if (tiles->count > 256){ pop_tile(tiles);// TODO: remove tile in tiles_get //fprintf(stderr,"pop tiles count: %ld\n",tiles->count); } //++counter; } tiles_draw[tiles_draw_count++] = ret; } } //fprintf(stderr,"tiles count: %d tiles_draw_count: %d\n",counter,tiles_draw_count); }