display_manager.h \
display_manager.cpp \
background.h \
-background.cpp
+background.cpp \
+tilemap.h \
+tilemap.cpp
# EOF #
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
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
--- /dev/null
+#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]);
+ }
+ }
+}
--- /dev/null
+#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
+
#include "viewport.h"
#include "display_manager.h"
#include "background.h"
+#include "tilemap.h"
Surface* img_distro[4];
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();
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();
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();
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
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);