Fistashka & Pipius
Hey Pipius, imagine if we could code a game where the level layout spins around like a spinning top every time you hit a button—would you be up for the challenge?
That sounds insane, but I love insane. Let’s hash out a physics engine that treats the map as a rigid body, use a quaternion rotation around the center of mass each button press, and keep the collision mesh updated on the fly. I’ll start with a simple 2D prototype in SDL, then expand to 3D with my own light physics loop. Don’t worry about the UI, I’ll throw that out the window if it slows me down. Ready to spin?
Wow, this is going to be a whirlwind! I’m all in—let’s spin this into a wild ride! Just give me the first chunk of code, and I’ll jump in with a crazy idea for the collision mesh update. Let’s keep the UI optional, because who needs it when you can dance on the edge of physics? Let's do it!
```c
// spinning_level.c
#include <SDL.h>
#include <math.h>
#define WIDTH 800
#define HEIGHT 600
#define ROT_SPEED 0.05
typedef struct {
SDL_Rect rect;
double angle; // current rotation angle
} Tile;
Tile tiles[10]; // simple 10 tiles for demo
int numTiles = 10;
void initTiles() {
for (int i = 0; i < numTiles; ++i) {
tiles[i].rect.x = i * 70 + 50;
tiles[i].rect.y = HEIGHT / 2 - 25;
tiles[i].rect.w = 60;
tiles[i].rect.h = 50;
tiles[i].angle = 0;
}
}
void rotateTile(Tile *t, double delta) {
t->angle += delta;
if (t->angle > 2*M_PI) t->angle -= 2*M_PI;
if (t->angle < 0) t->angle += 2*M_PI;
}
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *win = SDL_CreateWindow("Spin",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
WIDTH, HEIGHT, 0);
SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
initTiles();
int running = 1;
while (running) {
SDL_Event e;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) running = 0;
if (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_SPACE) {
for (int i = 0; i < numTiles; ++i)
rotateTile(&tiles[i], ROT_SPEED);
}
}
SDL_SetRenderDrawColor(ren, 30, 30, 30, 255);
SDL_RenderClear(ren);
for (int i = 0; i < numTiles; ++i) {
SDL_Rect r = tiles[i].rect;
SDL_Point center = { r.x + r.w/2, r.y + r.h/2 };
SDL_RenderSetScale(ren, 1, 1); // reset scale
SDL_RenderSetViewport(ren, NULL);
// rotate the renderer's matrix
SDL_RenderSetScale(ren, cos(tiles[i].angle), sin(tiles[i].angle));
SDL_SetRenderDrawColor(ren, 200, 100, 50, 255);
SDL_RenderFillRect(ren, &r);
}
SDL_RenderPresent(ren);
SDL_Delay(16);
}
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
```