Début de rendu de la map et déplacement de la caméra

This commit is contained in:
Yannis 2023-12-22 21:34:42 +01:00
parent 6849ed2de4
commit 1c3d6a7d90
6 changed files with 658 additions and 17 deletions

4
assets/tiles.tsx Normal file
View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.1" name="tiles" tilewidth="16" tileheight="16" tilecount="256" columns="16">
<image source="tiles.png" width="256" height="256"/>
</tileset>

563
maps/map1.tmj Normal file
View file

@ -0,0 +1,563 @@
{ "compressionlevel":-1,
"height":20,
"infinite":true,
"layers":[
{
"chunks":[
{
"data":[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 2, 2],
"height":16,
"width":16,
"x":48,
"y":80
}],
"height":96,
"id":1,
"name":"Calque de Tuiles 1",
"opacity":1,
"startx":0,
"starty":0,
"type":"tilelayer",
"visible":true,
"width":64,
"x":0,
"y":0
}],
"nextlayerid":2,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.10.1",
"tileheight":16,
"tilesets":[
{
"firstgid":1,
"source":"..\/assets\/tiles.tsx"
}],
"tilewidth":16,
"type":"map",
"version":"1.10",
"width":30
}

View file

@ -1,3 +1,4 @@
from src.camera import Camera
from src.event_handler import EventHandler from src.event_handler import EventHandler
from src.map_manager import MapManager from src.map_manager import MapManager
from src.renderer import Renderer from src.renderer import Renderer
@ -7,7 +8,7 @@ import pygame
class Engine: class Engine:
"""Classe principale qui regroupe tous les composants du programme (Renderer, MapManager, EventHandler, etc ...)""" """Classe principale qui regroupe tous les composants du programme (Renderer, MapManager, EventHandler, etc ...)"""
def __init__(self): def __init__(self):
# L'initialisation de Pygame est nécéssaire pour tous les modules # L'initialisation de Pygame est nécessaire pour tous les modules
pygame.init() pygame.init()
self.clock = pygame.time.Clock() self.clock = pygame.time.Clock()
@ -16,8 +17,9 @@ class Engine:
self.renderer = Renderer(self) self.renderer = Renderer(self)
self.event_handler = EventHandler(self) self.event_handler = EventHandler(self)
self.map_manager = MapManager() self.map_manager = MapManager()
self.camera = Camera()
self.map_manager.load_new("maps/map0.tmj") self.map_manager.load_new("maps/map1.tmj")
self.renderer.load_tile_set("assets/tiles.png", 16) self.renderer.load_tile_set("assets/tiles.png", 16)
@ -36,6 +38,6 @@ class Engine:
self.event_handler.update() self.event_handler.update()
def stop(self): def stop(self):
"""Arrete le programme.""" """Arrête le programme."""
self.running = False self.running = False
pygame.quit() pygame.quit()

View file

@ -1,5 +1,5 @@
from pygame import event from pygame import event
from pygame.locals import QUIT from pygame.locals import *
import src.engine as engine import src.engine as engine
@ -8,9 +8,29 @@ class EventHandler:
"""Classe utilisée pour traiter les pygame.event.get() et gérer les interactions avec le reste du programme.""" """Classe utilisée pour traiter les pygame.event.get() et gérer les interactions avec le reste du programme."""
def __init__(self, core: 'engine.Engine'): def __init__(self, core: 'engine.Engine'):
self.engine = core self.engine = core
self.key_pressed = []
def update(self): def update(self):
"""Vérifie s'il y a de nouvelles interactions et les traites.""" """Vérifie s'il y a de nouvelles interactions et les traites."""
# Récupère les événements
for e in event.get(): for e in event.get():
if e.type == QUIT: if e.type == QUIT:
self.engine.stop() self.engine.stop()
elif e.type == KEYDOWN:
self.key_pressed.append(e.key)
elif e.type == KEYUP:
self.key_pressed.remove(e.key)
if K_RIGHT in self.key_pressed:
self.engine.camera.x += 2
if K_LEFT in self.key_pressed:
self.engine.camera.x -= 2
if K_UP in self.key_pressed:
self.engine.camera.y -= 2
if K_DOWN in self.key_pressed:
self.engine.camera.y += 2
if K_x in self.key_pressed:
self.engine.camera.zoom *= 1.01
if K_c in self.key_pressed:
self.engine.camera.zoom *= 0.99

View file

