Advertisement
SlaskPrask

Untitled

Jul 17th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. #include "TileImportObj.h"
  2.  
  3.  
  4.  
  5. TileImportObj::TileImportObj()
  6. {
  7. spriteSet(0)->load();
  8. activeSet = 0;
  9. x = minX;
  10. tSetS = "";
  11.  
  12. for (int i = 0; i < TILESET; i++)
  13. {
  14. for (int j = 0; j < TILE; j++)
  15. {
  16. tileID[i][j] = 0;
  17. }
  18. }
  19. }
  20.  
  21.  
  22. TileImportObj::~TileImportObj()
  23. {
  24. }
  25.  
  26. void TileImportObj::getTiles()
  27. {
  28. showingX = 6;
  29.  
  30. if (tilesY < 7)
  31. amountX = tilesX;
  32. else
  33. amountX = tilesX * 2;
  34.  
  35. spots = amountX - 6;
  36. X2 = 0;
  37.  
  38. minX = 1920 - 512 + 128 + 48;
  39. maxX = 1920 - 96;
  40. }
  41.  
  42. void TileImportObj::draw()
  43. {
  44. drawRectangle(1920 - 64 * 6, 0, 64 * 6, 1080, .9, .9, .9, 1);
  45.  
  46. if (activeSet != 0)
  47. {
  48. for (int i = 0; i < tilesY; i++)
  49. {
  50. for (int j = 0; j < tilesX; j++)
  51. {
  52. if (i < 6)
  53. drawSpritePart(getSprite(activeSet, 0), 1536 + j * 64 - X2, 696 + i * 64, 64, 64, 1 / tilesX * j, 1 / tilesY * i, 1 / tilesX * (j + 1), 1 / tilesY * (i + 1));
  54. else
  55. drawSpritePart(getSprite(activeSet, 0), 1536 + tilesX * 64 + j * 64 - X2, 696 + (i - 6) * 64, 64, 64, 1 / tilesX * j, 1 / tilesY * i, 1 / tilesX * (j + 1), 1 / tilesY * (i + 1));
  56. }
  57. }
  58.  
  59. drawSprite(getSprite(0, 0), 1920 - 512 + 128, 1080 - 512 + 128 - 48, 48, 48);
  60. drawSpritePart(getSprite(0, 0), 1920 - 48, 1080 - 512 + 128 - 48, 48, 48, 1, 0, 0, 1);
  61. drawSprite(getSprite(0, 1), x, 1080 - 512 + 128 - 48, 48, 48);
  62. }
  63.  
  64. if (loadSet)
  65. {
  66. this->setDepth(-2);
  67. drawRectangle(10, 10, 1900, 1060, .8, .8, .8, 1);
  68. drawTextCenter(getFont(0, 0), "What title set do you want to load?", getCameraWidth() / 2, 20, 20, 0, 0, 0, 1);
  69. drawRectangle(getCameraWidth() / 2 - 50, 50, 100, 75, .7, .7, .7, 1);
  70. drawTextCenter(getFont(0, 0), tSetS, getCameraWidth() / 2, 65, 40, 0, 0, 0, 1);
  71. }
  72. else
  73. this->setDepth(0);
  74. }
  75.  
  76. void TileImportObj::run()
  77. {
  78. if (activeSet == 0)
  79. loadSet = true;
  80.  
  81. if (loadSet)
  82. {
  83. actiontag->disableRun();
  84.  
  85. if (tSetS.length() < 2)
  86. {
  87. if (getKeyPress(Key::Num0) || getKeyPress(Key::Num1) || getKeyPress(Key::Num2) || getKeyPress(Key::Num3) || getKeyPress(Key::Num4) || getKeyPress(Key::Num5) || getKeyPress(Key::Num6) || getKeyPress(Key::Num7) || getKeyPress(Key::Num8) || getKeyPress(Key::Num9))
  88. keyboardTextBuffer(&tSetS);
  89. }
  90.  
  91. if (getKeyPress(Key::BackSpace))
  92. keyboardTextBuffer(&tSetS);
  93. else if (tSetS.length() > 0 && getKeyPress(Key::Return))
  94. {
  95. activeSet = atoi(tSetS.c_str());
  96. tSetS = "";
  97. if (spriteSet(activeSet) != NULL && activeSet != 0)
  98. {
  99. setTileset();
  100. }
  101. }
  102. }
  103.  
  104. if (spots > 1 && !loadSet)
  105. {
  106. if (getMousePress(0))
  107. {
  108.  
  109. if (inside(getMouseX(), getMouseY(), 1920 - 512 + 128, 1080 - 512 + 128 - 48, 1920 - 512 + 128 + 48, 1080 - 512 + 128))
  110. {
  111.  
  112. if (showingX < 7)
  113. showingX = 6;
  114. else
  115. {
  116. showingX -= 1;
  117. pos = (1826 - 1588) / spots;
  118. x -= pos;
  119. X2 -= 64;
  120. }
  121.  
  122.  
  123. }
  124. if (inside(getMouseX(), getMouseY(), 1920 - 48, 1080 - 512 + 128 - 48, 1920, 1080 - 512 + 128))
  125. {
  126. if (showingX >= amountX)
  127. showingX = amountX;
  128. else
  129. {
  130. showingX += 1;
  131. pos = (1826 - 1588) / spots;
  132. x += pos;
  133. X2 += 64;
  134. }
  135. }
  136.  
  137. x = (x < minX ? minX : (x > maxX ? maxX : x));
  138. }
  139. }
  140. }
  141.  
  142. void TileImportObj::setTags(Tag *t, Tag *t2)
  143. {
  144. actiontag = t2;
  145. mytag = t;
  146. }
  147.  
  148. void TileImportObj::setTileset()
  149. {
  150. if (spriteSet(activeSet)->isLoaded() == false)
  151. spriteSet(activeSet)->load();
  152. tilesX = getSprite(activeSet, 0)->getWidth() / 32;
  153. tilesY = getSprite(activeSet, 0)->getHeight() / 32;
  154. getTiles();
  155. std::cout << "Loading set " << activeSet << std::endl;
  156. actiontag->enableRun();
  157. loadSet = false;
  158.  
  159. for (int i = 0; i < (tilesX * tilesY) + 1; i++)
  160. {
  161. tileID[activeSet][i] = i; //0 should be null
  162. }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement