2025-02-05 15:41:06 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
#include "raymath.h"
|
|
|
|
|
|
|
|
#define ROPE_LEN 20
|
|
|
|
#define ROPE_WIDTH 10
|
|
|
|
|
|
|
|
#define NB_ROPE 50
|
|
|
|
Vector2 ropes[NB_ROPE];
|
|
|
|
Vector2 forces[NB_ROPE];
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
InitWindow(1920, 1080, "speedrun");
|
|
|
|
SetWindowState(FLAG_FULLSCREEN_MODE|FLAG_WINDOW_RESIZABLE);
|
|
|
|
SetTargetFPS(60);
|
|
|
|
|
|
|
|
while (!WindowShouldClose()) {
|
|
|
|
BeginDrawing();
|
|
|
|
{
|
|
|
|
ClearBackground(GRAY);
|
|
|
|
|
|
|
|
ropes[0] = GetMousePosition();
|
|
|
|
DrawCircleV(ropes[0], 5, YELLOW);
|
|
|
|
|
|
|
|
for (int i = 1; i < NB_ROPE; i++) {
|
|
|
|
Vector2 old = ropes[i];
|
|
|
|
|
|
|
|
if (!IsKeyDown(KEY_SPACE))
|
2025-02-05 15:48:40 +01:00
|
|
|
forces[i].y += 9.8*69*GetFrameTime();
|
2025-02-05 15:41:06 +01:00
|
|
|
|
|
|
|
ropes[i] = Vector2Add(ropes[i], forces[i]);
|
|
|
|
|
|
|
|
float dist = Vector2Distance(ropes[i-1], ropes[i]);
|
|
|
|
if (!dist) dist = ROPE_LEN;
|
|
|
|
ropes[i] = Vector2Lerp(ropes[i-1], ropes[i], ROPE_LEN/dist);
|
|
|
|
|
|
|
|
Vector2 snap = Vector2Subtract(old, ropes[i]);
|
|
|
|
snap = Vector2Negate(snap);
|
|
|
|
snap = Vector2Scale(snap, GetFrameTime()*37);
|
|
|
|
|
|
|
|
forces[i] = snap;
|
|
|
|
|
|
|
|
DrawCircleV(ropes[i], ROPE_WIDTH/2, YELLOW);
|
|
|
|
DrawLineEx(ropes[i-1], ropes[i], ROPE_WIDTH, YELLOW);
|
|
|
|
|
|
|
|
// DEBUG:
|
|
|
|
// DrawLineEx(old, ropes[i], ROPE_WIDTH, RED);
|
|
|
|
// DrawText(TextFormat("%.3f %.3f", forces[i].x, forces[i].y), 0, (i-1)*25, 25, ORANGE);
|
|
|
|
}
|
|
|
|
|
2025-02-05 15:48:40 +01:00
|
|
|
DrawText(" Mode: ", 0, 1080-25, 25, ORANGE);
|
2025-02-05 15:41:06 +01:00
|
|
|
if (IsKeyDown(KEY_SPACE)) {
|
2025-02-05 15:48:40 +01:00
|
|
|
DrawText("SPACE", MeasureText(" Mode: ", 25), 1080-25, 25, DARKBLUE);
|
2025-02-05 15:41:06 +01:00
|
|
|
} else {
|
2025-02-05 15:48:40 +01:00
|
|
|
DrawText("GRAVITY", MeasureText(" Mode: ", 25), 1080-25, 25, BROWN);
|
2025-02-05 15:41:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EndDrawing();
|
|
|
|
}
|
|
|
|
}
|