Core menu implementation, work in progress...
This commit is contained in:
parent
f31e02ac80
commit
202fc7dc8c
@ -228,6 +228,45 @@ world_t * game_world (number_t width, number_t height, ...) {
|
||||
return (world);
|
||||
}
|
||||
|
||||
menu_t * game_menu (string_t text, /*number_t width, number_t height, number_t x, number_t y, number_t reorient, number_t override, */...) {
|
||||
menu_t * menu;
|
||||
va_list list;
|
||||
menu_t * item;
|
||||
|
||||
menu = memorize ((number_t) sizeof (* menu));
|
||||
|
||||
string_copy ((menu->text = memorize (string_length (text) + 1)), text);
|
||||
|
||||
menu->scroll = 0;
|
||||
menu->item_count = 0;
|
||||
menu->items = NULL;
|
||||
|
||||
//~menu->width = width;
|
||||
//~menu->height = height;
|
||||
//~menu->x = x;
|
||||
//~menu->y = y;
|
||||
//~menu->reorient = reorient;
|
||||
//~menu->override = override;
|
||||
|
||||
//~va_start (list, override);
|
||||
va_start (list, text);
|
||||
|
||||
for (;;) {
|
||||
item = (menu_t *) va_arg (list, void *);
|
||||
|
||||
if (item != NULL) {
|
||||
menu->item_count += 1;
|
||||
//~menu->items = memorize ((number_t) sizeof (item));
|
||||
menu->items = memorize ((number_t) sizeof (* menu->items));
|
||||
menu->items [menu->item_count - 1] = item;
|
||||
} else break;
|
||||
}
|
||||
|
||||
va_end (list);
|
||||
|
||||
return (menu);
|
||||
}
|
||||
|
||||
procedure_t game_render_attribute (attribute_t * attribute, number_t x, number_t y) {
|
||||
curses_render_string (attribute->name, COLOUR_CYAN, EFFECT_NORMAL, x, y);
|
||||
|
||||
@ -266,6 +305,31 @@ procedure_t game_render_world (world_t * world, number_t x, number_t y, number_t
|
||||
}
|
||||
}
|
||||
|
||||
procedure_t game_render_menu (menu_t * menu, number_t x, number_t y) {
|
||||
number_t item;
|
||||
|
||||
curses_render_string (menu->text, 1, 1, x, y);
|
||||
|
||||
y += 1;
|
||||
|
||||
if (menu->item_count == 0) {
|
||||
return;
|
||||
} else {
|
||||
game_render_menu (menu->items [0], x, y);
|
||||
//~for (item = 0; item != menu->item_count - 1; ++item) {
|
||||
//~game_render_menu (menu->items [item], x, y + item);
|
||||
//~}
|
||||
}
|
||||
|
||||
//~if (menu->item_count == 0) {
|
||||
//~curses_render_string (menu->text, 1, 1, x, y);
|
||||
//~} else {
|
||||
//~for (item = 0; item != menu->item_count; ++item) {
|
||||
//~game_render_menu (menu->items [item], x, y + item);
|
||||
//~}
|
||||
//~}
|
||||
}
|
||||
|
||||
procedure_t play_game (procedure_t) {
|
||||
generator_t * full_fill = game_generator (generate_full_fill_function);
|
||||
generator_t * rectangle_fill = game_generator (generate_rectangle_fill_function);
|
||||
@ -294,7 +358,21 @@ procedure_t play_game (procedure_t) {
|
||||
world_t * world = game_world (80, 24, full_fill, 0, 0, 0, 0, grass,
|
||||
rectangle_fill, 5, 9, 2, 4, stone_floor,
|
||||
rectangle_line, 5, 9, 2, 4, stone_wall,
|
||||
NULL);
|
||||
0);
|
||||
|
||||
//~menu_t * main_menu = game_menu ("Main Menu", 40, 20, 50, 10, FALSE, FALSE, GAME_MENU_ITEM_BUTTON,
|
||||
//~GAME_MENU_ITEM_BUTTON,
|
||||
//~GAME_MENU_ITEM_BUTTON,
|
||||
//~0);
|
||||
|
||||
menu_t * menu_play = game_menu ("> Play", NULL);
|
||||
menu_t * menu_options = game_menu ("> Options", NULL);
|
||||
menu_t * menu_exit = game_menu ("> Exit", NULL);
|
||||
|
||||
menu_t * menu_main = game_menu ("Main Menu", menu_play,
|
||||
menu_options,
|
||||
menu_exit,
|
||||
NULL);
|
||||
|
||||
curses_configure ();
|
||||
|
||||
@ -319,10 +397,12 @@ procedure_t play_game (procedure_t) {
|
||||
game_render_skill (rune_magic, 2, 12);
|
||||
game_render_skill (charm_magic, 2, 13);
|
||||
|
||||
game_render_world (world, 0, 0, curses_screen_width, curses_screen_height);
|
||||
game_render_world (world, 40, 0, curses_screen_width, curses_screen_height);
|
||||
|
||||
game_render_player (player);
|
||||
|
||||
game_render_menu (menu_main, 120, 0);
|
||||
|
||||
switch (curses_character) {
|
||||
case SIGNAL_ARROW_UP: player->y -= 1; limit (& player->y, 0, world->height - 1); break;
|
||||
case SIGNAL_ARROW_DOWN: player->y += 1; limit (& player->y, 0, world->height - 1); break;
|
||||
|
@ -38,6 +38,12 @@ typedef enum action_t {
|
||||
GAME_ACTION_COUNT
|
||||
} action_t;
|
||||
|
||||
typedef enum menu_item_t {
|
||||
GAME_MENU_ITEM_NONE,
|
||||
GAME_MENU_ITEM_SEPARATOR, GAME_MENU_ITEM_TEXT, GAME_MENU_ITEM_BUTTON, GAME_MENU_ITEM_LIST,
|
||||
GAME_MENU_ITEM_COUNT
|
||||
} menu_item_t;
|
||||
|
||||
typedef struct bundle_t {
|
||||
number_t minimum, maximum, current;
|
||||
} bundle_t;
|
||||
@ -48,7 +54,8 @@ typedef struct symbol_t {
|
||||
|
||||
typedef struct attribute_t {
|
||||
string_t name;
|
||||
number_t positive_count, negative_count;
|
||||
number_t positive_count;
|
||||
number_t negative_count;
|
||||
bundle_t * points;
|
||||
action_t * positive;
|
||||
action_t * negative;
|
||||
@ -56,14 +63,16 @@ typedef struct attribute_t {
|
||||
|
||||
typedef struct skill_t {
|
||||
string_t name;
|
||||
number_t positive_count, learning_rate;
|
||||
number_t positive_count;
|
||||
number_t learning_rate;
|
||||
bundle_t * points;
|
||||
action_t * positive;
|
||||
} skill_t;
|
||||
|
||||
typedef struct player_t {
|
||||
string_t name;
|
||||
number_t x, y;
|
||||
number_t x;
|
||||
number_t y;
|
||||
symbol_t * symbol;
|
||||
//~bundle_t * health, * armour, * mana, * stamina;
|
||||
//~attribute_t strength, edurance, intelligence, agility;
|
||||
@ -73,15 +82,31 @@ typedef struct player_t {
|
||||
|
||||
typedef struct block_t {
|
||||
string_t name;
|
||||
number_t collision, override;
|
||||
number_t collision;
|
||||
number_t override;
|
||||
symbol_t * symbol;
|
||||
} block_t;
|
||||
|
||||
typedef struct world_t {
|
||||
number_t width, height;
|
||||
number_t width;
|
||||
number_t height;
|
||||
block_t * * block;
|
||||
} world_t;
|
||||
|
||||
typedef struct menu_t {
|
||||
string_t text;
|
||||
//~number_t width;
|
||||
//~number_t height;
|
||||
//~number_t x;
|
||||
//~number_t y;
|
||||
//~number_t reorient;
|
||||
//~number_t override;
|
||||
number_t scroll;
|
||||
number_t item_count;
|
||||
//~menu_item_t * items;
|
||||
struct menu_t * * items;
|
||||
} menu_t;
|
||||
|
||||
typedef procedure_t (* generate_t) (world_t *, number_t, number_t, number_t, number_t, block_t *);
|
||||
|
||||
typedef struct generator_t {
|
||||
@ -90,8 +115,8 @@ typedef struct generator_t {
|
||||
|
||||
extern memory_t memorize (number_t size);
|
||||
|
||||
extern bundle_t * format_bundle (number_t minimum, number_t maximum, number_t current);
|
||||
extern symbol_t * format_symbol (number_t character, number_t colour, number_t effect);
|
||||
extern bundle_t * format_bundle (number_t minimum, number_t maximum, number_t current);
|
||||
extern symbol_t * format_symbol (number_t character, number_t colour, number_t effect);
|
||||
|
||||
extern generator_t * game_generator (generate_t generator);
|
||||
extern attribute_t * game_attribute (string_t name, bundle_t * points, ...);
|
||||
@ -99,12 +124,14 @@ extern skill_t * game_skill (string_t name, bundle_t * points, ...);
|
||||
extern player_t * game_player (string_t name, symbol_t * symbol);
|
||||
extern block_t * game_block (string_t name, symbol_t * symbol, number_t collision, number_t override);
|
||||
extern world_t * game_world (number_t width, number_t height, ...);
|
||||
extern menu_t * game_menu (string_t text, /*number_t width, number_t height, number_t x, number_t y, number_t reorient, number_t override,*/ ...);
|
||||
|
||||
extern procedure_t game_render_attribute (attribute_t * attribute, number_t x, number_t y);
|
||||
extern procedure_t game_render_skill (skill_t * skill, number_t x, number_t y);
|
||||
extern procedure_t game_render_player (player_t * player);
|
||||
extern procedure_t game_render_block (block_t * block, number_t x, number_t y);
|
||||
extern procedure_t game_render_world (world_t * world, number_t x, number_t y, number_t width, number_t height);
|
||||
extern procedure_t game_render_menu (menu_t * menu, number_t x, number_t y);
|
||||
|
||||
extern procedure_t play_game (procedure_t);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user