forked from xolatile/xhartae
210 lines
8.2 KiB
C
210 lines
8.2 KiB
C
/*
|
|
Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
|
|
|
|
Xhartae is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
|
|
And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version.
|
|
It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
|
|
*/
|
|
|
|
#ifndef CHAPTER_5_SOURCE
|
|
#define CHAPTER_5_SOURCE
|
|
|
|
#include "chapter_5.h"
|
|
|
|
/*
|
|
So, what are actually getters and setters, and why you should never use them? Lets explain.
|
|
|
|
@C
|
|
static number_t game_get_screen_width (game_t * game) { return (game->screen_width); }
|
|
static number_t game_get_screen_height (game_t * game) { return (game->screen_height); }
|
|
static number_t game_set_screen_width (game_t * game, number_t width) { return (game->screen_width = width); }
|
|
static number_t game_set_screen_height (game_t * game, number_t height) { return (game->screen_height = height); }
|
|
@
|
|
*/
|
|
|
|
#define MEMORY_LIMIT (1024 * 1024)
|
|
|
|
static string_t memory_store [MEMORY_LIMIT];
|
|
|
|
static memory_t memorize (number_t size) {
|
|
static number_t memory_count = 0;
|
|
|
|
fatal_failure (memory_count + size >= MEMORY_LIMIT, "memorize: You have reached the 1 MiB memory limit.");
|
|
|
|
memory_count += size;
|
|
|
|
return ((memory_t) ((string_t) memory_store + memory_count - size));
|
|
}
|
|
|
|
static void move_player (void) { ++player.x; }
|
|
|
|
static void game_configure (void) {
|
|
curses_configure ();
|
|
|
|
curses_bind (SIGNAL_W, move_player);
|
|
curses_bind (SIGNAL_S, move_player);
|
|
curses_bind (SIGNAL_A, move_player);
|
|
curses_bind (SIGNAL_D, move_player);
|
|
|
|
game.active = curses_active;
|
|
game.screen_width = curses_screen_width;
|
|
game.screen_height = curses_screen_height;
|
|
|
|
player.x = 0;
|
|
player.y = 0;
|
|
}
|
|
|
|
static void game_synchronize (void) {
|
|
return;
|
|
}
|
|
|
|
game_t game;
|
|
player_t player;
|
|
|
|
skill_t * game_skill (string_t name, bundle_t * points, ...) {
|
|
skill_t * skill;
|
|
va_list list;
|
|
number_t action;
|
|
|
|
va_start (list, points);
|
|
|
|
skill = memorize ((int) sizeof (* skill));
|
|
|
|
string_copy ((skill->name = memorize (string_length (name) + 1)), name);
|
|
memory_copy ((skill->points = memorize ((int) sizeof (* skill->points))), points, (int) sizeof (* points));
|
|
|
|
for (;;) {
|
|
action = (number_t) va_arg (list, int);
|
|
|
|
if (action > 0) {
|
|
skill->positive_count += 1;
|
|
skill->positive = memorize ((int) sizeof (action));
|
|
skill->positive [skill->positive_count - 1] = (action_t) action;
|
|
} else break;
|
|
}
|
|
|
|
va_end (list);
|
|
|
|
return (skill);
|
|
}
|
|
|
|
attribute_t * game_attribute (string_t name, bundle_t * points, ...) {
|
|
attribute_t * attribute;
|
|
va_list list;
|
|
number_t action;
|
|
|
|
va_start (list, points);
|
|
|
|
attribute = memorize ((int) sizeof (* attribute));
|
|
|
|
|
|
string_copy ((attribute->name = memorize (string_length (name) + 1)), name);
|
|
memory_copy ((attribute->points = memorize ((int) sizeof (* attribute->points))), points, (int) sizeof (* points));
|
|
|
|
for (;;) {
|
|
action = (number_t) va_arg (list, int);
|
|
|
|
if (action > 0) {
|
|
attribute->positive_count += 1;
|
|
attribute->positive = memorize ((int) sizeof (action));
|
|
attribute->positive [attribute->positive_count - 1] = (action_t) action;
|
|
} else if (action < 0) {
|
|
attribute->negative_count += 1;
|
|
attribute->negative = memorize ((int) sizeof (action));
|
|
attribute->negative [attribute->negative_count - 1] = (action_t) action;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
|
|
va_end (list);
|
|
|
|
return (attribute);
|
|
}
|
|
|
|
void game_render_skill (skill_t * skill, number_t x, number_t y) {
|
|
curses_render_string (skill->name, COLOUR_CYAN, EFFECT_NORMAL, x, y);
|
|
|
|
curses_render_string ("[ ", COLOUR_GREY, EFFECT_BOLD, x + 18, y);
|
|
curses_render_string (format_to_string (skill->points->minimum, 0, 10, 4, ' '), COLOUR_RED, EFFECT_NORMAL, x = 22, y);
|
|
curses_render_string (format_to_string (skill->points->current, 0, 10, 4, ' '), COLOUR_WHITE, EFFECT_NORMAL, x = 26, y);
|
|
curses_render_string (format_to_string (skill->points->maximum, 0, 10, 4, ' '), COLOUR_GREEN, EFFECT_NORMAL, x = 30, y);
|
|
curses_render_string (" ]", COLOUR_GREY, EFFECT_BOLD, x = 34, y);
|
|
}
|
|
|
|
void game_render_attribute (attribute_t * attribute, number_t x, number_t y) {
|
|
curses_render_string (attribute->name, COLOUR_CYAN, EFFECT_NORMAL, x, y);
|
|
|
|
curses_render_string ("[ ", COLOUR_GREY, EFFECT_BOLD, x + 18, y);
|
|
curses_render_string (format_to_string (attribute->points->minimum, 0, 10, 4, ' '), COLOUR_RED, EFFECT_NORMAL, x = 22, y);
|
|
curses_render_string (format_to_string (attribute->points->current, 0, 10, 4, ' '), COLOUR_WHITE, EFFECT_NORMAL, x = 26, y);
|
|
curses_render_string (format_to_string (attribute->points->maximum, 0, 10, 4, ' '), COLOUR_GREEN, EFFECT_NORMAL, x = 30, y);
|
|
curses_render_string (" ]", COLOUR_GREY, EFFECT_BOLD, x = 34, y);
|
|
}
|
|
|
|
void play_game (void) {
|
|
bundle_t skill_points = { 10, 120, 0, 0 };
|
|
bundle_t attribute_points = { 1, 12, 0, 0 };
|
|
|
|
skill_t * blades, * axes, * bows, * spears, * puppet_magic, * nature_magic, * rune_magic, * charm_magic;
|
|
attribute_t * strength, * edurance, * wisdom, * agility;
|
|
|
|
strength = game_attribute ("Strength", & attribute_points, GAME_ACTION_SWING_BLADE, GAME_ACTION_SWING_AXE, -GAME_ACTION_CAMP, 0);
|
|
edurance = game_attribute ("Edurance", & attribute_points, GAME_ACTION_WALK, GAME_ACTION_CAMP, -GAME_ACTION_REST, 0);
|
|
wisdom = game_attribute ("Wisdom", & attribute_points, GAME_ACTION_CITE_RUNE, GAME_ACTION_CAST_CHARM, -GAME_ACTION_WALK, 0);
|
|
agility = game_attribute ("Agility", & attribute_points, GAME_ACTION_SHOOT_ARROW, GAME_ACTION_THROW_SPEAR, -GAME_ACTION_WAIT, 0);
|
|
|
|
blades = game_skill ("Blades", & skill_points, GAME_ACTION_SWING_BLADE, 0);
|
|
axes = game_skill ("Axes", & skill_points, GAME_ACTION_SWING_AXE, 0);
|
|
bows = game_skill ("Bows", & skill_points, GAME_ACTION_SHOOT_ARROW, 0);
|
|
spears = game_skill ("Spears", & skill_points, GAME_ACTION_THROW_SPEAR, 0);
|
|
puppet_magic = game_skill ("Puppet Magic", & skill_points, GAME_ACTION_SUMMON_PUPPET, 0);
|
|
nature_magic = game_skill ("Nature Magic", & skill_points, GAME_ACTION_CALL_NATURE, 0);
|
|
rune_magic = game_skill ("Rune Magic", & skill_points, GAME_ACTION_CITE_RUNE, 0);
|
|
charm_magic = game_skill ("Charm Magic", & skill_points, GAME_ACTION_CAST_CHARM, 0);
|
|
|
|
game_configure ();
|
|
|
|
while (curses_active) {
|
|
curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL);
|
|
|
|
curses_render_string ("Attributes:", COLOUR_WHITE, EFFECT_BOLD, 0, 0);
|
|
|
|
game_render_attribute (strength, 2, 1);
|
|
game_render_attribute (edurance, 2, 2);
|
|
game_render_attribute (wisdom, 2, 3);
|
|
game_render_attribute (agility, 2, 4);
|
|
|
|
curses_render_string ("Skills:", COLOUR_WHITE, EFFECT_BOLD, 0, 5);
|
|
|
|
game_render_skill (blades, 2, 6);
|
|
game_render_skill (axes, 2, 7);
|
|
game_render_skill (bows, 2, 8);
|
|
game_render_skill (spears, 2, 9);
|
|
game_render_skill (puppet_magic, 2, 10);
|
|
game_render_skill (nature_magic, 2, 11);
|
|
game_render_skill (rune_magic, 2, 12);
|
|
game_render_skill (charm_magic, 2, 13);
|
|
|
|
curses_render_character ('@', COLOUR_CYAN, EFFECT_BOLD, player.x, player.y);
|
|
|
|
curses_synchronize ();
|
|
|
|
game_synchronize ();
|
|
}
|
|
|
|
//~char*a,*b,*c;
|
|
//~a=memorize(12); string_copy(a,"heyo world\n"); terminal_colour(1,1); echo(a); terminal_cancel();
|
|
//~b=memorize( 3); string_copy(b,"!\n"); terminal_colour(2,1); echo(b); terminal_cancel();
|
|
//~c=memorize(12); string_copy(c,"cyaa world\n"); terminal_colour(3,1); echo(c); terminal_cancel();
|
|
//~out(memory_store,512);
|
|
//~terminal_colour(1,1); echo(number_to_string((int)a)); terminal_cancel();
|
|
//~terminal_colour(2,1); echo(number_to_string((int)b)); terminal_cancel();
|
|
//~terminal_colour(3,1); echo(number_to_string((int)c)); terminal_cancel(); echo("\n");
|
|
//~terminal_colour(1,1); echo(a); terminal_cancel();
|
|
//~terminal_colour(2,1); echo(b); terminal_cancel();
|
|
//~terminal_colour(3,1); echo(c); terminal_cancel();
|
|
}
|
|
|
|
#endif
|