Guest User

Untitled

a guest
Jan 3rd, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. #include "newTiled.h"
  2. #include <cmath>
  3.  
  4. using namespace sf;
  5. using namespace std;
  6.  
  7. newTiled::newTiled(){
  8. if(!tileset_texture.loadFromFile("assets/images/tajlmap.png"))
  9. return;
  10.  
  11. if(!bg_txt.loadFromFile("assets/images/bg2.png"))
  12. return;
  13.  
  14.  
  15. tileset_sprite.setTexture(tileset_texture);
  16. bg_sprite.setTexture(bg_txt);
  17.  
  18.  
  19. }
  20.  
  21. newTiled::~newTiled(){
  22.  
  23. }
  24.  
  25. void newTiled::draw(RenderWindow &window){
  26. window.draw(bg_sprite);
  27.  
  28. /*int level[] ={
  29. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  30. 0, 0, 2, 2, 2, 0, 0, 2, 0, 0, 2, 0, 2, 2, 2, 0, 2, 2, 2, 2, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  31. 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 2, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  32. 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 2, 2, 2, 0, 2, 2, 2, 2, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33. 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34. 0, 0, 2, 0, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  35. 0, 0, 2, 2, 2, 0, 0, 2, 2, 2, 2, 0, 2, 0, 0, 0, 2, 0, 0, 2, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  36. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  37. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  38. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  39. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  41. };*/
  42.  
  43.  
  44. for(int y = 0; y < map_height; ++y){
  45. for(int x = 0; x < map_width; ++x){
  46. int tilecount = x + y * map_width;
  47.  
  48. tileset_sprite.setPosition(x * 64, y * 64);
  49. tileset_sprite.setTextureRect(IntRect(level[tilecount] * 64, 0, 64, 64));
  50.  
  51.  
  52.  
  53. window.draw(tileset_sprite);
  54. }
  55. }
  56.  
  57. }
  58.  
  59. void newTiled::Update(Player &player){
  60. int playerTileX = floor((int)(player.getRect().getPosition().x / 64));
  61. int playerTileY = floor((int)(player.getRect().getPosition().y / 64));
  62.  
  63. // int enemyTileX = floor((int)(snail.getRect().getPosition().x / 64));
  64. //int enemyTileY = floor((int)(snail.getRect().getPosition().y / 64));
  65.  
  66. for (int i = 0; i < map_height; i++){
  67. for (int j = 0; j < map_width; j++){
  68. int tilecount = playerTileX + playerTileY * map_width;
  69.  
  70.  
  71. //
  72.  
  73. if (level[tilecount] == 1){
  74. player.m_onGround = true;
  75. }else {
  76. player.m_onGround = false;
  77. }
  78.  
  79.  
  80. /* int tilecount2 = enemyTileX + enemyTileY * map_width;
  81. if (level[tilecount2] == 1){
  82. snail.m_onGround = true;
  83. } else {
  84. snail.m_onGround = false;
  85. }
  86.  
  87. if (level[tilecount2] == 2){
  88. snail.FlipX(1);
  89. } else {
  90. // snail.FlipX(-1);
  91. }*/
  92.  
  93. }
  94. }
  95. }
Add Comment
Please, Sign In to add comment