@@ -160,7 +160,7 @@ int curses_character = 0; | |||
int curses_signal = SIGNAL_NONE; | |||
int curses_screen_width = 0; | |||
int curses_screen_height = 0; | |||
int curses_active = 1; | |||
int curses_active = 0; | |||
/* | |||
I need to quickly explain how I'm structuring this subprogram. You can think of functions and variables starting with 'curses_*' as tiny standalone library if it's easier. They | |||
@@ -316,6 +316,8 @@ External function definitions, those found in "chapter_2.h" header file. | |||
*/ | |||
void curses_configure (void) { | |||
curses_active = TRUE; | |||
atexit (curses_deinitialize); // Deinitialization is automatically on exit. | |||
curses_initialize (); // Initializing curses, yaay. | |||
@@ -0,0 +1,57 @@ | |||
/* | |||
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" | |||
static void (* game_action [GAME_ACTION_COUNT]) (game_t * game, player_t * player); | |||
static number_t game_is_active (game_t * game) { return (game->active); } | |||
static number_t game_exit (game_t * game) { return (game->active = FALSE); }/* | |||
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); }*/ | |||
static void game_configure (game_t * game, player_t * player) { | |||
curses_configure (); | |||
curses_bind (SIGNAL_Q, game_exit); | |||
game->active = TRUE; | |||
game->screen_width = curses_screen_width; | |||
game->screen_height = curses_screen_height; | |||
player->x = 0; | |||
player->y = 0; | |||
} | |||
static void game_synchronize (game_t * game, player_t * player) { | |||
(void) game; | |||
curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL); | |||
curses_render_character ('@', COLOUR_CYAN, EFFECT_BOLD, player->x, player->y); | |||
curses_synchronize (); | |||
} | |||
void play_game (void) { | |||
game_t game; | |||
player_t player; | |||
game_configure (& game, & player); | |||
while (game_is_active (& game) && curses_active) { | |||
game_synchronize (& game, & player); | |||
} | |||
} | |||
#endif |
@@ -0,0 +1,70 @@ | |||
/* | |||
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_HEADER | |||
#define CHAPTER_5_HEADER | |||
#include "chapter_0.h" | |||
#include "chapter_1.h" | |||
#include "chapter_2.h" | |||
#include "chapter_3.h" | |||
/* | |||
Okay, we're finally on chapter five, and now we'll write something fun, not serious and boring. Before the Great Flood, when our ancestors were riding dinosaurs, building | |||
pyramids, killing African men and mating with Asian women, people didn't have dedicated nor integrated graphical processing units, called GPUs. They only had their terminals, | |||
built inside some of their spaceships. And what did they do with them? They played terminal rogue-like games, similar to those that archeologists discovered in ancient Egypt, | |||
Syria, Sumeria, Greece and Atlantis. They were reconstructed around 50 years ago by some guy that made the game Rogue. So, all those myths, sagas and legends about Anubis, | |||
Gilgamesh, Achilles, Inana, Gaea, they were just playable characters or main characters in those games, with different statistics, skills, attributes and back-story. Now, lets | |||
make a simple terminal rogue-like game using what we wrote in previous chapters. | |||
First of all, lets talk briefly about keyword 'typedef' and why I hate to use it. | |||
*/ | |||
typedef enum action_t { | |||
GAME_ACTION_IDLE, GAME_ACTION_WALK, GAME_ACTION_REST, GAME_ACTION_CAMP, | |||
GAME_ACTION_SWING_BLADE, GAME_ACTION_SWING_AXE, GAME_ACTION_SHOOT_ARROW, GAME_ACTION_THROW_SPEAR, | |||
GAME_ACTION_SUMMON_PUPPET, GAME_ACTION_CALL_NATURE, GAME_ACTION_CITE_RUNE, GAME_ACTION_CAST_CHARM, | |||
GAME_ACTION_COUNT | |||
} action_t; | |||
typedef int number_t; | |||
typedef char * string_t; | |||
typedef void * memory_t; | |||
typedef struct game_t { | |||
number_t active, screen_width, screen_height; | |||
} game_t; | |||
typedef struct bundle_t { | |||
number_t minimum, maximum, current, boosted; | |||
} bundle_t; | |||
/* | |||
typedef struct skill_t { | |||
string_t name; | |||
bundle_t stat; | |||
action_t positive [4]; | |||
} skill_t; | |||
typedef struct attribute_t { | |||
string_t name; | |||
bundle_t stat; | |||
action_t positive [4], negative [4]; | |||
} attribute_t; | |||
*/ | |||
typedef struct player_t { | |||
string_t name; | |||
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;*/ | |||
} player_t; | |||
extern void play_game (void); | |||
#endif |
@@ -9,10 +9,11 @@ gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_1.o chapter/chapter_1. | |||
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_2.o chapter/chapter_2.c | |||
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_3.o chapter/chapter_3.c | |||
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_4.o chapter/chapter_4.c | |||
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o chapter/chapter_5.o chapter/chapter_5.c | |||
gcc -g -Wall -Wextra -Wpedantic -O0 -c -o xhartae.o xhartae.c | |||
gcc -o xhartae xhartae.o chapter/chapter_0.o chapter/chapter_1.o chapter/chapter_2.o chapter/chapter_3.o chapter/chapter_4.o | |||
gcc -o xhartae xhartae.o chapter/chapter_0.o chapter/chapter_1.o chapter/chapter_2.o chapter/chapter_3.o chapter/chapter_4.o chapter/chapter_5.o | |||
#~splint -weak -warnposix -retvalother -syntax -type chapter/chapter_0.h | |||
#~splint -weak -warnposix -retvalother -syntax -type chapter/chapter_0.c | |||
@@ -24,6 +25,8 @@ gcc -o xhartae xhartae.o chapter/chapter_0.o chapter/chapter_1.o chapter/chapter | |||
#~splint -weak -warnposix -retvalother -syntax -type chapter/chapter_3.c | |||
#~splint -weak -warnposix -retvalother -syntax -type chapter/chapter_4.h | |||
#~splint -weak -warnposix -retvalother -syntax -type chapter/chapter_4.c | |||
#~splint -weak -warnposix -retvalother -syntax -type chapter/chapter_5.h | |||
#~splint -weak -warnposix -retvalother -syntax -type chapter/chapter_5.c | |||
#~splint -weak -warnposix -retvalother -syntax -type xhartae.c | |||
#~valgrind --show-leak-kinds=all --leak-check=full ./xhartae | |||
@@ -12,12 +12,14 @@ It is distributed in the hope that it will be useful or harmful, it really depen | |||
#include "chapter/chapter_2.c" | |||
#include "chapter/chapter_3.c" | |||
#include "chapter/chapter_4.c" | |||
#include "chapter/chapter_5.c" | |||
#else | |||
#include "chapter/chapter_0.h" | |||
#include "chapter/chapter_1.h" | |||
#include "chapter/chapter_2.h" | |||
#include "chapter/chapter_3.h" | |||
#include "chapter/chapter_4.h" | |||
#include "chapter/chapter_5.h" | |||
#endif | |||
/* | |||
@@ -132,5 +134,7 @@ int main (int argc, char * * argv) { | |||
preview_c_file ("program/example.c", curses_screen_width, curses_screen_height, 0, 0); | |||
play_game (); | |||
return (EXIT_SUCCESS); | |||
} |