diff --git a/src/conversation/textbox.c b/src/conversation/textbox.c index 505635e..1464ba6 100644 --- a/src/conversation/textbox.c +++ b/src/conversation/textbox.c @@ -7,7 +7,10 @@ #include "textbox.h" -char *TEXTBOX_TEXT; +char TEXTBOX_TEXT[TEXTBOX_BUFFER_MAX]; +uint8_t TEXTBOX_ROW_COUNT; +uint8_t TEXTBOX_ROW_CURRENT; + uint8_t TEXTBOX_TEXT_LENGTH; uint8_t TEXTBOX_STATE; uint8_t TEXTBOX_SCROLL; @@ -18,7 +21,7 @@ inline void conversationTextboxInit() { uint8_t TEXTBOX_TILES[TEXTBOX_TILES_MAX]; // Reset textbox state - TEXTBOX_TEXT = NULL; + TEXTBOX_TEXT[0] = '\0'; TEXTBOX_STATE = 0; TEXTBOX_TEXT_LENGTH = 0; TEXTBOX_SCROLL = 0; @@ -54,11 +57,19 @@ inline void conversationTextboxInit() { void conversationTextboxSetText(char *text, uint8_t length) { uint8_t i, j; + char c; uint8_t TEXTBOX_TILES[TEXTBOX_CHAR_ROWS * TEXTBOX_CHARS_PER_ROW]; + TEXTBOX_TEXT_LENGTH = 0; + i = 0; + + while((c = text[i]) != '\0') { + TEXTBOX_TEXT[i] = c; + TEXTBOX_TEXT_LENGTH++; + i++; + } + // Reset textbox state - TEXTBOX_TEXT = text; - TEXTBOX_TEXT_LENGTH = length; TEXTBOX_STATE = TEXTBOX_STATE_VISIBLE; TEXTBOX_SCROLL = 0; TEXTBOX_CHAR_POSITION = 0; diff --git a/src/conversation/textbox.h b/src/conversation/textbox.h index 2387e93..a3f9947 100644 --- a/src/conversation/textbox.h +++ b/src/conversation/textbox.h @@ -32,6 +32,8 @@ #define TEXTBOX_CHARS_PER_ROW (TEXTBOX_WIDTH_IN_TILES - 2) #define TEXTBOX_CHAR_ROWS (TEXTBOX_HEIGHT_IN_TILES - 2) +#define TEXTBOX_CHARS_MAX (TEXTBOX_CHAR_ROWS * TEXTBOX_CHARS_PER_ROW) +#define TEXTBOX_BUFFER_MAX (TEXTBOX_CHARS_MAX * 3) #define TEXTBOX_TILES_PER_ROW TEXTBOX_WIDTH_IN_TILES #define TEXTBOX_TILES_ROWS 3 @@ -41,7 +43,10 @@ STR_ ## name ## _DATA, STR_ ## name ## _LENGTH\ ) -extern char *TEXTBOX_TEXT; +extern char TEXTBOX_TEXT[TEXTBOX_BUFFER_MAX]; +extern uint8_t TEXTBOX_ROW_COUNT; +extern uint8_t TEXTBOX_ROW_CURRENT; + extern uint8_t TEXTBOX_TEXT_LENGTH; extern uint8_t TEXTBOX_STATE; extern uint8_t TEXTBOX_SCROLL; diff --git a/src/libs.h b/src/libs.h index d41e7c4..7883c60 100644 --- a/src/libs.h +++ b/src/libs.h @@ -11,4 +11,5 @@ #include // #include #include -#include \ No newline at end of file +#include +#include \ No newline at end of file diff --git a/src/main.c b/src/main.c index a275c14..e3cf4b8 100644 --- a/src/main.c +++ b/src/main.c @@ -7,11 +7,11 @@ #include "main.h" -uint8_t mainGetChar(char c) { +inline uint8_t mainGetChar(char c) { return c - 33 + 4; } -void mainBufferChar(uint8_t card, uint8_t *tiles) { +inline void mainBufferChar(uint8_t card, uint8_t *tiles) { uint8_t suit, number; if(card >= CARD_DECK_SIZE) { @@ -81,6 +81,55 @@ void mainBufferChar(uint8_t card, uint8_t *tiles) { } } +inline void mainDebugDraw() { + uint8_t j; + + // DEBUG DRAW + uint8_t tiles[10]; + for(j = 0; j < POKER_PLAYER_COUNT; j++) { + mainBufferChar(POKER_PLAYERS[j].hand[0], tiles); + mainBufferChar(POKER_PLAYERS[j].hand[1], tiles + 2); + + tiles[4] = COMMON_TILE_3; + + if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_FOLDED) == 0) { + tiles[5] = COMMON_TILE_3; + } else { + tiles[5] = mainGetChar('F'); + } + + if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_HAS_BET_THIS_ROUND) == 0) { + tiles[6] = COMMON_TILE_3; + } else { + tiles[6] = mainGetChar('H'); + } + + if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_OUT) == 0) { + tiles[7] = COMMON_TILE_3; + } else { + tiles[7] = mainGetChar('O'); + } + + if(j == POKER_PLAYER_BETTER) { + tiles[8] = mainGetChar('<'); + } else { + tiles[8] = COMMON_TILE_3; + } + set_bkg_tiles(0x00, j, 9, 1, tiles); + } + + for(j = 0; j < POKER_COMMUNITY_SIZE_MAX; j++) { + if(j >= POKER_COMMUNITY_SIZE) { + tiles[j*2] = COMMON_TILE_3; + tiles[(j*2) + 1] = COMMON_TILE_3; + } else { + mainBufferChar(POKER_COMMUNITY[j], tiles + (j * 2)); + } + } + + set_bkg_tiles(0x00, POKER_PLAYER_COUNT + 1, 10, 1, tiles); +} + void main() { int16_t j; uint8_t filled[GB_BACKGROUND_COLUMNS*GB_BACKGROUND_ROWS]; @@ -101,8 +150,8 @@ void main() { timeInit(); commonTilesInit(); conversationTextboxInit(); - conversationQueueInit(); - pokerInit(); + // conversationQueueInit(); + // pokerInit(); // Fill screen white for(j = 0; j < 0x20*0x20; j++) filled[j] = COMMON_TILE_3; @@ -116,7 +165,11 @@ void main() { wait_vbl_done(); // Alright begin the game logic here. - conversationQueueNext(); + // conversationQueueNext(); + char DEBUG_TEXT[] = "HEY"; + uint8_t DEBUG_TEXT_LENGTH = 3; + for(j = 0; j < DEBUG_TEXT_LENGTH; j++) DEBUG_TEXT[j] = DEBUG_TEXT[j] - 33 + 4; + conversationTextboxSetText(DEBUG_TEXT, DEBUG_TEXT_LENGTH); // Begin the loop while(1) { @@ -127,55 +180,10 @@ void main() { INPUT_STATE = joypad(); conversationTextboxUpdate(); - conversationPauseUpdate(); - conversationFadeUpdate(); + // conversationPauseUpdate(); + // conversationFadeUpdate(); - - - // DEBUG DRAW - uint8_t tiles[10]; - for(j = 0; j < POKER_PLAYER_COUNT; j++) { - mainBufferChar(POKER_PLAYERS[j].hand[0], tiles); - mainBufferChar(POKER_PLAYERS[j].hand[1], tiles + 2); - - tiles[4] = COMMON_TILE_3; - - if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_FOLDED) == 0) { - tiles[5] = COMMON_TILE_3; - } else { - tiles[5] = mainGetChar('F'); - } - - if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_HAS_BET_THIS_ROUND) == 0) { - tiles[6] = COMMON_TILE_3; - } else { - tiles[6] = mainGetChar('H'); - } - - if((POKER_PLAYERS[j].state & POKER_PLAYER_STATE_OUT) == 0) { - tiles[7] = COMMON_TILE_3; - } else { - tiles[7] = mainGetChar('O'); - } - - if(j == POKER_PLAYER_BETTER) { - tiles[8] = mainGetChar('<'); - } else { - tiles[8] = COMMON_TILE_3; - } - set_bkg_tiles(0x00, j, 9, 1, tiles); - } - - for(j = 0; j < POKER_COMMUNITY_SIZE_MAX; j++) { - if(j >= POKER_COMMUNITY_SIZE) { - tiles[j*2] = COMMON_TILE_3; - tiles[(j*2) + 1] = COMMON_TILE_3; - } else { - mainBufferChar(POKER_COMMUNITY[j], tiles + (j * 2)); - } - } - - set_bkg_tiles(0x00, POKER_PLAYER_COUNT + 1, 10, 1, tiles); + // mainDebugDraw(): // Tick time. timeUpdate(); diff --git a/src/poker/poker.c b/src/poker/poker.c index 5dec651..5c3e379 100644 --- a/src/poker/poker.c +++ b/src/poker/poker.c @@ -39,7 +39,7 @@ void pokerInit() { // TODO: Should this be randomized? POKER_PLAYER_DEALER = 0; POKER_GAME_BLINDS_CURRENT = 10; - POKER_PLAYER_COUNT = 3; + POKER_PLAYER_COUNT = POKER_PLAYER_COUNT_MAX; // Set up players for(i = 0; i < POKER_PLAYER_COUNT; i++) { @@ -145,6 +145,7 @@ inline void pokerBet(uint8_t player, uint16_t amount) { // player 2 has $700, and bets all o it. A new $300 sidepot auto creates // player 3 has $500 and bets all of it, Another sidepot with $200 is auto made. if(POKER_POT_CURRENT == POKER_POT_COUNT) POKER_POT_COUNT++; + POKER_PLAYERS[player].chips -= amount; POKER_POTS[POKER_POT_CURRENT].chips += amount; POKER_POTS[POKER_POT_CURRENT].players[player] += amount;