-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.c
70 lines (58 loc) · 1.26 KB
/
player.c
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
#include "fruit.h"
#include "player.h"
#include "monsters.h"
#include <conio.h>
Player *getPlayer()
{
Player *ptr = (Player *) calloc(1, sizeof(Player));
return ptr;
}
void destructPlayer(Player* player)
{
free(player);
}
int isPlayerGetTheFruit(Player *player, Fruit *fruit)
{
if(player->coordinateX == fruit->x && player->coordinateY == fruit->y){
return 1;
}
return 0;
}
/**
* Check if is a player on coordinates
*/
int isPlayer(Player *ptr, const int x,const int y)
{
if(ptr->coordinateX == x && ptr->coordinateY == y)
{
return 1;
}
return 0;
}
void playerRenderEngine(Player *ptr, Board *board)
{
if(kbhit()) {
switch(getch()) {
case 'w':
if(ptr->coordinateX != 1) {
ptr->coordinateX -= 1;
}
break;
case 's':
if(ptr->coordinateX != board->mapHeight - 1) {
ptr->coordinateX += 1;
}
break;
case 'a':
if(ptr->coordinateY != 1) {
ptr->coordinateY -= 1;
}
break;
case 'd':
if(ptr->coordinateY != board->mapWidth - 1){
ptr->coordinateY += 1;
}
break;
}
}
}