Witaj!
tBane dodał nowy post w wątku: Generowanie przejść między różnymi kafelkami mapy
Cześć. Piszę program do rysowania mapy i mam problem z generowaniem kafelów mapy. W programie są 4 rodzaje terenu - water, sands, grass, steps. Algorytm, który wykoprzystałem działa na zasadzie maski 16bitowej dla dwóch rodzajów terenu. Skoro tak, to po prostu wygenerowałem parę par terenów z przejściami - jak widać na palecie po prawej stronie. Chciałbym jednak zrobić ładniejsze przejścia i szukam do tego algorytmu. 
Kopiuj
int getTileIndex(int x, int y) { int ttype = terrain_types[y * size.x + x]; return getTileValue(x,y, ttype) | (getTileValue(x+1,y, ttype) << 1) | (getTileValue(x,y+1, ttype) << 2) | (getTileValue(x+1, y+1, ttype) << 3); } int getTileValue(int x, int y, int ttype) { if (ttype == terrain_types[y * size.x + x] == 0) return (terrain_values[y * size.x + x])? 0 : 1; else return terrain_values[y * size.x + x]; } void editTile(int x, int y, int terrain_type, int terrain_value) { terrain_types[y * size.x + x] = terrain_type; terrain_values[y * size.x + x] = terrain_value; for (int yy = y - 1; yy <= y + 1; yy++) { for (int xx = x - 1; xx <= x + 1; xx++) { if (xx >= size.x || yy >= size.y || xx < 0 || yy < 0) continue; int index = getTileIndex(xx, yy); sprites[yy * size.x + xx].setTextureRect(sf::IntRect(index * 64 + (yy * 16) % 64, terrain_types[yy * size.x + xx] * 64 + (xx * 16) % 64, 16, 16)); } } }
Z poważaniem, 4programmers.net
|