Joining the two logics together slowly.
This commit is contained in:
@ -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"
|
@ -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;
|
15
include/dawn/game/poker/pokergameassets.h
Normal file
15
include/dawn/game/poker/pokergameassets.h
Normal file
@ -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;
|
@ -5,6 +5,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// Settings
|
||||
#include "settings.h"
|
||||
|
||||
// Static Libs
|
||||
#include <cglm/cglm.h>
|
||||
#include <glad/glad.h>
|
||||
|
10
include/dawn/settings.h
Normal file
10
include/dawn/settings.h
Normal file
@ -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"
|
@ -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;
|
||||
|
27
include/dawn/vn/vnscene.h
Normal file
27
include/dawn/vn/vnscene.h
Normal file
@ -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;
|
@ -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;
|
||||
|
||||
// Hand off to the poker logic.
|
||||
pokerInit(&game->pokerGame.poker, &game->engine);
|
||||
// Load the Assets
|
||||
pokerGameAssetsInit(&pokerGame->assets);
|
||||
|
||||
// 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);
|
||||
}
|
@ -7,7 +7,13 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#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.
|
||||
|
20
src/game/poker/pokergameassets.c
Normal file
20
src/game/poker/pokergameassets.c
Normal file
@ -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);
|
||||
}
|
13
src/game/poker/pokergameassets.h
Normal file
13
src/game/poker/pokergameassets.h
Normal file
@ -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 <dawn/dawn.h>
|
||||
#include "../../file/asset.h"
|
||||
|
||||
bool pokerGameAssetsInit(pokergameassets_t *assets);
|
||||
void pokerGameAssetsDispose(pokergameassets_t *assets);
|
35
src/poker/actions/match.c
Normal file
35
src/poker/actions/match.c
Normal file
@ -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;
|
||||
}
|
20
src/poker/actions/match.h
Normal file
20
src/poker/actions/match.h
Normal file
@ -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 <dawn/dawn.h>
|
||||
#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);
|
68
src/poker/actions/round.c
Normal file
68
src/poker/actions/round.c
Normal file
@ -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;
|
||||
}
|
25
src/poker/actions/round.h
Normal file
25
src/poker/actions/round.h
Normal file
@ -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 <dawn/dawn.h>
|
||||
#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);
|
@ -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) {
|
||||
}
|
@ -7,23 +7,3 @@
|
||||
|
||||
#pragma once
|
||||
#include <dawn/dawn.h>
|
||||
#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);
|
@ -11,6 +11,9 @@ 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) {
|
||||
@ -23,6 +26,7 @@ void _vnConversationTalkUpdate(queue_t *queue,queueaction_t *action,uint8_t i) {
|
||||
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);
|
||||
}
|
||||
|
@ -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
|
||||
|
84
src/vn/vnscene.c
Normal file
84
src/vn/vnscene.c
Normal file
@ -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);
|
||||
}
|
24
src/vn/vnscene.h
Normal file
24
src/vn/vnscene.h
Normal file
@ -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 <dawn/dawn.h>
|
||||
#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);
|
Reference in New Issue
Block a user