changed worldmap format a bit to be more consistent with level format
[supertux.git] / src / object / coin.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 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
19 //  02111-1307, USA.
20
21 #include <config.h>
22
23 #include "coin.h"
24 #include "resources.h"
25 #include "video/drawing_context.h"
26 #include "sprite/sprite_manager.h"
27 #include "player.h"
28 #include "sector.h"
29 #include "player_status.h"
30 #include "gameobjs.h"
31 #include "statistics.h"
32 #include "object_factory.h"
33
34 Coin::Coin(const Vector& pos)
35 {
36   bbox.set_pos(pos);
37   bbox.set_size(32, 32);
38   sprite = sprite_manager->create("coin");
39 }
40
41 Coin::Coin(const lisp::Lisp& reader)
42 {
43   reader.get("x", bbox.p1.x);
44   reader.get("y", bbox.p1.y);
45   bbox.set_size(32, 32);
46   sprite = sprite_manager->create("coin");
47 }
48
49 Coin::~Coin()
50 {
51   delete sprite;
52 }
53
54 void
55 Coin::update(float )
56 {
57 }
58
59 void
60 Coin::draw(DrawingContext& context)
61 {
62   sprite->draw(context, get_pos(), LAYER_TILES);
63 }
64
65 void
66 Coin::collect()
67 {
68   Sector::current()->player->get_status()->incCoins();
69   Sector::current()->add_object(new BouncyCoin(get_pos()));
70   global_stats.add_points(COINS_COLLECTED_STAT, 1);
71   remove_me();
72 }
73
74 HitResponse
75 Coin::collision(GameObject& other, const CollisionHit& )
76 {
77   Player* player = dynamic_cast<Player*>(&other);
78   if(player == 0)
79     return ABORT_MOVE;
80
81   collect();
82   return ABORT_MOVE;
83 }
84
85 IMPLEMENT_FACTORY(Coin, "coin");