1
// $Id: conveyor_belt.cxx,v 1.22 2003/03/04 10:25:32 grumbel Exp $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
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.
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.
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.
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"
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"))
40
ConveyorBelt::draw (GraphicContext& gc)
42
gc.draw(left_sur, data->pos, static_cast<int>(data->counter));
43
for (int i=0; i < data->width; ++i)
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));
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));
56
ConveyorBelt::on_startup ()
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);
67
ConveyorBelt::update ()
69
data->counter += data->speed * 0.025f;
71
if (data->counter >= 14.0f)
73
else if (data->counter < 0.0f)
74
data->counter = middle_sur.get_num_frames() - 1;
76
PinguHolder* holder = world->get_pingus();
77
for (PinguIter pingu = holder->begin(); pingu != holder->end(); ++pingu)
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)
84
Vector pos = (*pingu)->get_pos();
85
pos.x -= data->speed * 0.025f;
86
(*pingu)->set_pos(pos);
92
ConveyorBelt::get_z_pos () const
97
} // namespace WorldObjs