Improve visual stuff.

master
sigonasr2 2 years ago
parent 03412fcfd9
commit fb497c1e41
  1. 57
      Solitaire/main.cpp

@ -19,6 +19,7 @@ class Solitaire : public olc::PixelGameEngine
DIAMOND, DIAMOND,
HEART, HEART,
SPADE, SPADE,
FACEDOWN,
}; };
enum SlotType { enum SlotType {
@ -57,19 +58,34 @@ class Solitaire : public olc::PixelGameEngine
std::vector<Card> faceUpCards; std::vector<Card> faceUpCards;
std::vector<Card> flippedOverCards; //Just for active play deck. Face up cards will contain the rest of the pile. std::vector<Card> flippedOverCards; //Just for active play deck. Face up cards will contain the rest of the pile.
void RenderCard(vf2d pos, Suit s, int number) { void RenderCard(vf2d pos, Suit s, int number) {
if (s == FACEDOWN) {
game->FillRectDecal(pos, CARD_SIZE, DARK_CYAN);
game->DrawRectDecal(pos, CARD_SIZE, BLACK);
}
else {
game->FillRectDecal(pos, CARD_SIZE, WHITE); game->FillRectDecal(pos, CARD_SIZE, WHITE);
game->DrawStringDecal(pos + vf2d{ 2,2 }, number==1?"A":number == 13 ? "K" : number == 12 ? "Q" : number == 11 ? "J" : std::to_string(number), s == CLUB || s == SPADE ? BLACK : DARK_RED, number == 10 ? vf2d{0.6,1} : vf2d{1,1}); game->DrawStringDecal(pos + vf2d{ 2,2 }, number == 1 ? "A" : number == 13 ? "K" : number == 12 ? "Q" : number == 11 ? "J" : std::to_string(number), s == CLUB || s == SPADE ? BLACK : DARK_RED, number == 10 ? vf2d{ 0.6,1 } : vf2d{ 1,1 });
game->DrawDecal(pos + vf2d{ 2,12 }, game->GetSprite(s), { 0.25,0.25 }); game->DrawDecal(pos + vf2d{ 2,12 }, game->GetSprite(s), { 0.25,0.25 });
game->DrawRotatedStringDecal(pos + CARD_SIZE - vf2d{ 2,2 }, number == 1 ? "A" : number == 13 ? "K" : number == 12 ? "Q" : number == 11 ? "J" : std::to_string(number), PI, { 0,0 }, s == CLUB||s==SPADE ? BLACK : DARK_RED, number == 10 ? vf2d{ 0.6,1 } : vf2d{ 1,1 }); game->DrawRotatedStringDecal(pos + CARD_SIZE - vf2d{ 2,2 }, number == 1 ? "A" : number == 13 ? "K" : number == 12 ? "Q" : number == 11 ? "J" : std::to_string(number), PI, { 0,0 }, s == CLUB || s == SPADE ? BLACK : DARK_RED, number == 10 ? vf2d{ 0.6,1 } : vf2d{ 1,1 });
game->DrawRotatedDecal(pos + CARD_SIZE - vf2d{ 2,12 }, game->GetSprite(s), PI, { 0,0 }, { 0.25, 0.25 }); game->DrawRotatedDecal(pos + CARD_SIZE - vf2d{ 2,12 }, game->GetSprite(s), PI, { 0,0 }, { 0.25, 0.25 });
game->DrawRectDecal(pos, CARD_SIZE, BLACK); game->DrawRectDecal(pos, CARD_SIZE, BLACK);
} }
}
void RenderCards() { void RenderCards() {
game->DrawRectDecal(pos, CARD_SIZE, BLACK); game->DrawRectDecal(pos, CARD_SIZE, BLACK);
switch (type) { switch (type) {
case PLAYDECK: { case PLAYDECK: {
if (faceDownCards.size() > 0) { if (faceDownCards.size() > 6*3) {
game->FillRectDecal(pos, CARD_SIZE, DARK_CYAN); RenderCard(pos+vi2d{-2,-2}, FACEDOWN, 0);
RenderCard(pos + vi2d{ -1,-1 }, FACEDOWN, 0);
RenderCard(pos, FACEDOWN, 0);
} else
if (faceDownCards.size() > 3 * 3) {
RenderCard(pos + vi2d{ -1,-1 }, FACEDOWN, 0);
RenderCard(pos, FACEDOWN, 0);
}
else {
RenderCard(pos, FACEDOWN, 0);
} }
}break; }break;
case ACTIVE_PLAYDECK: { case ACTIVE_PLAYDECK: {
@ -86,21 +102,42 @@ class Solitaire : public olc::PixelGameEngine
} }
}break; }break;
case HOME: { case HOME: {
if (faceUpCards.size() > 0) { if (faceUpCards.size() > 2) {
Card& c = faceUpCards[faceUpCards.size() - 1];
RenderCard(pos+vi2d{-2,-2}, c.s, c.number);
c = faceUpCards[faceUpCards.size() - 2];
RenderCard(pos + vi2d{ -1,-1 }, c.s, c.number);
c = faceUpCards[faceUpCards.size() - 3];
RenderCard(pos, c.s, c.number);
} else
if (faceUpCards.size() > 1) {
Card& c = faceUpCards[faceUpCards.size() - 1];
RenderCard(pos + vi2d{ -1,-1 }, c.s, c.number);
c = faceUpCards[faceUpCards.size() - 2];
RenderCard(pos, c.s, c.number);
}
else
if (faceUpCards.size() == 1) {
Card& c = faceUpCards[faceUpCards.size() - 1]; Card& c = faceUpCards[faceUpCards.size() - 1];
RenderCard(pos, c.s, c.number); RenderCard(pos, c.s, c.number);
} }
}break; }break;
case FIELD: { case FIELD: {
int cardSpacing = 16;
int totalCards = faceDownCards.size() + faceUpCards.size();
int spaceTakenUp = CARD_SIZE.y + totalCards * cardSpacing;
while (spaceTakenUp + pos.y > game->ScreenHeight()) {
cardSpacing--;
spaceTakenUp = CARD_SIZE.y + totalCards * cardSpacing;
}
for (int i = 0; i < faceDownCards.size(); i++) {
RenderCard(pos + vi2d{ 0,i * cardSpacing },FACEDOWN, 0);
}
if (faceUpCards.size() > 0) { if (faceUpCards.size() > 0) {
for (int i = 0; i < faceUpCards.size(); i++) { for (int i = 0; i < faceUpCards.size(); i++) {
Card& c = faceUpCards[i]; Card& c = faceUpCards[i];
RenderCard(pos + vi2d{ 0,i * 16 }, c.s, c.number); RenderCard(pos + vi2d{ 0,(i+(int)faceDownCards.size()) * cardSpacing }, c.s, c.number);
}
} }
else
if (faceDownCards.size()>0){
game->FillRectDecal(pos, CARD_SIZE, DARK_CYAN);
} }
}break; }break;
} }

Loading…
Cancel
Save