using static SplashKitSDK.SplashKit;
const string GAME_TIMER = "GameTimer";
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
const int SPIDER_RADIUS = 25;
const int SPIDER_SPEED = 3;
const int FLY_RADIUS = 10;
// Set the spider in the center of the screen
int spiderX = SCREEN_WIDTH / 2;
int spiderY = SCREEN_HEIGHT / 2;
int flyX = Rnd(SCREEN_WIDTH), flyY = Rnd(SCREEN_HEIGHT);
bool flyAppeared = false;
long appearAtTime = 1000 + Rnd(2000);
OpenWindow("Fly Catch", SCREEN_WIDTH, SCREEN_HEIGHT);
if (KeyDown(KeyCode.RightKey) && spiderX + SPIDER_RADIUS < SCREEN_WIDTH)
if (KeyDown(KeyCode.LeftKey) && spiderX - SPIDER_RADIUS > 0)
// Check if the fly should appear
if (!flyAppeared && TimerTicks(GAME_TIMER) > appearAtTime)
// Give it a new random position
flyX = Rnd(SCREEN_WIDTH);
flyY = Rnd(SCREEN_HEIGHT);
escapeAtTime = TimerTicks(GAME_TIMER) + 2000 + Rnd(5000);
else if (flyAppeared && TimerTicks(GAME_TIMER) > escapeAtTime)
appearAtTime = TimerTicks(GAME_TIMER) + 1000 + Rnd(2000);
// Test if the spider and fly are touching
if (CirclesIntersect(spiderX, spiderY, SPIDER_RADIUS, flyX, flyY, FLY_RADIUS))
appearAtTime = TimerTicks(GAME_TIMER) + 1000 + Rnd(2000);
ClearScreen(ColorWhite());
FillCircle(ColorBlack(), spiderX, spiderY, SPIDER_RADIUS);
FillCircle(ColorDarkGreen(), flyX, flyY, FLY_RADIUS);
// Get any new user interactions