4programmers.net

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.

03.png

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)); } } } 


Zobacz post

Z poważaniem,
4programmers.net

Jeżeli masz problemy z kliknięciem na przycisk "Zobacz post", skopiuj i wklej poniższy link w przeglądarce:

http://4programmers.net/Notification?path=%252FForum%252FGamedev%252F376544-generowanie_przejsc_miedzy_roznymi_kafelkami_mapy%253Fp%253D2003792%2523id2003792