aboutsummaryrefslogtreecommitdiff
path: root/games/gamecatch.c
diff options
context:
space:
mode:
Diffstat (limited to 'games/gamecatch.c')
-rw-r--r--games/gamecatch.c80
1 files changed, 68 insertions, 12 deletions
diff --git a/games/gamecatch.c b/games/gamecatch.c
index e12e48e..0b28c6e 100644
--- a/games/gamecatch.c
+++ b/games/gamecatch.c
@@ -34,35 +34,51 @@
// i just realized this is basically cmatrix with a little guy at the bottom
*/
-#define width 40;
-#define height 50;
+#define width 40
+#define height getmaxy(stdscr)
+#define maxdrops 70
int running;
+int won;
+int howmany;
typedef struct{
int posx;
int posy;
- char *symbol[3];
+ int active;
+ char *symbol;
}drop;
typedef struct{
int posx;
char *face[2];
+ int direction;
}cursor;
-void spawndrops(){
-
-return;
-
+static drop droop[maxdrops];
+void spawndrops() {
+ for (int i = 0; i < maxdrops; i++) {
+ if (!droop[i].active) {
+ droop[i].posx = 1 + rand() % (width - 2);
+ droop[i].posy = 0;
+ droop[i].active = 1;
+ char *symbols[] = {"O", "0", "o"};
+ droop[i].symbol = symbols[rand() % 3];
+ break;
+ }
+ }
}
void stop() {
if (!isendwin()) {
+ clear();
+ refresh();
endwin();
}
- addstat(&rat.clean);
+ if(won){addstat(&rat.clean);}
+ won = 0;
running = 0;
}
@@ -75,15 +91,17 @@ void gamecatch(){
static int initialized = 0;
if(initialized == 0){ initscr();}else{refresh();} // turns out you don't wanna call initscr() many times per session so do this because it glitches otherwise
++initialized;
+ howmany = 0;
noecho();
cbreak();
+ nodelay(stdscr, TRUE);
keypad(stdscr, TRUE);
curs_set(0);
- drop droop = {0, 0, {"O", "0", "o"}}; //on spawn random which symbol it'll use
- cursor curs = {20, {"(>.<)_", "_(>.<)" }}; //face[0] is going left face[1] is going right
+ cursor curs = {width / 2, {"(>.<)_", "_(>.<)"}, 0};
+ for (int i = 0; i < maxdrops; i++) droop[i].active = 0;
running = 1;
while (running) {
@@ -91,12 +109,50 @@ void gamecatch(){
switch (ch) {
case 'q': case 'Q': stop(); break;
case 'a': case 'A': case KEY_LEFT:
- curs.posx--;
+ curs.posx-= 2;
+ if(curs.posx < 0) curs.posx = width - 6;
+ curs.direction = 0;
break;
case 'd': case 'D': case KEY_RIGHT:
- curs.posx++;
+ curs.posx += 2;
+ if(curs.posx > width - 6) curs.posx = 0;
+ curs.direction = 1 ;
break;
}
+
+
+ if (!running) break;
+ if (rand() % 10 < 2) spawndrops();
+
+ clear();
+
+ mvprintw(0, width + 2, "caught: %d/30", howmany);
+ mvprintw(1, width + 2, "(catch 30 to win!)");
+ mvprintw(2, width + 2, "move with A and D");
+ mvprintw(3, width + 2, "or the or the corresponding arrows");
+
+
+
+ for (int i = 0; i < maxdrops; i++) {
+ if (droop[i].active) {
+ mvaddstr(droop[i].posy, droop[i].posx, droop[i].symbol);
+ droop[i].posy++;
+ if (droop[i].posy >= height) droop[i].active = 0;
+
+ if (droop[i].posy == height - 1 &&
+ droop[i].posx >= curs.posx &&
+ droop[i].posx <= curs.posx + 5) {
+ droop[i].active = 0;
+ howmany++;
+ if(howmany == 30){won = 1; running = 0;}
+ }
+ }
+ }
+
+ mvaddstr(height - 1, curs.posx, curs.face[curs.direction]);
+
+ refresh();
+ usleep(100000);
}
stop();