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

« back to all changes in this revision

Viewing changes to src/worldobjs/exit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-02-28 19:44:25 UTC
  • mfrom: (4.1.4 hardy)
  • Revision ID: james.westby@ubuntu.com-20080228194425-e8ilohlijv02kgcf
Tags: 0.7.2-2
* Fix FTBFS with gcc-4.3 by adding the missing include in
  src/input/evdev_device.cpp (Closes: #462238):
   + debian/patches/20_fix_FTBFS_with_gcc-4.3.
* Rename former patch so that the filename reflects the order in which
  the patches are applied:
   - debian/patches/data_dir.patch
   + debian/patches/10_fix_data_directory.
* Bump Standards-Version from 3.7.2 to 3.7.3, no changes needed.
* Add a dh_desktop call in the arch-dep part of debian/rules.
* Adjust the “missing-dep-for-interpreter guile” override since lintian
  now lists an alternative for that dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  $Id: exit.cpp 2986 2007-08-17 16:20:09Z grumbel $
 
2
//
 
3
//  Pingus - A free Lemmings clone
 
4
//  Copyright (C) 1999 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 <iostream>
 
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"
 
30
#include "exit.hpp"
 
31
 
 
32
namespace WorldObjs {
 
33
 
 
34
Exit::Exit(const FileReader& reader)
 
35
  : smallmap_symbol(Resource::load_sprite("core/misc/smallmap_exit"))
 
36
{
 
37
  reader.read_vector("position", pos);
 
38
  reader.read_desc  ("surface",  desc);
 
39
  reader.read_int   ("owner-id", owner_id);
 
40
 
 
41
  // Set default owner ID to 0
 
42
  if (owner_id < 0 || owner_id > 3) owner_id = 0;
 
43
 
 
44
  flag = Resource::load_sprite("core/misc/flag" + StringUtil::to_string(owner_id));
 
45
 
 
46
  sprite = Resource::load_sprite(desc);
 
47
 
 
48
  if (verbose > 2)
 
49
    std::cout << "Creating Exit" << std::endl;
 
50
}
 
51
 
 
52
Exit::~Exit ()
 
53
{
 
54
}
 
55
 
 
56
void
 
57
Exit::on_startup ()
 
58
{
 
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());
 
64
}
 
65
 
 
66
void
 
67
Exit::draw (SceneContext& gc)
 
68
{
 
69
  gc.color().draw(sprite, pos);
 
70
  gc.color().draw(flag, pos + Vector3f(40, 0));
 
71
}
 
72
 
 
73
void
 
74
Exit::draw_smallmap(SmallMap* smallmap)
 
75
{
 
76
  smallmap->draw_sprite(smallmap_symbol, pos);
 
77
}
 
78
 
 
79
void
 
80
Exit::update ()
 
81
{
 
82
  sprite.update();
 
83
 
 
84
  PinguHolder* holder = world->get_pingus();
 
85
 
 
86
  for (PinguIter pingu = holder->begin(); pingu != holder->end(); ++pingu)
 
87
    {
 
88
      // Make sure this particular exit is allowed for this pingu
 
89
      if ((*pingu)->get_owner()  == owner_id)
 
90
        {
 
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)
 
94
            {
 
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)
 
99
                {
 
100
                  // Pingu actually exits
 
101
                  (*pingu)->set_action(Actions::Exiter);
 
102
                }
 
103
            }
 
104
        }
 
105
    }
 
106
}
 
107
 
 
108
float
 
109
Exit::get_z_pos () const
 
110
{
 
111
  return pos.z;
 
112
}
 
113
 
 
114
} // namespace WorldObjs
 
115
 
 
116
/* EOF */