-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.cpp
More file actions
59 lines (52 loc) · 1.23 KB
/
Copy pathplayer.cpp
File metadata and controls
59 lines (52 loc) · 1.23 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
#include "player.h"
#include "tiles.h"
#include "time.h"
#include "world.h"
#include <stdlib.h>
void Player::check_and_move(int new_map_x, int new_map_y, int new_x, int new_y)
{
map_x = new_map_x;
map_y = new_map_y;
x = new_x;
y = new_y;
hunger -= 3;
thirst--;
}
void Player::move(int dx, int dy)
{
int new_x = x + dx;
int new_y = y + dy;
int new_map_x = map_x;
int new_map_y = map_y;
if (! ((new_x >= 0 && new_x < CHUNK_SIZE) && (new_y >= 0 && new_y < CHUNK_SIZE)))
{
if (new_x < 0 || new_x >= CHUNK_SIZE) {
new_map_x += dx;
new_x += -CHUNK_SIZE * dx;
if (!load_chunk(new_map_x, new_map_y)) return;
}
if (new_y < 0 || new_y >= CHUNK_SIZE)
{
new_map_y += dy;
new_y += -CHUNK_SIZE * dy;
if (!load_chunk(new_map_x, new_map_y)) return;
}
}
check_and_move(new_map_x, new_map_y, new_x, new_y);
}
Player::Player()
{
back_x=0;
back_y=0;
hunger=500;
thirst=250;
map_x = WORLD_CENTER;
map_y = WORLD_CENTER;
inventory = new InvList("inventory");
y = 0;
for (int i=0; i < 10; i++)
{
hotbar[i]=NULL;
craftbar[i]=0;
}
}