Translated code:
AniSprite.h:
#pragma once
extern "C"
{
#include <SFML/Graphics.h>
#include <SFML/Config.h>
#include <SFML/System.h>
typedef struct
{
sfImage* zdjecie;
sfSprite* duszek;
sfClock* clock;
float fps;
bool isPlaying;
int loopStart;
int loopEnd;
int currentFrame;
int frameWidth;
int frameHeight;
} AniSprite;
void ZerujDane(AniSprite* pointer);
void SetFrameSize(int frameW, int frameH, AniSprite* pointer);
int GetFrameCount(AniSprite* pointer);
sfIntRect GetFramePosition(int frame, AniSprite* pointer);
void SetFrame(int frame, AniSprite* pointer);
void SetLoopSpeed(float newfps, AniSprite* pointer);
void PlayUstalone(int start, int end, AniSprite* pointer);
void PlayZwykle(AniSprite* pointer);
void Stop(AniSprite* pointer);
void Update(AniSprite* pointer);
}
AniSprite.C
extern "C"
{
#include "AniSprite.h"
void ZerujDane(AniSprite* pointer);
void SetFrameSize(int frameW, int frameH, AniSprite* pointer);
int GetFrameCount(AniSprite* pointer);
sfIntRect GetFramePosition(int frame, AniSprite* pointer);
void SetFrame(int frame, AniSprite* pointer);
void SetLoopSpeed(float newfps, AniSprite* pointer);
void PlayUstalone(int start, int end, AniSprite* pointer);
void PlayZwykle(AniSprite* pointer);
void Stop(AniSprite* pointer);
void Update(AniSprite* pointer);
}
void ZerujDane(AniSprite* pointer)
{
pointer->duszek = NULL;
pointer->zdjecie = NULL;
pointer->clock = NULL;
pointer->fps = 1;
pointer->currentFrame=0;
pointer->isPlaying=false;
pointer->loopStart=0;
pointer->loopEnd=0;
pointer->frameHeight=0;
pointer->frameWidth=0;
}
void SetFrameSize(int frameW, int frameH, AniSprite* pointer)
{
pointer->frameWidth = frameW;
pointer->frameHeight = frameH;
sfIntRect pedal2;
pedal2.Left = 0;
pedal2.Top = 0;
pedal2.Right = frameW;
pedal2.Bottom = frameH;
sfSprite_SetSubRect(pointer->duszek,pedal2);
}
int GetFrameCount(AniSprite* pointer)
{
unsigned int across = (sfImage_GetWidth(pointer->zdjecie) / pointer->frameWidth);
unsigned int down = (sfImage_GetHeight(pointer->zdjecie) / pointer->frameHeight);
return across*down;
}
sfIntRect GetFramePosition(int frame, AniSprite* pointer)
{
unsigned int across = (sfImage_GetWidth(pointer->zdjecie) / pointer->frameWidth);
unsigned int down = (sfImage_GetHeight(pointer->zdjecie) / pointer->frameHeight);
int tileY = frame / across;
int tileX = frame % across;
sfIntRect result;
result.Left = tileX*pointer->frameWidth;
result.Top = tileY*pointer->frameHeight;
result.Right = tileX*pointer->frameWidth + pointer->frameWidth;
result.Bottom = tileY*pointer->frameHeight + pointer->frameHeight;
return result;
}
void SetFrame(int frame, AniSprite* pointer)
{
pointer->currentFrame = frame;
}
void SetLoopSpeed(float newfps, AniSprite* pointer)
{
pointer->fps = newfps;
}
void PlayUstalone(int start, int end, AniSprite* pointer)
{
pointer->loopStart = start;
pointer->loopEnd = end;
pointer->currentFrame = start;
pointer->isPlaying = true;
sfClock_Reset(pointer->clock);
}
void PlayZwykle(AniSprite* pointer)
{
PlayUstalone(0, GetFrameCount(pointer), pointer);
}
void Stop(AniSprite* pointer)
{
pointer->isPlaying = false;
}
void Update(AniSprite* pointer)
{
if(pointer->isPlaying)
{
int frameCount = pointer->loopEnd - pointer->loopStart;
float timePosition = (sfClock_GetTime(pointer->clock) * pointer->fps);
pointer->currentFrame = pointer->loopStart + (int) timePosition % frameCount;
sfSprite_SetSubRect(pointer->duszek, GetFramePosition(pointer->currentFrame, pointer));
}
}