playergame/src/movement.h

54 lines
1.6 KiB
C
Raw Normal View History

2022-03-08 08:36:06 -05:00
//TODO fix this bug
//there is a bug with the units arg
//it doesnt check weather EVERY spot in its path is vaiid so it allows the possibity of going thru walls if units is more than 1
2022-03-14 00:27:24 -04:00
int attempt_move(struct entity *fuck, int units, int direction) {
int xfuture = fuck->x;
int yfuture = fuck->y;
2022-03-05 11:22:25 -05:00
switch (direction) {
case 0: // right
xfuture = xfuture + units;
2022-03-14 00:27:24 -04:00
if (readmap(xfuture, fuck->y) == '&') {
2022-03-05 11:22:25 -05:00
return 0;
}
else {
2022-03-14 00:27:24 -04:00
fuck->x++;
fuck->under_char = readmap(fuck->x, fuck->y);
2022-03-05 11:22:25 -05:00
return 1;
}
case 1: // up
yfuture = yfuture - units; // we subtract because moving up
2022-03-14 00:27:24 -04:00
if (readmap(fuck->x, yfuture) == '&') {
2022-03-05 11:22:25 -05:00
return 0;
}
else {
2022-03-14 00:27:24 -04:00
fuck->y--;
fuck->under_char = readmap(fuck->x, fuck->y);
2022-03-05 11:22:25 -05:00
return 1;
}
case 2: // left
xfuture = xfuture - units;
2022-03-14 00:27:24 -04:00
if (readmap(xfuture, fuck->y) == '&') {
2022-03-05 11:22:25 -05:00
return 0;
}
else {
2022-03-14 00:27:24 -04:00
fuck->x--;
fuck->under_char = readmap(fuck->x, fuck->y);
2022-03-05 11:22:25 -05:00
return 1;
}
case 3: // down
yfuture = yfuture + units;
2022-03-14 00:27:24 -04:00
if (readmap(fuck->x, yfuture) == '&') {
2022-03-05 11:22:25 -05:00
return 0;
}
else {
2022-03-14 00:27:24 -04:00
fuck->y++;
fuck->under_char = readmap(fuck->x, fuck->y);
2022-03-05 11:22:25 -05:00
return 1;
}
}
return 0;
}
2022-03-14 00:27:24 -04:00
void all_entity(struct entity *fuck) {
fuck->x++;
}