Compare commits

3 Commits
dev1 ... main

Author SHA1 Message Date
ae78c19cd8 nebula animation 2025-11-26 17:26:42 -05:00
bc000ae2c0 Animation added with frames and air check. Nebula added no animation 2025-11-26 17:06:56 -05:00
2dcd58dbde Delta time for jump velocity 2025-11-26 04:24:07 -05:00

View File

@@ -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
@@ -22,18 +22,38 @@ int main() {
scarfyPos.x = windowWidth / 2 - scarfyRect.width / 2; scarfyPos.x = windowWidth / 2 - scarfyRect.width / 2;
scarfyPos.y = windowHeight - scarfyRect.height; scarfyPos.y = windowHeight - scarfyRect.height;
// Nebula setup
Texture2D nebula = LoadTexture("textures/12_nebula_spritesheet.png"); // Load the texture
Rectangle nebRect{0.0, 0.0, nebula.width / 8, nebula.height / 8};
Vector2 nebulaPos{windowWidth, windowHeight - nebRect.height};
int nebFrame{}; // Nebula animation frame
const float nebUpdateTime{1.0 / 12.0}; // Nebula running time
float nebRunningTime{}; // Nebula time since last frame change
int nebVel{-200}; // Nebula x velocity (pixels per second)
// Animation Frame
int frame{};
const float updateTime{1.0 / 12.0}; // Time between frames
float runningTime{}; // Time since last frame change
// Is the rectangle in the air // Is the rectangle in the air
bool isInAir{}; bool isInAir{};
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 +65,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,9 +74,48 @@ int main() {
velocity += jumpVelocity; // Jump velocity velocity += jumpVelocity; // Jump velocity
} }
// Update position // Nebula movement
scarfyPos.y += velocity; nebulaPos.x += nebVel * dT;
// Update position
scarfyPos.y += velocity * dT;
// Scarfy Animation Logic
if (!isInAir)
{
// Update running time
runningTime += dT;
if (runningTime >= updateTime)
{
runningTime = 0.0;
// Update animation frame
scarfyRect.x = frame * scarfyRect.width;
frame++;
if (frame > 5)
{
frame = 0;
}
}
}
// Nebula animation frame
nebRunningTime += dT;
if (nebRunningTime >= (nebUpdateTime))
{
nebRunningTime = 0.0;
nebRect.x = nebFrame * nebRect.width;
nebFrame++;
if (nebFrame > 7)
{
nebFrame = 0;
}
}
// draw Nebula
DrawTextureRec(nebula, nebRect, nebulaPos, WHITE); // Draw the texture
// draw Scarfy
DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture
// End Game Logic // End Game Logic
@@ -65,6 +124,7 @@ int main() {
// Unload texture // Unload texture
UnloadTexture(scarfy); UnloadTexture(scarfy);
UnloadTexture(nebula);
// Close the window properly // Close the window properly
CloseWindow(); CloseWindow();