diff --git a/include/dawn/dawn.h b/include/dawn/dawn.h index bbe2ac79..69460f24 100644 --- a/include/dawn/dawn.h +++ b/include/dawn/dawn.h @@ -36,7 +36,9 @@ // Game Logic #include "game/game.h" + #include "game/poker/pokergame.h" +#include "game/poker/pokergameassets.h" // Player Input #include "input/input.h" @@ -58,4 +60,5 @@ // Visual Novel Objects #include "vn/vncharacter.h" #include "vn/vnconversation.h" +#include "vn/vnscene.h" #include "vn/vntextbox.h" \ No newline at end of file diff --git a/include/dawn/game/poker/pokergame.h b/include/dawn/game/poker/pokergame.h index afd38aae..41582108 100644 --- a/include/dawn/game/poker/pokergame.h +++ b/include/dawn/game/poker/pokergame.h @@ -7,7 +7,10 @@ #pragma once #include "../../libs.h" +#include "pokergameassets.h" #include "../../poker/poker.h" +#include "../../vn/vnconversation.h" +#include "../../vn/vnscene.h" /** Name of the Poker Game */ #define POKER_GAME_NAME "Dawn Poker Game" @@ -15,4 +18,10 @@ typedef struct { /** Poker Game State */ poker_t poker; + + /** Visual Novel Engine */ + vnscene_t scene; + + /** Assets for the game. */ + pokergameassets_t assets; } pokergame_t; \ No newline at end of file diff --git a/include/dawn/game/poker/pokergameassets.h b/include/dawn/game/poker/pokergameassets.h new file mode 100644 index 00000000..3109a194 --- /dev/null +++ b/include/dawn/game/poker/pokergameassets.h @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "../../display/gui/font.h" +#include "../../display/shader.h" + +typedef struct { + font_t font; + shader_t shader; +} pokergameassets_t; \ No newline at end of file diff --git a/include/dawn/libs.h b/include/dawn/libs.h index 552810e5..1a33feb8 100644 --- a/include/dawn/libs.h +++ b/include/dawn/libs.h @@ -5,6 +5,9 @@ #pragma once +// Settings +#include "settings.h" + // Static Libs #include #include diff --git a/include/dawn/settings.h b/include/dawn/settings.h new file mode 100644 index 00000000..8e4e5552 --- /dev/null +++ b/include/dawn/settings.h @@ -0,0 +1,10 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once + +#define SETTING_GAME "poker" \ No newline at end of file diff --git a/include/dawn/vn/vnconversation.h b/include/dawn/vn/vnconversation.h index 8ca554ae..fcbf7fe4 100644 --- a/include/dawn/vn/vnconversation.h +++ b/include/dawn/vn/vnconversation.h @@ -8,6 +8,7 @@ #pragma once #include "../libs.h" #include "../display/animation/queue.h" +#include "vncharacter.h" #include "vntextbox.h" typedef struct _vnconversation_t vnconversation_t; diff --git a/include/dawn/vn/vnscene.h b/include/dawn/vn/vnscene.h new file mode 100644 index 00000000..3b60fe5f --- /dev/null +++ b/include/dawn/vn/vnscene.h @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "../libs.h" +#include "vncharacter.h" +#include "vnconversation.h" +#include "vntextbox.h" + +/** Maximum number of Visual Novel Characters the scene can support */ +#define VN_SCENE_CHARACTERS_MAX 6 + +typedef struct { + /** Camera used for rendering, updated frequently */ + camera_t camera; + + /** Internal conversation element */ + vnconversation_t conversation; + + /** Character array */ + vncharacter_t characters[VN_SCENE_CHARACTERS_MAX]; + uint8_t characterCount; +} vnscene_t; \ No newline at end of file diff --git a/src/game/poker/pokergame.c b/src/game/poker/pokergame.c index f243b883..6a200a63 100644 --- a/src/game/poker/pokergame.c +++ b/src/game/poker/pokergame.c @@ -8,16 +8,45 @@ #include "pokergame.h" bool pokerGameInit(game_t *game) { + pokergame_t *pokerGame = &game->pokerGame; + // Init the game game->name = POKER_GAME_NAME; + + // Load the Assets + pokerGameAssetsInit(&pokerGame->assets); - // Hand off to the poker logic. - pokerInit(&game->pokerGame.poker, &game->engine); -} + // Prep the VN Conversation Engine. + vnSceneInit(&pokerGame->scene, &pokerGame->assets.font); + + vnConversationTalk(&pokerGame->scene.conversation, "Start Match", NULL); + pokerActionMatchAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker); + vnConversationTalk(&pokerGame->scene.conversation, "Start Round", NULL); + pokerActionRoundAdd(&pokerGame->scene.conversation.actionQueue, &pokerGame->poker); + vnConversationTalk(&pokerGame->scene.conversation, "Betting Round", NULL); + + // Begin the VN conversation queue. + queueNext(&pokerGame->scene.conversation.actionQueue); + + return true; +} void pokerGameUpdate(game_t *game) { + pokergame_t *pokerGame; + pokerGame = &game->pokerGame; + + // Update the scene + vnSceneUpdate(&pokerGame->scene, &game->engine); + + // Bind the shader. + shaderUse(&pokerGame->assets.shader); + + // Render the visual novel scene + vnSceneRenderWorld(&pokerGame->scene, &game->engine, &pokerGame->assets.shader); + vnSceneRenderGui(&pokerGame->scene, &game->engine, &pokerGame->assets.shader); } void pokerGameDispose(game_t *game) { - + vnSceneDispose(&game->pokerGame.scene); + pokerGameAssetsDispose(&game->pokerGame.assets); } \ No newline at end of file diff --git a/src/game/poker/pokergame.h b/src/game/poker/pokergame.h index 108e64c6..0e9bf0e1 100644 --- a/src/game/poker/pokergame.h +++ b/src/game/poker/pokergame.h @@ -7,7 +7,13 @@ #pragma once #include +#include "pokergameassets.h" #include "../../poker/poker.h" +#include "../../vn/conversation/talk.h" +#include "../../vn/vnscene.h" + +#include "../../poker/actions/match.h" +#include "../../poker/actions/round.h" /** * Initializes the game state for the poker game. diff --git a/src/game/poker/pokergameassets.c b/src/game/poker/pokergameassets.c new file mode 100644 index 00000000..e33d4f27 --- /dev/null +++ b/src/game/poker/pokergameassets.c @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ +#include "pokergameassets.h" + +bool pokerGameAssetsInit(pokergameassets_t *assets) { + assetFontLoad(&assets->font, "fonts/opensans/OpenSans-Bold.ttf"); + assetShaderLoad(&assets->shader, + "shaders/textured.vert", "shaders/textured.frag" + ); + return true; +} + +void pokerGameAssetsDispose(pokergameassets_t *assets) { + shaderDispose(&assets->shader); + fontDispose(&assets->font); +} \ No newline at end of file diff --git a/src/game/poker/pokergameassets.h b/src/game/poker/pokergameassets.h new file mode 100644 index 00000000..95f61902 --- /dev/null +++ b/src/game/poker/pokergameassets.h @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "../../file/asset.h" + +bool pokerGameAssetsInit(pokergameassets_t *assets); +void pokerGameAssetsDispose(pokergameassets_t *assets); \ No newline at end of file diff --git a/src/poker/actions/match.c b/src/poker/actions/match.c new file mode 100644 index 00000000..f64dc610 --- /dev/null +++ b/src/poker/actions/match.c @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "match.h" + +void _pokerActionMatchOnStart(queue_t *queue, queueaction_t *action, uint8_t i){ + poker_t *poker; + uint8_t x; + + poker = (poker_t *)action->data; + + // Reset the main game state. This does not init the round. + pokerBetInit(&poker->bet); + poker->roundDealer = POKER_PLAYER_COUNT-2; + poker->round = POKER_ROUND_MATCH; + + for(x = 0; x < POKER_PLAYER_COUNT; x++) { + poker->players[x].state = 0x00; + poker->players[x].chips = POKER_BET_PLAYER_CHIPS_DEFAULT; + } + printf("Match Start\n"); + queueNext(queue); +} + +queueaction_t * pokerActionMatchAdd(queue_t *queue, poker_t *poker) { + queueaction_t *action; + action = queueAdd(queue); + action->data = (void *)poker; + action->onStart = &_pokerActionMatchOnStart; + return action; +} \ No newline at end of file diff --git a/src/poker/actions/match.h b/src/poker/actions/match.h new file mode 100644 index 00000000..96b7b449 --- /dev/null +++ b/src/poker/actions/match.h @@ -0,0 +1,20 @@ +// Copyright (c) 2021 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include +#include "../../display/animation/queue.h" + +/** Callback for when the poker match aciton starts */ +void _pokerActionMatchOnStart(queue_t *queue, queueaction_t *action, uint8_t i); + +/** + * Adds a Poker Match Begin Action onto a queue. + * + * @param queue Queue to add to + * @param poker Poker game instance to use. + * @return The queued match start action. + */ +queueaction_t * pokerActionMatchAdd(queue_t *queue, poker_t *poker); \ No newline at end of file diff --git a/src/poker/actions/round.c b/src/poker/actions/round.c new file mode 100644 index 00000000..9c5bb921 --- /dev/null +++ b/src/poker/actions/round.c @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "round.h" + +void _pokerActionRoundOnStart(queue_t *queue, queueaction_t *action ,uint8_t i){ + uint8_t j, indexDealer, indexSmallBlind, indexBigBlind; + bool foundDealer, foundSmallBlind; + pokerplayer_t *player; + poker_t *poker; + + poker = (poker_t *)action->data; + + poker->round = POKER_ROUND_START; + + // Prepare the initial game state + poker->round = POKER_ROUND_DEAL; + pokerBetReset(&poker->bet); + pokerDealerInit(&poker->dealer); + + // Reset the players + for(i = 0; i < POKER_PLAYER_COUNT; i++) { + pokerPlayerReset(poker->players + i); + } + + // Decide on the dealer + poker->roundDealer = (poker->roundDealer+1) % POKER_PLAYER_COUNT; + + // Find the players. + j = poker->roundDealer; + foundDealer = false; + foundSmallBlind = false; + while(true) { + player = poker->players + j; + if(!pokerPlayerIsAlive(player)) continue; + if(!foundDealer) { + indexDealer = j; + foundDealer = true; + } else if(!foundSmallBlind) { + indexSmallBlind = j; + foundSmallBlind = true; + } else { + indexBigBlind = j; + break; + } + j = (j + 1) % POKER_PLAYER_COUNT; + } + + // Update players for the round. + poker->roundDealer = indexDealer; + poker->roundBigBlind = indexBigBlind; + poker->roundSmallBlind = indexSmallBlind; + + printf("Round Start\n"); + queueNext(queue); +} + +queueaction_t * pokerActionRoundAdd(queue_t *queue, poker_t *poker) { + queueaction_t *action; + action = queueAdd(queue); + action->data = (void *)poker; + action->onStart = &_pokerActionRoundOnStart; + return action; +} \ No newline at end of file diff --git a/src/poker/actions/round.h b/src/poker/actions/round.h new file mode 100644 index 00000000..bd7853b6 --- /dev/null +++ b/src/poker/actions/round.h @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "../../display/animation/queue.h" +#include "../bet.h" +#include "../player.h" + +/** Callback for when the poker round start aciton begins. */ +void _pokerActionRoundOnStart(queue_t *queue, queueaction_t *action, uint8_t i); + +/** + * Queues the round action onto a queue. Round action should be queued at the + * start of every poker round. + * + * @param queue Queue to add to. + * @param poker Poker game instance. + * @return The queued action. + */ +queueaction_t * pokerActionRoundAdd(queue_t *queue, poker_t *poker); \ No newline at end of file diff --git a/src/poker/poker.c b/src/poker/poker.c index b145ee25..6e1e0760 100644 --- a/src/poker/poker.c +++ b/src/poker/poker.c @@ -6,27 +6,3 @@ */ #include "poker.h" - -void pokerInit(poker_t *poker) { - -} - -void pokerUpdate(poker_t *poker, engine_t *engine) { - // Game Logic - switch(poker->round) { - case POKER_ROUND_MATCH: - pokerMatchUpdate(poker, engine); - break; - case POKER_ROUND_BET0: - case POKER_ROUND_BET1: - case POKER_ROUND_BET2: - case POKER_ROUND_BET3: - pokerRoundBetUpdate(poker); - break; - default: - break; - } -} - -void pokerDispose(poker_t * poker) { -} \ No newline at end of file diff --git a/src/poker/poker.h b/src/poker/poker.h index f9624a6b..97d43ce5 100644 --- a/src/poker/poker.h +++ b/src/poker/poker.h @@ -6,24 +6,4 @@ */ #pragma once -#include -#include "round/match.h" - -/** - * Initializes the poker context for the first time. - * @param poker Poker context to initialize. - */ -void pokerInit(poker_t *poker); - -/** - * Updates the poker context. - * @param poker Poker game context. - * @param engine Engine that is running the game. - */ -void pokerUpdate(poker_t *poker, engine_t *engine); - -/** - * Cleans an existing poker game instance. - * @param poker Poker instance to cleanup - */ -void pokerDispose(poker_t *poker); \ No newline at end of file +#include \ No newline at end of file diff --git a/src/vn/conversation/talk.c b/src/vn/conversation/talk.c index ba3e9559..7e83d233 100644 --- a/src/vn/conversation/talk.c +++ b/src/vn/conversation/talk.c @@ -10,7 +10,10 @@ void _vnConversationTalkStart(queue_t *queue,queueaction_t *action,uint8_t i) { vnconversationitemdata_t *data; data = (vnconversationitemdata_t *)action->data; - + + printf("Speaking "); + printf(data->text); + printf("\n"); vnTextBoxSetText(&data->conversation->textbox, data->text); if(data->character != NULL) { @@ -21,8 +24,9 @@ void _vnConversationTalkStart(queue_t *queue,queueaction_t *action,uint8_t i) { void _vnConversationTalkUpdate(queue_t *queue,queueaction_t *action,uint8_t i) { vnconversationitemdata_t *data; data = (vnconversationitemdata_t *)action->data; - + if(data->conversation->textbox.state & VN_TEXTBOX_STATE_CLOSED) { + printf("Spoke\n"); if(data->character != NULL) data->character->talking = false; queueNext(queue); } diff --git a/src/vn/gui/vntextbox.c b/src/vn/gui/vntextbox.c index 4487dbbf..3756c319 100644 --- a/src/vn/gui/vntextbox.c +++ b/src/vn/gui/vntextbox.c @@ -21,6 +21,7 @@ void vnTextBoxSetText(vntextbox_t *box, char *text) { box->text = text; box->lineCurrent = 0; box->state = 0; + box->textScroll = 0; vnTextBoxRebuffer(box); } @@ -35,6 +36,7 @@ void vnTextBoxRebuffer(vntextbox_t *box) { fontTextClamp(box->font, &box->textInfo, box->text, box->widthMax); fontTextInit(box->font, &box->primitive, &box->textInfo); + // Test "Background" quadInit(&box->testPrimitive, 0, 0, 0, 0.3, 0.3, box->textInfo.width, box->textInfo.height, 0.6, 0.6 diff --git a/src/vn/vnscene.c b/src/vn/vnscene.c new file mode 100644 index 00000000..99d241dd --- /dev/null +++ b/src/vn/vnscene.c @@ -0,0 +1,84 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "vnscene.h" + +void vnSceneInit(vnscene_t *scene, font_t *font) { + // Init the conversation + vnConversationInit(&scene->conversation, font); + scene->conversation.textbox.linesMax = 3; + + // Reset character count + scene->characterCount = 0x00; +} + +void vnSceneUpdate(vnscene_t *scene, engine_t *engine) { + uint8_t i; + + // Update the conversation + vnConversationUpdate(&scene->conversation, engine); + + // Update the character states + for(i = 0; i < scene->characterCount; i++) { + vnCharacterUpdate(scene->characters + i, engine); + } +} + +void vnSceneDispose(vnscene_t *scene) { + vnConversationDispose(&scene->conversation); +} + +void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader) { + uint8_t i; + + // Adjust 3D Space position + cameraLookAt(&scene->camera, + 0.5, 0.5, 0.75, + 0.5, 0.5, -0.5 + ); + + // Set Camera Perspective + cameraPerspective(&scene->camera, 75, + engine->render.width/engine->render.height, + 0.01, 1000.0 + ); + + // Update Shader + shaderUseCamera(shader, &scene->camera); + + // Render each character + for(i = 0; i < scene->characterCount; i++) { + vnCharacterRender(scene->characters + i, shader); + } +} + +void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, shader_t *shader) { + // Do we need to update the width of the GUI element(s) ? + if(engine->render.width != scene->conversation.textbox.widthMax) { + scene->conversation.textbox.widthMax = engine->render.width; + vnTextBoxRebuffer(&scene->conversation.textbox); + } + + // Move the camera in space + cameraLookAt(&scene->camera, + 0, 0, 10, + 0, 0, 0 + ); + + // Orthogonalize Camera + cameraOrtho(&scene->camera, + 0, engine->render.width, + engine->render.height, 0, + 0.01, 1000.0 + ); + + // Update Shader + shaderUseCamera(shader, &scene->camera); + + // Render Conversation Element + vnConversationRender(&scene->conversation, shader); +} \ No newline at end of file diff --git a/src/vn/vnscene.h b/src/vn/vnscene.h new file mode 100644 index 00000000..3b1d5008 --- /dev/null +++ b/src/vn/vnscene.h @@ -0,0 +1,24 @@ +/** + * Copyright (c) 2021 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include +#include "vncharacter.h" +#include "conversation/vnconversation.h" +#include "gui/vntextbox.h" +#include "../display/camera.h" +#include "../display/shader.h" + +void vnSceneInit(vnscene_t *scene, font_t *font); + +void vnSceneUpdate(vnscene_t *scene, engine_t *engine); + +void vnSceneDispose(vnscene_t *scene); + +void vnSceneRenderWorld(vnscene_t *scene, engine_t *engine, shader_t *shader); + +void vnSceneRenderGui(vnscene_t *scene, engine_t *engine, shader_t *shader); \ No newline at end of file diff --git a/src/poker/round/bet.c b/temp/round/bet.c similarity index 100% rename from src/poker/round/bet.c rename to temp/round/bet.c diff --git a/src/poker/round/bet.h b/temp/round/bet.h similarity index 100% rename from src/poker/round/bet.h rename to temp/round/bet.h diff --git a/src/poker/round/blinds.c b/temp/round/blinds.c similarity index 100% rename from src/poker/round/blinds.c rename to temp/round/blinds.c diff --git a/src/poker/round/blinds.h b/temp/round/blinds.h similarity index 100% rename from src/poker/round/blinds.h rename to temp/round/blinds.h diff --git a/src/poker/round/deal.c b/temp/round/deal.c similarity index 100% rename from src/poker/round/deal.c rename to temp/round/deal.c diff --git a/src/poker/round/deal.h b/temp/round/deal.h similarity index 100% rename from src/poker/round/deal.h rename to temp/round/deal.h diff --git a/src/poker/round/flop.c b/temp/round/flop.c similarity index 100% rename from src/poker/round/flop.c rename to temp/round/flop.c diff --git a/src/poker/round/flop.h b/temp/round/flop.h similarity index 100% rename from src/poker/round/flop.h rename to temp/round/flop.h diff --git a/src/poker/round/match.c b/temp/round/match.c similarity index 100% rename from src/poker/round/match.c rename to temp/round/match.c diff --git a/src/poker/round/match.h b/temp/round/match.h similarity index 100% rename from src/poker/round/match.h rename to temp/round/match.h diff --git a/src/poker/round/start.c b/temp/round/start.c similarity index 100% rename from src/poker/round/start.c rename to temp/round/start.c diff --git a/src/poker/round/start.h b/temp/round/start.h similarity index 100% rename from src/poker/round/start.h rename to temp/round/start.h diff --git a/src/poker/round/winner.c b/temp/round/winner.c similarity index 100% rename from src/poker/round/winner.c rename to temp/round/winner.c diff --git a/src/poker/round/winner.h b/temp/round/winner.h similarity index 100% rename from src/poker/round/winner.h rename to temp/round/winner.h