nebula animation
This commit is contained in:
33
dasher.cpp
33
dasher.cpp
@@ -24,10 +24,14 @@ int main() {
|
||||
|
||||
// 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)
|
||||
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{};
|
||||
@@ -70,9 +74,13 @@ int main() {
|
||||
velocity += jumpVelocity; // Jump velocity
|
||||
}
|
||||
|
||||
// Nebula movement
|
||||
nebulaPos.x += nebVel * dT;
|
||||
|
||||
// Update position
|
||||
scarfyPos.y += velocity * dT;
|
||||
|
||||
|
||||
// Scarfy Animation Logic
|
||||
if (!isInAir)
|
||||
{
|
||||
// Update running time
|
||||
@@ -91,8 +99,21 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
// 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, nebulaRect, nebulaPos, WHITE); // Draw the texture
|
||||
DrawTextureRec(nebula, nebRect, nebulaPos, WHITE); // Draw the texture
|
||||
|
||||
// draw Scarfy
|
||||
DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture
|
||||
|
||||
Reference in New Issue
Block a user