~ubuntu-branches/ubuntu/precise/pingus/precise

« back to all changes in this revision

Viewing changes to src/worldobjs/conveyor_belt.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Goulais
  • Date: 2004-08-09 10:26:00 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040809102600-lg2q9lfars0q1p42
Tags: 0.6.0-8
Applied patch from Andreas Jochens (Closes: #263992)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  $Id: conveyor_belt.cxx,v 1.22 2003/03/04 10:25:32 grumbel Exp $
 
2
//
 
3
//  Pingus - A free Lemmings clone
 
4
//  Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
 
5
//
 
6
//  This program is free software; you can redistribute it and/or
 
7
//  modify it under the terms of the GNU General Public License
 
8
//  as published by the Free Software Foundation; either version 2
 
9
//  of the License, or (at your option) any later version.
 
10
//
 
11
//  This program is distributed in the hope that it will be useful,
 
12
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
//  GNU General Public License for more details.
 
15
//
 
16
//  You should have received a copy of the GNU General Public License
 
17
//  along with this program; if not, write to the Free Software
 
18
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 
 
20
#include "../col_map.hxx"
 
21
#include "../gui/graphic_context.hxx"
 
22
#include "../pingu.hxx"
 
23
#include "../pingu_holder.hxx"
 
24
#include "../pingus_resource.hxx"
 
25
#include "../world.hxx"
 
26
#include "../worldobjsdata/conveyor_belt_data.hxx"
 
27
#include "conveyor_belt.hxx"
 
28
 
 
29
namespace WorldObjs {
 
30
 
 
31
ConveyorBelt::ConveyorBelt (const WorldObjsData::ConveyorBeltData& data_)
 
32
  : data(new WorldObjsData::ConveyorBeltData(data_)),
 
33
    left_sur  (PingusResource::load_surface ("conveyorbelt_left",   "worldobjs")),
 
34
    right_sur (PingusResource::load_surface ("conveyorbelt_right",  "worldobjs")),
 
35
    middle_sur(PingusResource::load_surface ("conveyorbelt_middle", "worldobjs"))
 
36
{
 
37
}
 
38
 
 
39
void
 
40
ConveyorBelt::draw (GraphicContext& gc)
 
41
{
 
42
  gc.draw(left_sur, data->pos, static_cast<int>(data->counter));
 
43
  for (int i=0; i < data->width; ++i)
 
44
    gc.draw(middle_sur, 
 
45
            static_cast<int>(data->pos.x + left_sur.get_width() + i * middle_sur.get_width()),
 
46
            static_cast<int>(data->pos.y), 
 
47
            static_cast<int>(data->counter));
 
48
  
 
49
  gc.draw(right_sur,
 
50
          static_cast<int>(data->pos.x + left_sur.get_width() + data->width * middle_sur.get_width()),
 
51
          static_cast<int>(data->pos.y),
 
52
          static_cast<int>(data->counter));
 
53
}
 
54
 
 
55
void
 
56
ConveyorBelt::on_startup ()
 
57
{
 
58
  CL_Surface sur(PingusResource::load_surface("conveyorbelt_cmap", "worldobjs"));
 
59
  for (int i=0; i < (data->width + 2); ++i)
 
60
    world->get_colmap()->put(sur,
 
61
                             static_cast<int>(data->pos.x) + (15 * i),
 
62
                             static_cast<int>(data->pos.y),
 
63
                             Groundtype::GP_SOLID);
 
64
}
 
65
 
 
66
void 
 
67
ConveyorBelt::update ()
 
68
{
 
69
  data->counter += data->speed * 0.025f;
 
70
 
 
71
  if (data->counter >= 14.0f)
 
72
    data->counter = 0.0f;
 
73
  else if (data->counter < 0.0f)
 
74
    data->counter = middle_sur.get_num_frames() - 1;
 
75
 
 
76
  PinguHolder* holder = world->get_pingus();
 
77
  for (PinguIter pingu = holder->begin(); pingu != holder->end(); ++pingu)
 
78
    {
 
79
      if (   (*pingu)->get_x() > data->pos.x
 
80
          && (*pingu)->get_x() < data->pos.x + 15 * (data->width + 2)
 
81
          && (*pingu)->get_y() > data->pos.y - 2
 
82
          && (*pingu)->get_y() < data->pos.y + 10)
 
83
        {
 
84
          Vector pos = (*pingu)->get_pos();
 
85
          pos.x -= data->speed * 0.025f;
 
86
          (*pingu)->set_pos(pos);
 
87
        }
 
88
    }
 
89
}
 
90
 
 
91
float
 
92
ConveyorBelt::get_z_pos () const
 
93
{
 
94
  return data->pos.z;
 
95
}
 
96
 
 
97
} // namespace WorldObjs
 
98
 
 
99
/* EOF */