Bruh? 😳

This commit is contained in:
2022-01-08 21:44:02 -08:00
parent 36ad463505
commit c426d0e929
21 changed files with 445 additions and 46 deletions

View File

@@ -1,5 +1,7 @@
const GAME_STRINGS = {
'HELLO': 'Hello World!\nHow are you today?\nThank god!'
'HELLO': 'Hello World!\nHow are you today?\nThank god!',
'POKER_GAME_START': 'Poker game started!'
};
module.exports = { GAME_STRINGS };

View File

@@ -7,8 +7,8 @@
"license": "MIT",
"scripts": {
"clean": "node ./scripts/clean",
"build": "node ./scripts/build",
"start": "bgb64.exe ./build/Penny.gb"
"build": "npm run clean && node ./scripts/build",
"start": "npm run build && bgb64.exe ./build/Penny.gb"
},
"dependencies": {
"pngjs": "^6.0.0",

24
src/conversation/pause.c Normal file
View File

@@ -0,0 +1,24 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "pause.h"
uint16_t PAUSE_END;
void conversationPauseInit() {
PAUSE_END = 0;
}
void conversationPause(uint16_t duration) {
PAUSE_END = TIME_CURRENT + (duration * TIME_PER_SECOND);
}
void conversationPauseUpdate() {
if(PAUSE_END == 0 || TIME_CURRENT != PAUSE_END) return;
conversationQueueNext();
PAUSE_END = 0;
}

17
src/conversation/pause.h Normal file
View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#include "../time.h"
#include "queue.h"
extern uint16_t PAUSE_END;
void conversationPauseInit();
void conversationPause(uint16_t duration);
void conversationPauseUpdate();

36
src/conversation/queue.c Normal file
View File

@@ -0,0 +1,36 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "queue.h"
#include "pause.h"
#include "textbox.h"
uint16_t QUEUE_ITEM;
void conversationQueueInit() {
QUEUE_ITEM = 0;
}
void conversationQueueNext() {
BGB_printf("Queue item: %d\n", QUEUE_ITEM);
switch(QUEUE_ITEM) {
case 0:
conversationTextboxSetText(STR_POKER_GAME_START_DATA, STR_POKER_GAME_START_LENGTH);
QUEUE_ITEM++;
break;
case 1:
conversationPause(3);
QUEUE_ITEM++;
break;
case 2:
conversationTextboxSetText(STR_POKER_GAME_START_DATA, STR_POKER_GAME_START_LENGTH);
break;
}
}

16
src/conversation/queue.h Normal file
View File

@@ -0,0 +1,16 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#include "HELLO.h"
#include "POKER_GAME_START.h"
extern uint16_t QUEUE_ITEM;
void conversationQueueInit();
void conversationQueueNext();

View File

@@ -13,7 +13,7 @@ uint8_t TEXTBOX_STATE;
uint8_t TEXTBOX_SCROLL;
uint8_t TEXTBOX_TILES[TEXTBOX_TILES_MAX];
void textboxInit() {
void conversationTextboxInit() {
uint8_t i;
// Reset textbox state
@@ -44,13 +44,14 @@ void textboxInit() {
}
}
void textboxSetText(char *text, uint8_t length) {
void conversationTextboxSetText(char *text, uint8_t length) {
uint8_t i, j;
// Reset textbox state
TEXTBOX_TEXT = text;
TEXTBOX_TEXT_LENGTH = length;
TEXTBOX_STATE = TEXTBOX_STATE_VISIBLE;
TEXTBOX_SCROLL = 0;
// Fill blank characters
for(j = 0; j < TEXTBOX_CHAR_ROWS; j++) {
@@ -69,36 +70,47 @@ void textboxSetText(char *text, uint8_t length) {
SHOW_WIN;
}
void textboxClose() {
TEXTBOX_STATE &= ~TEXTBOX_STATE_VISIBLE;
HIDE_WIN;
}
void textboxUpdate() {
void conversationTextboxUpdate() {
uint8_t i, j;
// Is the textbox visible?
if(!(TEXTBOX_STATE & TEXTBOX_STATE_VISIBLE)) return;
// Has the textbox finished scrolling?
if(TEXTBOX_STATE & TEXTBOX_STATE_SCROLLED) {
// Is the player attempting to close the textbox?
if(INPUT_STATE & J_A) {
TEXTBOX_STATE &= ~TEXTBOX_STATE_VISIBLE;
HIDE_WIN;
conversationQueueNext();
}
return;
}
// Move to the next character.
TEXTBOX_SCROLL++;
j = TEXTBOX_WIDTH_IN_TILES + 1;
for(i = 0; i < TEXTBOX_SCROLL; i++) {
// Whitespace, do nothing.
if(TEXTBOX_TEXT[i] == ' ') {
j++;
continue;
}
// Newline character, move the next tile to the next row.
if(TEXTBOX_TEXT[i] == '\n') {
j = (
(j / TEXTBOX_WIDTH_IN_TILES)*TEXTBOX_WIDTH_IN_TILES
) + TEXTBOX_WIDTH_IN_TILES + 1;
continue;
}
// Reveal the next character
TEXTBOX_TILES[j] = TEXTBOX_TEXT[i];
j++;
}
// Update the window tilemap
set_win_tiles(
0, 0,
TEXTBOX_WIDTH_IN_TILES,
@@ -106,6 +118,8 @@ void textboxUpdate() {
TEXTBOX_TILES
);
// Update state. TODO: I actually don't really need this state, it's just here
// incase I want to check if the state has scrolled later on? Doubt it though.
if(TEXTBOX_SCROLL == TEXTBOX_TEXT_LENGTH) {
TEXTBOX_STATE |= TEXTBOX_STATE_SCROLLED;
}

View File

@@ -6,10 +6,12 @@
*/
#pragma once
#include "libs.h"
#include "util.h"
#include "common_tiles.h"
#include "memory.h"
#include "../libs.h"
#include "../util.h"
#include "../input.h"
#include "../display/common.h"
#include "../display/tilemap.h"
#include "queue.h"
#define BORDER_TILE_TOP_LEFT BORDER_DATA_POSITION
#define BORDER_TILE_TOP_CENTER BORDER_TILE_TOP_LEFT + 1
@@ -41,6 +43,6 @@ extern uint8_t TEXTBOX_STATE;
extern uint8_t TEXTBOX_SCROLL;
extern uint8_t TEXTBOX_TILES[];
void textboxInit();
void textboxSetText(char *text, uint8_t length);
void textboxUpdate();
void conversationTextboxInit();
void conversationTextboxSetText(char *text, uint8_t length);
void conversationTextboxUpdate();

View File

@@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT
*/
#include "common_tiles.h"
#include "common.h"
const uint8_t COMMON_TILES[] = {
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

View File

@@ -6,7 +6,7 @@
*/
#pragma once
#include "libs.h"
#include "../libs.h"
#define COMMON_TILE_COUNT 0x04

View File

@@ -5,5 +5,6 @@
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "libs.h"
#include "input.h"
uint8_t INPUT_STATE = 0x00;

View File

@@ -7,6 +7,8 @@
#pragma once
#include <gb/gb.h>
#include <gb/bgb_emu.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdbool.h>
#include <rand.h>

View File

@@ -5,48 +5,58 @@
* https://opensource.org/licenses/MIT
*/
#include "libs.h"
#include "textbox.h"
#include "time.h"
#include "common_tiles.h"
#include "memory.h"
#include "HELLO.h"
#include "main.h"
void main() {
int16_t j;
uint8_t filled[0x20*0x20];
uint8_t filled[GB_BACKGROUND_COLUMNS*GB_BACKGROUND_ROWS];
// Set up the GAMEBOY's registers.
disable_interrupts();
DISPLAY_OFF;
LCDC_REG = LCDCF_OFF | LCDCF_WIN9C00 | LCDCF_BG8800 | LCDCF_BG9800 | LCDCF_BGON;
BGP_REG = OBP0_REG = OBP1_REG = 0xE4U;
BGP_REG = 0xE4U;
// Prepare tiles.
// Init the random seed
initarand(DIV_REG);
// Prepare time and input
TIME_CURRENT = 0;
INPUT_STATE = joypad();
// Init things
commonTilesInit();
textboxInit();
set_bkg_data(SM_DATA_POSITION, SM_IMAGE_TILES, SM_IMAGE);
conversationTextboxInit();
conversationPauseInit();
conversationQueueInit();
pokerInit();
// Fill screen white
for(j = 0; j < 0x20*0x20; j++) filled[j] = COMMON_TILE_3;
set_bkg_tiles(0x00, 0x00, 0x20, 0x20, filled);
uint8_t sm[SM_IMAGE_TILES];
for(j = 0; j < SM_IMAGE_TILES; j++) sm[j] = j + SM_DATA_POSITION;
set_bkg_tiles(0x00, 0x00, SM_IMAGE_COLUMNS, SM_IMAGE_ROWS, sm);
set_bkg_tiles(0x00, 0x00, GB_BACKGROUND_COLUMNS, GB_BACKGROUND_ROWS, filled);
SCX_REG = 0x00;
SCY_REG = 0x00;
// Now turn the screen on
DISPLAY_ON;
enable_interrupts();
wait_vbl_done();
// Testing.
textboxSetText(STR_HELLO_DATA, STR_HELLO_LENGTH);
// Alright begin the game logic here.
conversationQueueNext();
// Begin the loop
while(1) {
// Wait for VSYNC
wait_vbl_done();
textboxUpdate();
time++;
// Update the input state
INPUT_STATE = joypad();
conversationTextboxUpdate();
conversationPauseUpdate();
// Tick time.
TIME_CURRENT++;
}
}

23
src/main.h Normal file
View File

@@ -0,0 +1,23 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "libs.h"
#include "time.h"
#include "display/common.h"
#include "display/tilemap.h"
#include "poker/poker.h"
#include "conversation/pause.h"
#include "conversation/queue.h"
#include "conversation/textbox.h"
#define GB_BACKGROUND_COLUMNS 0x20
#define GB_BACKGROUND_ROWS 0x20
void main();

107
src/poker/card.h Normal file
View File

@@ -0,0 +1,107 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
////////////////////////////////////////////////////////////////////////////////
// Cards
////////////////////////////////////////////////////////////////////////////////
// Aces
#define CARD_CLUBS_TWO 0x00
#define CARD_CLUBS_THREE 0x01
#define CARD_CLUBS_FOUR 0x02
#define CARD_CLUBS_FIVE 0x03
#define CARD_CLUBS_SIX 0x04
#define CARD_CLUBS_SEVEN 0x05
#define CARD_CLUBS_EIGHT 0x06
#define CARD_CLUBS_NINE 0x07
#define CARD_CLUBS_TEN 0x08
#define CARD_CLUBS_JACK 0x09
#define CARD_CLUBS_QUEEN 0x0A
#define CARD_CLUBS_KING 0x0B
#define CARD_CLUBS_ACE 0x0C
// Diamonds
#define CARD_DIAMONDS_TWO 0x0D
#define CARD_DIAMONDS_THREE 0x0E
#define CARD_DIAMONDS_FOUR 0x0F
#define CARD_DIAMONDS_FIVE 0x10
#define CARD_DIAMONDS_SIX 0x11
#define CARD_DIAMONDS_SEVEN 0x12
#define CARD_DIAMONDS_EIGHT 0x13
#define CARD_DIAMONDS_NINE 0x14
#define CARD_DIAMONDS_TEN 0x15
#define CARD_DIAMONDS_JACK 0x16
#define CARD_DIAMONDS_QUEEN 0x17
#define CARD_DIAMONDS_KING 0x18
#define CARD_DIAMONDS_ACE 0x19
// Hearts
#define CARD_HEARTS_TWO 0x1A
#define CARD_HEARTS_THREE 0x1B
#define CARD_HEARTS_FOUR 0x1C
#define CARD_HEARTS_FIVE 0x1D
#define CARD_HEARTS_SIX 0x1E
#define CARD_HEARTS_SEVEN 0x1F
#define CARD_HEARTS_EIGHT 0x20
#define CARD_HEARTS_NINE 0x21
#define CARD_HEARTS_TEN 0x22
#define CARD_HEARTS_JACK 0x23
#define CARD_HEARTS_QUEEN 0x24
#define CARD_HEARTS_KING 0x25
#define CARD_HEARTS_ACE 0x26
// Spades
#define CARD_SPADES_TWO 0x27
#define CARD_SPADES_THREE 0x28
#define CARD_SPADES_FOUR 0x29
#define CARD_SPADES_FIVE 0x2A
#define CARD_SPADES_SIX 0x2B
#define CARD_SPADES_SEVEN 0x2C
#define CARD_SPADES_EIGHT 0x2D
#define CARD_SPADES_NINE 0x2E
#define CARD_SPADES_TEN 0x2F
#define CARD_SPADES_JACK 0x30
#define CARD_SPADES_QUEEN 0x31
#define CARD_SPADES_KING 0x32
#define CARD_SPADES_ACE 0x33
////////////////////////////////////////////////////////////////////////////////
// Suits
////////////////////////////////////////////////////////////////////////////////
#define CARD_SUIT_CLUBS 0x00
#define CARD_SUIT_DIAMONDS 0x01
#define CARD_SUIT_HEARTS 0x02
#define CARD_SUIT_SPADES 0x03
////////////////////////////////////////////////////////////////////////////////
// Card numbers
////////////////////////////////////////////////////////////////////////////////
#define CARD_TWO 0x00
#define CARD_THREE 0x01
#define CARD_FOUR 0x02
#define CARD_FIVE 0x03
#define CARD_SIX 0x04
#define CARD_SEVEN 0x05
#define CARD_EIGHT 0x06
#define CARD_NINE 0x07
#define CARD_TEN 0x08
#define CARD_JACK 0x09
#define CARD_QUEEN 0x0A
#define CARD_KING 0x0B
#define CARD_ACE 0x0C
/** Count of cards in each suit */
#define CARD_COUNT_PER_SUIT 13
/** Count of suits */
#define CARD_SUIT_COUNT 4
/** Standard Card Deck Size */
#define CARD_DECK_SIZE 52

29
src/poker/player.h Normal file
View File

@@ -0,0 +1,29 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#include "card.h"
#define POKER_PLAYER_COUNT_MAX 4
#define POKER_PLAYER_HAND_SIZE_MAX 2
#define POKER_PLAYER_STATE_FOLDED 1 << 0
#define POKER_PLAYER_STATE_OUT 1 << 1
#define POKER_PLAYER_STATE_HAS_BET_THIS_ROUND 1 << 2
// #define POKER_PLAYER_STATE_SHOWING 1 << 3
typedef struct {
uint16_t chips;
uint8_t hand[POKER_PLAYER_HAND_SIZE_MAX];
uint8_t state;
// int32_t currentBet;
// uint8_t timesRaised;
} pokerplayer_t;
extern pokerplayer_t POKER_PLAYERS[];

88
src/poker/poker.c Normal file
View File

@@ -0,0 +1,88 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "poker.h"
pokerplayer_t POKER_PLAYERS[POKER_PLAYER_COUNT_MAX];
uint8_t POKER_DECK[CARD_DECK_SIZE];
uint8_t POKER_DECK_SIZE;
uint8_t POKER_COMMUNITY[POKER_COMMUNITY_SIZE_MAX];
uint8_t POKER_COMMUNITY_SIZE;
uint8_t POKER_PLAYER_DEALER;
uint8_t POKER_PLAYER_SMALL_BLIND;
uint8_t POKER_PLAYER_BIG_BLIND;
void pokerInit() {
uint8_t i;
// Set up players
for(i = 0; i < POKER_PLAYER_COUNT_MAX; i++) {
POKER_PLAYERS[i].chips = 10000;
POKER_PLAYERS[i].state = 0;
}
// Set up the initial state.
// TODO: Should this be randomized?
POKER_PLAYER_DEALER = 0;
// Reset the round state (For the first round)
pokerNewRound();
}
void pokerNewRound() {
uint8_t i, j, k;
uint8_t found;
// Reset round state
POKER_COMMUNITY_SIZE = 0;
// Fill deck
for(i = 0; i < CARD_DECK_SIZE; i++) POKER_DECK[i] = i;
POKER_DECK_SIZE = CARD_DECK_SIZE;
// Shuffle Deck
for(i = CARD_DECK_SIZE-1; i > 0; i--) {
k = POKER_DECK[i];
j = rand() % (i+1);
POKER_DECK[i] = POKER_DECK[j];
POKER_DECK[j] = k;
}
// Reset Players and decide new blinds.
found = 0;
POKER_PLAYER_DEALER++;
for(i = 0; i < POKER_PLAYER_COUNT_MAX; i++) {
POKER_PLAYERS[i].state &= ~(
POKER_PLAYER_STATE_FOLDED |
POKER_PLAYER_STATE_HAS_BET_THIS_ROUND
);
// Have we found the dealer, small blind, and big blind players?
if(found != 3 && (POKER_PLAYERS[i].state & POKER_PLAYER_STATE_OUT) == 0){
k = (POKER_PLAYER_DEALER + i) % POKER_PLAYER_COUNT_MAX;
if(found == 0) {// Have we found the dealer?
POKER_PLAYER_DEALER = i;
found++;
} else if(found == 1) {// Have we found the small blind?
POKER_PLAYER_SMALL_BLIND = i;
found++;
} else if(found == 2) {// Have we found the big blind?
POKER_PLAYER_BIG_BLIND = i;
found++;
}
}
// Deal two cards to the player.
for(j = 0; j < POKER_PLAYER_HAND_SIZE_MAX; j++) {
POKER_PLAYERS[i].hand[j] = POKER_DECK[POKER_DECK_SIZE--];
}
}
}

27
src/poker/poker.h Normal file
View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) 2022 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "../libs.h"
#include "card.h"
#include "player.h"
#define POKER_COMMUNITY_SIZE_MAX 5
extern uint8_t POKER_DECK[];
extern uint8_t POKER_DECK_SIZE;
extern uint8_t POKER_COMMUNITY[];
extern uint8_t POKER_COMMUNITY_SIZE;
extern uint8_t POKER_PLAYER_DEALER;
extern uint8_t POKER_PLAYER_SMALL_BLIND;
extern uint8_t POKER_PLAYER_BIG_BLIND;
void pokerInit();
void pokerNewRound();

View File

@@ -7,4 +7,4 @@
#include "time.h"
uint8_t time = 0;
uint16_t TIME_CURRENT;

View File

@@ -8,4 +8,5 @@
#pragma once
#include "libs.h"
extern uint8_t time;
#define TIME_PER_SECOND 60
extern uint16_t TIME_CURRENT;