tibia-client/src/map.cpp

58 lines
1.6 KiB
C++
Raw Normal View History

2011-08-11 07:52:30 +02:00
#include "map.h"
#include "game.h"
2011-08-12 04:04:28 +02:00
#include <graphics/graphics.h>
2011-08-11 07:52:30 +02:00
2011-08-12 02:06:01 +02:00
void Map::draw(int x, int y)
2011-08-11 07:52:30 +02:00
{
2011-08-12 03:38:54 +02:00
if(!m_framebuffer)
2011-08-12 06:34:21 +02:00
m_framebuffer = FrameBufferPtr(new FrameBuffer(15*32, 11*32));
2011-08-12 03:38:54 +02:00
m_framebuffer->bind();
2011-08-11 07:52:30 +02:00
Position playerPos = g_game.getPlayer()->getPosition();
2011-08-12 06:34:21 +02:00
// player is above 7
if(playerPos.getZ() <= 7) {
// player pos it 8-6. check if we can draw upper floors.
bool draw = true;
for(int jz = 6; jz >= 0; --jz) {
if(m_map[8+(6-jz)][6+(6-jz)][jz].getStackSize() > 0) {
draw = false;
}
}
for(int iz = 7; iz > 0; --iz) {
// +1 in draws cause 64x64 items may affect view.
for(int ix = 0; ix < 24; ++ix) {
for(int iy = 0; iy < 20; ++iy) {
m_map[ix+1][iy+1][iz].draw(ix, iy, iz);
2011-08-11 07:52:30 +02:00
}
}
2011-08-12 06:34:21 +02:00
if(!draw)
break;
2011-08-11 07:52:30 +02:00
}
2011-08-12 06:34:21 +02:00
2011-08-11 07:52:30 +02:00
}
2011-08-12 06:34:21 +02:00
2011-08-12 03:38:54 +02:00
m_framebuffer->unbind();
2011-08-12 04:04:28 +02:00
2011-08-12 06:34:21 +02:00
m_framebuffer->draw(x, y, g_graphics.getScreenSize().width(), g_graphics.getScreenSize().height());
2011-08-11 07:52:30 +02:00
}
void Map::addThing(Thing *thing, const Position& pos)
{
Position playerPos = g_game.getPlayer()->getPosition();
Position relativePos = Position(pos.getX() - playerPos.getX() + 8, pos.getY() - playerPos.getY() + 6, pos.getZ());
2011-08-12 06:34:21 +02:00
if(relativePos.getX() >= 25 || relativePos.getY() >= 21 || relativePos.getZ() >= 15) {
2011-08-11 07:52:30 +02:00
logDebug("relativePos is invalid.");
2011-08-12 06:34:21 +02:00
return;
}
2011-08-11 07:52:30 +02:00
2011-08-12 02:06:01 +02:00
//logDebug("x: ", (int)relativePos.getX(), " y: ", (int)relativePos.getY(), " z: ", (int)relativePos.getZ());
2011-08-11 07:52:30 +02:00
m_map[relativePos.getX()][relativePos.getY()][relativePos.getZ()].addThing(thing);
}