summaryrefslogtreecommitdiffstats
path: root/src/area.c
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-02-19 17:34:25 (EST)
committer P. J. McDermott <pjm@nac.net>2013-02-19 17:34:25 (EST)
commit2bc98ed29afcb79c9cdfab6f0940378e4f195280 (patch)
tree8e518d50c15bd9c3ad29963640df6643f222eaf8 /src/area.c
parent953782576764dc42ba2abfc1097255f53060ce71 (diff)
downloadoverworld-rpg-2bc98ed29afcb79c9cdfab6f0940378e4f195280.zip
overworld-rpg-2bc98ed29afcb79c9cdfab6f0940378e4f195280.tar.gz
overworld-rpg-2bc98ed29afcb79c9cdfab6f0940378e4f195280.tar.bz2
Limit surfaces to 8 bpp. Set keys and palettes.
Also clean up main() a bit more.
Diffstat (limited to 'src/area.c')
-rw-r--r--src/area.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/area.c b/src/area.c
index 12cbc6c..f8857b2 100644
--- a/src/area.c
+++ b/src/area.c
@@ -26,11 +26,33 @@ area_new(struct map *map)
static void
blit_map_layers(struct area *area)
{
+ SDL_Color colors[256];
+ int i;
+ SDL_Rect dstrect;
+
+ for (i = 0; i < 256; ++i) {
+ colors[i].r = (i % 8) * 36;
+ colors[i].g = (i % 64 / 8) * 36;
+ colors[i].b = (i / 64) * 85;
+ }
+
+ dstrect.x = 0;
+ dstrect.y = 0;
+ dstrect.w = area->map->width * area->map->tilewidth;
+ dstrect.h = area->map->height * area->map->tileheight;
+
area->map_layers[AREA_LAYER_BOT] = SDL_CreateRGBSurface(
SDL_HWSURFACE | SDL_SRCCOLORKEY,
area->map->width * area->map->tilewidth,
area->map->height * area->map->tileheight,
- 32, 0, 0, 0, 0);
+ 8, 0, 0, 0, 0);
+ SDL_FillRect(area->map_layers[AREA_LAYER_BOT], &dstrect,
+ SDL_MapRGB(area->map_layers[AREA_LAYER_BOT]->format,
+ 0xFC, 0x00, 0xFF));
+ SDL_SetColorKey(area->map_layers[AREA_LAYER_BOT], SDL_SRCCOLORKEY,
+ SDL_MapRGB(area->map_layers[AREA_LAYER_BOT]->format,
+ 0xFC, 0x00, 0xFF));
+ SDL_SetColors(area->map_layers[AREA_LAYER_BOT], colors, 0, 256);
blit_map_layer(area, MAP_LAYER_GROUND, AREA_LAYER_BOT);
blit_map_layer(area, MAP_LAYER_OBJ_LOW, AREA_LAYER_BOT);
@@ -38,14 +60,28 @@ blit_map_layers(struct area *area)
SDL_HWSURFACE | SDL_SRCCOLORKEY,
area->map->width * area->map->tilewidth,
area->map->height * area->map->tileheight,
- 32, 0, 0, 0, 0);
+ 8, 0, 0, 0, 0);
+ SDL_FillRect(area->map_layers[AREA_LAYER_MID], &dstrect,
+ SDL_MapRGB(area->map_layers[AREA_LAYER_MID]->format,
+ 0xFC, 0x00, 0xFF));
+ SDL_SetColorKey(area->map_layers[AREA_LAYER_MID], SDL_SRCCOLORKEY,
+ SDL_MapRGB(area->map_layers[AREA_LAYER_MID]->format,
+ 0xFC, 0x00, 0xFF));
+ SDL_SetColors(area->map_layers[AREA_LAYER_MID], colors, 0, 256);
blit_map_layer(area, MAP_LAYER_OBJ_MID, AREA_LAYER_MID);
area->map_layers[AREA_LAYER_TOP] = SDL_CreateRGBSurface(
SDL_HWSURFACE | SDL_SRCCOLORKEY,
area->map->width * area->map->tilewidth,
area->map->height * area->map->tileheight,
- 32, 0, 0, 0, 0);
+ 8, 0, 0, 0, 0);
+ SDL_FillRect(area->map_layers[AREA_LAYER_TOP], &dstrect,
+ SDL_MapRGB(area->map_layers[AREA_LAYER_TOP]->format,
+ 0xFC, 0x00, 0xFF));
+ SDL_SetColorKey(area->map_layers[AREA_LAYER_TOP], SDL_SRCCOLORKEY,
+ SDL_MapRGB(area->map_layers[AREA_LAYER_TOP]->format,
+ 0xFC, 0x00, 0xFF));
+ SDL_SetColors(area->map_layers[AREA_LAYER_TOP], colors, 0, 256);
blit_map_layer(area, MAP_LAYER_OBJ_HIGH, AREA_LAYER_TOP);
}
@@ -60,7 +96,6 @@ blit_map_layer(struct area *area, enum map_layer map_layer,
Uint32 mts_lastgid;
SDL_Rect tilerect, layerrect;
- SDL_SetColorKey(area->map_layers[area_layer], SDL_SRCCOLORKEY, 0);
for (i = 0; i < area->map->width * area->map->height; ++i) {
gid = area->map->layers[map_layer].tiles[i];
if (gid == 0) {
@@ -138,7 +173,7 @@ render_area_to_surface(struct area *area, SDL_Rect *arearect,
/* Fast fill with black to avoid artifacts in off-map pixels. */
/* NB: This is gray, at least temporarily. */
SDL_FillRect(surface, &dstrect,
- SDL_MapRGB(surface->format, 63, 63, 63));
+ SDL_MapRGB(surface->format, 0, 0, 0));
/* For demo */
tmprect.x = dstrect.x + 120 - 8;