3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 Matthias Braun <matze@braunis.de
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "screen/drawing_context.h"
28 TileMap::TileMap(Level* newlevel)
31 tilemanager = TileManager::instance();
39 TileMap::action(float )
44 TileMap::draw(const std::vector<unsigned int>& tiles, DrawingContext& context,
47 float start_x = context.get_translation().x;
48 float start_y = context.get_translation().y;
49 float end_x = std::min(start_x + screen->w, float(level->width * 32));
50 float end_y = std::min(start_y + screen->h, float(level->height * 32));
51 start_x -= int(start_x) % 32;
52 start_y -= int(start_y) % 32;
53 int tsx = int(start_x / 32); // tilestartindex x
54 int tsy = int(start_y / 32); // tilestartindex y
58 for(pos.x = start_x, tx = tsx; pos.x < end_x; pos.x += 32, ++tx) {
59 for(pos.y = start_y, ty = tsy; pos.y < end_y; pos.y += 32, ++ty) {
60 tilemanager->draw_tile(context, tiles[ty*level->width + tx], pos, layer);
66 TileMap::draw(DrawingContext& context)
68 draw(level->bg_tiles, context, LAYER_BACKGROUNDTILES);
69 draw(level->ia_tiles, context, LAYER_TILES);
70 draw(level->fg_tiles, context, LAYER_FOREGROUNDTILES);