Testing suite automatically enables/disables itself via header now
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
		
							parent
							
								
									1719b29ed7
								
							
						
					
					
						commit
						42192e43e3
					
				| @ -1,6 +1,6 @@ | ||||
| build.sh:ca58f10d4e30d807987ea0105930ae51  - | ||||
| build.sh:6fbec04ed16be42bab846f1eed603133  - | ||||
| commit.sh:d03a46e721060c22ccb146e19d27e70a  - | ||||
| debug.sh:cd1190f874a6f85a7ac7631ef0a00490  - | ||||
| debug.sh:7f57c6640be5f262988961c3b45dce97  - | ||||
| lines.sh:3b907786f7fc9204025993016c9080de  - | ||||
| release.sh:0a525311cc14b9c8aefc6f2b816129a1  - | ||||
| temp:d41d8cd98f00b204e9800998ecf8427e  - | ||||
|  | ||||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										164
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										164
									
								
								main.cpp
									
									
									
									
									
								
							| @ -1,156 +1,24 @@ | ||||
| #define OLC_PGE_APPLICATION | ||||
| #include "pixelGameEngine.h" | ||||
| 
 | ||||
| #if defined(__EMSCRIPTEN__) | ||||
| #include <emscripten.h> | ||||
| #define FILE_RESOLVE(url, file) emscripten_wget(url, file); emscripten_sleep(0) | ||||
| #else | ||||
| #define FILE_RESOLVE(url, file) | ||||
| #endif | ||||
| 
 | ||||
| using namespace olc; | ||||
| 
 | ||||
| enum state{ | ||||
|     PLAYER_CLICK, | ||||
|     PLAYER_DRAG, | ||||
|     BOARD_MOVE, | ||||
|     RED_WON, | ||||
|     BLUE_WON, | ||||
| class Object{ | ||||
|     public: | ||||
|     olc::vd2d pos; | ||||
|     Object(olc::vd2d pos) | ||||
|     :pos(pos) {} | ||||
|     virtual bool collidesWidth(Object&obj); | ||||
| }; | ||||
| 
 | ||||
| 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; | ||||
| class NPC:public Object{ | ||||
|     olc::vd2d size; | ||||
|     NPC(olc::vd2d pos,olc::vd2d size) | ||||
|     :Object(pos),size(size) {} | ||||
|     bool collidesWidth(Object&obj)override{ | ||||
|         return obj.pos.x>=pos.x&&obj.pos.x<=pos.x+size.x | ||||
|             && obj.pos.y>=pos.y&&obj.pos.y<=pos.y+size.y; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| // 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.r<p.b) { | ||||
|                                     AllRed=false; | ||||
|                                 } | ||||
|                                 if (p.b<p.r) { | ||||
|                                     AllBlue=false; | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                         board.Decal()->Update(); | ||||
|                         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() | ||||
| { | ||||
|     SlideAndConquer demo; | ||||
|     if (demo.Construct(256, 256, 4, 4)) | ||||
|         demo.Start(); | ||||
| int main() { | ||||
|     return 0; | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user