|
|
@ -67,6 +67,8 @@ class CardGameRef : public olc::PixelGameEngine |
|
|
|
CardPile startingPile,drawPile,discardPile; |
|
|
|
CardPile startingPile,drawPile,discardPile; |
|
|
|
QuickGUI::Manager playerPickMenu; |
|
|
|
QuickGUI::Manager playerPickMenu; |
|
|
|
QuickGUI::Button *TwoPlayerButton,*ThreePlayerButton,*FourPlayerButton; |
|
|
|
QuickGUI::Button *TwoPlayerButton,*ThreePlayerButton,*FourPlayerButton; |
|
|
|
|
|
|
|
vf2d drawPilePos={100,88}; |
|
|
|
|
|
|
|
vf2d discardPilePos={156,88}; |
|
|
|
|
|
|
|
|
|
|
|
GameState state=AIPICK; |
|
|
|
GameState state=AIPICK; |
|
|
|
|
|
|
|
|
|
|
@ -122,40 +124,50 @@ public: |
|
|
|
return deg*(PI/180); |
|
|
|
return deg*(PI/180); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float radToDeg(float rad){ |
|
|
|
|
|
|
|
return rad*57.2957795130823208767; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DrawGameBoard(){ |
|
|
|
void DrawGameBoard(){ |
|
|
|
DisplayCardPile({100,88},drawPile); |
|
|
|
DisplayCardPile(drawPilePos,drawPile); |
|
|
|
DisplayCardPile({156,88},discardPile); |
|
|
|
DisplayCardPile(discardPilePos,discardPile); |
|
|
|
|
|
|
|
|
|
|
|
vf2d playerHandCenter = {128,220}; |
|
|
|
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]; |
|
|
|
Hand&playerHand=hands[0]; |
|
|
|
float spreadAngle=15; |
|
|
|
float spreadAngle=15; |
|
|
|
float currentAngle=-90; |
|
|
|
float currentAngle=-90; |
|
|
|
float cardDistance=64; |
|
|
|
float cardDistance=64; |
|
|
|
if(playerHand.size()>8){ //Handle a case where the hand size is really large. We max out at 120 degrees.
|
|
|
|
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.
|
|
|
|
} 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
|
|
|
|
struct CardDrawData{ |
|
|
|
//currentAngle value, we will pretend there's an additional card but we'll skip it.
|
|
|
|
vf2d drawPos; |
|
|
|
if(playerHand.size()%2==0){ |
|
|
|
float angle; |
|
|
|
return playerHand.size()+1; |
|
|
|
Card*card=nullptr; |
|
|
|
} else { |
|
|
|
|
|
|
|
return playerHand.size(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
for(int i=0;i<GetHandLoopCounter();i++){ |
|
|
|
|
|
|
|
if(playerHand.size()%2==0&&playerHand.size()/2==i){ |
|
|
|
CardDrawData selectedCardData; |
|
|
|
continue; //The middle section will be dropped if we have an even number of cards.
|
|
|
|
int cardIndex=0; |
|
|
|
} |
|
|
|
for(int i=0;i<playerHand.size();i++){ |
|
|
|
Card¤tCard=playerHand[i]; |
|
|
|
Card¤tCard=playerHand[cardIndex]; |
|
|
|
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(cursorDist>32&&cursorDist<100&&abs(cursorDir-currentAngle)<spreadAngle/2){ |
|
|
|
if(playerHand.size()>8){ |
|
|
|
selectedCardData={playerHandCenter+vf2d{cos(degToRad(currentAngle)),sin(degToRad(currentAngle))}*(cardDistance+10),degToRad(currentAngle+90),¤tCard}; |
|
|
|
currentAngle+=120/playerHand.size(); |
|
|
|
} else { |
|
|
|
}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}); |
|
|
|
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}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -185,25 +197,28 @@ public: |
|
|
|
if(card->sprite->GetPixel(x,y)==Pixel{235,235,235}){ |
|
|
|
if(card->sprite->GetPixel(x,y)==Pixel{235,235,235}){ |
|
|
|
card->sprite->SetPixel({x,y},targetCol); |
|
|
|
card->sprite->SetPixel({x,y},targetCol); |
|
|
|
} else
|
|
|
|
} else
|
|
|
|
if(card->sprite->GetPixel(x,y)==Pixel{103,103,103}){ |
|
|
|
if(card->sprite->GetPixel(x,y)==Pixel{103,103,103}){ |
|
|
|
card->sprite->SetPixel({x,y},targetCol/2); |
|
|
|
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); |
|
|
|
DrawPartialSprite({0,0},cardTilesheet->sprite,cardBorder.pos,cardBorder.size); |
|
|
|
switch(numb){ |
|
|
|
switch(numb){ |
|
|
|
case SKIP:{ |
|
|
|
case SKIP:{ |
|
|
|
DrawPartialSprite(vi2d{24,32}-skip.size/2,cardTilesheet->sprite,skip.pos,skip.size); |
|
|
|
DrawPartialSprite(vi2d{24,32}-skip.size/2,cardTilesheet->sprite,skip.pos,skip.size); |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case REVERSE:{ |
|
|
|
case REVERSE:{ |
|
|
|
DrawPartialSprite(vi2d{24,32}-reverse.size/2,cardTilesheet->sprite,reverse.pos,reverse.size); |
|
|
|
DrawPartialSprite(vi2d{24,32}-reverse.size/2,cardTilesheet->sprite,reverse.pos,reverse.size); |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case DRAWTWO:{ |
|
|
|
case DRAWTWO:{ |
|
|
|
DrawPartialSprite(vi2d{24,32}-drawTwo.size/2,cardTilesheet->sprite,drawTwo.pos,drawTwo.size); |
|
|
|
DrawPartialSprite(vi2d{24,32}-drawTwo.size/2,cardTilesheet->sprite,drawTwo.pos,drawTwo.size); |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
default:{ |
|
|
|
default:{ |
|
|
|
DrawString(vi2d{24,32}-GetTextSize(std::to_string(numb))/2*3,std::to_string(numb),WHITE,3); |
|
|
|
DrawString(vi2d{24,32}-GetTextSize(std::to_string(numb))/2*3,std::to_string(numb),WHITE,3); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
card->Update(); |
|
|
|
card->Update(); |
|
|
|
IMAGES.push_back(card); |
|
|
|
IMAGES.push_back(card); |
|
|
@ -258,6 +273,7 @@ public: |
|
|
|
public: |
|
|
|
public: |
|
|
|
bool OnUserCreate() override |
|
|
|
bool OnUserCreate() override |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
srand(time(NULL)); |
|
|
|
// Called once at the start, so create things here
|
|
|
|
// Called once at the start, so create things here
|
|
|
|
|
|
|
|
|
|
|
|
cardBorder={{0,0},{48,64}}; |
|
|
|
cardBorder={{0,0},{48,64}}; |
|
|
@ -361,13 +377,23 @@ public: |
|
|
|
state=GameState::PICK; |
|
|
|
state=GameState::PICK; |
|
|
|
} |
|
|
|
} |
|
|
|
if(playerTurn==0){ |
|
|
|
if(playerTurn==0){ |
|
|
|
DrawString({0,224},"Player is drawing cards...");
|
|
|
|
DrawStringDecal({0,224},"Player is drawing cards...");
|
|
|
|
} else { |
|
|
|
} 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; |
|
|
|
}break; |
|
|
|
case PICK:{ |
|
|
|
case PICK:{ |
|
|
|
DrawGameBoard(); |
|
|
|
DrawGameBoard(); |
|
|
|
|
|
|
|
if(GetMouse(0).bPressed&& |
|
|
|
|
|
|
|
GetMouseX()>=drawPilePos.x&&GetMouseX()<drawPilePos.x+48&& |
|
|
|
|
|
|
|
GetMouseY()>=drawPilePos.y&&GetMouseY()<drawPilePos.y+48){ |
|
|
|
|
|
|
|
DrawCard(hands[playerTurn],true); |
|
|
|
|
|
|
|
} |
|
|
|
}break; |
|
|
|
}break; |
|
|
|
case RESULT:{ |
|
|
|
case RESULT:{ |
|
|
|
DrawGameBoard(); |
|
|
|
DrawGameBoard(); |
|
|
|