00001 // SuperTux 00002 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> 00003 // 00004 // This program is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 00017 #include "badguy/bouncing_snowball.hpp" 00018 00019 #include "sprite/sprite.hpp" 00020 #include "supertux/object_factory.hpp" 00021 00022 static const float JUMPSPEED = -450; 00023 static const float BSNOWBALL_WALKSPEED = 80; 00024 00025 BouncingSnowball::BouncingSnowball(const Reader& reader) 00026 : BadGuy(reader, "images/creatures/bouncing_snowball/bouncing_snowball.sprite") 00027 { 00028 } 00029 00030 BouncingSnowball::BouncingSnowball(const Vector& pos, Direction d) 00031 : BadGuy(pos, d, "images/creatures/bouncing_snowball/bouncing_snowball.sprite") 00032 { 00033 } 00034 00035 void 00036 BouncingSnowball::initialize() 00037 { 00038 physic.set_velocity_x(dir == LEFT ? -BSNOWBALL_WALKSPEED : BSNOWBALL_WALKSPEED); 00039 sprite->set_action(dir == LEFT ? "left" : "right"); 00040 } 00041 00042 bool 00043 BouncingSnowball::collision_squished(GameObject& object) 00044 { 00045 sprite->set_action("squished"); 00046 kill_squished(object); 00047 return true; 00048 } 00049 00050 void 00051 BouncingSnowball::collision_solid(const CollisionHit& hit) 00052 { 00053 if(hit.bottom) { 00054 if(get_state() == STATE_ACTIVE) { 00055 physic.set_velocity_y(JUMPSPEED); 00056 } else { 00057 physic.set_velocity_y(0); 00058 } 00059 } else if(hit.top) { 00060 physic.set_velocity_y(0); 00061 } 00062 00063 if(hit.left || hit.right) { // left or right collision 00064 dir = dir == LEFT ? RIGHT : LEFT; 00065 sprite->set_action(dir == LEFT ? "left" : "right"); 00066 physic.set_velocity_x(-physic.get_velocity_x()); 00067 } 00068 } 00069 00070 HitResponse 00071 BouncingSnowball::collision_badguy(BadGuy& , const CollisionHit& hit) 00072 { 00073 collision_solid(hit); 00074 return CONTINUE; 00075 } 00076 00077 /* EOF */