4
Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
6
This program is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published by the
8
Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
You should have received a copy of the GNU General Public License along
17
with this program; if not, write to the Free Software Foundation, Inc.,
18
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
contact: plee-the-bear@gamned.org
22
Please add the tag [Bear] in the subject of your mails.
25
* \file block_align_top.cpp
26
* \brief Implementation of the bear::block_align_top class.
27
* \author Sebastien Angibaud
29
#include "generic_items/block_align_top.hpp"
31
#include "universe/collision_info.hpp"
32
#include "universe/collision_repair.hpp"
33
#include "engine/export.hpp"
35
BASE_ITEM_EXPORT( block_align_top, bear )
37
/*----------------------------------------------------------------------------*/
41
bear::block_align_top::block_align_top()
45
} // block_align_top::block_align_top()
47
/*----------------------------------------------------------------------------*/
49
* \brief Check if the collision is on a solid side and align the other item.
50
* \param that The other item of the collision.
51
* \param info Some informations about the collision.
53
void bear::block_align_top::collision_check_and_align
54
( engine::base_item& that, universe::collision_info& info )
56
if ( satisfy_collision_condition(that) )
57
if ( ( that.get_left() + that.get_size().x/2 >= get_left() ) &&
58
( that.get_left() + that.get_size().x/2 <= get_right() ) )
60
bear::universe::position_type pos(info.get_bottom_left_on_contact());
61
pos.y = get_top()+0.1;
63
if ( ! info.other_item().is_phantom() )
65
info.other_item().set_bottom_left( pos );
66
info.other_item().set_bottom_contact();
69
info.get_collision_repair().set_contact_normal
70
(info.other_item(), bear::universe::vector_type(0, 1));
72
that.set_contact_friction(m_top_friction);
76
} // block_align_top::collision_check_and_align()
78
/*----------------------------------------------------------------------------*/
80
* \brief Call collision_check_and_align().
81
* \param that The other item of the collision.
82
* \param info Some informations about the collision.
84
void bear::block_align_top::collision
85
( engine::base_item& that, universe::collision_info& info )
87
collision_check_and_align(that, info);
88
} // block_align_top::collision()
90
/*----------------------------------------------------------------------------*/
92
* \brief Set a field of type \c real.
93
* \param name The name of the field.
94
* \param value The new value of the field.
95
* \return false if the field "name" is unknow, true otherwise.
98
bear::block_align_top::set_real_field( const std::string& name, double value )
102
if (name == "top_friction")
103
m_top_friction = value;
105
result = super::set_real_field(name,value);
108
} // block_aligne_top::set_real_field()