From 3e7dabc94e8e9beb61e2e5b16d215e3e51a95387 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 26 Nov 2020 21:59:48 +0100 Subject: [PATCH] Wrap perfectly the map on the screen, bricks won't teleport randomly anymore --- squirrelbattle/display/display_manager.py | 5 ++++- squirrelbattle/display/mapdisplay.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/squirrelbattle/display/display_manager.py b/squirrelbattle/display/display_manager.py index d50dfa1..2c7baf1 100644 --- a/squirrelbattle/display/display_manager.py +++ b/squirrelbattle/display/display_manager.py @@ -48,7 +48,10 @@ class DisplayManager: if self.game.state == GameMode.PLAY: # The map pad has already the good size self.mapdisplay.refresh(0, 0, self.rows * 4 // 5, - self.cols * 4 // 5, resize_pad=False) + self.mapdisplay.pack.tile_width + * (self.cols * 4 // 5 + // self.mapdisplay.pack.tile_width), + resize_pad=False) self.statsdisplay.refresh(0, self.cols * 4 // 5 + 1, self.rows, self.cols // 5 - 1) self.logsdisplay.refresh(self.rows * 4 // 5 + 1, 0, diff --git a/squirrelbattle/display/mapdisplay.py b/squirrelbattle/display/mapdisplay.py index ce134a5..ae4caa3 100644 --- a/squirrelbattle/display/mapdisplay.py +++ b/squirrelbattle/display/mapdisplay.py @@ -31,9 +31,17 @@ class MapDisplay(Display): smaxrow = min(smaxrow, self.height - 1) smaxcol = self.pack.tile_width * self.map.width - \ (x + deltax) + self.width - 1 + + # Wrap perfectly the map according to the width of the tiles + pmincol = self.pack.tile_width * (pmincol // self.pack.tile_width) + smincol = self.pack.tile_width * (smincol // self.pack.tile_width) + smaxcol = self.pack.tile_width \ + * (smaxcol // self.pack.tile_width + 1) - 1 + smaxcol = min(smaxcol, self.width - 1) pminrow = max(0, min(self.map.height, pminrow)) pmincol = max(0, min(self.pack.tile_width * self.map.width, pmincol)) + self.pad.clear() self.update_pad() self.refresh_pad(self.pad, pminrow, pmincol, sminrow, smincol, smaxrow,