-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.c
45 lines (38 loc) · 934 Bytes
/
background.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "background.h"
#include <math.h>
const float scrollSpeed = 120; //speed background scrolls
static float offsetX = 0;
extern SDL_Rect lightBackgroundClip;
extern SDL_Rect darkBackgroundClip;
SDL_Rect *currentTypeClip;
int backgroundCreate (BackgroundType type)
{
if (type==light)
currentTypeClip = &lightBackgroundClip;
else
currentTypeClip = &darkBackgroundClip;
return 0;
}
void backgroundDestroy ()
{
}
void backgroundLogicStep (unsigned int dt)
{
offsetX -= scrollSpeed*(float)dt/1000.0f;
if (-offsetX>(*currentTypeClip).w)
{
offsetX = 0;
}
}
void backgroundDraw (SDL_Surface *destination)
{
SDL_Rect offset;
short int anOffset = floor (offsetX);
offset.y = (destination->h - (*currentTypeClip).h);
while (anOffset<destination->w)
{
offset.x = anOffset;
SDL_BlitSurface (spritesheet, currentTypeClip, destination, &offset);
anOffset += (*currentTypeClip).w;
}
}