begin rop
This commit is contained in:
commit
d38e35b092
|
@ -0,0 +1 @@
|
|||
rope
|
|
@ -0,0 +1,8 @@
|
|||
all:
|
||||
gcc main.c -lraylib -o rope
|
||||
|
||||
run: all
|
||||
./rope
|
||||
|
||||
clean:
|
||||
rm rope
|
|
@ -0,0 +1,62 @@
|
|||
#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))
|
||||
forces[i].y += 9.8*100*GetFrameTime();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
DrawText("Mode: ", 0, 1080-25, 25, ORANGE);
|
||||
if (IsKeyDown(KEY_SPACE)) {
|
||||
DrawText("SPACE", MeasureText("Mode: ", 25), 1080-25, 25, DARKBLUE);
|
||||
} else {
|
||||
DrawText("GRAVITY", MeasureText("Mode: ", 25), 1080-25, 25, BROWN);
|
||||
}
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue