I followed the videos line per line but my workspace is riddled with errors and won’t make the nebulae like it’s shown in the video
instructor: Stephen Ulibarri
Course: C++ Fundamentals: Game Programming For Beginners
i’ll paste my code here
#include “raylib.h”
struct AnimData
{
Rectangle rec;
Vector2 pos;
int frame;
float updateTime;
float runningTime;
};
int main()
{
int windowDimensions[2];
windowDimensions[0] = 512;
windowDimensions[1] = 380;
// initialize the window
InitWindow(windowDimensions[0], windowDimensions[1], "Dapper Dasher!");
// acceleration due to gravity (pixel/s/s
const int gravity{1'000};
// nebula variables
Texture2D nebula = LoadTexture("textures/12_nebula_spritesheet.png");
const int sizeofNebulae{6};
AnimData nebulae[sizeofNebulae]{};
for (int i = 0; i < sizeofNebulae; i++)
{
nebulae[i].rec.x = 0.0;
nebulae[i].rec.y = 0.0;
nebulae[i].rec.width = nebula.width/8;
nebulae[i].rec.height = nebula.height/8;
nebulae[i].pos.y = windowDimensions[1] - nebula.height/8;
nebulae[i].frame = 0;
nebulae[i].runningTime = 0.0;
nebulae[i].updateTime = 0.0;
nebulae[i].pos.x = windowDimensions[0] + i * 300;
}
// nebula x velocity (pixels/second)
int nebVel{-200};
// scarfy variables
Texture2D scarfy = LoadTexture("textures/scarfy.png");
AnimData scarfyData;
scarfydata.rec.width = scarfy.width/6;
scarfyData.rec.height = scarfy.height;
scarfyData.rec.x = 0;
scarfyData.rec.y = 0;
scarfyData.pos.x = windowDimensions[0]/2 - scarfyData.rec.width/2;
scarfyData.pos.y = windowDimensions[1] - scarfyData.rec.height;
scarfyData.frame = 0;
scarfyData.updateTime = 1.0/12.0;
scarfyData.runningTime = 0.0;
// jump velocity (pixels/second)
const int jumpVel{-600};
// rectangle is in the air?
bool isInAir{};
int velocity{0};
SetTargetFPS(60);
while (!WindowShouldClose())
{
// delta time (time since last frame)
const float dT{GetFrameTime()};
// start drawing
BeginDrawing();
ClearBackground(WHITE);
if (scarfyData.pos.y >= windowDimensions[1] - scarfyData.rec.height )
{
// rectangle is on the ground
velocity = 0;
isInAir = false;
}
else
{
// rectangle is in the air
velocity += gravity * dT;
isInAir = true;
}
// check for jumping
if (IsKeyPressed(KEY_SPACE) && !isInAir)
{
velocity += jumpVel;
}
for(int i = 0; i < sizeofNebulae; i++)
{
//update the position of each nebula
nebulae[i].pos.x += nebVel * dT;
}
// update scarfy position
scarfyData.pos.y += velocity * dT;
// update scarfy's animation frame
if (!isInAir)
{
// update running time
runningTime += dT;
if(scarfyData.runningTime >= scarfyData.updateTime)
{
scarfyData.runningTime = 0.0;
// update animation frame
scarfyData.rec.x = scarfyData.frame * scarfyData.rec.width;
scarfyData.frame++;
if (scarfyData.frame > 5)
{
scarfyData.frame = 0;
}
}
}
for (int i = 0; i < sizeofNebulae; i++)
{
// update nebula animation frame
nebulae[i].RunningTime += dT;
if (nebulae[i].RunningTime >= nebulae[i].UpdateTime)
{
nebulae[i].RunningTime = 0.0;
nebulae[i].rec.x = nebulae[i].Frame * nebRec.width;
nebulae[i].Frame++;
if (nebulae[i].Frame > 7)
{
nebulae[i].Frame = 0;
}
}
}
for (int i = 0; i < sizeofNebulae, i++)
{
// draw nebula
DrawTextureRec(nebula, nebulae[i].Rec, nebulae[i].Pos, WHITE);
}
// draw Scarfy
DrawTextureRec(scarfy, scarfyData.rec, scarfyData.pos, WHITE);
// stop drawing
EndDrawing();
}
UnloadTexture(scarfy);
UnloadTexture(nebula);
CloseWindow();
}