made the anti go off screen code non existant by making map.h return & if invalid

This commit is contained in:
zombie maniac 2022-03-14 00:46:29 -04:00
parent 35ff2debdb
commit 3af2f2fd21
Signed by: nbrooks211
GPG key ID: F43C85C0DF0C334E
3 changed files with 15 additions and 29 deletions

View file

@ -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;
} }

View file

@ -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));

View file

@ -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'},