fix
[supertux.git] / src / badguy / spike.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 #include <config.h>
21
22 #include "spike.h"
23
24 Spike::Spike(const Vector& pos, Direction dir)
25 {
26   sprite = sprite_manager->create("spike");
27   start_position = pos;
28   bbox.set_pos(Vector(0, 0));
29   bbox.set_size(32, 32);
30   set_direction(dir);
31   countMe = false;
32 }
33
34 Spike::Spike(const lisp::Lisp& reader)
35 {
36   sprite = sprite_manager->create("spike");
37   reader.get("x", start_position.x);
38   reader.get("y", start_position.y);
39   bbox.set_size(32, 32);
40   int idir = 0;
41   reader.get("direction", idir);
42   set_direction((Direction) idir);
43   countMe = false;
44 }
45
46 void
47 Spike::set_direction(Direction dir)
48 {
49   spikedir = dir;
50   switch(spikedir) {
51     case NORTH:
52       sprite->set_action("north");
53       break;
54     case SOUTH:
55       sprite->set_action("south");
56       break;
57     case WEST:
58       sprite->set_action("west");
59       break;
60     case EAST:
61       sprite->set_action("east");
62       break;
63     default:
64       break;
65   }
66 }
67
68 void
69 Spike::write(lisp::Writer& writer)
70 {
71   writer.start_list("spike");
72   writer.write_float("x", start_position.x);
73   writer.write_float("y", start_position.y);
74   writer.write_int("direction", spikedir);
75   writer.end_list("spike");
76 }
77
78 void
79 Spike::kill_fall()
80 {
81   // you can't kill a spike
82 }
83
84 void
85 Spike::active_update(float )
86 {
87 }
88
89 IMPLEMENT_FACTORY(Spike, "spike")