Animation added with frames and air check. Nebula added no animation

This commit is contained in:
2025-11-26 17:06:56 -05:00
parent 2dcd58dbde
commit bc000ae2c0

View File

@@ -22,6 +22,19 @@ int main() {
scarfyPos.x = windowWidth / 2 - scarfyRect.width / 2;
scarfyPos.y = windowHeight - scarfyRect.height;
// Nebula setup
Texture2D nebula = LoadTexture("textures/12_nebula_spritesheet.png"); // Load the texture
Rectangle nebulaRect{0.0, 0.0, nebula.width / 8, nebula.height / 8};
Vector2 nebulaPos{windowWidth, windowHeight - nebulaRect.height};
int nevVel{-600}; // 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
bool isInAir{};
@@ -56,11 +69,32 @@ int main() {
if (IsKeyPressed(KEY_SPACE) && !isInAir) {
velocity += jumpVelocity; // Jump velocity
}
// Update position
scarfyPos.y += velocity * dT;
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;
}
}
}
// draw Nebula
DrawTextureRec(nebula, nebulaRect, nebulaPos, WHITE); // Draw the texture
// draw Scarfy
DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture
// End Game Logic
@@ -69,6 +103,7 @@ int main() {
// Unload texture
UnloadTexture(scarfy);
UnloadTexture(nebula);
// Close the window properly
CloseWindow();