Guest User

Untitled

a guest
Jan 30th, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. void RoomController::LoadRoom()
  2. {
  3.  
  4. //First parse the string from the specific room
  5. //For now, use the given room
  6. int roomID = 0;
  7. string room = rooms[roomID];
  8. istringstream roomParser(room);
  9. string tile;
  10.  
  11. //While we still have numbers in the list, go through it int by int until we reach the end
  12. while (getline(roomParser, tile, ','))
  13. {
  14.  
  15. //Get the current tile
  16. int currentTile = stoi(tile);
  17.  
  18. //Get the position in the tilesheet
  19. int tileXPos = tilesetCoordinates[currentTile].x;
  20. int tileYPos = tilesetCoordinates[currentTile].y;
  21.  
  22. //Get a pointer to the current tile's quad
  23. Vertex* quad = &currentRoom[(xIterator + yIterator * roomXSize) * 4];
  24.  
  25. //Set the positions of each of the 4 vertices
  26. int x1 = 8 * xIterator;
  27. int y1 = 8 * yIterator;
  28. int x2 = 8 * (1 + xIterator);
  29. int y2 = 8 * (1 + yIterator);
  30. quad[0].position = Vector2f(x1, y1);
  31. quad[1].position = Vector2f(x2, y1);
  32. quad[2].position = Vector2f(x2, y2);
  33. quad[3].position = Vector2f(x1, y2);
  34.  
  35. //Set the texture coordinates of each of the 4 vertices
  36. x1 = tileXPos;
  37. y1 = tileYPos;
  38. x2 = tileXPos + 8;
  39. y2 = tileYPos + 8;
  40. quad[0].texCoords = Vector2f(x1, y1);
  41. quad[1].texCoords = Vector2f(x2, y1);
  42. quad[2].texCoords = Vector2f(x2, y2);
  43. quad[3].texCoords = Vector2f(x1, y2);
  44.  
  45. if (xIterator < 16)
  46. {
  47. xIterator += 1;
  48. }
  49. else
  50. {
  51. xIterator = 0;
  52. yIterator += 1;
  53. }
  54.  
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment