diff options
author | BoredGuy <osome3717@gmail.com> | 2025-07-05 13:33:08 +0300 |
---|---|---|
committer | BoredGuy <osome3717@gmail.com> | 2025-07-05 13:33:08 +0300 |
commit | 8a835ff8e378fecc67da5dd01a12a60774a998e6 (patch) | |
tree | 20ada6eda94c7646ac457472cedc4f2d0a612305 | |
parent | 393b5fd3751cf34a81ecb1821ee37d34c72355fe (diff) |
Some work IG?
-rw-r--r-- | src/game.c | 41 |
1 files changed, 30 insertions, 11 deletions
@@ -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; |