Implemented hand display and card selection. Card drawing.

master
sigonasr2 1 year ago
parent bbd0165a67
commit 9e28d3b869
  1. 104
      CardGameRef/CardGame.cpp
  2. 2
      CardGameRef/CardGameRef.vcxproj

@ -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;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.
}
Card&currentCard=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;
CardDrawData selectedCardData;
int cardIndex=0;
for(int i=0;i<playerHand.size();i++){
Card&currentCard=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),&currentCard};
} 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+=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}){
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.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();

@ -91,6 +91,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@ -120,6 +121,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

Loading…
Cancel
Save