1
// $Id: exit.cpp 2986 2007-08-17 16:20:09Z grumbel $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 1999 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.
21
#include "../display/scene_context.hpp"
22
#include "../col_map.hpp"
23
#include "../world.hpp"
24
#include "../globals.hpp"
25
#include "../pingu_holder.hpp"
26
#include "../pingu.hpp"
27
#include "../components/smallmap.hpp"
28
#include "../resource.hpp"
29
#include "../string_util.hpp"
34
Exit::Exit(const FileReader& reader)
35
: smallmap_symbol(Resource::load_sprite("core/misc/smallmap_exit"))
37
reader.read_vector("position", pos);
38
reader.read_desc ("surface", desc);
39
reader.read_int ("owner-id", owner_id);
41
// Set default owner ID to 0
42
if (owner_id < 0 || owner_id > 3) owner_id = 0;
44
flag = Resource::load_sprite("core/misc/flag" + StringUtil::to_string(owner_id));
46
sprite = Resource::load_sprite(desc);
49
std::cout << "Creating Exit" << std::endl;
59
// FIXME: This will fail with exits that contain multiple frames
60
CollisionMask mask(desc);
61
world->get_colmap()->remove(mask,
62
static_cast<int>(pos.x) - sprite.get_width()/2,
63
static_cast<int>(pos.y) - sprite.get_height());
67
Exit::draw (SceneContext& gc)
69
gc.color().draw(sprite, pos);
70
gc.color().draw(flag, pos + Vector3f(40, 0));
74
Exit::draw_smallmap(SmallMap* smallmap)
76
smallmap->draw_sprite(smallmap_symbol, pos);
84
PinguHolder* holder = world->get_pingus();
86
for (PinguIter pingu = holder->begin(); pingu != holder->end(); ++pingu)
88
// Make sure this particular exit is allowed for this pingu
89
if ((*pingu)->get_owner() == owner_id)
91
// Now, make sure the pingu is within range
92
if ( (*pingu)->get_pos().x > pos.x - 1 && (*pingu)->get_pos().x < pos.x + 1
93
&& (*pingu)->get_pos().y > pos.y - 5 && (*pingu)->get_pos().y < pos.y + 2)
95
// Now, make sure the pingu isn't already exiting, gone, or dead
96
if ( (*pingu)->get_status() != PS_EXITED
97
&& (*pingu)->get_status() != PS_DEAD
98
&& (*pingu)->get_action() != Actions::Exiter)
100
// Pingu actually exits
101
(*pingu)->set_action(Actions::Exiter);
109
Exit::get_z_pos () const
114
} // namespace WorldObjs