-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_widget.cpp
52 lines (46 loc) · 1.58 KB
/
map_widget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "map_widget.hpp"
#include "managers/kernel.hpp"
#include "a10_game.hpp"
//------------------------------------------------------------------------------
MapWidget::MapWidget(A10_Game* _game, string name, Kernel* k)
: Widget(name,k), game(_game), map(NULL), delta(0,0), draw_creatures(false)
{
assert(_game);
};
//------------------------------------------------------------------------------
void
MapWidget::_draw()
{
assert(this->map);
for(int y=max(-delta.y/this->map->getTileH()-2, Vect::T(0)); y<this->map->getHeight() and y<(-delta.y+this->height)/this->map->getTileH(); ++y)
for(int x=max(-delta.x/this->map->getTileW()-2, Vect::T(0)); x<this->map->getWidth() and x<(-delta.x+this->width )/this->map->getTileW(); ++x)
{
Tile* t = this->map->getData(x,y);
if(t) t->img.draw(Vect(x*this->map->getTileW()+delta.x, y*this->map->getTileH()+delta.y));
}
if(this->draw_creatures)
{
this->game->getPlayer().draw(delta);
}
};
//------------------------------------------------------------------------------
void
MapWidget::setDelta(Vect d)
{
for(int dim=1;dim<3;++dim)
{
if (d[dim] > 0)
d[dim] = 0;
else if(d[dim] < this->getSize(dim)-this->map->getPixelSize(dim))
d[dim] = this->getSize(dim)-this->map->getPixelSize(dim);
}
this->delta = d;
};
//------------------------------------------------------------------------------
void
MapWidget::setDeltaCenter(Vect d)
{
this->setDelta(d+this->getSize()/2);
};
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------