I made a Morph

Basically, the character is a knight when idling, but when running he is a goblin, this would be cool for a game where you have to hide from knights as a shapeshifter, this is my code:

#include “raylib.h”

#include “raymath.h”

int main()

{

const int windowWidth{384};

const int windowHeight{384};

InitWindow(windowWidth, windowHeight, "Classy Clash");

Texture2D map = LoadTexture("nature_tileset/OpenWorldMap24x24.png");

Vector2 mapPos{0.0, 0.0};

float speed{4.0};

Texture2D knightIdle = LoadTexture("characters/knight_idle_spritesheet.png");

Texture2D knightRun = LoadTexture("characters/goblin_run_spritesheet.png");

Texture2D knight = LoadTexture("characters/goblin_idle_spritesheet.png");

Vector2 knightPos{

    (float)windowWidth/2.0f - 4.0f * (0.5f * (float)knight.width/6.0f),

    (float)windowHeight/2.0f - 4.0f * (0.5f * (float)knight.height)

};

float RightLeft{1.f};

float RunningTime{};

int frame{};

int maxFrames{5};

const float UpdateTime{1.f/12.f};

SetTargetFPS(60);

while (!WindowShouldClose())

{

    BeginDrawing();

    ClearBackground(WHITE);

    Vector2 direction{};

    if (IsKeyDown(KEY_A)) direction.x -= 1.0;

    if (IsKeyDown(KEY_D)) direction.x += 1.0;

    if (IsKeyDown(KEY_W)) direction.y -= 1.0;

    if (IsKeyDown(KEY_S)) direction.y += 1.0;

    if (Vector2Length(direction) != 0.0)

    {

        // set mapPos = mapPos - directon

       

        mapPos = Vector2Subtract(mapPos, Vector2Scale(Vector2Normalize(direction), speed));

        //direction.x < 0.f ? RightLeft = -1.f : RightLeft = 1.f; // this is commented out because this is code that will flip the character if it moves up/down

        if (direction.x < 0.f)    RightLeft = -1;

        else if (direction.x > 0.f)    RightLeft = 1;

        knight = knightRun;

    }else{

        knight = knightIdle;

    }

   

    // Draw the map

    DrawTextureEx(map, mapPos, 0.0, 4.0, WHITE);

    RunningTime += GetFrameTime();

    if (RunningTime >= UpdateTime)

    {

        frame++;

        RunningTime=0.f;

        if (frame > maxFrames) frame = 0;

       

    }

   

    // Draw the character

    Rectangle source{(float)knight.width/6.f * frame, 0.f, RightLeft * (float)knight.width/6.f, (float)knight.height};

    Rectangle dest{knightPos.x, knightPos.y, 4.0f * (float)knight.width/6.0f, 4.0f * (float)knight.height};

    DrawTexturePro(knight, source, dest, Vector2{}, 0.f, WHITE);

    EndDrawing();

}

CloseWindow();

}
ezgif.com-gif-maker (1)

1 Like

all I really did was change the run knight sprite sheet to the run goblin sprite sheet

credit to @Maverick1868 for making it so that the character does not flip when moving

1 Like

Frankly, I just love it when a bug inspires creative design and you have it here. I can totally see that and you could even go the other way so you have a hide & seek game where you’re only truly hidden if you’re moving so that you have to dart from cover to cover while they search for you with vision cones on patrol paths.

1 Like

You’d be surprised how many bugs get turned into features in game development.

1 Like

The creeper, the most iconic Minecraft enemy, was originally a pig with a strange chest transform

Privacy & Terms