When I run my code, my game window closes immediately. I don’t see rectangle at all. It just flashes my window and immediately it disappears. My code looks the exact same as the instructors and for the life of me I can’t figure out what’s wrong. I know it’s gotta be something simple…
Here’s my code: (running on Win 11 with VS Code 1.85.2
#include “raylib.h”
int main ()
{
//WINDOW SIZE
const int windowWidth{512};
const int windowHeight{380};
//CREATE GAME WINDOW
InitWindow(windowHeight,windowWidth,"Dapper Dasher");
//RECTANGLE DIMENSIONS
const int width{50};
const int height{80};
// acceleration due to gravity (pixels per frame per frame.... (pixels/frame/frame)
const int gravity{1};
const int jumpVel{-22};
bool isInAir(false);
int posY{windowHeight - height};
int velocity{0};
SetTargetFPS(60);
while(WindowShouldClose())
{
//START DRAWING
BeginDrawing();
ClearBackground(WHITE);
//Ground CHeck
if (posY >= windowHeight - height)
{
//rectangle is on the ground
velocity = 0;
isInAir = false;
}
else
{
//rectangle is in the air
velocity += gravity;
isInAir=true;
}
if (IsKeyPressed(KEY_SPACE) && !isInAir)
{
velocity += jumpVel;
}
//Update Position
posY += velocity;
DrawRectangle(windowWidth/2, posY, width, height, BLUE);
//STOP DRAWING
EndDrawing();
}
CloseWindow();
}