Added card slots

master
sigonasr2 2 years ago
parent 5fb068d5ee
commit 511ac0a347
  1. 59
      Solitaire/main.cpp

@ -3,6 +3,13 @@
using namespace olc; using namespace olc;
const vi2d CARD_SIZE = vi2d{32,48};
PixelGameEngine*game;
class Example : public olc::PixelGameEngine
{
const float PI = 3.14159f; const float PI = 3.14159f;
enum Suit { enum Suit {
@ -12,14 +19,34 @@ enum Suit {
DIAMOND DIAMOND
}; };
const vi2d CARD_SIZE = vi2d{32,48}; enum SlotType {
PLAYDECK,
ACTIVE_PLAYDECK,
HOME,
FIELD
};
struct Card {
Suit s;
int number;
};
struct CardSlot {
vf2d pos;
SlotType type;
std::vector<Card> faceDownCards;
std::vector<Card> faceUpCards;
void RenderCards() {
game->DrawRectDecal(pos, CARD_SIZE, WHITE);
}
};
class Example : public olc::PixelGameEngine
{
public: public:
Example() Example()
{ {
sAppName = "Solitaire"; sAppName = "Solitaire";
game = this;
} }
void RenderCard(vf2d pos, Suit s, int number) { void RenderCard(vf2d pos, Suit s, int number) {
@ -29,16 +56,38 @@ public:
} }
public: public:
CardSlot PlayDeck{ {16,8},PLAYDECK };
CardSlot ActivePlayDeck{ {56,8},ACTIVE_PLAYDECK };
std::array<CardSlot, 4> Home;
std::array<CardSlot, 7> Field;
bool OnUserCreate() override bool OnUserCreate() override
{ {
for (int i = 0; i < Home.size();i++) {
CardSlot&c = Home[i];
c.pos = vi2d{ 136 + i * 40,8 };
c.type = SlotType::HOME;
}
for (int i = 0; i < Field.size(); i++) {
CardSlot&c = Field[i];
c.pos = vi2d{ 16 + i * 40,64 };
c.type = SlotType::FIELD;
}
return true; return true;
} }
bool OnUserUpdate(float fElapsedTime) override bool OnUserUpdate(float fElapsedTime) override
{ {
// called once per frame // called once per frame
RenderCard({ 48,48 }, HEART, 7); //RenderCard({ 48,48 }, HEART, 7);
PlayDeck.RenderCards();
ActivePlayDeck.RenderCards();
for (CardSlot& c : Home) {
c.RenderCards();
}
for (CardSlot& c : Field) {
c.RenderCards();
}
return true; return true;
} }
}; };

Loading…
Cancel
Save