Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/mapview.py
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-02-06 00:53:00 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2012-02-06 00:53:00 (GMT)
commit952583926af90301cfee57c19cf72f4de9954598 (patch)
treead6c0203329b8ff64144e8a6e2bee52a4be42e26 /mapview.py
parentf38aa41dc7e7553b7cd3d5c2b0ce744dd1262e77 (diff)
Add a class to test basic navigation in the map
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
Diffstat (limited to 'mapview.py')
-rw-r--r--mapview.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/mapview.py b/mapview.py
index c686324..3c1b193 100644
--- a/mapview.py
+++ b/mapview.py
@@ -16,9 +16,19 @@ class TopMapView(gtk.DrawingArea):
self._game_map = game_map
self._width = width
self._height = height
+ self._show_position = None
super(TopMapView, self).__init__()
+ self.set_size_request(width, height)
self.connect('expose_event', self.expose)
+ def show_position(self, x, y, direction):
+ self._show_position = {'x': x, 'y': y, 'direction': direction}
+ self.queue_draw()
+
+ def hide_position(self, x, y, direction):
+ self._show_position = None
+ self.queue_draw()
+
def calculate_sizes(self, width, height):
# calculate cell size
cell_width = self._width / self._game_map.data['max_x']
@@ -90,6 +100,42 @@ class TopMapView(gtk.DrawingArea):
ctx.line_to(x_pos, y_pos + self.cell_size)
ctx.stroke()
+ if self._show_position is not None:
+ x = self._show_position['x']
+ y = self._show_position['y']
+ direction = self._show_position['direction']
+ x_pos = self.margin_x + x * self.cell_size + self.cell_size / 2
+ y_pos = self.margin_y + y * self.cell_size + self.cell_size / 2
+ border = 3
+ if direction == 'N':
+ point2_x = self.margin_x + x * self.cell_size + border
+ point2_y = self.margin_y + y * self.cell_size + border
+ point3_x = self.margin_x + (x + 1) * self.cell_size - border
+ point3_y = self.margin_y + y * self.cell_size + border
+ elif direction == 'E':
+ point2_x = self.margin_x + (x + 1) * self.cell_size - border
+ point2_y = self.margin_y + y * self.cell_size + border
+ point3_x = self.margin_x + (x + 1) * self.cell_size - border
+ point3_y = self.margin_y + (y + 1) * self.cell_size - border
+ elif direction == 'S':
+ point2_x = self.margin_x + (x + 1) * self.cell_size - border
+ point2_y = self.margin_y + (y + 1) * self.cell_size - border
+ point3_x = self.margin_x + x * self.cell_size + border
+ point3_y = self.margin_y + (y + 1) * self.cell_size - border
+ elif direction == 'W':
+ point2_x = self.margin_x + x * self.cell_size + border
+ point2_y = self.margin_y + (y + 1) * self.cell_size - border
+ point3_x = self.margin_x + x * self.cell_size + border
+ point3_y = self.margin_y + y * self.cell_size + border
+
+ ctx.move_to(x_pos, y_pos)
+ ctx.line_to(point2_x, point2_y)
+ ctx.line_to(point3_x, point3_y)
+ ctx.close_path()
+ fill = (1, 0, 0)
+ ctx.set_source_rgb(*fill)
+ ctx.fill()
+
def have_door(self, wall_info):
_have_door = False
for wall_object in wall_info: