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 "object/player.hpp" 00018 #include "object/star.hpp" 00019 00020 static const float INITIALJUMP = -400; 00021 static const float STAR_SPEED = 150; 00022 static const float JUMPSTAR_SPEED = -300; 00023 00024 Star::Star(const Vector& pos, Direction direction) : 00025 MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING), 00026 physic() 00027 { 00028 physic.set_velocity((direction == LEFT) ? -STAR_SPEED : STAR_SPEED, INITIALJUMP); 00029 } 00030 00031 void 00032 Star::update(float elapsed_time) 00033 { 00034 movement = physic.get_movement(elapsed_time); 00035 } 00036 00037 void 00038 Star::collision_solid(const CollisionHit& hit) 00039 { 00040 if(hit.bottom) { 00041 physic.set_velocity_y(JUMPSTAR_SPEED); 00042 } else if(hit.top) { 00043 physic.set_velocity_y(0); 00044 } else if(hit.left || hit.right) { 00045 physic.set_velocity_x(-physic.get_velocity_x()); 00046 } 00047 } 00048 00049 HitResponse 00050 Star::collision(GameObject& other, const CollisionHit& ) 00051 { 00052 Player* player = dynamic_cast<Player*> (&other); 00053 if(player) { 00054 player->make_invincible(); 00055 remove_me(); 00056 return ABORT_MOVE; 00057 } 00058 00059 return FORCE_MOVE; 00060 } 00061 00062 /* EOF */