Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define OLC_PGE_APPLICATION
- #include "olcPixelGameEngine.h"
- class Example : public olc::PixelGameEngine
- {
- public:
- Example()
- {
- sAppName = "Example";
- }
- private:
- int world[200][160];
- int screen[100][80];
- int screenPosX = 100;
- int screenPosY = 80;
- int cursor = 2;
- public:
- bool OnUserCreate() override
- {
- //Called once at the start, so create things here
- for (int x = 0; x < 200; x++)
- for (int y = 0; y < 160; y++)
- world[x][y] = 1;
- return true;
- }
- bool OnUserUpdate(float fElapsedTime) override
- {
- //Called once per frame
- //update screen
- for (int x = screenPosX; x < screenPosX + 100; x++)
- for (int y = screenPosY; y < screenPosY + 100; y++)
- {
- switch (world[x][y])
- {
- case 1: Draw(x, y, olc::GREY);
- break;
- case 2: Draw(x, y, olc::DARK_GREY);
- break;
- case 3: Draw(x, y, olc::YELLOW);
- break;
- }
- //draw cursor
- if (x == GetMouseX() && y == GetMouseY())
- {
- switch (cursor)
- {
- case 1: Draw(x, y, olc::GREY);
- break;
- case 2: Draw(x, y, olc::DARK_GREY);
- break;
- case 3: Draw(x, y, olc::YELLOW);
- break;
- }
- }
- //Update world with cursor
- if (x == GetMouseX() && y == GetMouseY() && GetMouse(0).bHeld)
- {
- switch (cursor)
- {
- case 1: world[x][y] = 1;
- break;
- case 2: world[x][y] = 2;
- break;
- case 3: world[x][y] = 3;
- break;
- }
- }
- }
- //input
- //choose tile
- if (GetKey(olc::K1).bReleased)
- cursor = 2;
- if (GetKey(olc::K2).bReleased)
- cursor = 3;
- if (GetKey(olc::K3).bReleased)
- cursor = 1;
- //pan view
- if (GetKey(olc::W).bReleased)
- screenPosY -= 200;
- if (GetKey(olc::A).bReleased)
- screenPosX -= 1;
- if (GetKey(olc::S).bReleased)
- screenPosY += 200;
- if (GetKey(olc::D).bReleased)
- screenPosX += 1;
- //update world
- for (int x = 0; x < 200; x++)
- for (int y = 0; y < 160; y++)
- {
- }
- return true;
- }
- };
- int main()
- {
- Example demo;
- if (demo.Construct(100, 80, 8, 8))
- demo.Start();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement