aboutsummaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-09-27 17:03:06 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-11-01 16:26:16 +0100
commit980858186149651df5543b6fc99a4f7db0cdd089 (patch)
treed347200b0a562d84df505097651ad0642f207fdd /src/game
parent39f50e601d395bbd2d78d0147ac530b756da2fff (diff)
downloadjancity-980858186149651df5543b6fc99a4f7db0cdd089.tar.gz
WIP
Diffstat (limited to 'src/game')
-rw-r--r--src/game/CMakeLists.txt2
-rw-r--r--src/game/inc/game.h22
-rw-r--r--src/game/src/game.c73
3 files changed, 54 insertions, 43 deletions
diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt
index 0c21b0c..ce76968 100644
--- a/src/game/CMakeLists.txt
+++ b/src/game/CMakeLists.txt
@@ -1,6 +1,6 @@
add_library(game "src/game.c" "src/res.c")
target_include_directories(game PUBLIC "inc" PRIVATE "privinc")
-target_link_libraries(game PRIVATE
+target_link_libraries(game PUBLIC peripheral PRIVATE
building
container
font
diff --git a/src/game/inc/game.h b/src/game/inc/game.h
index 5298b9f..66e5e79 100644
--- a/src/game/inc/game.h
+++ b/src/game/inc/game.h
@@ -1,15 +1,35 @@
#ifndef GAME_H
#define GAME_H
-#include <stddef.h>
+#include <peripheral.h>
#ifdef __cplusplus
extern "C"
{
#endif
+enum
+{
+ GAME_MAX_PLAYERS = 4,
+ GAME_PLAYER_NAME_LEN = 16
+};
+
struct game_cfg
{
+ struct game_cfg_player
+ {
+ enum game_cfg_player_type
+ {
+ GAME_CFG_PLAYER_TYPE_HUMAN,
+ GAME_CFG_PLAYER_TYPE_BOT,
+ GAME_CFG_PLAYER_TYPE_NET
+ } type;
+
+ char name[GAME_PLAYER_NAME_LEN];
+ } *players;
+
+ size_t n;
+ union peripheral *p;
};
int game_resinit(void);
diff --git a/src/game/src/game.c b/src/game/src/game.c
index 83be2fd..baf9a86 100644
--- a/src/game/src/game.c
+++ b/src/game/src/game.c
@@ -11,36 +11,32 @@
int game(const struct game_cfg *const cfg)
{
int ret = -1;
- enum {HUMAN_PLAYERS = 1, MAP_RESOURCES = 3};
- struct human_player humans[HUMAN_PLAYERS];
+ enum {MAP_RESOURCES = 3};
+ struct human_player human;
struct terrain_map map;
terrain_init(&map);
building_set_alive_cb(terrain_block_update, &map);
- for (size_t i = 0; i < sizeof humans / sizeof *humans; i++)
+ const struct human_player_cfg hcfg =
{
- const struct human_player_cfg cfg =
+ .p = cfg->p,
+ .dim =
{
- .sel_periph = PERIPHERAL_TYPE_KEYBOARD_MOUSE,
- .padn = i,
- .dim =
- {
- .w = MAP_W,
- .h = MAP_H,
- },
+ .w = MAP_W,
+ .h = MAP_H,
+ },
- .pl =
- {
- .team = PLAYER_COLOR_BLUE,
- .x = 80,
- .y = 40
- }
- };
+ .pl =
+ {
+ .team = PLAYER_COLOR_BLUE,
+ .x = 80,
+ .y = 40
+ }
+ };
- if (human_player_init(&cfg, &humans[i]))
- goto end;
- }
+ if (human_player_init(&hcfg, &human))
+ goto end;
struct resource res[MAP_RESOURCES] = {0};
@@ -72,28 +68,23 @@ int game(const struct game_cfg *const cfg)
{
system_loop();
- for (size_t i = 0; i < sizeof humans / sizeof *humans; i++)
+ if (human.pl.alive)
{
- const struct human_player *const h = &humans[i];
-
- if (h->pl.alive)
+ struct player_others o =
{
- struct player_others o =
- {
- .res = res,
- .n_res = sizeof res / sizeof *res
- };
-
- human_player_update(&humans[i], &o);
- exit |= humans[i].periph.common.exit;
- terrain_update(&map);
-
- if (terrain_render(&map, &h->cam)
- || human_player_render(h, &o))
- goto end;
-
- /* TODO: render AI players. */
- }
+ .res = res,
+ .n_res = sizeof res / sizeof *res
+ };
+
+ human_player_update(&human, &o);
+ exit |= human.periph->common.exit;
+ terrain_update(&map);
+
+ if (terrain_render(&map, &human.cam)
+ || human_player_render(&human, &o))
+ goto end;
+
+ /* TODO: render AI players. */
}
instance_cyclic();