-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNPC.cpp
More file actions
72 lines (69 loc) · 1.6 KB
/
Copy pathNPC.cpp
File metadata and controls
72 lines (69 loc) · 1.6 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
#include"NPC.h"
#include<ctime>
void NPC::move()
{
//generate random direction to move
srand(time(nullptr));
CharactorState st;
npc_sourceX += (616/8);
npc_sourceX %= 616;
st = static_cast<CharactorState>(rand()%4);
int dx = dir[st][0];
int dy = dir[st][1];
this->set_state(st);
//move if the step is not out of range otherwise return
if(this->valid_move(dx,dy))
{
this->set_state(st);
this->step(dx * speed,dy * speed);
}
else
{
return;
}
}
bool NPC::dig()
{
//dif the grid with waste otherwise return
if(isfull( this->get_gridx(),this->get_gridy() ))
{
//mark the waste empty
//set_empty(this->get_gridx(),this->get_gridy());
//add point to the charactor
grid[get_gridx()][get_gridy()].set_discovered();
this->add_point(get_waste_value(
this->get_gridx(),this->get_gridy()
)
);
return true;
}
else
{
//printf("NPC: no waste\n");
return false;
}
}
void NPC::update()
{
Inc_count();
if(dig_time())
{
//reset count
set_count(0);
this->dig();
}
else
{
//std::cout << "HI\n" ;
move();
}
}
void NPC::PrintInfo()
{
std::cout<<"------------"<<"NPC Info"<<"----------"<<std::endl;
std::cout<<"posx: "<<get_posx()<<std::endl;
std::cout<<"posy: "<<get_posy()<<std::endl;
std::cout<<"gridx: "<<get_gridx()<<std::endl;
std::cout<<"gridy: "<<get_gridy()<<std::endl;
std::cout<<"------------------END----------------------"<<std::endl;
}