-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player_Action.c
61 lines (54 loc) · 1.66 KB
/
Player_Action.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Player_Action.h"
/**
* 创建一个PlayerAction结构体
* @return 一个PlayerAction结构体
*/
PlayerAction* Create_Player_Action(){
PlayerAction* action = (PlayerAction*)malloc(sizeof(PlayerAction));
return action;
}
/**
* 设置PlayerAction的surface
* @param action PlayerAction结构体指针
* @param path_format 路径格式
*/
void Set_Player_Action_Surface(PlayerAction* action, char* path_format){
int i;
for(i = 0; i < (action->nums_of_frames); i++) {
char path[100];
sprintf(path, path_format, i+1); /* 格式化路径 */
action->surface[i] = IMG_Load(path); /* 加载图片 */
}
}
/**
* 设置PlayerAction的texture
* @param action PlayerAction结构体指针
* @param renderer 窗口的渲染器
*/
void Set_Player_Action_Texture(PlayerAction* action, SDL_Renderer* renderer){
int i;
for(i = 0; i < action->nums_of_frames; i++) {
action->texture[i] = SDL_CreateTextureFromSurface(renderer, action->surface[i]);
}
}
/**
* 销毁PlayerAction结构体
* @param action PlayerAction结构体指针
*/
void Destroy_Player_Action(PlayerAction* action){
int i;
for(i = 0; i < action->nums_of_frames; i++) {
SDL_FreeSurface(action->surface[i]);
SDL_DestroyTexture(action->texture[i]);
}
free(action);
}
/**
* 绘制PlayerAction
* @param renderer 窗口的渲染器
* @param action PlayerAction结构体指针
*/
void Draw_Player_Action(SDL_Renderer* renderer, PlayerAction* action){
int frame = action->current_frame;
SDL_RenderCopy(renderer, action->texture[frame], NULL, &action->rect);
}