~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to plee-the-bear/src/ptb/item/code/clingable.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
  Plee the Bear
3
3
 
4
 
  Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
5
5
 
6
6
  This program is free software; you can redistribute it and/or modify it
7
7
  under the terms of the GNU General Public License as published by the
27
27
 * \author Sebastien Angibaud
28
28
 */
29
29
#include "ptb/item/clingable.hpp"
 
30
#include "ptb/player.hpp"
30
31
 
31
 
#include "ptb/item/plee/plee.hpp"
 
32
#include <algorithm>
32
33
 
33
34
BASE_ITEM_EXPORT( clingable, ptb )
34
35
 
35
36
/*----------------------------------------------------------------------------*/
36
37
/**
 
38
 * \brief Do post creation actions.
 
39
 */
 
40
void ptb::clingable::build()
 
41
{
 
42
  super::build();
 
43
 
 
44
  m_last_position = get_top_left();
 
45
} // clingable::build()
 
46
 
 
47
/*----------------------------------------------------------------------------*/
 
48
/**
 
49
 * \brief Do one step in the progression of the item.
 
50
 * \param elapsed_time Elasped time since the last progress.
 
51
 */
 
52
void ptb::clingable::progress( bear::universe::time_type elapsed_time )
 
53
{
 
54
  super::progress( elapsed_time );
 
55
 
 
56
  item_list::iterator it;
 
57
  std::list<item_list::iterator> dead;
 
58
 
 
59
  for (it=m_list_items.begin(); it!=m_list_items.end(); ++it)
 
60
    if ( *it == NULL )
 
61
      dead.push_front(it);
 
62
 
 
63
  for( ; !dead.empty(); dead.pop_front() )
 
64
    m_list_items.erase( dead.front() );
 
65
} // clingable::progress()
 
66
 
 
67
/*----------------------------------------------------------------------------*/
 
68
/**
 
69
 * \brief Apply the movement of the item.
 
70
 * \param elapsed_time Elasped time since the last call.
 
71
 */
 
72
void ptb::clingable::move( bear::universe::time_type elapsed_time )
 
73
{
 
74
  super::move(elapsed_time);
 
75
 
 
76
  item_list::iterator it;
 
77
  bear::universe::position_type position = get_top_left();
 
78
 
 
79
  for(it=m_list_items.begin(); it!=m_list_items.end(); ++it)
 
80
    if ( *it != NULL )
 
81
      {
 
82
        (*it)->set_left((*it)->get_left() + position.x - m_last_position.x);
 
83
        (*it)->set_bottom
 
84
          ((*it)->get_bottom() + position.y - m_last_position.y);
 
85
      }
 
86
 
 
87
  for(it=m_old_items.begin(); it!=m_old_items.end(); ++it)
 
88
    if ( *it != NULL )
 
89
      if ( std::find(m_list_items.begin(), m_list_items.end(), *it)
 
90
           == m_list_items.end() ) // item is not on me anymore
 
91
        (*it)->set_speed
 
92
          ( (*it)->get_speed() + bear::universe::speed_type(get_speed()) );
 
93
 
 
94
  m_last_position = position;
 
95
  std::swap(m_old_items, m_list_items);
 
96
  m_list_items.clear();
 
97
} // clingable::move()
 
98
 
 
99
/*----------------------------------------------------------------------------*/
 
100
/**
37
101
 * \brief Check if the collision is with a player.
38
102
 * \param that The other item of the collision.
39
103
 * \param info Some informations about the collision.
41
105
void ptb::clingable::collision_check_and_apply
42
106
( bear::engine::base_item& that, bear::universe::collision_info& info )
43
107
{
44
 
  plee* p = dynamic_cast<plee*>(&that);
 
108
  player* p = dynamic_cast<player*>(&that);
45
109
 
46
110
  if ( p != NULL )
47
 
    p->set_can_cling(true);
 
111
    {
 
112
      p->set_can_cling(true);
 
113
 
 
114
      if ( p->is_clung() )
 
115
        m_list_items.push_front(that);
 
116
    }
48
117
} // clingable::collision_check_and_apply()
49
118
 
50
119
/*----------------------------------------------------------------------------*/
57
126
( bear::engine::base_item& that, bear::universe::collision_info& info )
58
127
{
59
128
  collision_check_and_apply(that, info);
60
 
  
 
129
 
61
130
  super::collision(that,info);
62
131
} // clingable::collision()
63
132
 
64
 
 
 
133
/*----------------------------------------------------------------------------*/
 
134
/**
 
135
 * \brief Get the items concerned by a progress/move of this one.
 
136
 * \param d (out) A list to which are added such items.
 
137
 */
 
138
void ptb::clingable::get_dependent_items( std::list<physical_item*>& d ) const
 
139
{
 
140
  item_list::const_iterator it;
 
141
 
 
142
  for( it=m_list_items.begin(); it!=m_list_items.end(); ++it )
 
143
    if ( *it != NULL )
 
144
      d.push_front( it->get() );
 
145
 
 
146
  for( it=m_old_items.begin(); it!=m_old_items.end(); ++it )
 
147
    if ( *it != NULL )
 
148
      d.push_front( it->get() );
 
149
} // clingable::get_dependent_items()