diff --git a/gamedata/assets/backgroundsep.png b/gamedata/assets/backgroundsep.png new file mode 100644 index 0000000..7d96879 Binary files /dev/null and b/gamedata/assets/backgroundsep.png differ diff --git a/gamedata/assets/backgroundseparator.png b/gamedata/assets/backgroundseparator.png new file mode 100644 index 0000000..a1bca8b Binary files /dev/null and b/gamedata/assets/backgroundseparator.png differ diff --git a/gamedata/game.py b/gamedata/game.py index 2cf1cc2..635fc0b 100644 --- a/gamedata/game.py +++ b/gamedata/game.py @@ -36,8 +36,9 @@ class Game(): mapdico = {} mapdico["name"] = mapfolder.split(os.sep)[-1] mapdico["cover"] = None - mapdico["background"] = None + mapdico["backgrounds"] = [] mapdico["data"] = None + mapdico["filler"] = None mapdico["tilesets"] = {} scanner = os.scandir(path=mapfolder) for i in scanner: # Je check tout les fichiers du dossier @@ -46,10 +47,12 @@ class Game(): if name.endswith(".png"): if name=="cover.png": mapdico["cover"] = pygame.image.load(i.path) - elif name=="background.png": - mapdico["background"] = pygame.image.load(i.path) + elif name.startswith("background"): + mapdico["backgrounds"].append({"sprite":pygame.image.load(i.path).convert_alpha(),"name":i.path}) + elif name=="filler.png": + mapdico["filler"] = pygame.image.load(i.path).convert_alpha() else: - mapdico["tilesets"][i.name] = pygame.image.load(i.path) + mapdico["tilesets"][i.name] = pygame.image.load(i.path).convert_alpha() except: self.log("Erreur",mapfolder,name,"Fichier invalide") if name=="map.json": @@ -59,6 +62,7 @@ class Game(): except: self.log("Erreur",mapfolder,name) if mapdico["data"]: + mapdico["backgrounds"].sort(key=lambda x: x["name"]) return mapdico return None diff --git a/gamedata/maps/TulipFields/background.png b/gamedata/maps/TulipFields/background.png deleted file mode 100644 index b606cd2..0000000 Binary files a/gamedata/maps/TulipFields/background.png and /dev/null differ diff --git a/gamedata/maps/TulipFields/background0.png b/gamedata/maps/TulipFields/background0.png new file mode 100644 index 0000000..eae59e8 Binary files /dev/null and b/gamedata/maps/TulipFields/background0.png differ diff --git a/gamedata/maps/TulipFields/background1.png b/gamedata/maps/TulipFields/background1.png new file mode 100644 index 0000000..2cf88d1 Binary files /dev/null and b/gamedata/maps/TulipFields/background1.png differ diff --git a/gamedata/maps/TulipFields/background2.png b/gamedata/maps/TulipFields/background2.png new file mode 100644 index 0000000..5f53a92 Binary files /dev/null and b/gamedata/maps/TulipFields/background2.png differ diff --git a/gamedata/maps/TulipFields/background3.png b/gamedata/maps/TulipFields/background3.png new file mode 100644 index 0000000..40197fa Binary files /dev/null and b/gamedata/maps/TulipFields/background3.png differ diff --git a/gamedata/maps/TulipFields/filler.png b/gamedata/maps/TulipFields/filler.png new file mode 100644 index 0000000..5dedf3a Binary files /dev/null and b/gamedata/maps/TulipFields/filler.png differ diff --git a/gamedata/objects/combat/tileset.py b/gamedata/objects/combat/tileset.py index 1264d90..a493c28 100644 --- a/gamedata/objects/combat/tileset.py +++ b/gamedata/objects/combat/tileset.py @@ -16,9 +16,11 @@ class TilesetRenderer(BaseObject): self.level = game.levels_lib[mapfoldername] self.reinit(self.level) - self.bg = game.sprite_lib["fallbackground.png"] - if self.level["background"]: - self.bg = self.level["background"] + self.bgs = [game.sprite_lib["fallbackground.png"]] + if len(self.level["backgrounds"]): + self.bgs = self.level["backgrounds"] + + self.bgoffset = self.layers[0]["surface"].get_height()/2-self.game.globals["camerah"] def step(self): # Spawning ennemies @@ -28,7 +30,25 @@ class TilesetRenderer(BaseObject): self.game.gameloop.summon(e) def draw(self): - self.game.window.blit(self.game.pygame.transform.scale(self.bg,(self.game.globals["cameraw"],self.game.globals["camerah"])),[0,0]) + wratio = self.game.globals["cameraw"]/self.game.DISPLAY_WIDTH + hratio = self.game.globals["camerah"]/self.game.DISPLAY_HEIGHT + lastoffset = 0 + for i,bg in enumerate(self.bgs): + ratio = 1-(len(self.bgs)-i)/len(self.bgs) + width, height = round(bg["sprite"].get_width()*wratio),round(bg["sprite"].get_height()*hratio) + sprite = self.game.pygame.transform.scale(bg["sprite"],(width,height)) + nbs = self.game.globals["cameraw"]/width + lastoffset = self.rect[1]+(self.bgoffset-self.game.globals["cameray"])*ratio + for i in range(round(nbs+0.5)): + self.game.window.blit(sprite,[(-self.game.globals["camerax"]*ratio)%width+(i-1)*width,lastoffset]) + # Draw filler + if self.level["filler"]: + filleroffset = lastoffset+height + self.game.window.blit(self.level["filler"],[0,filleroffset]) + # Separator + sep = self.game.pygame.transform.scale(self.game.sprite_lib["backgroundseparator.png"],[self.game.globals["cameraw"],self.game.globals["camerah"]]) + self.game.window.blit(sep,[0,0]) + # Layers for layer in self.layers: self.game.window.blit(layer["surface"],(layer["offsets"][0]-self.game.globals["camerax"],layer["offsets"][1]-self.game.globals["cameray"]))