Delta time for jump velocity
This commit is contained in:
14
dasher.cpp
14
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;
|
||||
}
|
||||
|
||||
@@ -54,8 +57,9 @@ int main() {
|
||||
velocity += jumpVelocity; // Jump velocity
|
||||
}
|
||||
|
||||
|
||||
// Update position
|
||||
scarfyPos.y += velocity;
|
||||
scarfyPos.y += velocity * dT;
|
||||
|
||||
DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture
|
||||
|
||||
|
||||
Reference in New Issue
Block a user