-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·105 lines (97 loc) · 2.59 KB
/
Copy pathmain.cpp
File metadata and controls
executable file
·105 lines (97 loc) · 2.59 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <vector>
#include <stdio.h>
#include <unistd.h>
#include <string>
#include <termios.h>
#include <stdlib.h>
using namespace std;
vector<struct NPC>NPCs;
class BufferToggle {
private:
struct termios t;
public:
void off(void){
tcgetattr(STDIN_FILENO, &t);
t.c_lflag &= ~ICANON & ~ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &t);
}
void on(void){
tcgetattr(STDIN_FILENO, &t);
t.c_lflag |= ICANON & ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &t);
}
};
int abs(int x){
if(x > 0){
return x;
}
return -x;
}
void displayNPCs(void){
for(int i=0; i < NPCs.size(); i++){
y[NPCs[i].ypos][NPCs[i].x] = NPCs[i].mychar;
}
}
int main()
{
Entity player = new Entity();
struct Player player;
player.pChar='@';
makeMap(25);
player.ypos = y.size() / 2;
player.x = y[player.ypos].size() / 2;
NPCs.reserve(10);
BufferToggle bt;
bt.off();
string u_input;
makeNPC("King Mexis", 16, 2, '&', "Ravioli Ravioli what's in the pocketoli???");
makeNPC("Andrei the Romanian", 20, 4, '$', "Ey mang you wan sum computer science???");
makeNPC("Ol'Dally", 13, 12, '%' , "Uhh, weiners.");
while(true){
y[player.ypos][player.x] = player.pChar;
for(int i = 0; i < NPCs.size(); i++){
y[NPCs[i].ypos][NPCs[i].x] = ' ';
NPCs[i].findPath(player.x,player.ypos);
}
displayNPCs();
makeWall(0,0,1,4);
makeWall(1,3,3,1);
makeWall(6,3,3,1);
makeWall(9,0,1,4);
makeWall(1,0,8,1);
makeWall(7,7,5,1);
makeWall(14,7,5,1);
makeWall(7,8,1,8);
makeWall(18,8,1,8);
makeWall(7,16,12,1);
printMap();
for(int i=0; i < NPCs.size(); i++){
if(abs(player.x - NPCs[i].x) <= 1 && abs(player.ypos - NPCs[i].ypos) <= 1){
NPCs[i].say(NPCs[i].message);
}
}
y[player.ypos][player.x] = ' ';
cout << endl << endl << endl;
if(getchar() == '\033'){
getchar();
switch(getchar()){
case 'A':
player.mv("up");
break;
case 'B':
player.mv("down");
break;
case 'C':
player.mv("right");
break;
case 'D':
player.mv("left");
break;
}
}
system("clear");
}
bt.off();
return 0;
}