Animation added with frames and air check. Nebula added no animation
This commit is contained in:
37
dasher.cpp
37
dasher.cpp
@@ -22,6 +22,19 @@ 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 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
|
// Is the rectangle in the air
|
||||||
bool isInAir{};
|
bool isInAir{};
|
||||||
|
|
||||||
@@ -57,10 +70,31 @@ int main() {
|
|||||||
velocity += jumpVelocity; // Jump velocity
|
velocity += jumpVelocity; // Jump velocity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update position
|
// Update position
|
||||||
scarfyPos.y += velocity * dT;
|
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
|
DrawTextureRec(scarfy, scarfyRect, scarfyPos, WHITE); // Draw the texture
|
||||||
|
|
||||||
// End Game Logic
|
// End Game Logic
|
||||||
@@ -69,6 +103,7 @@ int main() {
|
|||||||
|
|
||||||
// Unload texture
|
// Unload texture
|
||||||
UnloadTexture(scarfy);
|
UnloadTexture(scarfy);
|
||||||
|
UnloadTexture(nebula);
|
||||||
|
|
||||||
// Close the window properly
|
// Close the window properly
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
|
|||||||
Reference in New Issue
Block a user