made it so the player cant leave the playable area and made a border around the playable area

This commit is contained in:
zombie maniac 2022-03-04 12:32:15 -05:00
parent a7ec60390c
commit afa8ddbaa2
Signed by: nbrooks211
GPG key ID: F43C85C0DF0C334E
2 changed files with 62 additions and 3 deletions

View file

@ -18,6 +18,6 @@ int zom_putcharat(int x, int y, char chara){
mvaddch(y, x, chara); //flipped to match screen coords
return 0;
}
char zom_getch(void){
char zom_getch(void) {
return getch();
}

View file

@ -1,8 +1,30 @@
#include <stdio.h> //printf and shit
#include <time.h>
#include "linux.h"
#include "linux.h" //TODO make this detect and change depending on os
int render_border (int width, int height) {
width++;
height++;
// int widthold = width;
int heightold = height;
while(height > 0){
zom_putcharat(width, height, '&');
height--;
}
height = heightold;
while(width > 0){
zom_putcharat(width, height, '&');
width--;
}
return 0;
}
int main( int argc, char *argv[] ) { //yoinked from the internet argc is number of args and argv is a "array of arguments"
clock_t prevtime, currenttime;
prevtime = clock();
@ -26,10 +48,14 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
zom_scrinit();
render_border(80, 40);
while(gamerun) {
currenttime = clock();
dosspin = clock() % 4;
if ((currenttime - prevtime) > delay) {
//TODO fix the timing cancer
// if ((currenttime - prevtime) > delay) {
if ((currenttime % 5000)==0) {
player.xold = player.x;
player.yold = player.y;
enemy.xold = enemy.x;
@ -84,6 +110,33 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
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 > 80) {
player.x = 80;
}
if (player.y < 0) {
player.y = 0;
}
if (player.y > 40) {
player.y = 40;
}
prevtime = currenttime;
}
//entity rendering
@ -116,5 +169,11 @@ int main( int argc, char *argv[] ) { //yoinked from the internet argc is number
printf("Args %d",argc); //anti Wall Werror Wextra
puts(argv[0]);//anti Wall Werror Wextra
printf("%d", delay);
printf("%ld", prevtime);
return 0;
}