-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPidginImage.c
44 lines (39 loc) · 1.27 KB
/
PidginImage.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
/*
* PidginImage.c
*
* Created on: 26.01.2020
* Author: victor
*/
#include "pidgin_image.h"
#include "catch.h"
static int animation_index = 0, delay, ax = 1;
static SDL_Rect sdl_rect_output, sdl_rect_source;
static SDL_Surface* image_pidgin;
SDL_Surface* image_pidgin_dead;
void Pidgin_Init() {
SDL_RWops* rwops = SDL_RWFromConstMem(pidgin_bmp, sizeof(pidgin_bmp) / sizeof(char));
image_pidgin = SDL_LoadBMP_RW(rwops,1);
SDL_SetColorKey(image_pidgin, SDL_SRCCOLORKEY, SDL_MapRGB(image_pidgin->format, 255, 0, 255));
rwops = SDL_RWFromConstMem(pidgin_dead_bmp, sizeof(pidgin_dead_bmp) / sizeof(char));
image_pidgin_dead = SDL_LoadBMP_RW(rwops,1);
SDL_SetColorKey(image_pidgin_dead, SDL_SRCCOLORKEY, SDL_MapRGB(image_pidgin->format, 255, 0, 255));
sdl_rect_source.x = 0;
sdl_rect_source.w = PIDGIN_WIDTH;
sdl_rect_source.h = PIDGIN_HEIGHT;
}
void draw_Pidgin(SDL_Surface* surface, int x, int y) {
sdl_rect_output.x = x;
sdl_rect_output.y = y;
SDL_BlitSurface(image_pidgin, &sdl_rect_source, surface, &sdl_rect_output);
}
void Pidgin_IncrementFrame() {
delay++;
//printf("%d\n", delay);
if(delay >= 10) {
delay = 0;
animation_index+=ax;
sdl_rect_source.y = animation_index * PIDGIN_HEIGHT;
if(animation_index > 1) ax = -1;
if(animation_index < 1) ax = 1;
}
}