When I added the array WinDimensions everything stopped running. My sprites are still and nothing moves.
What happened? I’ve checked and re-checked…
No fatal errors detected… just narrowing of int to float… (screenshot below)
#include "raylib.h"
//STRUCT
struct AnimData {
Rectangle Rec;
Vector2 Pos;
int frame;
float UpdateTime;
float RunningTime;
};
//MAIN
int main () {
int WinDimensions[2];
WinDimensions[0] = 1280;
WinDimensions[1] = 720;
InitWindow(WinDimensions[0], WinDimensions[1], "ECCOCI!");
SetTargetFPS(60);
//GAME VARIABLES
const int gravity{1'000};
const int JumpVel{-600};
bool CHECKAIR{};
const float dT{GetFrameTime()};
//characters velocity
int Nvelocity{-20};
int Svelocity{0};
//---------------------------------------
//TEXTURES
Texture2D nebula = LoadTexture("nebula.png");
Texture2D scarfy = LoadTexture("scarfy.png");
//NEBULA 1 E 2
////short struct initialization
AnimData nebulaData{
{0.0, 0.0, nebula.width/8, nebula.height/8},//REC
{WinDimensions[0], WinDimensions[1]-nebula.height/8}, //POS
0, //FRAME
1.0/34.0, //Update time
0, // Running Time
};
AnimData nebula2Data{
{0.0, 0.0, nebula.width/8, nebula.height/8},//REC
{WinDimensions[0] + 300, WinDimensions[1]-nebula.height/8}, //POS
0, //FRAME
1.0/34.0, //Update time
0, // Running Time
};
//SCARFY
//long struct initialization
AnimData scarfyData;
scarfyData.Rec.x=0;
scarfyData.Rec.y=0;
scarfyData.Rec.width=scarfy.width/6;
scarfyData.Rec.height=scarfy.height;
scarfyData.Pos.x = WinDimensions[0]/3 - scarfyData.Rec.width/2;
scarfyData.Pos.y = WinDimensions[1] - scarfyData.Rec.height;
scarfyData.frame=0;
scarfyData.UpdateTime = 1.0/8.0;
scarfyData.RunningTime = 0;
//----------------------------------------
while(WindowShouldClose()==false) {
BeginDrawing();
ClearBackground(BLACK);
//check gravity
if(scarfyData.Pos.y>=WinDimensions[1]-scarfyData.Rec.height) {
Svelocity = 0;
CHECKAIR=false;
}
else {
Svelocity += gravity *dT;
CHECKAIR=true;
}
//check space press
if(IsKeyPressed(KEY_SPACE) && !CHECKAIR) {
Svelocity += JumpVel;
}
//UPDATE ANIMATION POSITIONS
nebulaData.Pos.x += Nvelocity*dT;
nebula2Data.Pos.x += Nvelocity*dT;
scarfyData.Pos.y += Svelocity*dT;
//UPDATE ANIMATION
//update scarfy
if(!CHECKAIR){
scarfyData.RunningTime+=dT;
if(scarfyData.RunningTime>=scarfyData.UpdateTime) {
scarfyData.RunningTime=0.0;
scarfyData.Rec.x=scarfyData.frame*scarfyData.Rec.width;
scarfyData.frame++;
if(scarfyData.frame>5) {
scarfyData.frame=0;
}
}
}
nebulaData.RunningTime+=dT;
if(nebulaData.RunningTime>=nebulaData.UpdateTime) {
nebulaData.RunningTime=0.0;
nebulaData.Rec.x=nebulaData.frame*nebulaData.Rec.width;
nebulaData.frame++;
if(nebulaData.frame>7) {
nebulaData.frame=0;
}
}
nebula2Data.RunningTime+=dT;
if(nebula2Data.RunningTime>=nebula2Data.UpdateTime) {
nebula2Data.RunningTime=0.0;
nebula2Data.Rec.x=nebula2Data.frame*nebula2Data.Rec.width;
nebula2Data.frame++;
if(nebula2Data.frame>7) {
nebula2Data.frame=0;
}
}
//draw textures
DrawTextureRec(nebula, nebulaData.Rec, nebulaData.Pos, WHITE);
DrawTextureRec(nebula, nebula2Data.Rec, nebula2Data.Pos, GREEN);
DrawTextureRec(scarfy,scarfyData.Rec,scarfyData.Pos,WHITE);
EndDrawing();
}
UnloadTexture(scarfy);
UnloadTexture(nebula);
CloseWindow();
}
edit: I’ve been erasing all parts getting back to stage one of the course basically ahah