Added rectangle rendering...

This commit is contained in:
Ognjen Milan Robovic 2023-11-28 15:30:55 -05:00
parent 642459a19c
commit 3639266117
4 changed files with 24 additions and 10 deletions

View File

@ -464,6 +464,14 @@ void curses_render_background (char character, int colour, int effect) {
}
}
void curses_render_rectangle (char character, int colour, int effect, int x, int y, int width, int height) {
for (int j = 0; j < height; ++j) { // Iterating through rows (by height) of our framebuffer ('curses_screen').
for (int i = 0; i < width; ++i) { // Iterating through columns (by width) of our framebuffer.
curses_render_character (character, colour, effect, x + i, y + j); // Now, we can use function 'curses_render_character' to simplify our life...
}
}
}
/*
We've mentioned before, in chapter zero, that you can implement 'string_*' functions by 'string_*_limit', and here's an example of that. Functions below are quite self
explanatory, so you can do a "homework" of reading them and trying to understand what they'll do. Since I use very verbose naming style, I hope that won't be a problem...

View File

@ -170,6 +170,8 @@ extern void curses_render_cursor (int x, int y); // Render terminal cursor at po
extern void curses_render_character (char character, int colour, int effect, int x, int y); // Render single character at position X and Y.
extern void curses_render_background (char character, int colour, int effect); // Render entire buffer with the same character.
extern void curses_render_rectangle (char character, int colour, int effect, int x, int y, int width, int height); // Guess what this function does...?
// Remember that in chapter zero, I've separated 'string_*' and 'string_*_limit' functions. Now, there's always more ways to logically organize your code, for example, as below:
extern int curses_render_string (char * string, int colour, int effect, int x, int y);
extern int curses_render_number (int number, int colour, int effect, int x, int y);

View File

@ -18,6 +18,9 @@ gcc -o xhartae xhartae.o chapter/chapter_0.o chapter/chapter_1.o chapter/chapter
gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -o program/program_0 program/program_0.c
gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -o program/program_1 program/program_1.c
gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -o program/program_2 program/program_2.c
gcc -g -Wall -Wextra -Wpedantic -Werror -Ofast -o play_game program/program_z.c
#~splint -weak -warnposix -retvalother -syntax -type chapter/chapter_0.h
#~splint -weak -warnposix -retvalother -syntax -type chapter/chapter_0.c

View File

@ -22,23 +22,24 @@ int main (void) {
terminal_show_cursor (FALSE);
curses_configure ();
/*
curses_bind (SIGNAL_ARROW_UP, player_move_up);
curses_bind (SIGNAL_ARROW_DOWN, player_move_down);
curses_bind (SIGNAL_ARROW_LEFT, player_move_left);
curses_bind (SIGNAL_ARROW_RIGHT, player_move_right);
*/
while (curses_active) {
curses_render_background ('.', COLOUR_GREY, EFFECT_BOLD);
curses_render_background (' ', COLOUR_WHITE, EFFECT_NORMAL);
curses_render_rectangle ('.', COLOUR_GREY, EFFECT_BOLD, 0, 0, 80, 24);
curses_render_character ('@', COLOUR_CYAN, EFFECT_BOLD, player_x, player_y);
switch (curses_character) {
case 'w': player_move_up (); break;
case 'a': player_move_down (); break;
case 's': player_move_left (); break;
case 'd': player_move_right (); break;
default: break;
}
//~switch (curses_character) {
//~case 'w': player_move_up (); break;
//~case 's': player_move_down (); break;
//~case 'a': player_move_left (); break;
//~case 'd': player_move_right (); break;
//~default: break;
//~}
curses_synchronize ();
}