Card slots can be dragged.

master
sigonasr2 2 years ago
parent b0fd3cfd97
commit dbccc87399
  1. 37
      Solitaire/main.cpp

@ -72,6 +72,7 @@ class Solitaire : public olc::PixelGameEngine
SlotType type; SlotType type;
std::vector<Card> faceDownCards; std::vector<Card> faceDownCards;
std::vector<Card> faceUpCards; std::vector<Card> faceUpCards;
int cardSpacing = 16;
void RenderCards() { void RenderCards() {
game->DrawRectDecal(pos, CARD_SIZE, BLACK); game->DrawRectDecal(pos, CARD_SIZE, BLACK);
switch (type) { switch (type) {
@ -137,7 +138,7 @@ class Solitaire : public olc::PixelGameEngine
} }
}break; }break;
case FIELD: { case FIELD: {
int cardSpacing = 16; cardSpacing = 16;
int totalCards = faceDownCards.size() + faceUpCards.size(); int totalCards = faceDownCards.size() + faceUpCards.size();
int spaceTakenUp = CARD_SIZE.y + totalCards * cardSpacing; int spaceTakenUp = CARD_SIZE.y + totalCards * cardSpacing;
while (spaceTakenUp + pos.y > game->ScreenHeight()) { while (spaceTakenUp + pos.y > game->ScreenHeight()) {
@ -165,9 +166,17 @@ class Solitaire : public olc::PixelGameEngine
GetMouseY() >= slot.pos.y && GetMouseY() <= slot.pos.y + CARD_SIZE.y; GetMouseY() >= slot.pos.y && GetMouseY() <= slot.pos.y + CARD_SIZE.y;
}break; }break;
case ACTIVE_PLAYDECK: { case ACTIVE_PLAYDECK: {
return GetMouseX() >= slot.pos.x && GetMouseX() <= slot.pos.x + CARD_SIZE.x + (std::min(3,(int)slot.faceUpCards.size())-1)*12 &&
GetMouseY() >= slot.pos.y && GetMouseY() <= slot.pos.y + CARD_SIZE.y;
}break;
case HOME: {
return GetMouseX() >= slot.pos.x && GetMouseX() <= slot.pos.x + CARD_SIZE.x && return GetMouseX() >= slot.pos.x && GetMouseX() <= slot.pos.x + CARD_SIZE.x &&
GetMouseY() >= slot.pos.y && GetMouseY() <= slot.pos.y + CARD_SIZE.y; GetMouseY() >= slot.pos.y && GetMouseY() <= slot.pos.y + CARD_SIZE.y;
}break; }break;
case FIELD: {
return GetMouseX() >= slot.pos.x && GetMouseX() <= slot.pos.x + CARD_SIZE.x &&
GetMouseY() >= slot.pos.y && GetMouseY() <= slot.pos.y + CARD_SIZE.y + (slot.faceDownCards.size()+slot.faceUpCards.size()-1)*slot.cardSpacing;
}break;
} }
return false; return false;
} }
@ -198,6 +207,32 @@ class Solitaire : public olc::PixelGameEngine
ActivePlayDeck.faceUpCards[ActivePlayDeck.faceUpCards.size() - 1].number = -1; ActivePlayDeck.faceUpCards[ActivePlayDeck.faceUpCards.size() - 1].number = -1;
} }
} }
for (int i = 0; i < Home.size(); i++) {
if (GetMouse(0).bPressed && MouseOver(Home[i])) {
if (Home[i].faceUpCards.size() > 0) {
Card& card = Home[i].faceUpCards[Home[i].faceUpCards.size() - 1];
draggedCard = { card.s,card.number };
previousCardInteraction = &Home[i].faceUpCards[Home[i].faceUpCards.size() - 1];
Home[i].faceUpCards[Home[i].faceUpCards.size() - 1].number = -1;
}
}
}
for (int i = 0; i < Field.size(); i++) {
if (GetMouse(0).bPressed && MouseOver(Field[i])) {
if (Field[i].faceUpCards.size() > 0) {
Card& card = Field[i].faceUpCards[Field[i].faceUpCards.size() - 1];
draggedCard = { card.s,card.number };
previousCardInteraction = &Field[i].faceUpCards[Field[i].faceUpCards.size() - 1];
Field[i].faceUpCards[Field[i].faceUpCards.size() - 1].number = -1;
} else
if (Field[i].faceDownCards.size() > 0) {
Card card = Field[i].faceDownCards[Field[i].faceDownCards.size() - 1];
Field[i].faceUpCards.push_back(card);
Field[i].faceDownCards.erase(Field[i].faceDownCards.end() - 1);
}
}
}
if (GetMouse(0).bReleased && draggedCard.number !=-1) { if (GetMouse(0).bReleased && draggedCard.number !=-1) {
previousCardInteraction->number = draggedCard.number; previousCardInteraction->number = draggedCard.number;

Loading…
Cancel
Save