| 1 |
/** |
| 2 |
* Draw background from tiles |
| 3 |
|
| 4 |
* Copyright (C) 1997, 1998, 1999, 2002, 2003 Seth A. Robinson |
| 5 |
* Copyright (C) 2007, 2008, 2009 Sylvain Beucler |
| 6 |
|
| 7 |
* This file is part of GNU FreeDink |
| 8 |
|
| 9 |
* GNU FreeDink is free software; you can redistribute it and/or |
| 10 |
* modify it under the terms of the GNU General Public License as |
| 11 |
* published by the Free Software Foundation; either version 3 of the |
| 12 |
* License, or (at your option) any later version. |
| 13 |
|
| 14 |
* GNU FreeDink is distributed in the hope that it will be useful, but |
| 15 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
* General Public License for more details. |
| 18 |
|
| 19 |
* You should have received a copy of the GNU General Public License |
| 20 |
* along with this program. If not, see |
| 21 |
* <http://www.gnu.org/licenses/>. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifdef HAVE_CONFIG_H |
| 25 |
#include <config.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
#include "gfx_tiles.h" |
| 29 |
|
| 30 |
#include "editor_screen.h" |
| 31 |
#include "gfx.h" |
| 32 |
#include "log.h" |
| 33 |
|
| 34 |
/* Animated tiles current status */ |
| 35 |
static unsigned int water_timer = 0; |
| 36 |
static int fire_flip = 0; |
| 37 |
|
| 38 |
|
| 39 |
/** |
| 40 |
* Draw tile number 'dsttile_square_id0x' (in [0, 96-1]) in the |
| 41 |
* current screen |
| 42 |
*/ |
| 43 |
void gfx_tiles_draw(IOGfxSurface** gfx_tiles, int srctileset_idx0, int srctile_square_idx0, int dsttile_square_idx0) |
| 44 |
{ |
| 45 |
SDL_Rect src; |
| 46 |
int srctile_square_x = srctile_square_idx0 % GFX_TILES_SCREEN_W; |
| 47 |
int srctile_square_y = srctile_square_idx0 / GFX_TILES_SCREEN_W; |
| 48 |
src.x = srctile_square_x * GFX_TILES_SQUARE_SIZE; |
| 49 |
src.y = srctile_square_y * GFX_TILES_SQUARE_SIZE; |
| 50 |
src.w = GFX_TILES_SQUARE_SIZE; |
| 51 |
src.h = GFX_TILES_SQUARE_SIZE; |
| 52 |
|
| 53 |
int dsttile_x = dsttile_square_idx0 % GFX_TILES_SCREEN_W; |
| 54 |
int dsttile_y = dsttile_square_idx0 / GFX_TILES_SCREEN_W; |
| 55 |
SDL_Rect dst; |
| 56 |
dst.x = GFX_PLAY_LEFT + dsttile_x * GFX_TILES_SQUARE_SIZE; |
| 57 |
dst.y = GFX_PLAY_TOP + dsttile_y * GFX_TILES_SQUARE_SIZE; |
| 58 |
|
| 59 |
IOGFX_background->blit(gfx_tiles[srctileset_idx0 + 1], &src, &dst); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Draw all background tiles in the current screen |
| 64 |
*/ |
| 65 |
void gfx_tiles_draw_screen(IOGfxSurface** gfx_tiles, struct editor_screen_tilerefs* tilerefs) |
| 66 |
{ |
| 67 |
int x = 0; |
| 68 |
for (; x < GFX_TILES_PER_SCREEN; x++) |
| 69 |
{ |
| 70 |
int srctileset_idx0 = tilerefs[x].square_full_idx0 / 128; |
| 71 |
int srctile_square_idx0 = tilerefs[x].square_full_idx0 % 128; |
| 72 |
gfx_tiles_draw(gfx_tiles, srctileset_idx0, srctile_square_idx0, x); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
/* Game-specific: animate background (water, fire, ...) */ |
| 77 |
void process_animated_tiles(IOGfxSurface** gfx_tiles, struct editor_screen_tilerefs* tilerefs, Uint32 thisTickCount) |
| 78 |
{ |
| 79 |
// Water: |
| 80 |
if (water_timer < thisTickCount) |
| 81 |
{ |
| 82 |
|
| 83 |
water_timer = thisTickCount + (rand() % 2000); |
| 84 |
int flip = rand() % 2; |
| 85 |
|
| 86 |
int x = 0; |
| 87 |
for (; x < 96; x++) |
| 88 |
{ |
| 89 |
int screen_square_full_idx0 = tilerefs[x].square_full_idx0; |
| 90 |
int start_full_idx0 = (8-1) * 128; // 8th tileset -> 896 |
| 91 |
if (screen_square_full_idx0 >= start_full_idx0 |
| 92 |
&& screen_square_full_idx0 < (start_full_idx0 + 128)) |
| 93 |
gfx_tiles_draw(gfx_tiles, (8-1) + flip, screen_square_full_idx0 % 128, x); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
// Fire: |
| 99 |
{ |
| 100 |
fire_flip--; |
| 101 |
if (fire_flip < 0) |
| 102 |
fire_flip = 4; |
| 103 |
|
| 104 |
int x = 0; |
| 105 |
for (; x < 96; x++) |
| 106 |
{ |
| 107 |
int screen_square_full_idx0 = tilerefs[x].square_full_idx0; |
| 108 |
int start_full_idx0 = (19-1) * 128; // 19th tileset -> 2304 |
| 109 |
if (screen_square_full_idx0 >= start_full_idx0 |
| 110 |
&& screen_square_full_idx0 < (start_full_idx0 + 128)) |
| 111 |
gfx_tiles_draw(gfx_tiles, (19-1) + fire_flip, screen_square_full_idx0 % 128, x); |
| 112 |
} |
| 113 |
} |
| 114 |
} |