1
// $Id: SmallMap.cc,v 1.36 2002/01/15 10:48:49 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.
22
#include "boost/smart_ptr.hpp"
23
#include "ExitData.hh"
24
#include "EntranceData.hh"
28
#include "PinguHolder.hh"
30
#include "Playfield.hh"
32
#include "PingusResource.hh"
33
#include "SmallMap.hh"
53
unsigned char* buffer;
54
unsigned char* cbuffer;
55
unsigned char current_pixel;
58
entrance_sur = PingusResource::load_surface("misc/smallmap_entrance", "core");
59
exit_sur = PingusResource::load_surface("misc/smallmap_exit", "core");
61
world = client->get_server()->get_world();
63
colmap = world->get_colmap();
64
buffer = colmap->get_data();
65
plf = world->get_plf();
67
canvas = new CL_Canvas(width, height);
71
cbuffer = static_cast<unsigned char*>(canvas->get_data());
73
for(int y = 0; y < height; y++)
75
for (int x = 0; x < width; x++)
77
tx = x * colmap->get_width() / width;
78
ty = y * colmap->get_height() / height;
80
current_pixel = buffer[tx + (ty * colmap->get_width())];
82
if (current_pixel == ColMap::NOTHING)
84
cbuffer[4 * ((y * width) + x) + 0] = 150;
85
cbuffer[4 * ((y * width) + x) + 1] = 0;
86
cbuffer[4 * ((y * width) + x) + 2] = 0;
87
cbuffer[4 * ((y * width) + x) + 3] = 0;
89
else if (current_pixel & ColMap::BRIDGE)
91
cbuffer[4 * ((y * width) + x) + 0] = 255;
92
cbuffer[4 * ((y * width) + x) + 1] = 100;
93
cbuffer[4 * ((y * width) + x) + 2] = 255;
94
cbuffer[4 * ((y * width) + x) + 3] = 0;
96
else if (current_pixel & ColMap::LAVA)
98
cbuffer[4 * ((y * width) + x) + 0] = 255;
99
cbuffer[4 * ((y * width) + x) + 1] = 100;
100
cbuffer[4 * ((y * width) + x) + 2] = 100;
101
cbuffer[4 * ((y * width) + x) + 3] = 255;
103
else if (current_pixel & ColMap::SOLID)
105
cbuffer[4 * ((y * width) + x) + 0] = 255;
106
cbuffer[4 * ((y * width) + x) + 1] = 100;
107
cbuffer[4 * ((y * width) + x) + 2] = 100;
108
cbuffer[4 * ((y * width) + x) + 3] = 100;
112
cbuffer[4 * ((y * width) + x) + 0] = 255;
113
cbuffer[4 * ((y * width) + x) + 1] = 200;
114
cbuffer[4 * ((y * width) + x) + 2] = 200;
115
cbuffer[4 * ((y * width) + x) + 3] = 200;
121
std::vector<ExitData> exit_d = plf->get_exit();
122
for(std::vector<ExitData>::iterator i = exit_d.begin(); i != exit_d.end(); i++)
124
// FIXME: Replace this with put_target() when it is bug free
125
Blitter::put_surface(canvas, exit_sur,
126
i->pos.x * width / colmap->get_width() - (exit_sur.get_width()/2),
127
i->pos.y * height / colmap->get_height());
130
std::vector<EntranceData> entrance_d = plf->get_entrance();
131
for(std::vector<EntranceData>::iterator i = entrance_d.begin(); i != entrance_d.end(); i++)
133
Blitter::put_surface(canvas, entrance_sur,
134
i->pos.x * width / colmap->get_width() - (entrance_sur.get_width()/2),
135
i->pos.y * height / colmap->get_height() - (entrance_sur.get_height()));
140
sur = CL_Surface(canvas, true);
143
y_pos = CL_Display::get_height() - sur.get_height();
145
rwidth = CL_Display::get_width() * width / client->get_server()->get_world()->get_colmap()->get_width();
146
rheight = CL_Display::get_height() * height / client->get_server()->get_world()->get_colmap()->get_height();
150
SmallMap::set_client(Client* c)
159
boost::shared_ptr<Playfield> playfield = client->get_playfield();
161
int x_of = playfield->get_x_offset();
162
int y_of = playfield->get_y_offset();
164
sur.put_screen(0, CL_Display::get_height() - sur.get_height());
166
x_of = -x_of * width / client->get_server()->get_world()->get_colmap()->get_width();
167
y_of = -y_of * height / client->get_server()->get_world()->get_colmap()->get_height();
169
Display::draw_rect(x_of,
170
y_of + CL_Display::get_height() - sur.get_height(),
171
x_of + std::min(rwidth, int(sur.get_width())),
172
y_of + std::min(rheight, int(sur.get_height())) + CL_Display::get_height() - sur.get_height(),
175
// FIXME: This should use put_target(), but put_target(), does not
177
/* vector<exit_data> exit_d = plf->get_exit();
178
for(std::vector<exit_data>::iterator i = exit_d.begin(); i != exit_d.end(); i++)
180
exit_sur->put_screen(i->x_pos * width / colmap->get_width() + x_pos - 3,
181
i->y_pos * height / colmap->get_height() + y_pos - 3);
184
vector<entrance_data> entrance_d = plf->get_entrance();
185
for(std::vector<entrance_data>::iterator i = entrance_d.begin(); i != entrance_d.end(); i++)
187
entrance_sur->put_screen(i->x_pos * width / colmap->get_width() + x_pos - 3,
188
i->y_pos * height / colmap->get_height() + y_pos);
195
SmallMap::draw_pingus()
199
PinguHolder* pingus = client->get_server()->get_world()->get_pingu_p();
201
for(std::list<boost::shared_ptr<Pingu> >::iterator i = pingus->begin();
202
i != pingus->end(); i++)
204
//FIXME: Replace this with put pixel
205
x = x_pos + ((*i)->get_x() * width / client->get_server()->get_world()->get_colmap()->get_width());
206
y = y_pos + ((*i)->get_y() * height / client->get_server()->get_world()->get_colmap()->get_height());
208
CL_Display::draw_line(x, y, x, y-1, 1.0, 1.0, 0.0, 1.0);
213
SmallMap::update(float delta)
216
ColMap* colmap = client->get_server()->get_world()->get_colmap();
220
cx = (int(CL_Mouse::get_x()) - x_pos) * int(colmap->get_width()) / width;
221
cy = (int(CL_Mouse::get_y()) - y_pos) * int(colmap->get_height()) / height ;
223
std::cout << "Viewpoint: " << cx << " " << cy << std::endl;
225
client->get_playfield()->set_viewpoint(cx, cy);
230
SmallMap::mouse_over()
232
//std::cout << "x_pos: " << CL_Mouse::get_x() << " y_pos: " << CL_Mouse::get_y() << std::endl;
234
if (CL_Mouse::get_x() > x_pos && CL_Mouse::get_x() < x_pos + (int)width
235
&& CL_Mouse::get_y() > y_pos && CL_Mouse::get_y() < y_pos + (int)height)
246
SmallMap::on_button_press(const CL_Key& key)
250
case CL_MOUSE_LEFTBUTTON:
262
SmallMap::on_button_release(const CL_Key& key)
266
case CL_MOUSE_LEFTBUTTON: