Mentions légales du service

Skip to content
Snippets Groups Projects
Commit c1a9b93b authored by PEDERSEN Ny Aina's avatar PEDERSEN Ny Aina
Browse files

arcade: update on resize

- fix resize misplaced player due to float precision
- remove top and right black borders if we can
- add min scale
parent 41fad7de
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ class Tiles:
SPRITE_SIZE = 32
TILE_SIZE = 32
MIN_SCALE = 2
class Anim:
......
......@@ -48,7 +48,7 @@ class Character(arcade.Sprite):
# Coordinates of the starting tile if in movement
self.coord_x: int = 0
self.coord_y: int = map_height
self.coord_y: int = map_height - 1
# Coordinates of the target tile
self.target_x: int = self.coord_x
......
......@@ -2,6 +2,7 @@
from os.path import dirname
from typing import Optional
from math import ceil
import arcade
import arcade.gui
......@@ -74,6 +75,9 @@ class GameView(EmptyView):
int(self.tile_map.height),
int(self.tile_map.width),
)
# TODO: move this in a setup method
self.scale = 1.0
self.scale_old = 1.0
self.on_resize(0, 0) # dummy resize to scale everything
def on_map_resize(self) -> None:
......@@ -97,7 +101,8 @@ class GameView(EmptyView):
scale_x = win_width / map_width / cst.Tiles.TILE_SIZE
scale_y = win_height / map_height / cst.Tiles.TILE_SIZE
self.scale = min(scale_x, scale_y)
scale_candidate = ceil(min(scale_x, scale_y))
self.scale = max(cst.Tiles.MIN_SCALE, scale_candidate)
return self.scale
......@@ -178,11 +183,16 @@ class GameView(EmptyView):
screen_center_x = max(screen_center_x, 0)
screen_center_y = max(screen_center_y, 0)
# Do not scroll if the map can fit in one axis
if self.scaled_tile * self.tile_map.width <= vp_w:
screen_center_y = 0
if self.scaled_tile * self.tile_map.height <= vp_h:
screen_center_x = 0
# Avoid black borders on the top
map_height_px = self.scaled_tile * self.tile_map.height
if map_height_px >= vp_h:
top_vp_center = map_height_px - vp_h
screen_center_y = min(screen_center_y, top_vp_center)
# Avoid black borders on the right
map_width_px = self.scaled_tile * self.tile_map.width
if map_width_px >= vp_w:
top_vp_center = map_width_px - vp_w
screen_center_x = min(screen_center_x, top_vp_center)
# Here's our center, move to it
player_centered = screen_center_x, screen_center_y
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment