#include “raylib.h”
int main()
{
//window dimensions
const int winWidth{512};
const int winHeight{380};
int velocity{0};
//acceleration due to gravity (pixels/frame/frame)
const int gravity{1};
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 = winWidth/2 - scarfyRec.width/2;
scarfyPos.y = winHeight - scarfyRec.height;
//jump velocity
const int jumpVel{-22};
bool isinAir{};
//initialize window
InitWindow(winWidth, winHeight, "Dapper Dasher!");
SetTargetFPS(60);
while (!WindowShouldClose())
{
//start drawing
BeginDrawing();
ClearBackground(WHITE);
//ground check
if (scarfyPos.y >= winHeight -scarfy.height)
{
//rectangle on ground
velocity = 0;
isinAir = false;
}
else
{
//rectangle in air
velocity += gravity;
isinAir = true;
}
//check for jumping
if (IsKeyPressed(KEY_SPACE) && !isinAir)
{
velocity += jumpVel;
}
// update position
scarfyPos.y += velocity;
//start texture
DrawTextureRec(scarfy, scarfyRec, scarfyPos, WHITE);
//stop drawing
EndDrawing();
}
UnloadTexture(scarfy);
CloseWindow();
}