diff --git a/CardGameRef/CardGame.cpp b/CardGameRef/CardGame.cpp index d81becd..ebc90be 100644 --- a/CardGameRef/CardGame.cpp +++ b/CardGameRef/CardGame.cpp @@ -67,6 +67,8 @@ class CardGameRef : public olc::PixelGameEngine CardPile startingPile,drawPile,discardPile; QuickGUI::Manager playerPickMenu; QuickGUI::Button *TwoPlayerButton,*ThreePlayerButton,*FourPlayerButton; + vf2d drawPilePos={100,88}; + vf2d discardPilePos={156,88}; GameState state=AIPICK; @@ -122,40 +124,50 @@ public: return deg*(PI/180); } + float radToDeg(float rad){ + return rad*57.2957795130823208767; + } + void DrawGameBoard(){ - DisplayCardPile({100,88},drawPile); - DisplayCardPile({156,88},discardPile); + DisplayCardPile(drawPilePos,drawPile); + DisplayCardPile(discardPilePos,discardPile); vf2d playerHandCenter = {128,220}; + float cursorDir = radToDeg(atan2(playerHandCenter.y-GetMouseY(),playerHandCenter.x-GetMouseX()))-180; + float cursorDist = sqrt(pow(playerHandCenter.x-GetMouseX(),2)+pow(playerHandCenter.y-GetMouseY(),2)); Hand&playerHand=hands[0]; float spreadAngle=15; float currentAngle=-90; float cardDistance=64; if(playerHand.size()>8){ //Handle a case where the hand size is really large. We max out at 120 degrees. - currentAngle=-int(playerHand.size())/2*120/playerHand.size()-90; + spreadAngle=120.f/playerHand.size(); + currentAngle=-60+spreadAngle/2-90; } else { //Small hand size, we can slowly fan out further. - currentAngle=-int(playerHand.size())/2*15-90; + currentAngle=-float(playerHand.size()-1)/2*15-90; + spreadAngle=15; } - auto GetHandLoopCounter = [&](){ - //Because an even amount of cards needs to skip the center but we increment by the same - //currentAngle value, we will pretend there's an additional card but we'll skip it. - if(playerHand.size()%2==0){ - return playerHand.size()+1; - } else { - return playerHand.size(); - } + + struct CardDrawData{ + vf2d drawPos; + float angle; + Card*card=nullptr; }; - for(int i=0;i8){ - currentAngle+=120/playerHand.size(); - }else{ - currentAngle+=15; + + CardDrawData selectedCardData; + int cardIndex=0; + for(int i=0;i32&&cursorDist<100&&abs(cursorDir-currentAngle)sprite->GetPixel(x,y)==Pixel{235,235,235}){ card->sprite->SetPixel({x,y},targetCol); } else - if(card->sprite->GetPixel(x,y)==Pixel{103,103,103}){ - card->sprite->SetPixel({x,y},targetCol/2); - } + if(card->sprite->GetPixel(x,y)==Pixel{103,103,103}){ + card->sprite->SetPixel({x,y},targetCol/2); + } else + if(card->sprite->GetPixel(x,y)==Pixel{0,0,0}){ + card->sprite->SetPixel({x,y},{0,0,0,0}); + } } } DrawPartialSprite({0,0},cardTilesheet->sprite,cardBorder.pos,cardBorder.size); switch(numb){ - case SKIP:{ - DrawPartialSprite(vi2d{24,32}-skip.size/2,cardTilesheet->sprite,skip.pos,skip.size); - }break; - case REVERSE:{ - DrawPartialSprite(vi2d{24,32}-reverse.size/2,cardTilesheet->sprite,reverse.pos,reverse.size); - }break; - case DRAWTWO:{ - DrawPartialSprite(vi2d{24,32}-drawTwo.size/2,cardTilesheet->sprite,drawTwo.pos,drawTwo.size); - }break; - default:{ - DrawString(vi2d{24,32}-GetTextSize(std::to_string(numb))/2*3,std::to_string(numb),WHITE,3); - } + case SKIP:{ + DrawPartialSprite(vi2d{24,32}-skip.size/2,cardTilesheet->sprite,skip.pos,skip.size); + }break; + case REVERSE:{ + DrawPartialSprite(vi2d{24,32}-reverse.size/2,cardTilesheet->sprite,reverse.pos,reverse.size); + }break; + case DRAWTWO:{ + DrawPartialSprite(vi2d{24,32}-drawTwo.size/2,cardTilesheet->sprite,drawTwo.pos,drawTwo.size); + }break; + default:{ + DrawString(vi2d{24,32}-GetTextSize(std::to_string(numb))/2*3,std::to_string(numb),WHITE,3); + } } card->Update(); IMAGES.push_back(card); @@ -258,6 +273,7 @@ public: public: bool OnUserCreate() override { + srand(time(NULL)); // Called once at the start, so create things here cardBorder={{0,0},{48,64}}; @@ -361,13 +377,23 @@ public: state=GameState::PICK; } if(playerTurn==0){ - DrawString({0,224},"Player is drawing cards..."); + DrawStringDecal({0,224},"Player is drawing cards..."); } else { - DrawString({0,224},"Opponent "+std::to_string(playerTurn)+" is drawing cards..."); + DrawStringDecal({0,224},"Opponent "+std::to_string(playerTurn)+" is drawing cards..."); + } + if(GetMouse(0).bPressed&& + GetMouseX()>=drawPilePos.x&&GetMouseX()=drawPilePos.y&&GetMouseY()=drawPilePos.x&&GetMouseX()=drawPilePos.y&&GetMouseY()true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp17 Console @@ -120,6 +121,7 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp17 Console