forked from treeman/Rejection
/
Tile.cpp
75 lines (67 loc) · 1.41 KB
/
Tile.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "Tile.hpp"
Tile::Tile( Vec2D p, boost::shared_ptr<SpriteLoader> spr_loader ) : pos( p )
{
flow = spr_loader->Get( "flow" );
flow->spr->SetHotSpot( 16, 16 );
flow_power = 0;
}
boost::shared_ptr<TileObject> Tile::Attachment()
{
return attachment;
}
bool Tile::Attach( boost::shared_ptr<TileObject> a )
{
if( attachment ) { return false; }
else {
attachment = a;
attachment->SetPos( pos );
return true;
}
}
void Tile::Detach()
{
attachment.reset();
}
bool Tile::IsWalkable()
{
if( attachment ) return attachment->IsWalkable();
else return true;
}
bool Tile::IsSeeThrough()
{
if( attachment ) return attachment->IsSeeThrough();
else return true;
}
float Tile::GetFlowPower()
{
return flow_power;
}
Vec2D Tile::GetFlowDirection()
{
return flow_dir;
}
void Tile::SetFlowDirection( Vec2D dir, float power )
{
if( flow_dir == Vec2D::zero || power > flow_power ) {
flow_dir = dir;
flow_power = power;
}
}
void Tile::ClearFlow()
{
flow_dir = Vec2D::zero;
}
Tree::Rect Tile::Bounds() const
{
return Tree::Rect( pos.x, pos.y, 32, 32 );
}
void Tile::RenderFlow()
{
if( flow_dir == Vec2D::zero ) return;
float rotation = 0;
if( flow_dir == Vec2D::left ) rotation = math::PI;
else if( flow_dir == Vec2D::right ) rotation = 0;
else if( flow_dir == Vec2D::up ) rotation = 3 * math::PI_2;
else if( flow_dir == Vec2D::down ) rotation = math::PI_2;
flow->spr->RenderEx( pos.x + 16, pos.y + 16, rotation );
}