Hello, the sprite isn’t showing. Could someone please let me know the fix or if I’m missing something. Code is below.
Thanks!
#include “raylib.h”
main()
{
//window dimensions
const int window_width{1280};
const int window_height{720};
//Initialize window with framerate 60fps
InitWindow(window_width,window_height,“Dapper Dasher: Scarfy Go!”);
SetTargetFPS(60);
//Speed calculations
int velocity {0};
const int gravity {1}; //pixel per frame / per frame
const int jumpSpeed {-20};
bool isInAir {};
//Sprite Variables
Texture2D scarfy = LoadTexture(“Dasher_Project_010923\textures\scarfy.png”);
Rectangle scarfyRec;
scarfyRec.width = scarfy.width/6;
scarfyRec.height = scarfy.height;
scarfyRec.x = 0;
scarfyRec.y = 0;
Vector2 scarfyPos;
scarfyPos.x = window_width/2 - scarfyRec.width/2;
scarfyPos.y = window_height - scarfyRec.height;
// ! - negation operator is the same as ==false
while(!WindowShouldClose())
{
BeginDrawing();
ClearBackground(SKYBLUE);
// Rectangele touches top of window
if (scarfyPos.y <= 0)
{
velocity += gravity;
}
//Rectangle touches bottom of window
if (scarfyPos.y >= window_height - scarfyRec.height)
{
//ground rectangle
velocity =0;
isInAir = false;
}
else
{
//apply gravity to velocity
velocity += gravity;
isInAir = true;
}
// Increase jump velocity with spacebar if not in air
if (IsKeyPressed(KEY_SPACE) && !isInAir)
{
velocity += jumpSpeed;
}
//update Y position
scarfyPos.y += velocity;
DrawTextureRec(scarfy, scarfyRec, scarfyPos, WHITE);
//stop drawing
EndDrawing();
}
UnloadTexture(scarfy);
CloseWindow();
}