From 36d4f4741cd2559362de7e64820ca4b29b022121 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Sat, 7 Jan 2023 23:24:04 -0500 Subject: Initial commit --- src/main.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/main.cpp (limited to 'src/main.cpp') 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 +#include + +#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(); + } +} -- cgit v1.2.3