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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
*
* sprite.cpp
*
* 19th March 2009: Created sprite.cpp from parts of event.cpp and player.cpp
* 26th July 2009: Created anim.cpp from parts of sprite.cpp
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "video.h"
#include "sprite.h"
Sprite::Sprite () {
pixels = NULL;
return;
}
Sprite::~Sprite () {
if (pixels) SDL_FreeSurface(pixels);
return;
}
void Sprite::clearPixels () {
unsigned char *data;
if (pixels) SDL_FreeSurface(pixels);
data = new unsigned char[1];
*data = SKEY;
pixels = createSurface(data, 1, 1);
SDL_SetColorKey(pixels, SDL_SRCCOLORKEY, SKEY);
return;
}
void Sprite::setPixels (unsigned char *data, int width, int height) {
if (pixels) SDL_FreeSurface(pixels);
pixels = createSurface(data, width, height);
SDL_SetColorKey(pixels, SDL_SRCCOLORKEY, SKEY);
return;
}
int Sprite::getWidth () {
return pixels->w;
}
int Sprite::getHeight() {
return pixels->h;
}
void Sprite::setPalette (SDL_Color *palette, int start, int amount) {
SDL_SetPalette(pixels, SDL_LOGPAL, palette + start, start, amount);
return;
}
void Sprite::flashPalette (int index) {
SDL_Color palette[256];
int count;
// Map the whole palette to one index
for (count = 0; count < 256; count++)
palette[count].r = palette[count].g = palette[count].b = index;
SDL_SetPalette(pixels, SDL_LOGPAL, palette, 0, 256);
return;
}
void Sprite::restorePalette () {
::restorePalette(pixels);
return;
}
void Sprite::draw (int x, int y) {
SDL_Rect dst;
dst.x = x + xOffset;
dst.y = y + yOffset;
SDL_BlitSurface(pixels, NULL, screen, &dst);
return;
}