#include #include #include #include "platform.c" void PaintMask(float *mask, float x, float y, float color, float size) { for (int j = y - size / 2; j < y + size / 2; j++) { for (int i = x - size / 2; i < x + size / 2; i++) { if (i > 0 && i < WINDOW_W && j > 0 && j < WINDOW_H) { size_t index = i + j * WINDOW_W; mask[index] = color; } } } } void GameMain() { // Terrain generation float *mask = calloc(WINDOW_W * WINDOW_H, sizeof(float)); for (int i = 0; i < 100 * WINDOW_W; i++) { mask[i] = 1.0; } // Player variables float player_x = 100; float player_y = 500; float player_vy = 0; float player_ay = -9.8; // Timer variables float old_t = 0.0; // Event handling int exit = 0; while (!exit) { SDL_Event event; while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { exit = 1; } } int mouse_x, mouse_y; Uint32 mouse_state = SDL_GetMouseState(&mouse_x, &mouse_y); float size = 100; if (mouse_state & SDL_BUTTON_LMASK) { PaintMask(mask, mouse_x, WINDOW_H - mouse_y, 1.0, size); } else if (mouse_state & SDL_BUTTON_RMASK) { PaintMask(mask, mouse_x, WINDOW_H - mouse_y, 0.0, size); } // Time delta calculation double new_t = GetCurrentTimestamp(); double dt = new_t - old_t; old_t = new_t; // Player logic if (mask[(int)player_x + (int)player_y * WINDOW_W] == 0.0) { player_y += player_vy * dt; player_vy += player_ay * dt; } else { player_y += 1; player_vy = 0; } RenderScene(mask, player_x, player_y); SDL_Delay(1); } } int main() { PlatformMain(GameMain); return 0; }