forked from zserge/fenster
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dff3b5
commit 5e56895
Showing
1 changed file
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#include "fenster.h" | ||
#include <math.h> | ||
|
||
#define COOKIE_BASE_SIZE 60 | ||
#define PULSE_SPEED 2 | ||
#define PULSE_AMOUNT 10 | ||
|
||
struct AutoClicker { | ||
const char* name; | ||
unsigned long long int cost; | ||
unsigned long long int cps; | ||
unsigned long long int owned; | ||
}; | ||
|
||
static struct AutoClicker autoclickers[] = { | ||
{"Cursor", 15, 1, 0}, | ||
{"Grandma", 100, 5, 0}, | ||
{"Farm", 1100, 25, 0}, | ||
{"Mine", 12000, 100, 0}, | ||
{"Factory", 130000, 500, 0} | ||
}; | ||
|
||
static int run() { | ||
struct fenster f = {.title = "Cookie Clicker", .width = 800, .height = 600}; | ||
fenster_open(&f); | ||
|
||
const uint32_t BG_COLOR = 0x2A2A2A; | ||
const uint32_t COOKIE_COLOR = 0x8B4513; | ||
const uint32_t TEXT_COLOR = 0xFFFFFF; | ||
const uint32_t BUTTON_COLOR = 0x404040; | ||
const uint32_t HIGHLIGHT_COLOR = 0x606060; | ||
|
||
FensterFontList fonts = fenster_loadfontlist(); | ||
FensterFont* font = fenster_loadfont(fonts.paths[0]); | ||
|
||
int pulse = 0; | ||
unsigned long long int cookies = 0; | ||
unsigned long long int last_time = 0; | ||
unsigned long long int cookies_per_sec = 0; | ||
|
||
while (fenster_loop(&f) == 0 && f.keys[27] == 0) { | ||
fenster_fill(&f, BG_COLOR); | ||
int hovering_cursor = 1; | ||
|
||
pulse += PULSE_SPEED; | ||
int current_size = COOKIE_BASE_SIZE + (int)(sin(pulse / 30.0f) * PULSE_AMOUNT); | ||
|
||
int cookie_x = f.width / 2; | ||
int cookie_y = f.height / 2; | ||
fenster_drawcirc(&f, cookie_x, cookie_y, current_size, COOKIE_COLOR); | ||
|
||
int dx = f.mpos[0] - cookie_x; | ||
int dy = f.mpos[1] - cookie_y; | ||
|
||
if (dx * dx + dy * dy < current_size * current_size) { | ||
hovering_cursor = 2; | ||
if (f.mclick[0]) { | ||
cookies++; | ||
} | ||
} | ||
|
||
unsigned long long int current_time = f.lastsync; | ||
unsigned long long int dt = current_time - last_time; | ||
if (dt >= 1000) { | ||
cookies_per_sec = 0; | ||
for (int i = 0; i < 5; i++) { | ||
cookies_per_sec += autoclickers[i].owned * autoclickers[i].cps; | ||
} | ||
cookies += cookies_per_sec; | ||
last_time = current_time; | ||
} | ||
|
||
fenster_drawtext(&f, font, vsformat("Cookies: %llu", cookies), 10, 30); | ||
fenster_drawtext(&f, font, vsformat("Per Second: %llu", cookies_per_sec), 10, 60); | ||
|
||
const int button_width = 200; | ||
const int button_height = 80; | ||
const int start_y = 100; | ||
|
||
for (int i = 0; i < 5; i++) { | ||
int x = 10; | ||
int y = start_y + i * (button_height + 10); | ||
|
||
int hover = f.mpos[0] >= x && f.mpos[0] <= x + button_width && | ||
f.mpos[1] >= y && f.mpos[1] <= y + button_height; | ||
|
||
if (hover) { | ||
hovering_cursor = 2; | ||
} | ||
|
||
fenster_drawrec(&f, x, y, button_width, button_height, hover ? HIGHLIGHT_COLOR : BUTTON_COLOR); | ||
|
||
fenster_drawtext(&f, font, vsformat("%s\n Cost: %llu\n Owned: %llu", | ||
autoclickers[i].name, autoclickers[i].cost, autoclickers[i].owned), | ||
x + 10, y + 10); | ||
|
||
if (f.mclick[0] && hover && cookies >= autoclickers[i].cost) { | ||
cookies -= autoclickers[i].cost; | ||
autoclickers[i].owned++; | ||
autoclickers[i].cost = autoclickers[i].cost * 115 / 100; | ||
} | ||
} | ||
|
||
fenster_cursor(&f, hovering_cursor); | ||
fenster_sync(&f, 60); | ||
} | ||
|
||
fenster_freefont(font); | ||
fenster_freefontlist(&fonts); | ||
fenster_close(&f); | ||
return 0; | ||
} | ||
|
||
#if defined(_WIN32) | ||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) { | ||
(void)hInstance, (void)hPrevInstance, (void)pCmdLine, (void)nCmdShow; | ||
return run(); | ||
} | ||
#else | ||
int main() { return run(); } | ||
#endif |