-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSprite.c
95 lines (68 loc) · 1.76 KB
/
Sprite.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**********************************************
* *
* RGE v 0.3 *
* Retro Game Engine *
* Copyright 2011-2014 *
* by Pedro Gil Guirado - Balrog Soft *
* www.amigaskool.net *
* *
**********************************************/
#include <stdio.h>
#include <stdlib.h>
#include <proto/exec.h>
#include "Sprite.h"
#include "Bitmap.h"
Sprite* sp_load(char* file)
{
Sprite* spr = (Sprite*)malloc(sizeof(Sprite));
spr->bm = bm_load(file);
spr->rest_bm = NULL;
bm_createMask(spr->bm, 0);
spr->px[0] = spr->px[1] = 0;
spr->py[0] = spr->py[1] = 0;
spr->restore[0] = spr->restore[1] = FALSE;
spr->width = spr->bm->width;
spr->height = spr->bm->height;
spr->depth = spr->bm->depth;
spr->sheight = spr->bm->height;
spr->frameOffset = 0;
spr->frame = 0;
spr->rest_bm = bm_create(spr->width, spr->height<<1, spr->depth);
return spr;
}
Sprite* sp_loadSheet(char* file, int spriteHeight)
{
Sprite* spr = (Sprite*)malloc(sizeof(Sprite));
spr->bm = bm_load(file);
spr->rest_bm = NULL;
bm_createMask(spr->bm, 0);
spr->px[0] = spr->px[1] = 0;
spr->py[0] = spr->py[1] = 0;
spr->restore[0] = spr->restore[1] = FALSE;
spr->width = spr->bm->width;
spr->height = spriteHeight;
spr->depth = spr->bm->depth;
spr->sheight = spr->bm->height;
spr->frameOffset = 0;
spr->frame = 0;
spr->rest_bm = bm_create(spr->width, spr->height<<1, spr->depth);
return spr;
}
void sp_setFrame(Sprite* spr, int frame)
{
if (frame * spr->height + spr->height > spr->sheight)
return;
spr->frame = frame;
spr->frameOffset = frame * spr->height;
}
void sp_dealloc(Sprite* spr)
{
if (spr)
{
if (spr->bm)
bm_dealloc(spr->bm);
if (spr->rest_bm)
bm_dealloc(spr->rest_bm);
free(spr);
}
}