Add card numbers and setup card displays for active play deck and play deck.
This commit is contained in:
parent
511ac0a347
commit
7531981c08
@ -3,14 +3,13 @@
|
||||
|
||||
using namespace olc;
|
||||
|
||||
|
||||
const float PI = 3.14159f;
|
||||
const vi2d CARD_SIZE = vi2d{32,48};
|
||||
|
||||
PixelGameEngine*game;
|
||||
|
||||
class Example : public olc::PixelGameEngine
|
||||
{
|
||||
const float PI = 3.14159f;
|
||||
|
||||
enum Suit {
|
||||
SPADE,
|
||||
@ -36,8 +35,34 @@ struct CardSlot {
|
||||
SlotType type;
|
||||
std::vector<Card> faceDownCards;
|
||||
std::vector<Card> faceUpCards;
|
||||
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) {
|
||||
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 ? 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 ? BLACK : DARK_RED, number == 10 ? vf2d{ 0.6,1 } : vf2d{ 1,1 });
|
||||
game->DrawRectDecal(pos, CARD_SIZE, BLACK);
|
||||
}
|
||||
void RenderCards() {
|
||||
game->DrawRectDecal(pos, CARD_SIZE, WHITE);
|
||||
switch (type) {
|
||||
case PLAYDECK: {
|
||||
if (faceDownCards.size() > 0) {
|
||||
game->FillRectDecal(pos, CARD_SIZE, DARK_CYAN);
|
||||
}
|
||||
}break;
|
||||
case ACTIVE_PLAYDECK: {
|
||||
if (flippedOverCards.size() > 0) {
|
||||
for (int i = 0; i < flippedOverCards.size(); i++) {
|
||||
Card& c = flippedOverCards[i];
|
||||
RenderCard(pos + vi2d{ i * 12,0 }, c.s, c.number);
|
||||
}
|
||||
} else {
|
||||
if (faceUpCards.size() > 0) {
|
||||
Card& c = faceUpCards[faceUpCards.size() - 1];
|
||||
RenderCard(pos, c.s, c.number);
|
||||
}
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -49,12 +74,6 @@ public:
|
||||
game = this;
|
||||
}
|
||||
|
||||
void RenderCard(vf2d pos, Suit s, int number) {
|
||||
FillRectDecal(pos, CARD_SIZE, WHITE);
|
||||
DrawStringDecal(pos + vf2d{ 2,2 }, std::to_string(number), s <= CLUB ? BLACK : DARK_RED);
|
||||
DrawRotatedStringDecal(pos + CARD_SIZE - vf2d{2,2}, std::to_string(number), PI, {0,0}, s <= CLUB ? BLACK : DARK_RED);
|
||||
}
|
||||
|
||||
public:
|
||||
CardSlot PlayDeck{ {16,8},PLAYDECK };
|
||||
CardSlot ActivePlayDeck{ {56,8},ACTIVE_PLAYDECK };
|
||||
@ -62,7 +81,11 @@ public:
|
||||
std::array<CardSlot, 7> Field;
|
||||
bool OnUserCreate() override
|
||||
{
|
||||
|
||||
PlayDeck.faceDownCards.push_back({SPADE,4});
|
||||
ActivePlayDeck.faceUpCards.push_back({ CLUB,9 });
|
||||
ActivePlayDeck.flippedOverCards.push_back({ HEART,3 });
|
||||
ActivePlayDeck.flippedOverCards.push_back({ HEART,10 });
|
||||
ActivePlayDeck.flippedOverCards.push_back({ SPADE,1 });
|
||||
for (int i = 0; i < Home.size();i++) {
|
||||
CardSlot&c = Home[i];
|
||||
c.pos = vi2d{ 136 + i * 40,8 };
|
||||
|
Loading…
x
Reference in New Issue
Block a user