diff --git a/dasher.cpp b/dasher.cpp index 85775fd..3741392 100644 --- a/dasher.cpp +++ b/dasher.cpp @@ -9,7 +9,7 @@ int main() { InitWindow(windowWidth, windowHeight, "ECS Dapper Dasher"); // Acceleration due to gravity (pixels per frame/frame) - const int gravity{ 1 }; + const int gravity{ 1'000 }; // Scarfy setup Texture2D scarfy = LoadTexture("textures/scarfy.png"); // Load the texture @@ -27,13 +27,16 @@ int main() { int velocity{}; // Current velocity - // Jump velocity - const int jumpVelocity{-22}; + // Jump velocity (pixels per second) + const int jumpVelocity{-600}; // Main game loop SetTargetFPS(60); while (!WindowShouldClose()) { + // Delta time + const float dT = GetFrameTime(); // Delta time (time since last frame) + // Start Game Logic BeginDrawing(); ClearBackground(WHITE); @@ -45,7 +48,7 @@ int main() { } else { - velocity += gravity; // Apply gravity when in the air + velocity += gravity * dT; // Apply gravity when in the air isInAir = true; } @@ -53,9 +56,10 @@ int main() { if (IsKeyPressed(KEY_SPACE) && !isInAir) { velocity += jumpVelocity; // Jump velocity } + // Update position - scarfyPos.y += velocity; + scarfyPos.y += velocity * dT; DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture