As soon as I start to think maybe C++ has changed enough since the syntax emotionally scarred me during my undergrad 20 years ago, I start remembering why we had such a mutual hatred for each other. T_T
VSC told me the ) at the end of WindowShouldClose() “cannot be used as a function gcc” and the false right after it (or true if I change it to != true) is “not declared in this scope gcc”. Here is a copy/paste of everything that was in VSC when that happened.
#include “raylib.h”
int main()
{
int width = 350;
InitWindow(width, 200, “Kalas’ Window”);
while (WindowShouldClose() == false)
{
BeginDrawing();
ClearBackground(RED);
EndDrawing();
}
}
I then deleted everything, typed what is below and it magically worked. What is different between these two? I have absolutely no idea.
#include “raylib.h”
int main()
{
int width = 350;
InitWindow(width, 200, “Kalas’ Window”);
@KalasZX If you are using VS Code and you see a red squiggle under an #include it means VS Code cannot find that file (e.g., raylib.h). Depending how you compile, it may mean that VC or gcc can’t find it either.
There are various ways to cure that depending on environment and/or VS Code settings magic. In the Visual Studio IDE, configuration settings can be used.
I’m starting to wonder if VS code is intentionally trolling me. Here’s what I have about halfway through Dapper Dasher:
#include “raylib.h”
int main()
{
//window dimensions
const int windowWidth{512};
const int windowHeight{380};
InitWindow(windowWidth, windowHeight, "Dapper Dasher");
//acceleration due to gravity (pixels/frame)/frame
const int gravity{1000};
const int jumpVel{-600};
//is the rectangle in the air
bool isInAir{};
//nebula variables
Texture2D nebula = LoadTexture("textures/12_nebula_spritesheet.png");
Rectangle nebRec {0, 0, nebula.width/8, nebula.height/8};
Vector2 nebPos{windowWidth, windowHeight - nebRec.height};
//mebula x velocity (pixels per second)
int nebVel{-600};
//scarfy variables
Texture2D scarfy = LoadTexture("textures/scarfy.png");
Rectangle scarfyRec;
scarfyRec.width = scarfy.width/6;
scarfyRec.height = scarfy.height;
scarfyRec.x = 0;
scarfyRec.y = 0;
Vector2 scarfyPos;
scarfyPos.x = windowWidth/2 - scarfyRec.width/2;
scarfyPos.y = windowHeight - scarfyRec.height;
//animeation frame
int frame{0};
int velocity{0};
//amount of time before updating the animation frame
const float updateTime{1.0/12.0};
float runningTime{0};
//initialize the window
SetTargetFPS(60);
while (!WindowShouldClose())
{
//delta time (time since last frame)
const float dT{GetFrameTime()};
//start drawing
BeginDrawing();
ClearBackground(WHITE);
if (scarfyPos.y >= windowHeight - scarfyRec.height)
{
//rectangle is on the ground
velocity = 0;
isInAir = false;
}
else
{
//rectangle is in the air, apply gravity
velocity += gravity * dT;
isInAir = true;
}
//check for jumping
if (IsKeyPressed(KEY_SPACE) && !isInAir)
{
velocity += jumpVel;
}
//update position
scarfyPos.y += velocity * dT;
//update running time
runningTime += dT;
if (runningTime >= updateTime)
{
runningTime = 0.0;
//update animation frame
scarfyRec.x = frame * scarfyRec.width;
frame++;
if (frame > 5)
{
frame = 0;
}
}
//Draw nebula
DrawTextureRec{nebula, nebRec, nebPos, WHITE};
//Draw Scarfy
DrawTextureRec(scarfy, scarfyRec, scarfyPos, WHITE);
//stop drawing
EndDrawing();
}
UnloadTexture(scarfy);
UnloadTexture(nebula);
CloseWindow();
}
Adding the line “DrawTextureRec{nebula, nebRec, nebPos, WHITE};” is breaking the program. By adding this line I am apparently missing a semicolon that prevents the program from compiling. It runs just fine when I remove that line, although it will sometimes put a red squiggle on the empty space with the same error message. It’s just adding code that looks right that prevents it from compiling. I’ve looked at it for 15 minutes and I have absolutely no idea what the problem could be. Clicking quick fix offers to turn off the error message but does not actually make the code compile so I’m not sure what value that is supposed to have either. A screenshot is attached on the chance that I am explaining this incorrectly.