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");
|
InitWindow(windowWidth, windowHeight, "ECS Dapper Dasher");
|
||||||
|
|
||||||
// Acceleration due to gravity (pixels per frame/frame)
|
// Acceleration due to gravity (pixels per frame/frame)
|
||||||
const int gravity{ 1 };
|
const int gravity{ 1'000 };
|
||||||
|
|
||||||
// Scarfy setup
|
// Scarfy setup
|
||||||
Texture2D scarfy = LoadTexture("textures/scarfy.png"); // Load the texture
|
Texture2D scarfy = LoadTexture("textures/scarfy.png"); // Load the texture
|
||||||
@@ -27,13 +27,16 @@ int main() {
|
|||||||
|
|
||||||
int velocity{}; // Current velocity
|
int velocity{}; // Current velocity
|
||||||
|
|
||||||
// Jump velocity
|
// Jump velocity (pixels per second)
|
||||||
const int jumpVelocity{-22};
|
const int jumpVelocity{-600};
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
|
// Delta time
|
||||||
|
const float dT = GetFrameTime(); // Delta time (time since last frame)
|
||||||
|
|
||||||
// Start Game Logic
|
// Start Game Logic
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(WHITE);
|
ClearBackground(WHITE);
|
||||||
@@ -45,7 +48,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
velocity += gravity; // Apply gravity when in the air
|
velocity += gravity * dT; // Apply gravity when in the air
|
||||||
isInAir = true;
|
isInAir = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,8 +57,9 @@ int main() {
|
|||||||
velocity += jumpVelocity; // Jump velocity
|
velocity += jumpVelocity; // Jump velocity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update position
|
// Update position
|
||||||
scarfyPos.y += velocity;
|
scarfyPos.y += velocity * dT;
|
||||||
|
|
||||||
DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture
|
DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user