and are loading the ones from BaseCharacter which is the knight texture
main.cpp
#include "raylib.h"
#include "raymath.h"
#include "Character.h"
#include "Prop.h"
#include "Enemy.h"
#include <cstdio>
int main()
{
const int windowWidth{384};
const int windowHeight{384};
char gameName[] = "classy_clash";
InitWindow(windowWidth, windowHeight, gameName);
Texture2D map = LoadTexture("nature_tileset/OpenWorldMap24x24.png");
Vector2 mapPos{};
float mapScale = 4.0f;
Character knight{windowWidth, windowHeight};
// knight.SetScreenPos(windowWidth, windowHeight);
// Prop rock(Vector2{}, LoadTexture("nature_tileset/Rock.png"));
Prop props[2]
{
Prop(Vector2{600.0f, 300.0f}, LoadTexture("nature_tileset/Rock.png")),
Prop(Vector2{400.0f, 500.0f}, LoadTexture("nature_tileset/Log.png"))
};
Enemy goblin
{
Vector2{},
LoadTexture("characters/goblin_idle_spritesheet.png"),
LoadTexture("characters/goblin_run_spritesheet.png")
};
SetTargetFPS(60);
while (!WindowShouldClose())
{
BeginDrawing();
ClearBackground(WHITE);
mapPos = Vector2Scale(knight.GetWorldPos(), -1.f);
// Draw map
DrawTextureEx(map, mapPos, 0.0, mapScale, WHITE);
// rock.Render(knight.GetWorldPos());
// Draw the props
for (auto prop : props)
{
prop.Render(knight.GetWorldPos());
}
knight.Tick(GetFrameTime());
// Check map bounds
if (knight.GetWorldPos().x < 0.f ||
knight.GetWorldPos().y < 0.f ||
knight.GetWorldPos().x + windowWidth > map.width * mapScale ||
knight.GetWorldPos().y + windowHeight > map.height * mapScale)
{
knight.UndoMovement();
}
// Check for prop collision
for (auto prop : props)
{
if (CheckCollisionRecs(prop.GetCollision(knight.GetWorldPos()), knight.GetCollision()))
{
knight.UndoMovement();
}
}
goblin.Tick(GetFrameTime());
// DrawFPS(0, 0);
EndDrawing();
}
UnloadTexture(map);
CloseWindow();
}
BaseCharacter.cpp
#ifndef BASE_CHARACTER_H
#define BASE_CHARACTER_H
#include "raylib.h"
class BaseCharacter
{
public:
BaseCharacter();
Vector2 GetWorldPos() { return worldPos; }
void UndoMovement();
Rectangle GetCollision();
protected:
Texture2D texture{LoadTexture("characters/knight_idle_spritesheet.png")};
Texture2D idle{LoadTexture("characters/knight_idle_spritesheet.png")};
Texture2D run{LoadTexture("characters/knight_run_spritesheet.png")};
Vector2 worldPos{};
Vector2 screenPos{};
Vector2 worldPosLastFrame{};
// used to tell what direction character is facing
float flip = 1.0f;
// Animation variables
float runningTime{};
float updateTime{1.0f / 12.0f};
int frame{};
int maxFrames{6};
float speed = 4.0f;
float width{};
float height{};
float scale{4.0f};
private:
};
#endif
Enemy.cpp
#include "Enemy.h"
#include "raymath.h"
Enemy::Enemy(Vector2 pos, Texture2D idle_texture, Texture2D run_texture)
{
worldPos = pos;
idle = idle_texture;
run = run_texture;
width = texture.width / maxFrames;
height = texture.height;
}
void Enemy::Tick(float deltaTime)
{
worldPosLastFrame = worldPos;
runningTime += deltaTime;
if (runningTime >= updateTime)
{
runningTime = 0.0f;
frame++;
if (frame > maxFrames)
{
frame = 0;
}
}
// Draw Character
Rectangle textureSource
{
frame * width,
0.0f,
flip * width,
height
};
Rectangle textureDest
{
screenPos.x,
screenPos.y,
scale * width,
scale * height
};
Vector2 textureOrigin{};
DrawTexturePro(texture, textureSource, textureDest, textureOrigin, 0.0f, WHITE);
}
No errors, maybe its something I’m missing