Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #define OLC_PGE_APPLICATION
  2. #include "olcPixelGameEngine.h"
  3.  
  4. class Example : public olc::PixelGameEngine
  5. {
  6. public:
  7. Example()
  8. {
  9. sAppName = "Example";
  10. }
  11.  
  12. private:
  13. int world[200][160];
  14. int screen[100][80];
  15. int screenPosX = 100;
  16. int screenPosY = 80;
  17. int cursor = 2;
  18. public:
  19. bool OnUserCreate() override
  20. {
  21. //Called once at the start, so create things here
  22. for (int x = 0; x < 200; x++)
  23. for (int y = 0; y < 160; y++)
  24. world[x][y] = 1;
  25. return true;
  26. }
  27.  
  28. bool OnUserUpdate(float fElapsedTime) override
  29. {
  30. //Called once per frame
  31. //update screen
  32. for (int x = screenPosX; x < screenPosX + 100; x++)
  33. for (int y = screenPosY; y < screenPosY + 100; y++)
  34. {
  35. switch (world[x][y])
  36. {
  37. case 1: Draw(x, y, olc::GREY);
  38. break;
  39. case 2: Draw(x, y, olc::DARK_GREY);
  40. break;
  41. case 3: Draw(x, y, olc::YELLOW);
  42. break;
  43. }
  44. //draw cursor
  45. if (x == GetMouseX() && y == GetMouseY())
  46. {
  47. switch (cursor)
  48. {
  49. case 1: Draw(x, y, olc::GREY);
  50. break;
  51. case 2: Draw(x, y, olc::DARK_GREY);
  52. break;
  53. case 3: Draw(x, y, olc::YELLOW);
  54. break;
  55. }
  56. }
  57. //Update world with cursor
  58. if (x == GetMouseX() && y == GetMouseY() && GetMouse(0).bHeld)
  59. {
  60. switch (cursor)
  61. {
  62. case 1: world[x][y] = 1;
  63. break;
  64. case 2: world[x][y] = 2;
  65. break;
  66. case 3: world[x][y] = 3;
  67. break;
  68. }
  69. }
  70. }
  71. //input
  72. //choose tile
  73. if (GetKey(olc::K1).bReleased)
  74. cursor = 2;
  75. if (GetKey(olc::K2).bReleased)
  76. cursor = 3;
  77. if (GetKey(olc::K3).bReleased)
  78. cursor = 1;
  79. //pan view
  80. if (GetKey(olc::W).bReleased)
  81. screenPosY -= 200;
  82. if (GetKey(olc::A).bReleased)
  83. screenPosX -= 1;
  84. if (GetKey(olc::S).bReleased)
  85. screenPosY += 200;
  86. if (GetKey(olc::D).bReleased)
  87. screenPosX += 1;
  88.  
  89. //update world
  90. for (int x = 0; x < 200; x++)
  91. for (int y = 0; y < 160; y++)
  92. {
  93.  
  94. }
  95.  
  96. return true;
  97. }
  98. };
  99.  
  100.  
  101. int main()
  102. {
  103. Example demo;
  104. if (demo.Construct(100, 80, 8, 8))
  105. demo.Start();
  106.  
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement