125 lines
6.0 KiB
C
125 lines
6.0 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_6_SOURCE
|
||
|
#define CHAPTER_6_SOURCE
|
||
|
|
||
|
#include "chapter_6.h"
|
||
|
|
||
|
#define UNUSED(variable) (void) variable
|
||
|
|
||
|
static procedure_t generate_full_fill_function (world_t * world, number_t width, number_t height, number_t x, number_t y, block_t * block) {
|
||
|
UNUSED (width);
|
||
|
UNUSED (height);
|
||
|
UNUSED (x);
|
||
|
UNUSED (y);
|
||
|
|
||
|
for (number_t j = 0; j < world->height; ++j) {
|
||
|
for (number_t i = 0; i < world->width; ++i) {
|
||
|
world->block [j * world->width + i] = block;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static procedure_t generate_rectangle_fill_function (world_t * world, number_t width, number_t height, number_t x, number_t y, block_t * block) {
|
||
|
for (number_t j = 0; j < height; ++j) {
|
||
|
for (number_t i = 0; i < width; ++i) {
|
||
|
world->block [(j + y) * world->width + (i + x)] = block;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static procedure_t generate_rectangle_line_function (world_t * world, number_t width, number_t height, number_t x, number_t y, block_t * block) {
|
||
|
for (number_t offset = 0; offset < width; ++offset) {
|
||
|
world->block [world->width * y + offset + x] = block;
|
||
|
world->block [world->width * (height - 1 + y) + offset + x] = block;
|
||
|
}
|
||
|
|
||
|
for (number_t offset = 0; offset < height; ++offset) {
|
||
|
world->block [world->width * (y + offset) + x] = block;
|
||
|
world->block [world->width * (y + offset) + width - 1 + x] = block;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
generator_t * rectangle_line = game_generator (generate_rectangle_line_function);
|
||
|
|
||
|
attribute_t * strength = game_attribute ("Strength", format_bundle (1, 12, 0), GAME_ACTION_SWING_BLADE, GAME_ACTION_SWING_AXE, -GAME_ACTION_CAMP, 0);
|
||
|
attribute_t * edurance = game_attribute ("Edurance", format_bundle (1, 12, 0), GAME_ACTION_WALK, GAME_ACTION_CAMP, -GAME_ACTION_REST, 0);
|
||
|
attribute_t * wisdom = game_attribute ("Wisdom", format_bundle (1, 12, 0), GAME_ACTION_CITE_RUNE, GAME_ACTION_CAST_CHARM, -GAME_ACTION_WALK, 0);
|
||
|
attribute_t * agility = game_attribute ("Agility", format_bundle (1, 12, 0), GAME_ACTION_SHOOT_ARROW, GAME_ACTION_THROW_SPEAR, -GAME_ACTION_WAIT, 0);
|
||
|
|
||
|
skill_t * blades = game_skill ("Blades", format_bundle (10, 120, 0), GAME_ACTION_SWING_BLADE, 0);
|
||
|
skill_t * axes = game_skill ("Axes", format_bundle (10, 120, 0), GAME_ACTION_SWING_AXE, 0);
|
||
|
skill_t * bows = game_skill ("Bows", format_bundle (10, 120, 0), GAME_ACTION_SHOOT_ARROW, 0);
|
||
|
skill_t * spears = game_skill ("Spears", format_bundle (10, 120, 0), GAME_ACTION_THROW_SPEAR, 0);
|
||
|
skill_t * puppet_magic = game_skill ("Puppet Magic", format_bundle (10, 120, 0), GAME_ACTION_SUMMON_PUPPET, 0);
|
||
|
skill_t * nature_magic = game_skill ("Nature Magic", format_bundle (10, 120, 0), GAME_ACTION_CALL_NATURE, 0);
|
||
|
skill_t * rune_magic = game_skill ("Rune Magic", format_bundle (10, 120, 0), GAME_ACTION_CITE_RUNE, 0);
|
||
|
skill_t * charm_magic = game_skill ("Charm Magic", format_bundle (10, 120, 0), GAME_ACTION_CAST_CHARM, 0);
|
||
|
|
||
|
player_t * player = game_player ("Riri", format_symbol ('@', COLOUR_CYAN, EFFECT_BOLD));
|
||
|
|
||
|
block_t * grass = game_block ("Grass", format_symbol (',', COLOUR_GREEN, EFFECT_BOLD), FALSE, FALSE);
|
||
|
block_t * stone_floor = game_block ("Stone Floor", format_symbol ('.', COLOUR_GREY, EFFECT_BOLD), FALSE, FALSE);
|
||
|
block_t * stone_wall = game_block ("Stone Wall", format_symbol ('#', COLOUR_GREY, EFFECT_BOLD), TRUE, FALSE);
|
||
|
|
||
|
world_t * world = game_world (300, 100, full_fill, 0, 0, 0, 0, grass,
|
||
|
rectangle_fill, 5, 9, 2, 4, stone_floor,
|
||
|
rectangle_line, 5, 9, 2, 4, stone_wall,
|
||
|
NULL);
|
||
|
|
||
|
curses_configure ();
|
||
|
|
||
|
terminal_show_cursor (FALSE);
|
||
|
|
||
|
number_t game_screen_offset = curses_screen_width - 40;
|
||
|
|
||
|
while (curses_active) {
|
||
|
curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL);
|
||
|
|
||
|
game_render_world (world, 0, 0, game_screen_offset, curses_screen_height);
|
||
|
|
||
|
game_render_player (player);
|
||
|
|
||
|
curses_render_string (" Attributes:", COLOUR_WHITE, EFFECT_BOLD, game_screen_offset, 0);
|
||
|
|
||
|
game_render_attribute (strength, game_screen_offset, 1);
|
||
|
game_render_attribute (edurance, game_screen_offset, 2);
|
||
|
game_render_attribute (wisdom, game_screen_offset, 3);
|
||
|
game_render_attribute (agility, game_screen_offset, 4);
|
||
|
|
||
|
curses_render_string (" Skills:", COLOUR_WHITE, EFFECT_BOLD, game_screen_offset, 5);
|
||
|
|
||
|
game_render_skill (blades, game_screen_offset, 6);
|
||
|
game_render_skill (axes, game_screen_offset, 7);
|
||
|
game_render_skill (bows, game_screen_offset, 8);
|
||
|
game_render_skill (spears, game_screen_offset, 9);
|
||
|
game_render_skill (puppet_magic, game_screen_offset, 10);
|
||
|
game_render_skill (nature_magic, game_screen_offset, 11);
|
||
|
game_render_skill (rune_magic, game_screen_offset, 12);
|
||
|
game_render_skill (charm_magic, game_screen_offset, 13);
|
||
|
|
||
|
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;
|
||
|
case SIGNAL_ARROW_LEFT: player->x -= 1; limit (& player->x, 0, world->width - 1); break;
|
||
|
case SIGNAL_ARROW_RIGHT: player->x += 1; limit (& player->x, 0, world->width - 1); break;
|
||
|
default: break;
|
||
|
}
|
||
|
|
||
|
curses_synchronize ();
|
||
|
}
|
||
|
|
||
|
terminal_show_cursor (TRUE);
|
||
|
}
|
||
|
|
||
|
#endif
|