Skip to content

Commit

Permalink
Merge pull request #2 from jszczerbinsky/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jszczerbinsky committed Sep 24, 2022
2 parents a5d6af4 + ded8302 commit da3eba0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/

# Prerequisites
*.d

Expand Down
36 changes: 31 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ typedef struct
SDL_Texture *buffTex;
} Instance;

int lerp(int a, int b, float t)
{
return (int)((float)a + (float)t * ((float)b - (float)a));
}

#ifdef __WIN32
HWND iconWorkerw;
BOOL CALLBACK getIconWorkerw(HWND hWnd, LPARAM lParam)
Expand Down Expand Up @@ -150,18 +155,32 @@ int main(int argc, char *argv[])
);
}

SDL_SetRelativeMouseMode(SDL_TRUE);
#ifndef __WIN32
SDL_SetRelativeMouseMode(SDL_TRUE);
#endif

SDL_Event event;
int quit = 0;

int mx = 0;
int my = 0;

while(!quit)
{
int mx;

static int currentX = 0;
static int currentY = 0;

static int lastTicks = 0;

int ticks = SDL_GetTicks();
float dT = (ticks-lastTicks)/1000.0f;
lastTicks = ticks;

#ifdef __WIN32
POINT mPos;
GetCursorPos(&mPos);
mx = mPos.x;
my = mPos.y;
#endif

while(SDL_PollEvent(&event))
Expand All @@ -170,10 +189,16 @@ int main(int argc, char *argv[])
quit = 1;
#ifndef __WIN32
else if(event.type == SDL_MOUSEMOTION)
{
mx = event.motion.x;
my = event.motion.y;
}
#endif
}

currentX = lerp(currentX, mx, dT*8);
currentY = lerp(currentY, my, dT*8);

for(int u = 0; u < instancesCount; u++)
{
SDL_SetRenderTarget(renderer, instances[u].buffTex);
Expand All @@ -188,13 +213,14 @@ int main(int argc, char *argv[])
.h = srcHeight
};

int x = 0-(mx/20)*i;
int x = -((currentX-instances[u].dest.w/2)/20)*i;
int y = -((currentY-instances[u].dest.h/2)/20)*i;

for(int j = -1; j <= 1; j++)
{
SDL_Rect dest = {
.x = x + j*instances[u].dest.w,
.y = 0,
.y = y,
.w = instances[u].dest.w,
.h = instances[u].dest.h
};
Expand Down

0 comments on commit da3eba0

Please sign in to comment.