Statisticts now also count secret areas found
[supertux.git] / src / object / coin.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.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 "coin.hpp"
23 #include "resources.hpp"
24 #include "video/drawing_context.hpp"
25 #include "sprite/sprite_manager.hpp"
26 #include "player.hpp"
27 #include "sector.hpp"
28 #include "player_status.hpp"
29 #include "gameobjs.hpp"
30 #include "statistics.hpp"
31 #include "object_factory.hpp"
32 #include "level.hpp"
33
34 Coin::Coin(const Vector& pos)
35 {
36   bbox.set_pos(pos);
37   bbox.set_size(32, 32);
38   sprite = sprite_manager->create("images/objects/coin/coin.sprite");
39   set_group(COLGROUP_TOUCHABLE);
40 }
41
42 Coin::Coin(const lisp::Lisp& reader)
43 {
44   reader.get("x", bbox.p1.x);
45   reader.get("y", bbox.p1.y);
46   bbox.set_size(32, 32);
47   sprite = sprite_manager->create("images/objects/coin/coin.sprite");
48   set_group(COLGROUP_TOUCHABLE);
49 }
50
51 Coin::~Coin()
52 {
53   delete sprite;
54 }
55
56 void
57 Coin::update(float )
58 {
59 }
60
61 void
62 Coin::draw(DrawingContext& context)
63 {
64   sprite->draw(context, get_pos(), LAYER_TILES);
65 }
66
67 void
68 Coin::collect()
69 {
70   Sector::current()->player->get_status()->add_coins(1);
71   Sector::current()->add_object(new BouncyCoin(get_pos()));
72   Sector::current()->get_level()->stats.coins++;
73   remove_me();
74 }
75
76 HitResponse
77 Coin::collision(GameObject& other, const CollisionHit& )
78 {
79   Player* player = dynamic_cast<Player*>(&other);
80   if(player == 0)
81     return ABORT_MOVE;
82
83   collect();
84   return ABORT_MOVE;
85 }
86
87 IMPLEMENT_FACTORY(Coin, "coin");