import numpy as np import pygame from Champs import Champs as champ police = pygame.font.SysFont("Alef", 25) #pygame.font.get_fonts() -> liste des fonts class Infrastructure: def __init__ (self,pos,image): self.image = pygame.image.load(image) self.imageSize = np.array(self.image.get_size()) self.pos = pos self.rect = pygame.rect.Rect(self.pos, self.image.get_rect().size) self.rectScale = self.rect self.indiceDureeVie = 0 self.descripteurInfrastructure = { } self.imageSurfaceinfo = { } self.setInformation("Occupe", "Espace non occupé") self.setInformation("Nom","Emplacement vide") self.setInformation("coutEntretien","30€ d'entretien mensuel") self.setInformation("status", self.iconStatic,True) def draw (self, screen, camera): scaleImage = camera.scaleImage(self.image) if scaleImage: # != None self.imgZoom = scaleImage self.rectScale = pygame.rect.Rect(camera.convertLocation(self.pos), self.imgZoom.get_size()) if hasattr(self,'imagebat'): scaleBat = camera.scaleImage(self.imagebat) if scaleBat: self.BatZoom = scaleBat varlongueur = camera.convertLocation(self.pos) self.rectbatScal = pygame.rect.Rect(camera.convertLocation(self.pos), self.BatZoom.get_size()) screen.blit( self.BatZoom, ( varlongueur[0] + (self.rectScale.w-self.rectbatScal.w) /2, varlongueur[1] + (self.rectScale.h-self.rectbatScal.h) /2) ) def changeText (self, camera): scaleText = camera.scaleImage(self.text) if scaleText: self.zoomText = scaleText def setInformation(self,clef,valeur,isImage = False): self.descripteurInfrastructure[clef] = valeur if isImage : self.imageSurfaceinfo[clef] = valeur else : self.imageSurfaceinfo[clef] = police.render(str(valeur),True,(0,0,0)) def verifDureeVie(self): self.indiceDureeVie +=1 if(self.indiceDureeVie == 20): return True else: return False def showInfo(self,screen,rectangle): i = 0 for k,v in self.descripteurInfrastructure.items(): screen.blit(self.imageSurfaceinfo[k],(rectangle.x,rectangle.y + i)) i += 30 class Puit (Infrastructure): NameObjet = " puit" iconStatic = pygame.transform.scale(pygame.image.load('../assets/Batiment/puit.png'),(150,150)) textStatic = police.render('Puits',False, (255,255,255)) textDescriptionStatic = police.render("Moins efficace qu'un reservoir d'eau",False,(0,0,0)) montantAchat = 1000 def __init__ (self,pos): super().__init__(pos,'../assets/Plantation/champ.png') self.imagebat = pygame.transform.scale(pygame.image.load('../assets/Batiment/puit.png'),(120,120)) class ReservoirEau (Infrastructure): NameObjet = " réservoir à eau" iconStatic = pygame.transform.scale(pygame.image.load('../assets/Batiment/storagetank.png'),(150,150)) textStatic = police.render('Capteur eau de pluie',False, (255,255,255)) textDescriptionStatic = police.render("Permet de capturer l'eau de pluit",False,(0,0,0)) montantAchat = 2000 def __init__ (self,pos): super().__init__(pos,'../assets/Plantation/champ.png') self.imagebat = pygame.transform.scale(pygame.image.load('../assets/Batiment/storagetank.png'),(120,120)) class Irrigation (Infrastructure): NameObjet = " irrigation" iconStatic = pygame.transform.scale(pygame.image.load('../assets/Batiment/irrigation.png'),(150,150)) textStatic = police.render('Arrosoir automatique ',False, (255,255,255)) textDescriptionStatic = police.render("Permet d'arroser les plantes",False,(0,0,0)) montantAchat = 3000 def __init__ (self,pos): super().__init__(pos,'../assets/Plantation/champ.png') self.imagebat = pygame.transform.scale(pygame.image.load('../assets/Batiment/irrigation.png'),(90,90)) def draw (self, screen, camera): scaleImage = camera.scaleImage(self.image) if scaleImage: # != None self.imgZoom = scaleImage self.rectScale = pygame.rect.Rect(camera.convertLocation(self.pos), self.imgZoom.get_size()) if hasattr(self,'imagebat'): scaleBat = camera.scaleImage(self.imagebat) if scaleBat: self.BatZoom = scaleBat varlongueur = camera.convertLocation(self.pos) self.rectbatScal = pygame.rect.Rect(camera.convertLocation(self.pos), self.BatZoom.get_size()) screen.blit( self.BatZoom, ( varlongueur[0] +self.rectbatScal.w/3, varlongueur[1] + (self.rectScale.h-self.rectbatScal.h -self.rectbatScal.h -self.rectbatScal.h /3- (self.rectbatScal.w)) /2) ) """ def showInfo(self,screen,rectangle): i = 0 for k,v in self.descripteurInfrastructure.items(): screen.blit(self.imageSurfaceinfo[k],(rectangle.x,rectangle.y + i)) i += 30 """ class IrrigationGoutte (Infrastructure): NameObjet = " irrigation goutte à goutte" iconStatic = pygame.transform.scale(pygame.image.load('../assets/Batiment/irrigationGoutte.png'),(150,150)) textStatic = police.render('Système goutte à goutte',False, (255,255,255)) textDescriptionStatic = police.render("Permet d'arroser les plantes en économisant l'eau",False,(0,0,0)) montantAchat = 6000 def __init__ (self,pos): super().__init__(pos,'../assets/Plantation/champ.png') self.imagebat = pygame.transform.scale(pygame.image.load('../assets/Batiment/irrigationGoutte.png'),(90,90)) def draw (self, screen, camera): scaleImage = camera.scaleImage(self.image) if scaleImage: # != None self.imgZoom = scaleImage self.rectScale = pygame.rect.Rect(camera.convertLocation(self.pos), self.imgZoom.get_size()) if hasattr(self,'imagebat'): scaleBat = camera.scaleImage(self.imagebat) if scaleBat: self.BatZoom = scaleBat varlongueur = camera.convertLocation(self.pos) self.rectbatScal = pygame.rect.Rect(camera.convertLocation(self.pos), self.BatZoom.get_size()) screen.blit( self.BatZoom, ( varlongueur[0] +self.rectbatScal.w/3, varlongueur[1] + (self.rectScale.h-self.rectbatScal.h -self.rectbatScal.h -self.rectbatScal.h /3- (self.rectbatScal.w)) /2) ) class Serre (Infrastructure): NameObjet = " serre" iconoriginal = pygame.image.load('../assets/Batiment/serre.png') iconStatic = pygame.transform.scale(iconoriginal,(150,150)) textStatic = police.render('Serre',False, (255,255,255)) textDescriptionStatic = police.render("Permet de proteger les cultures du froid et de la chaleur",False,(0,0,0)) montantAchat = 1000 iconStaticCopie = pygame.transform.scale(iconoriginal.copy(), (250,200)) iconStaticCopie.fill((255, 255, 255, 70), None, pygame.BLEND_RGBA_MULT) def __init__ (self,pos): super().__init__(pos,'../assets/Plantation/champ.png') self.champsAfecte = None self.imagebat = pygame.transform.scale(pygame.image.load('../assets/Batiment/serre.png'),(120,120)) def draw (self, screen, camera): scaleImage = camera.scaleImage(Serre.iconStaticCopie) scaleChamp = camera.scaleImage(self.image) if scaleChamp : self.champZoom = scaleChamp self.champRect = pygame.rect.Rect(camera.convertLocation(self.pos),self.champZoom.get_size()) if scaleImage: # != None self.imgZoom = scaleImage self.rectScale = pygame.rect.Rect(camera.convertLocation(self.pos), self.imgZoom.get_size()) varlongueur = camera.convertLocation(self.pos) screen.blit(self.imgZoom, (varlongueur[0]+ (self.champRect.w - self.rectScale.w)/2,varlongueur[1]+ (self.champRect.h - self.rectScale.h)/2)) class Torche (Infrastructure): NameObjet = " torche" iconoriginal = pygame.image.load('../assets/Batiment/torche.png') iconStatic = pygame.transform.scale(pygame.image.load('../assets/Batiment/torche.png'),(150,150)) textStatic = police.render('Torche',False, (255,255,255)) textDescriptionStatic = police.render("Permet de proteger les cultures du froid ",False,(0,0,0)) iconStaticCopie = pygame.transform.scale(iconoriginal.copy(), (250,200)) iconStaticCopie.fill((255, 255, 255, 70), None, pygame.BLEND_RGBA_MULT) montantAchat = 750 def __init__ (self,pos): super().__init__(pos,'../assets/Plantation/champ.png') self.zoneafecte = None self.imagebat = pygame.transform.scale(pygame.image.load('../assets/Batiment/torche.png'),(120,120)) def draw (self, screen, camera): scaleImage = camera.scaleImage(self.image) if scaleImage: # != None self.imgZoom = scaleImage self.rectScale = pygame.rect.Rect(camera.convertLocation(self.pos), self.imgZoom.get_size()) if hasattr(self,'imagebat'): scaleBat = camera.scaleImage(self.imagebat) if scaleBat: self.BatZoom = scaleBat varlongueur = camera.convertLocation(self.pos) self.rectbatScal = pygame.rect.Rect(camera.convertLocation(self.pos), self.BatZoom.get_size()) screen.blit( self.BatZoom, ( varlongueur[0] - self.rectbatScal.w +(self.rectbatScal.w)/2, varlongueur[1] + (self.rectScale.h-self.rectbatScal.h) /2) ) screen.blit( self.BatZoom, ( varlongueur[0] + self.rectbatScal.w +(self.rectbatScal.w)/2, varlongueur[1] + (self.rectScale.h-self.rectbatScal.h) /2) ) typeBatiment = [Puit,ReservoirEau,Irrigation,IrrigationGoutte,Serre,Torche]