very bad collision(work in progress)

This commit is contained in:
swim67667
2026-06-22 01:29:58 -04:00
commit 22377c6f1a
26 changed files with 4453 additions and 0 deletions

21
OLD/Makefile Normal file
View File

@@ -0,0 +1,21 @@
# 1. Variables (to avoid repeating yourself)
CC = gcc
CFLAGS = -Iinclude
LDFLAGS = -Llib -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
# 2. Default target (runs when you just type 'make')
default: visual text
# 3. Specific build targets
visual: ray.c
$(CC) ray.c -o ray.out $(CFLAGS) $(LDFLAGS)
text: text_physics.c
$(CC) text_physics.c -o text_physics.out $(CFLAGS) $(LDFLAGS)
# 4. Cleanup targets (all mapped to the same action)
clean clear rm remove wipe:
rm -f ray.out text_physics.out
# 5. Phony targets (tells make these are actions, not actual files)
.PHONY: default visual text clean clear rm remove wipe

1743
OLD/include/raylib.h Executable file

File diff suppressed because it is too large Load Diff

BIN
OLD/lib/libraylib.a Executable file

Binary file not shown.

126
OLD/ray.c Normal file
View File

@@ -0,0 +1,126 @@
// ray.c A-0-i by team wholeworldcoding.
// working physics simulation with 1 object, limited playground and fixed parameters
// This is P7MJ, out.
// Changes:
// Reversing gravity makes it work?!!!
// Added scale factor, mathed the shit out of that.
#include <stdio.h>
#include <stdlib.h>
#include "raylib.h"
const float scale=43.7445319335; // We must find a scale factor, as gravity is calculated based on PIXELS rather than METERS. We say the character is 3 ft so we divide 40 pixels by the equvalent amount of meters for 3ft which is .9144. so 40/.9144 to get what one pixel is in terms of meters. Left as a variable because this will probably be recalculated eventually.
const float g = 9.81*scale; // Gravity is inversed cause raylib uses top right corner as origin.
float obj_x = 100; // Starting X (pixels)
float obj_y = 100; // Starting Y (pixels)
float obj_vel_x = 50; // Velocity X (pixels/second)
float obj_vel_y = 0; // Velocity Y (pixels/second)
float ground_y = 550; // Ground at 550 pixels (assuming 600px screen height)
float time_step = 0.0f;
float rect_size = 40; // Size of the rectangle
int main(void) {
const int screenWidth = 800;
const int screenHeight = 600;
InitWindow(screenWidth, screenHeight, "WrldBox // ray.c");
SetTargetFPS(60); // 60 frames per second
float deltaTime = 0.0f;
bool isSimulating = true;
printf(">= SIMULATION PARAMETERS =<\n");
printf("g= %f\nX= %.2f Y= %.2f GROUND_Y= %.2f\nVEL_X= %.2f VEL_Y= %.2f\n\n",
g, obj_x, obj_y, ground_y, obj_vel_x, obj_vel_y);
while (!WindowShouldClose()) {
// Calculate delta time (time since last frame)
deltaTime = GetFrameTime();
// Control simulation with spacebar
if (IsKeyPressed(KEY_SPACE)) {
isSimulating = !isSimulating;
}
// Reset with R key
if (IsKeyPressed(KEY_R)) {
obj_x = 100;
obj_y = 100;
obj_vel_x = 50;
obj_vel_y = 0;
time_step = 0.0f;
isSimulating = true;
printf("\n>= SIMULATION RESET =<\n");
}
// Update physics if simulating and object is above ground
if (isSimulating && obj_y + rect_size/2 < ground_y) {
// Your original physics logic with deltaTime
obj_vel_y += deltaTime * g; // v = u + at
obj_y += obj_vel_y * deltaTime; // s = ut + 1/2 at^2 is handled by this
obj_x += obj_vel_x * deltaTime;
time_step += deltaTime;
// Real-time console output (optional)
if ((int)(time_step * 60) % 30 == 0) { // Print every ~0.5 seconds
printf("\r[%.2fs] X: %.2f Y: %.2f VEL_X: %.2f VEL_Y: %.2f",
time_step, obj_x, obj_y, obj_vel_x, obj_vel_y);
fflush(stdout);
}
}
// Clamp to ground (prevent going through)
if (obj_y + rect_size/2 >= ground_y) {
obj_y = ground_y - rect_size/2;
if (isSimulating) {
printf("\n\n>= Object Hit Ground =<\n");
printf("X: %.2f, Y: %.2f, VEL_X: %.2f, VEL_Y: %.2f TIME: %.2f\n",
obj_x, obj_y, obj_vel_x, obj_vel_y, time_step);
isSimulating = false;
}
}
// Keep rectangle in screen bounds horizontally
if (obj_x - rect_size/2 < 0) obj_x = rect_size/2;
if (obj_x + rect_size/2 > screenWidth) obj_x = screenWidth - rect_size/2;
// Drawing
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw ground line
DrawLine(0, ground_y, screenWidth, ground_y, DARKGRAY);
// Draw ground label
DrawText("GROUND", 10, ground_y + 5, 20, DARKGRAY);
// Draw the falling rectangle
Rectangle rect = { obj_x - rect_size/2, obj_y - rect_size/2, rect_size, rect_size };
DrawRectangleRec(rect, RED);
DrawRectangleLinesEx(rect, 2, MAROON);
// Draw info text
DrawText(TextFormat("Time: %.2f s", time_step), 10, 10, 20, DARKGRAY);
DrawText(TextFormat("Position: (%.1f, %.1f)", obj_x, obj_y), 10, 35, 20, DARKGRAY);
DrawText(TextFormat("Velocity: (%.1f, %.1f)", obj_vel_x, obj_vel_y), 10, 60, 20, DARKGRAY);
DrawText(TextFormat("Status: %s", isSimulating ? "SIMULATING" : "PAUSED"), 10, 85, 20, isSimulating ? GREEN : RED);
// Draw controls help
DrawText("Controls:", screenWidth - 200, 10, 20, DARKGRAY);
DrawText("SPACE: Pause/Resume", screenWidth - 200, 35, 15, DARKGRAY);
DrawText("R: Reset", screenWidth - 200, 55, 15, DARKGRAY);
DrawText("ESC: Exit", screenWidth - 200, 75, 15, DARKGRAY);
// Draw velocity vector (optional visualization)
Vector2 velocityEnd = { obj_x + obj_vel_x * 0.1f, obj_y + obj_vel_y * 0.1f };
DrawLineEx((Vector2){obj_x, obj_y}, velocityEnd, 3, BLUE);
DrawText("Velocity Vector", obj_x + 5, obj_y - 10, 15, BLUE);
EndDrawing();
}
CloseWindow();
return 0;
}

