summaryrefslogtreecommitdiff
path: root/src/game.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.c')
-rw-r--r--src/game.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/game.c b/src/game.c
index 6456618..72afef6 100644
--- a/src/game.c
+++ b/src/game.c
@@ -20,6 +20,11 @@ typedef enum Suite {
SPADE = 3
} Suite;
+typedef enum GameState {
+ POLLING,
+ MOVING
+} GameState;
+
typedef struct Card {
//Info for game logic
Suite suite;
@@ -35,6 +40,7 @@ typedef struct Card {
typedef struct Game {
int turn;
+ GameState state;
Card deck[DECK_SIZE];
Card hands[MAX_NUM_PLAYERS][DECK_SIZE];
@@ -59,7 +65,7 @@ int main(void) {
srand((unsigned int)time(NULL));
LoadAssets();
- InitGame(2);
+ InitGame(4);
while(!WindowShouldClose()) {
UpdateGame(GetFrameTime());
@@ -161,9 +167,23 @@ void UpdateCard(Card* c, float dt) {
}
}
+static inline float HandWidth(int hand) {
+ return game.cardsInHand[hand] * CARD_WIDTH;
+}
+
//Moves all the cards in the hand indexed to their correct positions
void PositionCardsInHand(int hand) {
- float xpos = 0.0;
+ float centerXpos =
+ (WINDOW_WIDTH - HandWidth(hand)) / 2.0;
+ float positionsX[] =
+ {
+ game.playerCount < 3 ? centerXpos : 0.0f,
+ game.playerCount < 4 ? centerXpos : 0.0f,
+ WINDOW_WIDTH - HandWidth(hand),
+ WINDOW_WIDTH - HandWidth(hand)
+ };
+
+ float xpos = positionsX[hand];
float ypos =
(hand % 2) == 0 ? 0.0f : (WINDOW_HEIGHT - CARD_HEIGHT);
@@ -218,13 +238,6 @@ void Deal(int toPlayer) {
void NextTurn() {
game.turn = (game.turn + 1) % game.playerCount;
FlipCards();
-
- //If the player has no playable cards deal them one and if that is also
- //not playable just skip their turn
- for(int i = 0; i < game.cardsInHand[game.turn]; i++)
- if (CanPlayCard(&game.hands[game.turn][i])) return;
-
- Deal(game.turn);
}
bool IsSpecialCard(const Card* c) {
@@ -264,6 +277,12 @@ void UpdateGame(float dt) {
PositionCardsInHand(game.turn);
NextTurn();
+ //If the player has no playable cards deal them one and if that is also
+ //not playable just skip their turn
+ for(int i = 0; i < game.cardsInHand[game.turn]; i++)
+ if (CanPlayCard(&game.hands[game.turn][i])) return;
+
+ Deal(game.turn);
}
}
@@ -311,8 +330,8 @@ void InitGame(int playerCount) {
for(int j = 0; j < STARTING_HAND; j++) Deal(i);
}
- game.turn = 0;
- FlipCards();
+ game.turn = -1;
+ NextTurn();
//Find the first non-special card and send it to the stack to begin the game
int i;