4 // Copyright (C) 2005 Matthias Braun <matze@braunis.de>
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.
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.
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
25 static const float WALKSPEED = 50;
26 static const float WALKSPEED_SMALL = 30;
28 MrTree::MrTree(const lisp::Lisp& reader)
31 reader.get("x", start_position.x);
32 reader.get("y", start_position.y);
33 bbox.set_size(84.8, 95.8);
34 sprite = sprite_manager->create("images/creatures/mr_tree/mr_tree.sprite");
38 MrTree::write(lisp::Writer& writer)
40 writer.start_list("mrtree");
42 writer.write_float("x", start_position.x);
43 writer.write_float("y", start_position.y);
45 writer.end_list("mrtree");
51 if(mystate == STATE_BIG) {
52 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
53 sprite->set_action(dir == LEFT ? "left" : "right");
55 physic.set_velocity_x(dir == LEFT ? -WALKSPEED_SMALL : WALKSPEED_SMALL);
56 sprite->set_action(dir == LEFT ? "small-left" : "small-right");
61 MrTree::collision_squished(Player& player)
63 if(mystate == STATE_BIG) {
64 mystate = STATE_NORMAL;
67 sound_manager->play("sounds/squish.wav", get_pos());
70 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
71 kill_squished(player);
78 MrTree::collision_solid(GameObject& , const CollisionHit& hit)
80 if(fabsf(hit.normal.y) > .5) {
81 physic.set_velocity_y(0);
83 dir = dir == LEFT ? RIGHT : LEFT;
91 MrTree::collision_badguy(BadGuy& , const CollisionHit& hit)
93 if(fabsf(hit.normal.x) > .8) { // left or right hit
94 dir = dir == LEFT ? RIGHT : LEFT;
101 IMPLEMENT_FACTORY(MrTree, "mrtree")