4
OLD/structure.txt Normal file
View File

@@ -0,0 +1,4 @@
launcher.c
render.c
character.c
physics.c

38
OLD/text_physics.c Normal file
View File

@@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <windows.h>
#define cross_sleep(ms) Sleep(ms) // Windows Sleep takes milliseconds
#else
#include <unistd.h>
#define cross_sleep(ms) usleep(ms * 1000) // POSIX usleep takes microseconds
#endif
const float g = -9.81;
float obj_x = 0;
float obj_y = 100;
float obj_vel_x = 3;
float obj_vel_y = 0;
float ground_y = 0;
float time = 0;
int main() {
printf(">= SIMULATION PARAMETERS =<\n");
printf("g= %f\nX= %f Y= %f GROUND_Y= %f\nVEL_X= %.f VEL_Y= %f\n\n", g, obj_x, obj_y, ground_y, obj_vel_x, obj_vel_y);
while (obj_y > ground_y){
// Add to the vel;
obj_vel_y += 0.001 * g;
// calculate change based on new vel
obj_y += obj_vel_y * 0.001;
obj_x += obj_vel_x * 0.001;
printf("\r[%.2fs] X: %.2f Y: %.2f VEL_X: %.2f VEL_Y: %.2f", time, obj_x, obj_y, obj_vel_x, obj_vel_y);
fflush(stdout);
cross_sleep(1);
time += 0.001;
}
printf("\n\n>= Object End Stats =<\n");
printf("X: %.2f, Y: %.2f, VEL_X: %.2f, VEL_Y: %.2f TIME: %f\n", obj_x, obj_y, obj_vel_x, obj_vel_y, time);
return 0;
}