Added player movement...

This commit is contained in:
Ognjen Milan Robovic 2023-11-22 07:47:27 -05:00
parent 469e117e78
commit 7290620674
2 changed files with 82 additions and 64 deletions

View File

@ -24,9 +24,8 @@ static number_t game_set_screen_height (game_t * game, number_t height) { return
#define MEMORY_LIMIT (1024 * 1024)
static string_t memory_store [MEMORY_LIMIT];
static memory_t memorize (number_t size) {
static string_t memory_store [MEMORY_LIMIT] = { 0 };
static number_t memory_count = 0;
fatal_failure (memory_count + size >= MEMORY_LIMIT, "memorize: You have reached the 1 MiB memory limit.");
@ -36,31 +35,18 @@ static memory_t memorize (number_t size) {
return ((memory_t) ((string_t) memory_store + memory_count - size));
}
static void move_player (void) { ++player.x; }
static symbol_t * format_symbol (number_t character, number_t colour, number_t effect) {
symbol_t * symbol;
static void game_configure (void) {
curses_configure ();
symbol = memorize ((number_t) sizeof (* symbol));
curses_bind (SIGNAL_W, move_player);
curses_bind (SIGNAL_S, move_player);
curses_bind (SIGNAL_A, move_player);
curses_bind (SIGNAL_D, move_player);
symbol->character = character;
symbol->colour = colour;
symbol->effect = effect;
game.active = curses_active;
game.screen_width = curses_screen_width;
game.screen_height = curses_screen_height;
player.x = 0;
player.y = 0;
return (symbol);
}
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;
@ -68,17 +54,17 @@ skill_t * game_skill (string_t name, bundle_t * points, ...) {
va_start (list, points);
skill = memorize ((int) sizeof (* skill));
skill = memorize ((number_t) 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));
memory_copy ((skill->points = memorize ((number_t) sizeof (* skill->points))), points, (number_t) 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 = memorize ((number_t) sizeof (action));
skill->positive [skill->positive_count - 1] = (action_t) action;
} else break;
}
@ -95,26 +81,23 @@ attribute_t * game_attribute (string_t name, bundle_t * points, ...) {
va_start (list, points);
attribute = memorize ((int) sizeof (* attribute));
attribute = memorize ((number_t) 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));
memory_copy ((attribute->points = memorize ((number_t) sizeof (* attribute->points))), points, (number_t) 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 = memorize ((number_t) 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 = memorize ((number_t) sizeof (action));
attribute->negative [attribute->negative_count - 1] = (action_t) action;
} else {
break;
}
} else break;
}
va_end (list);
@ -122,6 +105,31 @@ attribute_t * game_attribute (string_t name, bundle_t * points, ...) {
return (attribute);
}
//~block_t * game_block (string_t name, symbol_t * symbol) {
//~block_t * block;
//~block = memorize ((number_t) sizeof (* block));
//~string_copy ((block->name = memorize (string_length (name) + 1)), name);
//~memory_copy ((block->symbol = memorize ((number_t) sizeof (* block->symbol))), symbol, (number_t) sizeof (* symbol));
//~return (block);
//~}
player_t * game_player (string_t name, symbol_t * symbol) {
player_t * player;
player = memorize ((number_t) sizeof (* player));
string_copy ((player->name = memorize (string_length (name) + 1)), name);
memory_copy ((player->symbol = memorize ((number_t) sizeof (* player->symbol))), symbol, (number_t) sizeof (* symbol));
player->x = 3;
player->y = 3;
return (player);
}
void game_render_skill (skill_t * skill, number_t x, number_t y) {
curses_render_string (skill->name, COLOUR_CYAN, EFFECT_NORMAL, x, y);
@ -143,8 +151,11 @@ void game_render_attribute (attribute_t * attribute, number_t x, number_t y) {
}
void play_game (void) {
bundle_t skill_points = { 10, 120, 0, 0 };
bundle_t attribute_points = { 1, 12, 0, 0 };
bundle_t skill_points = { 10, 120, 0 };
bundle_t attribute_points = { 1, 12, 0 };
player_t * player;
//~world_t * world;
skill_t * blades, * axes, * bows, * spears, * puppet_magic, * nature_magic, * rune_magic, * charm_magic;
attribute_t * strength, * edurance, * wisdom, * agility;
@ -163,7 +174,9 @@ void play_game (void) {
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 ();
player = game_player ("Riri", format_symbol ('@', COLOUR_CYAN, EFFECT_BOLD));
curses_configure ();
while (curses_active) {
curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL);
@ -186,24 +199,18 @@ void play_game (void) {
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_render_character ('@', COLOUR_CYAN, EFFECT_BOLD, player->x, player->y);
curses_synchronize ();
game_synchronize ();
switch (curses_character) {
case 'w': player->y -= 1; break;
case 's': player->y += 1; break;
case 'a': player->x -= 1; break;
case 'd': player->x += 1; break;
default: break;
}
//~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();
curses_synchronize ();
}
}
#endif

View File

@ -37,12 +37,12 @@ typedef enum action_t {
GAME_ACTION_COUNT
} action_t;
typedef struct game_t {
number_t active, screen_width, screen_height;
} game_t;
typedef struct symbol_t {
number_t character, colour, effect;
} symbol_t;
typedef struct bundle_t {
number_t minimum, maximum, current, booster;
number_t minimum, maximum, current;
} bundle_t;
typedef struct skill_t {
@ -60,20 +60,31 @@ typedef struct attribute_t {
action_t * positive, * negative;
} attribute_t;
//~typedef struct block_t {
//~string_t name;
//~symbol_t * symbol;
//~number_t collision;
//~} block_t;
typedef struct player_t {
string_t name;
symbol_t * symbol;
number_t x, y;
bundle_t health, armour, mana, stamina;
attribute_t strength, edurance, intelligence, agility;
skill_t blades, axes, bows, spears;
skill_t puppet_magic, nature_magic, rune_magic, charm_magic;
//~bundle_t * health, * armour, * mana, * stamina;
//~attribute_t strength, edurance, intelligence, agility;
//~skill_t blades, axes, bows, spears;
//~skill_t puppet_magic, nature_magic, rune_magic, charm_magic;
} player_t;
extern game_t game;
extern player_t player;
//~typedef struct world_t {
//~number_t width, height;
//~block_t * block;
//~} world_t;
extern skill_t * game_skill (string_t name, bundle_t * points, ...);
extern attribute_t * game_attribute (string_t name, bundle_t * points, ...);
//~extern block_t * game_block (string_t name, symbol_t * symbol);
extern player_t * game_player (string_t name, symbol_t * symbol);
extern void game_render_skill (skill_t * skill, number_t x, number_t y);
extern void game_render_attribute (attribute_t * attribute, number_t x, number_t y);