nebula animation
This commit is contained in:
33
dasher.cpp
33
dasher.cpp
@@ -24,10 +24,14 @@ int main() {
|
|||||||
|
|
||||||
// Nebula setup
|
// Nebula setup
|
||||||
Texture2D nebula = LoadTexture("textures/12_nebula_spritesheet.png"); // Load the texture
|
Texture2D nebula = LoadTexture("textures/12_nebula_spritesheet.png"); // Load the texture
|
||||||
Rectangle nebulaRect{0.0, 0.0, nebula.width / 8, nebula.height / 8};
|
Rectangle nebRect{0.0, 0.0, nebula.width / 8, nebula.height / 8};
|
||||||
Vector2 nebulaPos{windowWidth, windowHeight - nebulaRect.height};
|
Vector2 nebulaPos{windowWidth, windowHeight - nebRect.height};
|
||||||
|
|
||||||
int nevVel{-600}; // Nebula x velocity (pixels per second)
|
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
|
// Animation Frame
|
||||||
int frame{};
|
int frame{};
|
||||||
@@ -70,9 +74,13 @@ int main() {
|
|||||||
velocity += jumpVelocity; // Jump velocity
|
velocity += jumpVelocity; // Jump velocity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nebula movement
|
||||||
|
nebulaPos.x += nebVel * dT;
|
||||||
|
|
||||||
// Update position
|
// Update position
|
||||||
scarfyPos.y += velocity * dT;
|
scarfyPos.y += velocity * dT;
|
||||||
|
|
||||||
|
// Scarfy Animation Logic
|
||||||
if (!isInAir)
|
if (!isInAir)
|
||||||
{
|
{
|
||||||
// Update running time
|
// 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
|
// draw Nebula
|
||||||
DrawTextureRec(nebula, nebulaRect, nebulaPos, WHITE); // Draw the texture
|
DrawTextureRec(nebula, nebRect, nebulaPos, WHITE); // Draw the texture
|
||||||
|
|
||||||
// draw Scarfy
|
// draw Scarfy
|
||||||
DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture
|
DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture
|
||||||
|
|||||||
Reference in New Issue
Block a user