diff --git a/C++ProjectTemplate b/C++ProjectTemplate index 4d8ff5d..3855003 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/Map.cpp b/Map.cpp deleted file mode 100644 index e8dd690..0000000 --- a/Map.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Map.h" - -void Map::test(){ - printf("Hello Map\n"); -} - diff --git a/Map.h b/Map.h deleted file mode 100644 index 91cd82a..0000000 --- a/Map.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include - -class Player; - -class Map{ - public: - Player*p; - void test(); -}; \ No newline at end of file diff --git a/Player.cpp b/Player.cpp deleted file mode 100644 index 716b219..0000000 --- a/Player.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Player.h" - -void Player::test(){ - printf("Hello Player\n"); -} - diff --git a/Player.h b/Player.h deleted file mode 100644 index af5d8f0..0000000 --- a/Player.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once -#include - -class Map; - -class Player{ - public: - Map*map; - void test(); -}; \ No newline at end of file diff --git a/baseboard.png b/baseboard.png new file mode 100644 index 0000000..484b491 Binary files /dev/null and b/baseboard.png differ diff --git a/main.cpp b/main.cpp index 1485e96..d886773 100644 --- a/main.cpp +++ b/main.cpp @@ -1,20 +1,156 @@ -#include #define OLC_PGE_APPLICATION #include "pixelGameEngine.h" +#if defined(__EMSCRIPTEN__) +#include +#define FILE_RESOLVE(url, file) emscripten_wget(url, file); emscripten_sleep(0) +#else +#define FILE_RESOLVE(url, file) +#endif + using namespace olc; -struct MyStruct{ - int val=4; - friend std::ostream&operator<<(std::ostream&os,MyStruct&rhs){ - printf("Called\n"); - return os; - } +enum state{ + PLAYER_CLICK, + PLAYER_DRAG, + BOARD_MOVE, + RED_WON, + BLUE_WON, +}; + +state GameState; +vi2d startingpos; +const float PI=3.14159; +float slidedir; +float lastUpdate=0; +const float TIME_PER_UPDATE=0.01f; +float acc=0; +vf2d boardpos; + +// Override base class with your custom functionality +class SlideAndConquer : public olc::PixelGameEngine +{ +public: + SlideAndConquer() + { + // Name your application + sAppName = "Slide and Conquer"; + } + +public: + olc::Renderable board; + olc::Renderable originalBoard; + + void ResetGame() { + GameState=PLAYER_CLICK; + for (int x=0;x<256;x++) { + for (int y=0;y<256;y++) { + board.Sprite()->SetPixel(x,y,originalBoard.Sprite()->GetData()[y*256+x]); + } + } + board.Decal()->Update(); + DrawSprite({0,0},board.Sprite()); + } + bool OnUserCreate() override + { + + board.Load("baseboard.png"); + originalBoard.Load("baseboard.png"); + + GameState=PLAYER_CLICK; + DrawSprite({0,0},board.Sprite()); + return true; + } + + bool OnUserUpdate(float fElapsedTime) override + { + switch (GameState) { + case PLAYER_CLICK:{ + DrawStringDecal({1,1},"CLICK ON THE PLAYFIELD",BLACK,{1,2}); + if (GetMouse(0).bPressed) { + GameState=PLAYER_DRAG; + startingpos=GetMousePos(); + } + }break; + case PLAYER_DRAG:{ + float addedAngle=round((atan2f(GetMousePos().y-startingpos.y,GetMousePos().x-startingpos.x))/(PI/8))*(PI/8); + float dist=(GetMousePos()-startingpos).mag(); + DrawDecal({sin(PI/2-addedAngle)*dist/30,cos(PI/2-addedAngle)*dist/30},board.Decal()); + DrawPolygonDecal(nullptr, + { + {startingpos.x+sin(PI-addedAngle)*(dist/10),startingpos.y+cos(PI-addedAngle)*(dist/10)}, + {startingpos.x+sin(-addedAngle)*(dist/10),startingpos.y+cos(-addedAngle)*(dist/10)}, + {startingpos.x+sin(PI/2-addedAngle)*dist,startingpos.y+cos(PI/2-addedAngle)*dist} + }, + { + {0,0}, + {0,0}, + {0,0}, + },BLACK); + DrawStringDecal({1,1},"CHOOSE A SLIDE DIRECTION",BLACK,{1,2}); + if (GetMouse(0).bPressed) { + slidedir=PI/2-addedAngle; + GameState=BOARD_MOVE; + boardpos={0,0}; + } + }break; + case BOARD_MOVE:{ + DrawStringDecal({1,1},"WAITING...",BLACK,{1,2}); + if ((acc+=fElapsedTime)>TIME_PER_UPDATE) { + acc=0; + boardpos.x+=sin(slidedir); + boardpos.y+=cos(slidedir); + bool AllRed=true; + bool AllBlue=true; + if (boardpos.x>256||boardpos.x+256<0||boardpos.y>256||boardpos.y+256<0) { + GameState=PLAYER_CLICK; + SetDrawTarget(nullptr); + for (int x=0;x<256;x++) { + for (int y=0;y<256;y++) { + Pixel p = GetDrawTarget()->GetData()[y*256+x]; + board.Sprite()->SetPixel(x,y,p); + if (p.rUpdate(); + if (AllRed) { + GameState=RED_WON; + } + if (AllBlue) { + GameState=BLUE_WON; + } + break; + } else { + DrawSprite(boardpos,board.Sprite()); + } + } + }break; + case RED_WON:{ + DrawStringDecal({1,1},"RED WINS! CLICK TO PLAY AGAIN",DARK_BLUE,{1,2}); + if (GetMouse(0).bPressed) { + ResetGame(); + } + }break; + case BLUE_WON:{ + DrawStringDecal({1,1},"BLUE WINS! CLICK TO PLAY AGAIN",DARK_RED,{1,2}); + if (GetMouse(0).bPressed) { + ResetGame(); + } + }break; + } + return true; + } }; int main() { - MyStruct*st=new MyStruct({5}); - std::cout<<*st<