As title suggests I have those two errors popping up on my terminal in VS code. It first appeared on “looping through the hazards” in Dapper Dasher. For some reason, that isn’t my problem. My problem is that scarfy is moving at an absurd rate after I took out the code for scarfy.rec and the others and replaced it with “charData.(whatever)” and that’s my best guess as to where the problem started. He’s phasing on the X axis across the screen in a blur.
The “i” problem is at line 152.
Here is my current code:
#include <raylib.h>
struct AnimData
{
Rectangle rec;
Vector2 pos;
int frame;
float updateTime;
float runningTime;
};
int main()
{
//Using an Array for windowDimensions
int windowDimensions[2];
windowDimensions[0] = 512;
windowDimensions[1] = 380;
/* Window dimensions, const variables must be initialized immediately.
So we use curly brackets, or braced initialization. */
InitWindow(windowDimensions[0], windowDimensions[1], "Dasher!");
// acceleration due to gravity (pixels/s)/s
const int gravity{1'000};
//PPS
const int jmpVel{-600};
//Nebula init & variables
Texture2D nebula = LoadTexture("textures/12_nebula_spritesheet.png");
const int sizeOfNebulae{6};
AnimData nebulae[sizeOfNebulae]{};
for (int i = 0; i < sizeOfNebulae; i++)
{
nebulae[i].rec.x = 0.0;
nebulae[i].rec.y = 0.0;
nebulae[i].rec.width = nebula.width/8;
nebulae[i].rec.height = nebula.height/8;
nebulae[i].pos.y = windowDimensions[1] - nebula.height/8;
nebulae[i].frame = 0;
nebulae[i].updateTime = 1/12;
nebulae[i].runningTime = 0.0;
}
nebulae[0].pos.x = windowDimensions[0];
nebulae[1].pos.x = windowDimensions[0] + 300;
nebulae[2].pos.x = windowDimensions[0] + 600;
nebulae[3].pos.x = windowDimensions[0] + 900;
nebulae[4].pos.x = windowDimensions[0] + 1200;
nebulae[5].pos.x = windowDimensions[0] + 1500;
//Neb X velocity (PpS)
int nebVel{-200};
int velocity{0};
bool isInAir{};
//Character texture init
Texture2D character = LoadTexture("textures/scarfy.png");
AnimData charData;
charData.rec.width = character.width/6;
charData.rec.height = character.height;
charData.rec.x = 0;
charData.rec.y = 0;
charData.pos.x = windowDimensions[0]/2 - charData.rec.width/2;
charData.pos.y = windowDimensions[1] - charData.rec.height;
charData.frame = 0;
charData.updateTime = (1.0/12);
charData.runningTime = 0.0;
SetTargetFPS(60);
while (!WindowShouldClose())
{
const float dT{GetFrameTime()};
//Start drawing
BeginDrawing();
//We need the background to be white to prevent GI strobing.
ClearBackground(WHITE);
//Ground check
if (charData.pos.y >= windowDimensions[1] - charData.rec.height)
{
// rectangle on ground
velocity = 0 && isInAir == false;
isInAir = false;
}
else
{
//rectangle in air, apply gravity
velocity += gravity * dT;
isInAir = true;
}
//check for jumping
if (IsKeyPressed(KEY_SPACE) && !isInAir)
{
velocity += jmpVel;
}
for (int i = 0; i < sizeOfNebulae; i++)
{
// Update position of nebula hazard
nebulae[i].pos.x += nebVel * dT;
}
// Update pos of second nebula hazard
nebulae[1].pos.x += nebVel * dT;
// Update position of character
charData.pos.y += velocity * dT;
//Update character anim frame
if (!isInAir)
{
//Update running time each frame, then check if runningTime has reached > 1/12 of a second.
charData.runningTime += dT;
if (charData.runningTime >= charData.updateTime)
{
charData.runningTime = 0;
//update anim frame
charData.pos.x = charData.frame * charData.rec.width;
charData.frame++;
if (charData.frame > 5)
{
charData.frame = 0;
}
}
}
//Update nebula one's animation frame
for (int i = 0; i < sizeOfNebulae; i++)
nebulae[i].runningTime += dT;
if (nebulae[i].runningTime >= nebulae[i].updateTime)
{
nebulae[i].runningTime = 0.0;
nebulae[i].rec.x = nebulae[i].frame * nebulae[i].rec.width;
nebulae[i].frame++;
if (nebulae[i].frame > 7)
{
nebulae[i].frame = 0;
}
}
for (int i = 0; i < sizeOfNebulae; i++)
{
//Draw danger nebula hazard
DrawTextureRec(nebula, nebulae[i].rec, nebulae[i].pos, WHITE);
}
//Draw character
DrawTextureRec(character, charData.rec, charData.pos, WHITE);
//Stop drawing
EndDrawing();
}
//Unload texture
UnloadTexture(character);
UnloadTexture(nebula);
CloseWindow();
}