From 80e6ca1a8ae7d63f4c96d227eab447cb10640c49 Mon Sep 17 00:00:00 2001 From: zombie Date: Sun, 27 Feb 2022 10:24:03 -0500 Subject: [PATCH] added playergame into its own repo --- playergame.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 playergame.c diff --git a/playergame.c b/playergame.c new file mode 100644 index 0000000..2301983 --- /dev/null +++ b/playergame.c @@ -0,0 +1,126 @@ +#include //printf and shit +#include +#include + + +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(); + int delay = 1000; + int dosspin = 0; + + + bool gamerun = true; + + struct entity { + int x; + int y; + int xold; + int yold; + } + + player = {0, 0, 0, 0}, + enemy = {24, 16, 0, 0}, + debugent_x = {0, 0, 0, 0}, + debugent_y = {0, 0, 0, 0}; + + initscr(); + //cbreak(); + nodelay(stdscr, true);//cbreak would wait for you to press a key this doesnt + noecho(); + + clear(); + + while(gamerun) { + currenttime = clock(); + dosspin = clock() % 4; + if ((currenttime - prevtime) > delay) { + player.xold = player.x; + player.yold = player.y; + enemy.xold = enemy.x; + enemy.yold = enemy.y; + debugent_x.xold = debugent_x.x; + debugent_x.yold = debugent_x.y; + debugent_y.xold = debugent_y.x; + debugent_y.yold = debugent_y.y; + + switch (getch()) { + case 'a': + player.y--; + break; + + case 'w': + player.x--; + break; + + case 'd': + player.y++; + break; + + case 's': + player.x++; + break; + + case 'q': + gamerun = false; + break; + case 't': + player.x = 9; + player.y = 9; + break; + //debug case + case 'l': + debugent_x.x++; + debugent_y.y++; + break; + } + //game logic not kb dependent + if ((enemy.x == player.x) && (enemy.y == player.y)){ + endwin(); + puts("you lose :("); + return 0; //TODO fix this this should not be here... + } + //TODO fix enemy movement (it works but its kinda broken) + if ((clock() % 100) == 1) { + if (enemy.x > player.x) { + enemy.x--; + } else {enemy.x++;} + if (enemy.y > player.y) { + enemy.y--; + } else {enemy.y++;} + } + prevtime = currenttime; + } + //entity rendering + mvaddch(enemy.xold, enemy.yold, ' '); + switch (dosspin) { + case 0: + mvaddch(enemy.x, enemy.y, '-'); + break; + case 1: + mvaddch(enemy.x, enemy.y, '/'); + break; + case 2: + mvaddch(enemy.x, enemy.y, '|'); + break; + case 3: + mvaddch(enemy.x, enemy.y, '\\'); + break; + } + + mvaddch(player.xold, player.yold, ' '); + mvaddch(player.x, player.y, '#'); + mvaddch(debugent_x.xold, debugent_x.yold, ' '); + mvaddch(debugent_x.x, debugent_x.y, 'X'); + mvaddch(debugent_y.xold, debugent_y.yold, ' '); + mvaddch(debugent_y.x, debugent_y.y, 'Y'); + } + + //cleanup + endwin(); + + printf("Args %d",argc); //anti Wall Werror Wextra + + puts(argv[0]);//anti Wall Werror Wextra + return 0; +}