Compare commits

...

1 Commits

Author SHA1 Message Date
4f7a6660d8 found an old version on an old hard drive
i hate git why do i have to make a new branch
2024-01-07 00:01:21 -07:00
3 changed files with 162 additions and 0 deletions

162
older/rfk.c Normal file
View File

@ -0,0 +1,162 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//todo:
//add robot
//challenges:
//populate, addrobot, and addkitten could all be put into one function
int in = 0;
int objects = 30; //1-30 are objects, 31 is kitten, 32 is robot
int x[32]; int y[32]; //int x[(objects + 2)]; int y[(objects + 2)]; the + 2 makes room for kitten and robot, but these should be excluded from for loops
char object_symbol[32]; //char object_symbol[(objects + 2)];
int object_color[32]; //int object_color[(objects + 2)];
int object_brightness[32]; //int object_brightness[(objects + 2)];
int populate_stop = 1;
int addrobot_stop = 1;
int addkitten_stop = 1;
time_t t;
//30 objects, kitten, and robot
//\033[%d;%dH move cursor to spot
//\033[%dm color text
void populate() {
for(int i = 0; i < objects; i++) { //initial position randomization
x[i] = (rand() % 128);
y[i] = (rand() % 64);
object_symbol[i] = ((rand() % 93) + 32); //ansi 33-126
object_color[i] = ((rand() % 8) + 29); //ansi escape code color 30-37
object_brightness[i] = (rand() % 2); //brightness for color value
}
while(populate_stop) { //check if multiple positions are the same, if so then re-randomize those positions
for(int i = 0; i < objects; i++) {
for(int j = 0; j < objects; j++) {
if((x[i] == x[j]) && (y[i] == y[j])) {
x[i] = (rand() % 128);
y[i] = (rand() % 64);
} else {
populate_stop = 0;
}
}
}
}
for (int i = 0; i < objects; i++) { //move cursor to screen position and place object
if (object_brightness) {
printf("\033[%d;%dH\033[%d;1m%c\033[0m",(y[i] + 3),(x[i] + 1),object_color[i],(object_symbol[i]));
} else {
printf("\033[%d;%dH\033[%dm%c\033[0m",(y[i] + 3),(x[i] + 1),object_color[i],(object_symbol[i]));
}
}
}
void addkitten() {
x[31] = (rand() % 128);
y[31] = (rand() % 64);
object_symbol[31] = ((rand() % 93) + 32); //ansi 33-126
object_color[31] = ((rand() % 8) + 29); //ansi escape code color 30-37
object_brightness[31] = (rand() % 2); //brightness for color value
while(addkitten_stop) {
for(int i = 0; i < objects; i++) {
for(int j = 0; j < objects; j++) {
if((x[31] == x[j]) && (y[31] == y[j])) {
x[31] = (rand() % 128);
y[31] = (rand() % 64);
} else {
addkitten_stop = 0;
}
}
}
}
if (object_brightness) {
printf("\033[%d;%dH\033[%d;47;1m%c\033[0m",(y[31] + 3),(x[31] + 1),object_color[31],(object_symbol[31]));
} else {
printf("\033[%d;%dH\033[%d;47m%c\033[0m",(y[31] + 3),(x[31] + 1),object_color[31],(object_symbol[31]));
}
}
void addrobot() {
x[32] = (rand() % 128);
y[32] = (rand() % 64);
object_symbol[32] = 35; //robot is always a bright white #
object_color[32] = 37;
object_brightness[32] = 1;
while(addrobot_stop) {
for(int i = 0; i < objects; i++) {
for(int j = 0; j < objects; j++) {
if((x[32] == x[j]) && (y[32] == y[j])) {
x[32] = (rand() % 128);
y[32] = (rand() % 64);
} else {
addrobot_stop = 0;
}
}
}
}
printf("\033[%d;%dH\033[%d;1m%c\033[0m",(y[32] + 3),(x[32] + 1),object_color[32],(object_symbol[32]));
}
void moverobot(int direction) {
switch(direction) {
case 72 : //up
printf("\033[%d;%dH ",(y[32] + 3),(x[32] + 1));
//for all objects including kitten
//if robot coords + 1 in wahatever direction equal the coords of something else then dont move, otherwise set the coods to that position
for(int i = 0; i < (objects + 1); i++) { //objects + 1 to account for kitten
if((x[32] == x[i]) && ((y[32] - 1) == y[i])) { //trying to have same coords as an object
printf("\033[%d;%dH\033[%d;1m%c\033[0m",(y[32] + 3),(x[32] + 1),object_color[32],(object_symbol[32]));
break;
} else {
y[32] = y[32] - 1;
printf("\033[%d;%dH\033[%d;1m%c\033[0m",(y[32] + 3),(x[32] + 1),object_color[32],(object_symbol[32]));
break;
}
}
case 80 : //down
printf("\033[%d;%dH ",(y[32] + 3),(x[32] + 1));
case 75 : //left
printf("\033[%d;%dH ",(y[32] + 3),(x[32] + 1));
case 77 : //right
printf("\033[%d;%dH ",(y[32] + 3),(x[32] + 1));
}
}
int main() {
{ //initialization
srand(time(t));
system("mode con: cols=128 lines=66");
}
{ //start screen
printf("\033[8;8Hrfk\033[9;8Hyou know the drill\033[10;8Hplaceholder\033[12;8Hpress something");
getch();
system("cls");
}
{ //initial population
printf("\033[1;1Hstatus: the game has started");
printf("\033[2;1H--------------------------------------------------------------------------------------------------------------------------------");
populate();
addkitten();
addrobot();
}
while(in != 27) {
in = getch();
if (in == 0 || in == 0xE0) in = getch(); //got dang ol windows makes you call functions and arrows keys twice to get the input
switch(in) {
case 72 : //up
moverobot(in);
case 80 : //down
moverobot(in);
case 75 : //left
moverobot(in);
case 77 : //right
moverobot(in);
/*default :
printf("pizdec");*/
}
}
}

BIN
older/rfk.exe Normal file

Binary file not shown.

BIN
older/rfk.o Normal file

Binary file not shown.