diff options
author | Cara Salter <cara@devcara.com> | 2023-01-07 23:24:04 -0500 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2023-01-07 23:24:04 -0500 |
commit | 36d4f4741cd2559362de7e64820ca4b29b022121 (patch) | |
tree | 172537aa08f946e2a6dc65bc4bec40985f6e1f95 /src/main.cpp | |
download | cpp-rl-36d4f4741cd2559362de7e64820ca4b29b022121.tar.gz cpp-rl-36d4f4741cd2559362de7e64820ca4b29b022121.zip |
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..7a27f82 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,71 @@ +/* + * ===================================================================================== + * + * Filename: main.cpp + * + * Description: Entrypoint + * + * Version: 1.0 + * Created: 01/07/2023 09:36:42 PM + * Revision: none + * Compiler: gcc + * + * Author: Cara Salter (muirrum), cara@devcara.com + * Organization: + * + * ===================================================================================== + */ +#include <stdlib.h> +#include <ncurses.h> + +#include "screen.hpp" +#include "mob.hpp" +#include "frame.hpp" + +void game_loop(Frame &map, Frame &viewport, Mob &character, int ch); + +int main() { + Screen scr; + + scr.add("Welcome to the game!\nPress any key to start."); + + int ch = getch(); + + Frame game_map(2*scr.height(), 2*scr.width(), 0, 0); + + Frame viewport(game_map, scr.height(), scr.width(), 0, 0); + + Mob character('@', game_map.height()/2, game_map.width()/2); + + game_map.gen_Perlin(237); + + game_loop(game_map, viewport, character, ch); + + return 0; +} + +void game_loop(Frame &map, Frame &viewport, Mob &character, int ch) { + if (ch == 'q' || ch == 'Q') return; + + map.place_mob(character); + viewport.center(character); + viewport.refresh(); + + for(;;) { + ch = getch(); + + if (ch == 'h') { + map.place_mob(character, character.row(), character.col() -1); + } else if (ch == 'j') { + map.place_mob(character, character.row() + 1, character.col()); + } else if (ch == 'k') { + map.place_mob(character, character.row() - 1, character.col()); + } else if (ch == 'l') { + map.place_mob(character, character.row(), character.col() + 1); + } else if (ch == 'q') { + break; + } + viewport.center(character); + viewport.refresh(); + } +} |