Fix coverity issues (uninitialized members)
[supertux.git] / src / badguy / iceflame.cpp
1 //  SuperTux badguy - Iceflame a flame-like enemy that can be killed with fireballs
2 //  Copyright (C) 2013 LMH <lmh.0013@gmail.com>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "badguy/iceflame.hpp"
18
19 #include <math.h>
20
21 #include "audio/sound_manager.hpp"
22 #include "math/random_generator.hpp"
23 #include "sprite/sprite.hpp"
24 #include "sprite/sprite_manager.hpp"
25 #include "object/sprite_particle.hpp"
26 #include "supertux/object_factory.hpp"
27 #include "supertux/sector.hpp"
28 #include "util/reader.hpp"
29
30 Iceflame::Iceflame(const Reader& reader) :
31   BadGuy(reader, "images/creatures/flame/iceflame.sprite", LAYER_FLOATINGOBJECTS),
32   angle(0),
33   radius(100),
34   speed(2),
35   light(0.0f,0.0f,0.0f),
36   lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite"))
37 {
38   reader.get("radius", radius);
39   reader.get("speed", speed);
40   bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
41                       start_position.y + sin(angle) * radius));
42   countMe = false;
43   SoundManager::current()->preload("sounds/sizzle.ogg");
44
45   set_colgroup_active(COLGROUP_TOUCHABLE);
46
47   lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
48   lightsprite->set_color(Color(0.00f, 0.13f, 0.18f));
49
50 }
51
52 void
53 Iceflame::active_update(float elapsed_time)
54 {
55   angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
56   Vector newpos(start_position.x + cos(angle) * radius,
57                 start_position.y + sin(angle) * radius);
58   movement = newpos - get_pos();
59
60   if (sprite->get_action() == "fade" && sprite->animation_done()) remove_me();
61 }
62
63 void
64 Iceflame::draw(DrawingContext& context)
65 {
66   context.push_target();
67   //Rotate the Sprite (3 rotations per revolution)
68   sprite->set_angle(angle * 360.0f / (2*M_PI) * 3);
69   //Draw the Sprite.
70   sprite->draw(context, get_pos(), LAYER_OBJECTS);
71   //Draw the light if dark
72   context.get_light( get_bbox().get_middle(), &light );
73   if (light.blue + light.green < 2.0){
74     context.set_target(DrawingContext::LIGHTMAP);
75     lightsprite->draw(context, get_bbox().get_middle(), 0);
76   }
77   context.pop_target();
78 }
79
80
81 void
82 Iceflame::kill_fall()
83 {
84 }
85
86 void
87 Iceflame::ignite()
88 {
89   SoundManager::current()->play("sounds/sizzle.ogg", get_pos());
90   sprite->set_action("fade", 1);
91   Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/smoke.sprite",
92                                                                  "default",
93                                                                  bbox.get_middle(), ANCHOR_MIDDLE,
94                                                                  Vector(0, -150), Vector(0,0),
95                                                                  LAYER_BACKGROUNDTILES+2));
96   set_group(COLGROUP_DISABLED);
97
98   // start dead-script
99   run_dead_script();
100 }
101
102 bool
103 Iceflame::is_flammable() const
104 {
105   return true;
106 }
107
108 /* EOF */