@ -4,18 +4,44 @@ import json
class MapManager: class MapManager:
"""Stocke les cartes du jeu.""" """Stocke les cartes du jeu."""
def __init__(self): def __init__(self):
# structure : [layers[chunks[x, y]{width, height, data [tiles id]}] # structure : [layers{chunks[x, y][data]}
self.map_layers = [] self.map_layers = []
self.chunk_width = 16
self.chunk_height = 16
def load_new(self, file_path: str): def load_new(self, file_path: str):
"""Charge une map infinie au format tiled.""" """Charge une map infinie au format tiled."""
with open(file_path, "r") as file: with open(file_path, "r") as file:
data = json.loads(file.read()) data = json.loads(file.read())
for layer in data["layers"]: for layer in data["layers"]:
self.map_layers.append(layer["chunks"]) chunks = {}
for chunk in layer["chunks"]:
chunks[(chunk["x"]//self.chunk_width, chunk["y"]//self.chunk_height)] = chunk["data"]
self.map_layers.append(chunks)
print(self.map_layers) print(self.map_layers)
def get_tile_at(self, x: int, y: int, layer: int): def get_tile_at(self, x: int, y: int, layer_id: int):
"""Done 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."""
return
# On récupère la couche demandée
layer = self.map_layers[layer_id]
# On calcule les coordonées du chunk
coordinates = (x//self.chunk_width, y//self.chunk_height)
# On transforme les coordonnées globales en coordonnées dans le chunk
x %= 16
y %= 16
if coordinates not in layer:
return 0
chunk = layer[coordinates]
# On vérifie que la tile demandée existe sinon on répond "vide"
if x >= self.chunk_width or x < 0 or y >= self.chunk_height or y < 0:
return 0
# On calcule l'index et on renvoie la tile
return chunk[x+y*self.chunk_width]

View file

@ -1,4 +1,5 @@
from pygame import display, image from pygame import display, image, surface, transform
from pygame.locals import RESIZABLE
import src.engine as engine import src.engine as engine
@ -7,19 +8,22 @@ class Renderer:
"""Classe contenant le moteur de rendu. On utilise, pour cela la bibliothèque Pygame.""" """Classe contenant le moteur de rendu. On utilise, pour cela la bibliothèque Pygame."""
def __init__(self, core: 'engine.Engine'): def __init__(self, core: 'engine.Engine'):
self.engine = core self.engine = core
self.window = display.set_mode((600, 600)) self.window = display.set_mode((600, 600), RESIZABLE)
self.tiles = [] self.tiles = []
self.tile_size = 0
def load_tile_set(self, file_path: str, tile_size: int): def load_tile_set(self, file_path: str, tile_size: int):
"""Charge le jeu de tuiles en utilisant le fichier donné et la taille donnée.""" """Charge le jeu de tuiles en utilisant le fichier donné et la taille donnée."""
tile_set = image.load(file_path).convert_alpha() tile_set = image.load(file_path).convert_alpha()
self.tile_size = tile_size
# Scan tout le tile set et le découpe pour créer des tiles de {tile_size} px de hauteur et de largeur # Scan tout le tile set et le découpe pour créer des tiles de {tile_size} px de hauteur et de largeur
for y in range(tile_set.get_height()//tile_size): for y in range(tile_set.get_height()//tile_size):
for x in range(tile_set.get_width()//tile_size): for x in range(tile_set.get_width()//tile_size):
tile = tile_set.subsurface((x*tile_size, y*tile_size, tile_size, tile_size)) tile = tile_set.subsurface((x*tile_size, y*tile_size, tile_size, tile_size))
self.tiles.append(tile) self.tiles.append(tile)
print(self.tiles) #print(self.tiles)
def update(self): def update(self):
"""Fait le rendu du jeu.""" """Fait le rendu du jeu."""
@ -30,11 +34,33 @@ class Renderer:
display.update() display.update()
def render_map(self): def render_map(self):
x_offset = 0 x_map_range = int(display.get_window_size()[0] // 16 // self.engine.camera.zoom) + 2
y_offset = 0 y_map_range = int(display.get_window_size()[1] // 16 // self.engine.camera.zoom) + 2
x_map_offset = int(self.engine.camera.x)
y_map_offset = int(self.engine.camera.y)
for i in range(4): rendered_surface_size = (x_map_range*self.tile_size, y_map_range*self.tile_size)
self.window.blit(self.tiles[i], (i*16, 0))
self.rendered_surface = None # On crée une surface temporaire qui nous permettra de la redimensionner
rendered_surface = surface.Surface(rendered_surface_size)
# On itère pour chaque couche, toutes les tiles visibles par la caméra
for i in range(len(self.engine.map_manager.map_layers)):
for x in range(x_map_offset, x_map_offset + x_map_range):
for y in range(y_map_offset, y_map_offset + y_map_range):
# On récupère l'id de la tile à la position donnée
tile_id = self.engine.map_manager.get_tile_at(x, y, i)
# Si l'id est 0, il s'agit de vide donc on saute le rendu
if tile_id == 0:
continue
# Puis, on cherche à quelle image elle correspond et on la colle sur notre surface
rendered_surface.blit(self.tiles[tile_id-1],
((x-self.engine.camera.x/self.engine.camera.zoom)*self.tile_size,
(y-self.engine.camera.y/self.engine.camera.zoom)*self.tile_size))
# Enfin, on redimensionne notre surface et on la colle sur la fenêtre principale
self.window.blit(transform.scale(rendered_surface, (rendered_surface_size[0]*self.engine.camera.zoom, rendered_surface_size[1]*self.engine.camera.zoom)), (0, 0))