From afa8ddbaa20ffa4b3059d5fbbc2eba2b0699db31 Mon Sep 17 00:00:00 2001 From: zombie Date: Fri, 4 Mar 2022 12:32:15 -0500 Subject: [PATCH] made it so the player cant leave the playable area and made a border around the playable area --- src/linux.h | 2 +- src/main.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/linux.h b/src/linux.h index 3ad7380..c011b6d 100644 --- a/src/linux.h +++ b/src/linux.h @@ -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(); } diff --git a/src/main.c b/src/main.c index d37463b..7108e2a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,8 +1,30 @@ #include //printf and shit #include -#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; } +