-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.c
72 lines (72 loc) · 1.87 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
71
72
//#include "conio.h/conio.h"
#include "Inventory.c"
#include "Entity.c"
#ifndef MAP
#include "Map.c"
#endif
struct player{
struct Pos pos;
Entity entity;
Inventory inventory;
};
typedef struct player Player;
/*struct Pos{
int x;
int y;
int minx;
int miny;
};*/
struct Pos __attribute__((weak)) move(int input,int window_height,struct Pos pos,int map_size,struct Map map){
//Move
int a = 97;
int d = 100;
//if(input == w && pos.y > 1 && !map.map[pos.x][pos.y-1].noAir)pos.y -= 1;
//if(input == s && pos.y < window_height && !map.map[pos.x][pos.y+1].noAir)pos.y += 1;
if(input == a && pos.x > 1){
if(!map.map[pos.x-1][pos.y].noAir){
pos.x -= 1;
}
else if(!map.map[pos.x-1][pos.y-1].noAir && !map.map[pos.x][pos.y-1].noAir){
pos.x -= 1;
pos.y -= 1;
}
if(pos.x >= 2 && pos.x - pos.minx <= 1){
pos.minx -= 1;
}
}
if(input == d && pos.x < map_size && map_size - pos.x >= 1){
if(!map.map[pos.x+1][pos.y].noAir){
pos.x += 1;
}
else if(!map.map[pos.x+1][pos.y-1].noAir && !map.map[pos.x][pos.y-1].noAir){
pos.x += 1;
pos.y -= 1;
}
if(pos.x > window_height-1 && (window_height + pos.minx)-pos.x <= 2){
pos.minx += 1;
}
}
return pos;
}
Player Gravity(Player player,struct Map map){
float height = 0;
while(!map.map[player.pos.x][player.pos.y+1].noAir && player.pos.y < WINDOW_HEIGHT){
player.pos.y += 1;
height++;
}
if(height >=3){
player.entity.health -= height*0.5;
}
return player;
}
struct Map __attribute__((weak)) demolishBlock(int input,struct Pos pos,struct Map map){
int w = 119;
int s = 115;
int q = 113;
int e = 101;
if(input == w)map.map[pos.x][pos.y-1].noAir = false;
if(input == s)map.map[pos.x][pos.y+1].noAir = false;
if(input == q)map.map[pos.x-1][pos.y].noAir = false;
if(input == e)map.map[pos.x+1][pos.y].noAir = false;
return map;
}