[Super-tux-commit] supertux/src tilemap.cpp,NONE,1.1 tilemap.h,NONE,1.1 Makefile.am,1.22,1.23 displa
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-05-20 14:55:52
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27079 Modified Files: Makefile.am display_manager.h gameobjs.cpp world.cpp Added Files: tilemap.cpp tilemap.h Log Message: fixed score display and converted tilemap to a gameobject Index: Makefile.am =================================================================== RCS file: /cvsroot/super-tux/supertux/src/Makefile.am,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- Makefile.am 20 May 2004 12:12:37 -0000 1.22 +++ Makefile.am 20 May 2004 14:55:41 -0000 1.23 @@ -82,6 +82,8 @@ display_manager.h \ display_manager.cpp \ background.h \ -background.cpp +background.cpp \ +tilemap.h \ +tilemap.cpp # EOF # Index: gameobjs.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- gameobjs.cpp 20 May 2004 12:12:38 -0000 1.29 +++ gameobjs.cpp 20 May 2004 14:55:41 -0000 1.30 @@ -119,10 +119,10 @@ const Vector& pos, int score) : position(pos) { - displaymanager.add_drawable(this, LAYER_OBJECTS+1); + displaymanager.add_drawable(this, LAYER_OBJECTS); timer.start(1000); snprintf(str, 10, "%d", score); - position.x += - strlen(str) * 8; + position.x -= strlen(str) * 8; } void Index: world.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.cpp,v retrieving revision 1.100 retrieving revision 1.101 diff -u -d -r1.100 -r1.101 --- world.cpp 20 May 2004 12:12:38 -0000 1.100 +++ world.cpp 20 May 2004 14:55:41 -0000 1.101 @@ -36,6 +36,7 @@ #include "viewport.h" #include "display_manager.h" #include "background.h" +#include "tilemap.h" Surface* img_distro[4]; @@ -63,6 +64,9 @@ bg->set_gradient(level->bkgd_top, level->bkgd_bottom); } gameobjects.push_back(bg); + + // add tilemap + gameobjects.push_back(new TileMap(displaymanager, get_level())); activate_objects(); get_level()->load_song(); @@ -93,6 +97,8 @@ bg->set_gradient(level->bkgd_top, level->bkgd_bottom); } gameobjects.push_back(bg); + // add tilemap + gameobjects.push_back(new TileMap(displaymanager, get_level())); get_level()->load_song(); apply_bonuses(); @@ -198,39 +204,10 @@ void World::draw() { - int y,x; - - /* Draw the real background */ -#if 0 - drawgradient(level->bkgd_top, level->bkgd_bottom); - if(level->img_bkgd) - level->draw_bg(); -#endif - - /* Draw particle systems (background) */ + /* Draw objects */ displaymanager.get_viewport().set_translation(Vector(scroll_x, scroll_y)); displaymanager.draw(); - /* Draw background: */ - for (y = 0; y < VISIBLE_TILES_Y && y < level->height; ++y) - { - for (x = 0; x < VISIBLE_TILES_X; ++x) - { - Tile::draw(32*x - fmodf(scroll_x, 32), y * 32 - fmodf(scroll_y, 32), - level->bg_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]); - } - } - - /* Draw interactive tiles: */ - for (y = 0; y < VISIBLE_TILES_Y && y < level->height; ++y) - { - for (x = 0; x < VISIBLE_TILES_X; ++x) - { - Tile::draw(32*x - fmodf(scroll_x, 32), y * 32 - fmodf(scroll_y, 32), - level->ia_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]); - } - } - for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i) (*i)->draw(); @@ -244,16 +221,6 @@ for (unsigned int i = 0; i < upgrades.size(); ++i) upgrades[i].draw(); - - /* Draw foreground: */ - for (y = 0; y < VISIBLE_TILES_Y && y < level->height; ++y) - { - for (x = 0; x < VISIBLE_TILES_X; ++x) - { - Tile::draw(32*x - fmodf(scroll_x, 32), y * 32 - fmodf(scroll_y, 32), - level->fg_tiles[(int)y + (int)(scroll_y / 32)][(int)x + (int)(scroll_x / 32)]); - } - } } void @@ -275,7 +242,7 @@ for (Trampolines::iterator i = trampolines.begin(); i != trampolines.end(); ++i) (*i)->action(frame_ratio); - /* update particle systems */ + /* update objects */ for(std::vector<_GameObject*>::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) (*i)->action(frame_ratio); --- NEW FILE: tilemap.cpp --- #include "tilemap.h" #include "display_manager.h" #include "level.h" #include "tile.h" #include "globals.h" TileMap::TileMap(DisplayManager& display_manager, Level* newlevel) : level(newlevel) { display_manager.add_drawable(this, LAYER_BACKGROUNDTILES); display_manager.add_drawable(this, LAYER_TILES); display_manager.add_drawable(this, LAYER_FOREGROUNDTILES); } TileMap::~TileMap() { } void TileMap::action(float ) { } void TileMap::draw(ViewPort& viewport, int layer) { std::vector<std::vector<unsigned int> >* tiles; switch(layer) { case LAYER_BACKGROUNDTILES: tiles = &level->bg_tiles; break; case LAYER_TILES: tiles = &level->ia_tiles; break; case LAYER_FOREGROUNDTILES: tiles = &level->fg_tiles; break; default: assert(!"Wrong layer when drawing tilemap."); } int tsx = int(viewport.get_translation().x / 32); // tilestartindex x int tsy = int(viewport.get_translation().y / 32); // tilestartindex y int sx = - (int(viewport.get_translation().x) % 32); int sy = - (int(viewport.get_translation().y) % 32); for(int x = sx, tx = tsx; x < screen->w && tx < int((*tiles)[0].size()); x += 32, ++tx) { for(int y = sy, ty = tsy; y < screen->h && ty < int(tiles->size()); y += 32, ++ty) { Tile::draw(x, y, (*tiles) [ty][tx]); } } } --- NEW FILE: tilemap.h --- #ifndef __TILEMAP_H__ #define __TILEMAP_H__ #include "game_object.h" #include "drawable.h" class Level; /** * This class is reponsible for drawing the level tiles */ class TileMap : public _GameObject, public Drawable { public: TileMap(DisplayManager& manager, Level* level); virtual ~TileMap(); virtual void action(float elapsed_time); virtual void draw(ViewPort& viewport, int layer); virtual std::string type() const { return "TileMap"; } private: Level* level; }; #endif Index: display_manager.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/display_manager.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- display_manager.h 20 May 2004 12:12:38 -0000 1.1 +++ display_manager.h 20 May 2004 14:55:41 -0000 1.2 @@ -13,8 +13,9 @@ LAYER_BACKGROUNDTILES = -100, LAYER_TILES = 0, LAYER_OBJECTS = 100, - LAYER_FOREGROUND0 = 200, - LAYER_FOREGROUND1 = 300 + LAYER_FOREGROUNDTILES = 200, + LAYER_FOREGROUND0 = 300, + LAYER_FOREGROUND1 = 400 }; /** This class holds a list of all things that should be drawn to screen |