1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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();
}
}
|