|
#include "raylib.h" |
|
#include <math.h> |
|
#include <stdio.h> |
|
|
|
typedef struct { |
|
Vector2 pos; |
|
Color color; |
|
} Player; |
|
|
|
int load_next(Texture *t); |
|
|
|
#ifndef load_next_provided |
|
int load_next(Texture *t) { |
|
static int texnum = 0; |
|
UnloadTexture(*t); |
|
*t = LoadTexture(TextFormat("%d.png", ++texnum)); |
|
return 1; |
|
} |
|
#endif |
|
|
|
int main() { |
|
int SX = 1920; |
|
int SY = 1080; |
|
Player players[] = {{.pos = {0, 0}, .color = YELLOW}, |
|
{.pos = {0, 0}, .color = BLUE}, |
|
{.pos = {0, 0}, .color = GREEN}, |
|
{.pos = {0, 0}, .color = RED}}; |
|
|
|
float targetRadius = 0.200; |
|
|
|
SetConfigFlags(FLAG_MSAA_4X_HINT); |
|
SetConfigFlags(FLAG_WINDOW_RESIZABLE); |
|
|
|
InitWindow(SX, SY, "blame photo game [ floating ]"); |
|
InitAudioDevice(); |
|
HideCursor(); |
|
Sound fxSuccess = LoadSound("success.mp3"); |
|
Sound fxTick = LoadSound("tick.wav"); |
|
SetSoundVolume(fxTick, 0.25); |
|
|
|
Texture tex = {}; |
|
load_next(&tex); |
|
|
|
SetTargetFPS(60); |
|
|
|
double lastTick = GetTime(); |
|
Vector2 target = {1, 1}; |
|
bool debug = 0, quit = 0; |
|
while(!WindowShouldClose() && !quit) { |
|
bool next = 0; // next picture? |
|
SX = GetScreenWidth(); |
|
SY = GetScreenHeight(); |
|
|
|
double now = GetTime(); |
|
double delay = fmin(1.5, |
|
fmax(0.15, |
|
(fabs(players[0].pos.x - target.x) + |
|
fabs(players[0].pos.y - target.y)))); |
|
if(now - lastTick > delay) { |
|
PlaySound(fxTick); |
|
lastTick = now; |
|
} |
|
|
|
if(IsKeyPressed(KEY_N)) next = true; |
|
if(IsKeyPressed(KEY_SPACE)) PlaySound(fxTick); |
|
if(IsKeyPressed(KEY_H)) debug = !debug; |
|
|
|
static int pn = 0; |
|
|
|
BeginDrawing(); { |
|
ClearBackground(BLACK); |
|
Vector2 scale2 = {(float)SX / tex.width, (float)SY / tex.height}; |
|
float scale = scale2.x > scale2.y ? scale2.y : scale2.x; |
|
Vector2 pos = { |
|
(SX - scale*tex.width)/2, |
|
(SY - scale*tex.height)/2}; |
|
DrawTextureEx(tex, pos, 0, scale, WHITE); |
|
|
|
Color targetColor = (Color){255,255,0,240}; |
|
Color borderColor = (now - lastTick) > 0.05 |
|
? (Color){0, 0, 0, 100} |
|
: (Color){255, 255, 255, 200}; |
|
Vector2 center = (Vector2){target.x * SX, target.y * SY}; |
|
DrawCircleSector(center, targetRadius * SY + 100, 0, 360, 60, borderColor); |
|
DrawCircleSector(center, targetRadius * SY + 0, 0, 360, 50, targetColor); |
|
|
|
if(sqrt(pow(SX * (players[0].pos.x - target.x), 2) + |
|
pow(SY * (players[0].pos.y - target.y), 2)) < targetRadius * SY) { |
|
next = true; |
|
int rnd = GetRandomValue(0, 3); |
|
switch(rnd) { |
|
case 0: target = (Vector2){0, 0}; break; |
|
case 1: target = (Vector2){0, 1}; break; |
|
case 2: target = (Vector2){1, 0}; break; |
|
case 3: target = (Vector2){1, 1}; break; |
|
} |
|
players[0].pos.x = (1 - target.x); |
|
players[0].pos.y = (1 - target.y); |
|
} |
|
|
|
Vector2 *p = &players[pn].pos; |
|
float dx=0, dy=0; |
|
|
|
if (IsKeyPressed(KEY_LEFT) && pn > 0) pn--; |
|
if (IsKeyPressed(KEY_RIGHT)) pn++; |
|
|
|
if(debug) { |
|
DrawText(TextFormat("%d %.1f", GetFPS(), GetTime()), 10, 0, 50, PURPLE); |
|
//DrawText(TextFormat("delay=%f %f,%f", delay, players[0].pos.x, players[0].pos.y), 10, 50, 50, YELLOW); |
|
DrawText(TextFormat("pn=%d", pn), 10, 50, 50, YELLOW); |
|
} |
|
|
|
for(int j = 0 ; j < 8 ; j++) { |
|
if(IsGamepadAvailable(j)) { |
|
dx += GetGamepadAxisMovement(j, GAMEPAD_AXIS_LEFT_X); |
|
dy += GetGamepadAxisMovement(j, GAMEPAD_AXIS_LEFT_Y); |
|
|
|
dx += GetGamepadAxisMovement(j, GAMEPAD_AXIS_RIGHT_X); |
|
dy += GetGamepadAxisMovement(j, GAMEPAD_AXIS_RIGHT_Y); |
|
|
|
dx += IsGamepadButtonDown(j, GAMEPAD_BUTTON_LEFT_FACE_RIGHT) |
|
- IsGamepadButtonDown(j, GAMEPAD_BUTTON_LEFT_FACE_LEFT); |
|
|
|
dy += IsGamepadButtonDown(j, GAMEPAD_BUTTON_LEFT_FACE_DOWN) |
|
- IsGamepadButtonDown(j, GAMEPAD_BUTTON_LEFT_FACE_UP); |
|
|
|
if(IsGamepadButtonPressed(j, GAMEPAD_BUTTON_MIDDLE_RIGHT)) { |
|
next = true; |
|
} |
|
} |
|
} |
|
|
|
if(dx < -1) dx = -1; if(dx > 1) dx = 1; |
|
if(dy < -1) dy = -1; if(dy > 1) dy = 1; |
|
|
|
if(IsKeyDown(KEY_W)) dy = -1; |
|
if(IsKeyDown(KEY_A)) dx = -1; |
|
if(IsKeyDown(KEY_S)) dy = 1; |
|
if(IsKeyDown(KEY_D)) dx = 1; |
|
|
|
p->x += 0.01 * (dx * dx * dx); |
|
p->y += 0.01 * (dy * dy * dy); |
|
|
|
if(p->x < 0) p->x = 0; if(p->x > 1) p->x = 1; |
|
if(p->y < 0) p->y = 0; if(p->y > 1) p->y = 1; |
|
|
|
DrawRing((Vector2){p->x * SX, p->y * SY}, 110-4, 110+20, 0, 360, 30, (Color){40, 40, 40, 255}); |
|
DrawCircle(p->x * SX, p->y * SY, 110, (Color){40, 40, 40, 150}); |
|
DrawCircle(p->x * SX, p->y * SY, 60, players[pn].color); |
|
|
|
if(next) { |
|
PlaySound(fxSuccess); |
|
if(!load_next(&tex)) { |
|
quit = true; |
|
} |
|
} |
|
} EndDrawing(); |
|
} |
|
|
|
UnloadTexture(tex); |
|
UnloadSound(fxTick); |
|
|
|
CloseAudioDevice(); |
|
CloseWindow(); |
|
return 0; |
|
} |