1ff3ea70d24dce150d0b8fd7c01f3951bb229db8
[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   fading(false),
36   light(0.0f,0.0f,0.0f),
37   lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite"))
38 {
39   reader.get("radius", radius);
40   reader.get("speed", speed);
41   bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
42                       start_position.y + sin(angle) * radius));
43   countMe = false;
44   //TODO: get unique death sound
45   sound_manager->preload("sounds/fizz.wav");
46   
47   set_colgroup_active(COLGROUP_TOUCHABLE);
48   
49   lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
50   lightsprite->set_color(Color(0.00f, 0.13f, 0.18f));
51   
52 }
53
54 void
55 Iceflame::active_update(float elapsed_time)
56 {
57   angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
58   Vector newpos(start_position.x + cos(angle) * radius,
59                 start_position.y + sin(angle) * radius);
60   movement = newpos - get_pos();
61   
62   if(fading)
63     if (sprite->animation_done()) remove_me();
64 }
65
66 void
67 Iceflame::draw(DrawingContext& context)
68 {
69   context.push_target();
70   //Rotate the Sprite (3 rotations per revolution)
71   sprite->set_angle(angle * 360.0f / (2*M_PI) * 3);
72   //Draw the Sprite.
73   sprite->draw(context, get_pos(), LAYER_OBJECTS);
74   //Draw the light if dark
75   context.get_light( get_bbox().get_middle(), &light );
76   if (light.blue + light.green < 2.0){
77     context.set_target(DrawingContext::LIGHTMAP);
78     lightsprite->draw(context, get_bbox().get_middle(), 0);
79   }
80   context.pop_target();
81 }
82
83
84 void
85 Iceflame::kill_fall()
86 {
87 }
88
89 void
90 Iceflame::ignite()
91 {
92   sound_manager->play("sounds/fizz.wav", get_pos());
93   sprite->set_action("fade", 1);
94   Vector ppos = bbox.get_middle();
95   Vector pspeed = Vector(0, -150);
96   Vector paccel = Vector(0,0);
97   Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_BACKGROUNDTILES+2));
98   fading = true;
99   
100   // start dead-script
101   run_dead_script();
102 }
103
104 bool
105 Iceflame::is_flammable() const
106 {
107   return true;
108 }
109
110 /* EOF */