gaming is now game

This commit is contained in:
zombie maniac 2022-02-12 05:48:58 -05:00
parent fcdab38217
commit d97333c39a
2 changed files with 96 additions and 0 deletions

BIN
a.out

Binary file not shown.

96
playergame.c Normal file
View file

@ -0,0 +1,96 @@
#include <stdio.h> //printf and shit
#include <curses.h>
#include <time.h>
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;
}
player = {0, 0},
enemy = {24, 16};
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) {
mvaddch(player.x, player.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;
}
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;
}
//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...
}
if ((clock() % 500) == 1) {
if (enemy.x > player.x) {
enemy.x--;
} else {enemy.x++;}
if (enemy.y > player.y) {
enemy.y--;
} else {enemy.y++;}
}
prevtime = currenttime;
}
mvaddch(player.x+1, player.y, '#'); //idk how to fix
}
//cleanup
endwin();
printf("Args %d",argc);
puts(argv[0]);
return 0;
}