2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "badguy/jumpy.hpp"
19 #include "object/player.hpp"
20 #include "sprite/sprite.hpp"
21 #include "supertux/object_factory.hpp"
23 static const float JUMPSPEED=-600;
24 static const float JUMPY_MID_TOLERANCE=4;
25 static const float JUMPY_LOW_TOLERANCE=2;
27 Jumpy::Jumpy(const Reader& reader) :
28 BadGuy(reader, "images/creatures/snowjumpy/snowjumpy.sprite"),
30 groundhit_pos_set(false)
32 // TODO create a nice sound for this...
33 //sound_manager->preload("sounds/skid.wav");
37 Jumpy::collision_solid(const CollisionHit& chit)
43 Jumpy::collision_badguy(BadGuy& , const CollisionHit& chit)
49 Jumpy::hit(const CollisionHit& chit)
52 if (!groundhit_pos_set)
54 pos_groundhit = get_pos();
55 groundhit_pos_set = true;
58 physic.set_velocity_y((frozen || get_state() == STATE_FALLING) ? 0 : JUMPSPEED);
59 // TODO create a nice sound for this...
60 //sound_manager->play("sounds/skid.wav");
62 physic.set_velocity_y(0);
69 Jumpy::active_update(float elapsed_time)
71 BadGuy::active_update(elapsed_time);
76 Player* player = this->get_nearest_player();
79 dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT;
82 if (!groundhit_pos_set)
84 sprite->set_action(dir == LEFT ? "left-middle" : "right-middle");
88 if ( get_pos().y < (pos_groundhit.y - JUMPY_MID_TOLERANCE ) )
89 sprite->set_action(dir == LEFT ? "left-up" : "right-up");
90 else if ( get_pos().y >= (pos_groundhit.y - JUMPY_MID_TOLERANCE) &&
91 get_pos().y < (pos_groundhit.y - JUMPY_LOW_TOLERANCE) )
92 sprite->set_action(dir == LEFT ? "left-middle" : "right-middle");
94 sprite->set_action(dir == LEFT ? "left-down" : "right-down");
101 physic.set_velocity_y(std::max(0.0f, physic.get_velocity_y()));
102 sprite->set_action(dir == LEFT ? "left-iced" : "right-iced");
106 Jumpy::is_freezable() const
111 IMPLEMENT_FACTORY(Jumpy, "jumpy");