1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (C) 2012-2017 by Bertram (Valyria Tear)
3 // All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See https://www.gnu.org/copyleft/gpl.html for details.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #include "modes/map/map_objects/map_halo.h"
11
12 #include "modes/map/map_mode.h"
13 #include "modes/map/map_object_supervisor.h"
14
15 #include "engine/video/video.h"
16
17 namespace vt_map
18 {
19
20 namespace private_map
21 {
22
Halo(const std::string & filename,float x,float y,const vt_video::Color & color)23 Halo::Halo(const std::string& filename,
24 float x, float y,
25 const vt_video::Color& color):
26 MapObject(NO_LAYER_OBJECT) // This is a special object
27 {
28 _color = color;
29 _tile_position.x = x;
30 _tile_position.y = y;
31
32 _object_type = HALO_TYPE;
33 _collision_mask = NO_COLLISION;
34
35 if(!_animation.LoadFromAnimationScript(filename))
36 PRINT_WARNING << "Couldn't load the Halo animation " << filename << " properly." << std::endl;
37
38 // Setup the image collision for the display update
39 SetImgPixelHalfWidth(_animation.GetWidth() / 2.0f);
40 SetImgPixelHeight(_animation.GetHeight());
41
42 ScaleToMapZoomRatio(_animation);
43
44 // Auto-registers to the object supervisor for later deletion handling
45 MapMode::CurrentInstance()->GetObjectSupervisor()->AddHalo(this);
46 }
47
Create(const std::string & filename,float x,float y,const vt_video::Color & color)48 Halo* Halo::Create(const std::string& filename,
49 float x, float y,
50 const vt_video::Color& color)
51 {
52 // The object auto registers to the object supervisor
53 // and will later handle deletion.
54 return new Halo(filename, x, y, color);
55 }
56
Update()57 void Halo::Update()
58 {
59 if(_updatable)
60 _animation.Update();
61 }
62
Draw()63 void Halo::Draw()
64 {
65 if(MapObject::ShouldDraw() && _animation.GetCurrentFrame())
66 vt_video::VideoManager->DrawHalo(*_animation.GetCurrentFrame(), _color);
67 }
68
69 } // namespace private_map
70
71 } // namespace vt_map
72