Fix du rendu dans les chunks à des coordonnées négatives

This commit is contained in:
Yannis 2023-12-26 19:03:31 +01:00
parent 43f9ba682c
commit 739f7a984a
4 changed files with 3264 additions and 19 deletions

3261
maps/map3.tmj Normal file

File diff suppressed because it is too large Load diff

View file

@ -19,8 +19,6 @@ class MapManager:
chunks[(chunk["x"]//self.chunk_width, chunk["y"]//self.chunk_height)] = chunk["data"] chunks[(chunk["x"]//self.chunk_width, chunk["y"]//self.chunk_height)] = chunk["data"]
self.map_layers.append(chunks) self.map_layers.append(chunks)
print(self.map_layers)
def get_tile_at(self, x: int, y: int, layer_id: int): def get_tile_at(self, x: int, y: int, layer_id: int):
"""Donne l'id de la tile aux coordonnées données et à la couche choisie.""" """Donne l'id de la tile aux coordonnées données et à la couche choisie."""

View file

@ -143,8 +143,8 @@ class Renderer:
y_middle_offset = display.get_window_size()[1] / 2 / self.engine.camera.zoom y_middle_offset = display.get_window_size()[1] / 2 / self.engine.camera.zoom
# On calcule le décalage du début de rendu des tiles # On calcule le décalage du début de rendu des tiles
x_map_offset = int((self.engine.camera.x - x_middle_offset) / self.tile_size) x_map_offset = math.floor((self.engine.camera.x - x_middle_offset) / self.tile_size)
y_map_offset = int((self.engine.camera.y - y_middle_offset) / self.tile_size) y_map_offset = math.floor((self.engine.camera.y - y_middle_offset) / self.tile_size)
# On itère pour chaque couche, toutes les tiles visibles par la caméra # On itère pour chaque couche, toutes les tiles visibles par la caméra
for x in range(x_map_offset, x_map_offset + x_map_range): for x in range(x_map_offset, x_map_offset + x_map_range):

View file

@ -7,7 +7,7 @@ from src.engine.engine import Engine
class Game(Engine): class Game(Engine):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.map_manager.load_new("maps/map2.tmj") self.map_manager.load_new("maps/map3.tmj")
self.renderer.load_tile_set("assets/textures/tiles.png", 16) self.renderer.load_tile_set("assets/textures/tiles.png", 16)
@ -23,19 +23,5 @@ class Game(Engine):
self.camera.follow_entity(player) self.camera.follow_entity(player)
for i in range(20):
anim = Anim(0.5)
anim.load_animation_from_directory("assets/textures/entities/player/none")
self.renderer.register_animation(anim, f"player_none_{i}")
test = self.entity_manager.register_entity(f"test_{i}")
test.x = random.randint(0, 200)
test.y = random.randint(0, 200)
test.link_animation(f"player_none_{i}")
test.collision_rect = [-7, -7, 7, 7]
test.set_default_life(10)
game = Game() game = Game()
game.loop() game.loop()