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 stay_on_platform = false;
34 reader.get("stay-on-platform", stay_on_platform);
35 bbox.set_size(84.8, 95.8);
36 sprite = sprite_manager->create("images/creatures/mr_tree/mr_tree.sprite");
40 MrTree::write(lisp::Writer& writer)
42 writer.start_list("mrtree");
44 writer.write_float("x", start_position.x);
45 writer.write_float("y", start_position.y);
47 writer.end_list("mrtree");
53 if(mystate == STATE_BIG) {
54 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
55 sprite->set_action(dir == LEFT ? "left" : "right");
57 physic.set_velocity_x(dir == LEFT ? -WALKSPEED_SMALL : WALKSPEED_SMALL);
58 sprite->set_action(dir == LEFT ? "small-left" : "small-right");
63 MrTree::active_update(float elapsed_time)
65 if (stay_on_platform && may_fall_off_platform())
67 dir = (dir == LEFT ? RIGHT : LEFT);
68 sprite->set_action(dir == LEFT ? "left" : "right");
69 physic.set_velocity_x(-physic.get_velocity_x());
72 BadGuy::active_update(elapsed_time);
76 MrTree::collision_squished(Player& player)
78 if(mystate == STATE_BIG) {
79 mystate = STATE_NORMAL;
82 sound_manager->play("sounds/squish.wav", get_pos());
85 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
86 kill_squished(player);
93 MrTree::collision_solid(GameObject& , const CollisionHit& hit)
95 if(fabsf(hit.normal.y) > .5) {
96 physic.set_velocity_y(0);
98 dir = dir == LEFT ? RIGHT : LEFT;
106 MrTree::collision_badguy(BadGuy& , const CollisionHit& hit)
108 if(fabsf(hit.normal.x) > .8) { // left or right hit
109 dir = dir == LEFT ? RIGHT : LEFT;
116 IMPLEMENT_FACTORY(MrTree, "mrtree")