merged new collision detection branch back into mainline
[supertux.git] / src / object / candle.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #include <config.h>
21
22 #include "candle.hpp"
23 #include "scripting/candle.hpp"
24 #include "scripting/squirrel_util.hpp"
25 #include "sector.hpp"
26 #include "object/sprite_particle.hpp"
27 #include "object_factory.hpp"
28
29 Candle::Candle(const lisp::Lisp& lisp)
30         : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true), name("")
31 {
32   lisp.get("name", name);
33   lisp.get("burning", burning);
34
35   if (burning) {
36     sprite->set_action("on");
37   } else {
38     sprite->set_action("off");
39   }
40 }
41
42 HitResponse
43 Candle::collision(GameObject&, const CollisionHit& )
44 {
45   return FORCE_MOVE;
46 }
47
48 void
49 Candle::expose(HSQUIRRELVM vm, SQInteger table_idx)
50 {
51   if (name == "") return;
52   Scripting::Candle* interface = new Scripting::Candle(this);
53   expose_object(vm, table_idx, interface, name, true);
54 }
55
56 void
57 Candle::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
58 {
59   if (name == "") return;
60   Scripting::unexpose_object(vm, table_idx, name);
61 }
62
63 void
64 Candle::puff_smoke()
65 {
66   Vector ppos = bbox.get_middle();
67   Vector pspeed = Vector(0, -150);
68   Vector paccel = Vector(0,0);
69   Sector::current()->add_object(new SpriteParticle("images/objects/particles/smoke.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_BACKGROUNDTILES+2));
70 }
71
72 bool
73 Candle::get_burning()
74 {
75   return burning;
76 }
77
78 void
79 Candle::set_burning(bool burning)
80 {
81   if (this->burning == burning) return;
82   this->burning = burning;
83   if (burning) {
84     sprite->set_action("on");
85     puff_smoke();
86   } else {
87     sprite->set_action("off");
88     puff_smoke();
89   }
90 }
91
92 IMPLEMENT_FACTORY(Candle, "candle");