Implemented hand display and card selection. Card drawing.
This commit is contained in:
parent
bbd0165a67
commit
9e28d3b869
@ -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
|
|
||||||
//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){
|
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[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];
|
currentAngle+=spreadAngle;
|
||||||
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});
|
cardIndex++;
|
||||||
if(playerHand.size()>8){
|
|
||||||
currentAngle+=120/playerHand.size();
|
|
||||||
}else{
|
|
||||||
currentAngle+=15;
|
|
||||||
}
|
}
|
||||||
|
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
|
} 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});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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();
|
||||||
|
@ -91,6 +91,7 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@ -120,6 +121,7 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user