|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
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(); |
|
|
|
|
currentAngle=-float(playerHand.size()-1)/2*15-90; |
|
|
|
|
spreadAngle=15; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct CardDrawData{ |
|
|
|
|
vf2d drawPos; |
|
|
|
|
float angle; |
|
|
|
|
Card*card=nullptr; |
|
|
|
|
}; |
|
|
|
|
for(int i=0;i<GetHandLoopCounter();i++){ |
|
|
|
|
if(playerHand.size()%2==0&&playerHand.size()/2==i){ |
|
|
|
|
continue; //The middle section will be dropped if we have an even number of cards.
|
|
|
|
|
|
|
|
|
|
CardDrawData selectedCardData; |
|
|
|
|
int cardIndex=0; |
|
|
|
|
for(int i=0;i<playerHand.size();i++){ |
|
|
|
|
Card¤tCard=playerHand[cardIndex]; |
|
|
|
|
if(cursorDist>32&&cursorDist<100&&abs(cursorDir-currentAngle)<spreadAngle/2){ |
|
|
|
|
selectedCardData={playerHandCenter+vf2d{cos(degToRad(currentAngle)),sin(degToRad(currentAngle))}*(cardDistance+10),degToRad(currentAngle+90),¤tCard}; |
|
|
|
|
} else { |
|
|
|
|
DrawRotatedDecal(playerHandCenter+vf2d{cos(degToRad(currentAngle)),sin(degToRad(currentAngle))}*cardDistance,GetCardImage(currentCard.col,currentCard.val,currentCard.faceDown),degToRad(currentAngle+90),{24,32},{0.6,0.6},{128,128,128,255}); |
|
|
|
|
} |
|
|
|
|
Card¤tCard=playerHand[i]; |
|
|
|
|
DrawRotatedDecal(playerHandCenter+vf2d{cos(degToRad(currentAngle)),sin(degToRad(currentAngle))}*cardDistance,GetCardImage(currentCard.col,currentCard.val,currentCard.faceDown),degToRad(currentAngle+90),{24,32},{0.6,0.6}); |
|
|
|
|
if(playerHand.size()>8){ |
|
|
|
|
currentAngle+=120/playerHand.size(); |
|
|
|
|
}else{ |
|
|
|
|
currentAngle+=15; |
|
|
|
|
currentAngle+=spreadAngle; |
|
|
|
|
cardIndex++; |
|
|
|
|
} |
|
|
|
|
if(selectedCardData.card!=nullptr){ |
|
|
|
|
Card&card=*selectedCardData.card; |
|
|
|
|
DrawRotatedDecal(selectedCardData.drawPos,GetCardImage(card.col,card.val,card.faceDown),selectedCardData.angle,{24,32},{0.6,0.6}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -187,6 +199,9 @@ public: |
|
|
|
|
} else
|
|
|
|
|
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}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -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.x+48&& |
|
|
|
|
GetMouseY()>=drawPilePos.y&&GetMouseY()<drawPilePos.y+48){ |
|
|
|
|
DrawCard(hands[playerTurn],true); |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case PICK:{ |
|
|
|
|
DrawGameBoard(); |
|
|
|
|
if(GetMouse(0).bPressed&& |
|
|
|
|
GetMouseX()>=drawPilePos.x&&GetMouseX()<drawPilePos.x+48&& |
|
|
|
|
GetMouseY()>=drawPilePos.y&&GetMouseY()<drawPilePos.y+48){ |
|
|
|
|
DrawCard(hands[playerTurn],true); |
|
|
|
|
} |
|
|
|
|
}break; |
|
|
|
|
case RESULT:{ |
|
|
|
|
DrawGameBoard(); |
|
|
|
|