2021-06-25 14:42:35 +02:00
|
|
|
from gamedata.objects.base import BaseObject
|
|
|
|
|
|
|
|
class BackgroundDrawer(BaseObject):
|
|
|
|
|
|
|
|
def __init__(self,x,y,game,w,h,sprite,ratio):
|
|
|
|
super().__init__(x,y,game,w,h)
|
|
|
|
self.ratio = ratio
|
|
|
|
self.depth = -1
|
2021-06-25 16:13:52 +02:00
|
|
|
self.fill(sprite) # Générer notre sprite de l'objet, le remplissant avec le sprite argument
|
2021-06-25 14:42:35 +02:00
|
|
|
|
2021-06-25 16:13:52 +02:00
|
|
|
def fill(self,sprite):
|
|
|
|
game = self.game
|
2021-06-25 14:42:35 +02:00
|
|
|
self.tilew = sprite.get_width()
|
|
|
|
self.tileh = sprite.get_height()
|
|
|
|
nbw = round(self.rect[2]/self.tilew+1.5)
|
|
|
|
nbh = round(self.rect[3]/self.tileh+1.5)
|
|
|
|
sw = nbw*self.tileh
|
|
|
|
sh = nbh*self.tileh
|
|
|
|
self.sprite = game.pygame.Surface((sw,sh),game.pygame.SRCALPHA)
|
|
|
|
|
|
|
|
for i in range(nbw):
|
|
|
|
for j in range(nbh):
|
|
|
|
self.sprite.blit(sprite,(i*self.tilew,j*self.tileh))
|
|
|
|
|
2021-06-25 16:13:52 +02:00
|
|
|
def draw(self):
|
|
|
|
game = self.game
|
2021-06-25 14:42:35 +02:00
|
|
|
# Affichage du sprite de mannière répétée
|
|
|
|
px = (self.rect[0]-game.globals["camerax"]*self.ratio)%self.tilew
|
|
|
|
py = (self.rect[1]-game.globals["cameray"]*self.ratio)%self.tileh
|
|
|
|
|
|
|
|
game.window.blit(self.sprite,(self.baserect[0]+px-self.tilew,self.baserect[1]+py-self.tileh))
|