made the anti go off screen code non existant by making map.h return & if invalid
This commit is contained in:
parent
35ff2debdb
commit
3af2f2fd21
3 changed files with 15 additions and 29 deletions
28
src/main.c
28
src/main.c
|
@ -152,34 +152,6 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
|
||||||
} else {enemy.y++;}
|
} else {enemy.y++;}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
TODO clean this shit up
|
|
||||||
this should apply to everything not just the player
|
|
||||||
it should also be generalized to all entitys using a for loop or somthing
|
|
||||||
*/
|
|
||||||
|
|
||||||
//anti go off screen
|
|
||||||
|
|
||||||
if (player.x < 0) {
|
|
||||||
player.x = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.x > (scrwidth - 1)) {
|
|
||||||
player.x = scrwidth - 1;
|
|
||||||
}
|
|
||||||
if (player.y < 0) {
|
|
||||||
player.y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.y > (scrheight - 1)) {
|
|
||||||
player.y = scrheight - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//scrwidth - 1 bc zero indexed moment
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
prevtime = currenttime;
|
prevtime = currenttime;
|
||||||
}
|
}
|
||||||
|
|
14
src/map.h
14
src/map.h
|
@ -1,10 +1,22 @@
|
||||||
char readmap(int x, int y) {
|
char readmap(int x, int y) {
|
||||||
|
if (x > (mapwidth - 1)) {
|
||||||
|
return '&';
|
||||||
|
}
|
||||||
|
if (y > (mapheight - 1)) {
|
||||||
|
return '&';
|
||||||
|
}
|
||||||
|
if (x < 0) {
|
||||||
|
return '&';
|
||||||
|
}
|
||||||
|
if (y < 0) {
|
||||||
|
return '&';
|
||||||
|
}
|
||||||
|
|
||||||
return maptest[y][x]; //TODO make it be able to rrad feom multiple maps but idk how to do that
|
return maptest[y][x]; //TODO make it be able to rrad feom multiple maps but idk how to do that
|
||||||
}
|
}
|
||||||
int render_map(void) {
|
int render_map(void) {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
//I think this is broken but maybe with with the border code idk TODO fix
|
|
||||||
for(y = 0; y < 40; y++) {
|
for(y = 0; y < 40; y++) {
|
||||||
for(x = 0; x < 80; x++) {
|
for(x = 0; x < 80; x++) {
|
||||||
zom_putcharat(x, y, readmap(x, y));
|
zom_putcharat(x, y, readmap(x, y));
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
//TODO make this read from a file instead of from this array pile
|
//TODO make this read from a file instead of from this array pile
|
||||||
|
int mapwidth = 80;
|
||||||
|
int mapheight = 40;
|
||||||
char maptest[40][80] = {
|
char maptest[40][80] = {
|
||||||
{'1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2'},
|
{'1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2'},
|
||||||
{'2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2'},
|
{'2', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '2'},
|
||||||
|
|
Loading…
Reference in a new issue