diff --git a/gamedata/objects/ingame/tileset.py b/gamedata/objects/ingame/tileset.py index edc17c9..184330f 100644 --- a/gamedata/objects/ingame/tileset.py +++ b/gamedata/objects/ingame/tileset.py @@ -23,6 +23,17 @@ class TilesetRenderer(BaseObject): self.bgoffset = self.layers[0]["surface"].get_height()/2-self.game.globals["camerah"] + # Prescale backgrounds + self.sep = self.game.pygame.transform.scale(self.game.sprite_lib["backgroundseparator.png"],[self.game.globals["cameraw"],self.game.globals["camerah"]]) + self.scaledbgs = [] + wratio = self.game.globals["cameraw"]/self.bgs[0]["sprite"].get_width() + hratio = self.game.globals["camerah"]/self.bgs[0]["sprite"].get_height() + for bg in 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)) + self.scaledbgs.append(sprite) + + def step(self): # Spawning ennemies while len(self.queue)>0: @@ -31,24 +42,21 @@ class TilesetRenderer(BaseObject): self.game.gameloop.summon(e) def draw(self): - wratio = self.game.globals["cameraw"]/self.bgs[0]["sprite"].get_width() - hratio = self.game.globals["camerah"]/self.bgs[0]["sprite"].get_height() lastoffset = 0 - for i,bg in enumerate(self.bgs): + for i,bg in enumerate(self.scaledbgs): 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)) + width = bg.get_width() + height = bg.get_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]) + self.game.window.blit(bg,[(-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]) + self.game.window.blit(self.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"]))