Copy paste broke my whole code

Hello during the last part of the video where we copy/paste our for loop of drawing the nebula and scarfy textures for collision, a majority of my lines of code turned red and brings up 79 problems.
Here is the code.

#include "raylib.h"vector2

struct AnimData

{

Rectangle rec;

Vector2 pos;

int frame;

float updateTime;

float runningTime;

};

bool isOnGround(AnimData data, int windowHeight)

{

return data.pos.y >= windowHeight - data.rec.height;

}

AnimData updateAnimData(AnimData data, float deltaTime, int maxFrame)

{

//update running time

data.runningTime += deltaTime;

if (data.runningTime >= data.updateTime)

{

    data.runningTime = 0.0;

    //update animation frame

    data.rec.x = data.frame * data.rec.width;

    data.frame++;

    if (data.frame > maxFrame)

    {

        data.frame = 0;

    }

}

return data;

}

int main()

{

int windowDimensions[2];

windowDimensions[0] = 512;

windowDimensions[1] = 380;

InitWindow(windowDimensions[0], windowDimensions[1], "Dapper-Dasher!");

//acceleration due to gravity (pixels/second)/second

const int gravity{1'000};

//jump velocity (pixels/second)

const int jumpVel{-600};

//boolian to determine if we are in the air when trying to jump

bool isInAir{};

//nebula variables

Texture2D nebula = LoadTexture("textures/12_nebula_spritesheet.png");

const int sizeOfNebulae{10};

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 = 1.0/16.0;

    nebulae[i].pos.x = windowDimensions[0] + i * 300;

}

float finishLine{ nebulae[sizeOfNebulae - 1].pos.x };

//nebula X velocity (pixels/second)

int nebVel{-200};

//scarfy variables

Texture2D scarfy = LoadTexture("textures/scarfy.png");

//AnimData for scarfy

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;

int velocity{0};

Texture2D background = LoadTexture("textures/far-buildings.png");

float bgX{};

Texture2D midground = LoadTexture("textures/back-buildings.png");

float mgX{};

Texture2D foreground = LoadTexture("textures/foreground.png");

float fgX{};

bool collision{};



SetTargetFPS(60);

while (!WindowShouldClose())

{

    //delta time (time since last frame)

    const float dT{GetFrameTime()};

    //start drawing

    BeginDrawing();

    ClearBackground(WHITE);

    //background scrolling at 20 pixels/second

    bgX -= 20 * dT;

    if (bgX <= -background.width*2)

    {

        bgX = 0.0;

    }

    //scroll the midground

    mgX -= 40 * dT;

    if (mgX <= -midground.width*2)

    {

        mgX = 0.0;

    }

    //scroll the foreground

    fgX -= 80 * dT;

    if (fgX <= -foreground.width*2)

    {

        fgX = 0.0;

    }

    //draw the background

    Vector2 bg1Pos{bgX, 0.0};

    DrawTextureEx(background, bg1Pos, 0.0, 2.0, WHITE);

    Vector2 bg2Pos{bgX + background.width*2, 0.0};

    DrawTextureEx(background, bg2Pos, 0.0, 2.0, WHITE);

    //draw the midground

    Vector2 mg1Pos{mgX, 0.0};

    DrawTextureEx(midground, mg1Pos, 0.0, 2.0, WHITE);

    Vector2 mg2Pos{mgX + midground.width*2, 0.0};

    DrawTextureEx(midground, mg2Pos, 0.0, 2.0, WHITE);

    //draw the foreground

    Vector2 fg1Pos{fgX, 0.0};

    DrawTextureEx(foreground, fg1Pos, 0.0, 2.0, WHITE);

    Vector2 fg2Pos{fgX + foreground.width*2, 0.0};

    DrawTextureEx(foreground, fg2Pos, 0.0, 2.0, WHITE);

 

    // perform ground check

    if (isOnGround(scarfyData, windowDimensions[1]))

    {

       //rectangle is on the ground

       velocity = 0;  

       isInAir = false;    

    }

    else

    {

       //rectangle is in the air

       velocity += gravity * dT;

       isInAir = true;

    }

   

    //jump check

    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 finish line

    finishLine += nebVel * dT;

    //update scarfy position

    scarfyData.pos.y += velocity * dT;

   

    //update scarfy animation frame

    if (!isInAir)

    {

        scarfyData = updateAnimData(scarfyData, dT, 5);

    }

    for (int i = 0; i < sizeOfNebulae; i++)

    {

        nebulae[i] = updateAnimData(nebulae[i], dT, 7);

    }

    for (AnimData nebula : nebulae)

    {

        float pad{50};

        Rectangle nebRec{

            nebula.pos.x + pad,

            nebula.pos.y + pad,

            nebula.rec.width - 2*pad,

            nebula.rec.height - 2*pad

        };

        Rectangle scarfyRec{

            scarfyData.pos.x,

            scarfyData.pos.y,

            scarfyData.rec.width,

            scarfyData.rec.height

        };

        if (CheckCollisionRecs(nebRec, scarfyRec))

        {

            collision = true;

        }

    }

    if (collision)

    {

        //lose the game

    }

    else

    {

        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(nebula);

UnloadTexture(scarfy);

UnloadTexture(background);

UnloadTexture(midground);

UnloadTexture(foreground);

CloseWindow();

}

If you remove the vector2 that’s next to #include "raylib.h" your code compiles successfully when I test it.

That did it. Thank you so much! not sure how that got there lol

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms