mirror of
https://git.squeakyrat.moe/petratc/
synced 2026-11-04 18:35:43 +01:00
changed name of files and fixed up a couple things
This commit is contained in:
1 parent
085c78540c
commit
6e132af562
4 files changed
+48
-36
No files matched your search
+1
-1
@@ -1 +1 @@
|
||||
cpetrat
|
||||
petratc
|
||||
@@ -1,7 +1,7 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -Wextra
|
||||
TARGET = cpetrat
|
||||
SRC = cpetrat.c
|
||||
TARGET = petratc
|
||||
SRC = petratc.c
|
||||
PREFIX = /usr/local
|
||||
|
||||
$(TARGET): $(SRC)
|
||||
|
||||
+45
-33
@@ -4,39 +4,33 @@
|
||||
#include <sys/stat.h>
|
||||
#include "rat.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define ratpath "%s/Library/Application Support/rat"
|
||||
#define ratsave "%s/Library/Application Support/rat/rat.txt"
|
||||
#else
|
||||
#define ratpath "%s/.local/share/rat"
|
||||
#define ratsave "%s/.local/share/rat/rat.txt"
|
||||
#endif
|
||||
|
||||
void save(void) {
|
||||
char path[256];
|
||||
#ifdef __APPLE__
|
||||
snprintf(path, sizeof(path), "%s/Library/Application Support/rat", getenv("HOME"));
|
||||
#else
|
||||
snprintf(path, sizeof(path), "%s/.local/share/rat", getenv("HOME"));
|
||||
#endif
|
||||
snprintf(path, sizeof(path), ratpath, getenv("HOME"));
|
||||
mkdir(path, 0755);
|
||||
#ifdef __APPLE__
|
||||
snprintf(path, sizeof(path), "%s/Library/Application Support/rat/rat.txt", getenv("HOME"));
|
||||
#else
|
||||
snprintf(path, sizeof(path), "%s/.local/share/rat/rat.txt", getenv("HOME"));
|
||||
#endif
|
||||
snprintf(path, sizeof(path), ratsave, getenv("HOME"));
|
||||
|
||||
FILE *f = fopen(path, "w");
|
||||
if (!f) return;
|
||||
|
||||
fprintf(f, "%f\n%f\n%f\n%f\n%f\n%d\n",
|
||||
rat.hunger, rat.love, rat.fun,
|
||||
rat.clean, rat.health, rat.age);
|
||||
rat.hunger, rat.love, rat.fun, rat.clean, rat.health, rat.age);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void load(void) {
|
||||
char path[256];
|
||||
#ifdef __APPLE__
|
||||
snprintf(path, sizeof(path), "%s/Library/Application Support/rat/rat.txt", getenv("HOME"));
|
||||
#else
|
||||
snprintf(path, sizeof(path), "%s/.local/share/rat/rat.txt", getenv("HOME"));
|
||||
#endif
|
||||
snprintf(path, sizeof(path), ratsave, getenv("HOME"));
|
||||
|
||||
FILE *f = fopen(path, "r");
|
||||
if (!f) {
|
||||
//first run
|
||||
rat.hunger = 100.0f;
|
||||
rat.love = 100.0f;
|
||||
rat.fun = 100.0f;
|
||||
@@ -45,10 +39,8 @@ void load(void) {
|
||||
rat.age = time(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
fscanf(f, "%f\n%f\n%f\n%f\n%f\n%d\n",
|
||||
&rat.hunger, &rat.love, &rat.fun,
|
||||
&rat.clean, &rat.health, &rat.age);
|
||||
&rat.hunger, &rat.love, &rat.fun, &rat.clean, &rat.health, &rat.age);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
@@ -58,18 +50,25 @@ float decay(float current, int timepassed, float rate) {
|
||||
}
|
||||
|
||||
void setstat(){
|
||||
//int n = rand() % 100;
|
||||
int timenow = time(NULL);
|
||||
int newage = timenow - rat.age;
|
||||
|
||||
rat.hunger = decay(100.0f, newage, 0.005f);
|
||||
rat.love = decay(100.0f, newage, 0.002f);
|
||||
rat.fun = decay(100.0f, newage, 0.006f);
|
||||
rat.clean = decay(100.0f, newage, 0.0002f);
|
||||
rat.health = decay(100.0f, newage, 0.00002f);
|
||||
rat.hunger = decay(rat.hunger, newage, 0.005f);
|
||||
rat.love = decay(rat.love, newage, 0.002f);
|
||||
rat.fun = decay(rat.fun, newage, 0.006f);
|
||||
rat.clean = decay(rat.clean, newage, 0.0002f);
|
||||
rat.health = decay(rat.health, newage, 0.00002f);
|
||||
|
||||
|
||||
rat.age = timenow; //while asking grok if the ifdefs for the mac path where fine he said something about time() returning a 64 int in mac but i don't know what that means so i'll ignore it
|
||||
rat.age = timenow; //thinking about this makes my cortisol spike so i'll just ignore it even more
|
||||
}
|
||||
|
||||
//stupid function but it's smart if you think about it. just ignore it
|
||||
void addstat(float *guy){
|
||||
|
||||
if(*guy < 98.5){
|
||||
*guy += 1.5;
|
||||
} else{*guy += 0.05;}
|
||||
}
|
||||
|
||||
void printrat(){
|
||||
@@ -77,7 +76,8 @@ void printrat(){
|
||||
printf("%s\n", ratart);
|
||||
int howmany = sizeof(messages) / sizeof(messages[0]);
|
||||
printf("%s\n", messages[rand() % howmany]);
|
||||
printf("rat hunger: %.2f, rat love: %.2f, rat fun: %.2f, rat dirt: %.2f, rat health: %.2f\n", rat. hunger, rat.love, rat.fun, rat.clean, rat.health);
|
||||
printf("rat hunger: %.2f, rat love: %.2f, rat fun: %.2f, rat dirt: %.2f, rat health: %.2f\n",
|
||||
rat.hunger, rat.love, rat.fun, rat.clean, rat.health);
|
||||
|
||||
}
|
||||
|
||||
@@ -102,11 +102,21 @@ void gameguess(){
|
||||
}else {printf("yes!! correct! squeaaakk!~\n"); solved = 1;}
|
||||
}
|
||||
|
||||
|
||||
if(rat.fun < 98.5){rat.fun += 1.5;} else {rat.fun += 0.05;} //stupid function but it's smart if you think about it. just ignore it
|
||||
addstat(&rat.fun);
|
||||
|
||||
}
|
||||
|
||||
void showergame(){
|
||||
|
||||
//ignore this i'm working on it
|
||||
|
||||
|
||||
|
||||
addstat(&rat.clean);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
srand(time(NULL));
|
||||
int choice;
|
||||
@@ -117,11 +127,13 @@ int truing = 1;
|
||||
printrat();
|
||||
|
||||
while(truing){
|
||||
printf("1: play a game! (fun up), 9: print me!, 0: exit...\n");
|
||||
printf("1: play a game! (fun up), 4: take a shower!, 9: print me!, 0: exit...\n");
|
||||
scanf("%d", &choice);
|
||||
switch(choice){
|
||||
|
||||
case 1: gameguess(); break;
|
||||
case 4: showergame(); break;
|
||||
case 8: printf("%d\n", rat.age); break;
|
||||
case 9: printrat(); break;
|
||||
case 0: truing = 0; break;
|
||||
}
|
||||
Reference in new issue
Block a user