diff --git a/assets/Interface/button.png b/assets/Interface/button.png old mode 100755 new mode 100644 diff --git a/assets/Interface/money.png b/assets/Interface/money.png old mode 100755 new mode 100644 diff --git a/assets/Interface/terre.png b/assets/Interface/terre.png old mode 100755 new mode 100644 diff --git a/assets/Plantation/champ.png b/assets/Plantation/champ.png old mode 100755 new mode 100644 diff --git a/assets/Temps/nice_weather.png b/assets/Temps/nice_weather.png new file mode 100644 index 0000000000000000000000000000000000000000..75e3024948bf6bed7af9f10eefdae966cdcbbbc4 Binary files /dev/null and b/assets/Temps/nice_weather.png differ diff --git a/src/Champs.py b/src/Champs.py old mode 100755 new mode 100644 index 2302bfa7168a3219dae7fa349e82976d0a20bd55..0f087653905afc3150c12c3c164118ec3b03c909 --- a/src/Champs.py +++ b/src/Champs.py @@ -1,247 +1,247 @@ -import pygame -import numpy as np -from Temps import * -from Image import transformImage - -listeImage = [pygame.transform.scale(pygame.image.load('../assets/Plantation/crop'+str(i)+'phase.png'),(120,120)) for i in range(1,5)] - - -#TODO : mettre une proba que les plantes meurent si il fait trop froid/chaud, et baisser cette proba de mourir avec une serre ou des torche pour l'hiver - -class Champs: - - iconInsecteStatic = pygame.transform.scale(pygame.image.load("../assets/Plantation/leech.png"),(90,90)) - def __init__ (self, temperature, humidite, tempsAvantMaturation, pos, image): - self.temperature = temperature - self.humidite = humidite - self.TAM = tempsAvantMaturation - self.pos = np.array(pos) - self.image = pygame.image.load(image) - self.imageSize = np.array(self.image.get_size()) - self.rect = pygame.rect.Rect(self.pos, self.image.get_rect().size) - self.rectScale = self.rect - self.police = pygame.font.SysFont("Alef", 22) #pygame.font.get_fonts() -> liste des fonts - self.imgZoom = pygame.transform.scale(self.image, self.imageSize) - self.indiceImage = 0 - self.champZoom = pygame.rect.Rect(self.pos,self.imgZoom.get_rect().size) - self.isInfeste = False - self.descripteurChamps = { - "Temperature" : None, - "Humidite" : None, - "Acidite" : None, - "Occupe" : None, - } - self.imageSurfaceinfo = { - "Temperature" : None, - "Humidite" : None, - "Acidite" : None, - "Occupe" : None, - } - self.setInformation("Temperature",self.temperature) - self.setInformation("Humidite", self.humidite) - self.setInformation("Acidite",0) - self.setInformation("Occupe", False) - - - - def plantationGrandit(self): - self.indiceImage +=1 - if self.indiceImage <4: - - self.imageChamp = listeImage[self.indiceImage] - else: - if(self.indiceImage == 4): - self.imageChamp =pygame.transform.scale(pygame.image.load('../assets/Plantation/damage.png'),(120,120)) - elif(self.indiceImage == 5): - self.isInfeste = False - self.imageChamp =pygame.transform.scale(pygame.image.load('../assets/Plantation/fanne.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()) - - - - screen.blit(self.imgZoom, camera.convertLocation(self.pos)) - if hasattr(self,'imageChamp'): - scaleChamp = camera.scaleImage(self.imageChamp) - if scaleChamp: - self.champZoom = scaleChamp - varlongueur = camera.convertLocation(self.pos) - self.rectChampScal = pygame.rect.Rect(varlongueur, self.champZoom.get_size()) - screen.blit( - self.champZoom, - ( - varlongueur[0] + - (self.rectScale.w-self.rectChampScal.w) - /2, - varlongueur[1] + - (self.rectScale.h-self.rectChampScal.h) - /2) - ) - self.setInformation("Occupe", True) - - if(self.isInfeste): - scaleInfecte = camera.scaleImage(Champs.iconInsecteStatic) - if scaleInfecte: - self.infecteZoom = scaleInfecte - varlongueur = camera.convertLocation(self.pos) - self.rectScalInfecte = pygame.rect.Rect(varlongueur, self.infecteZoom.get_size()) - screen.blit( - self.infecteZoom, - ( - varlongueur[0] + - (self.rectScale.w-self.rectScalInfecte.w) - /2, - varlongueur[1] + - (self.rectScale.h-self.rectScalInfecte.h) - /2) - ) - - - def changeText (self, camera): - scaleText = camera.scaleImage(self.text) - if scaleText: - self.zoomText = scaleText - - def setInformation(self,clef,valeur): - self.descr - - def setInformation(self,clef,valeur): - self.descripteurChamps[clef] = valeur - self.imageSurfaceinfo[clef] = police.render(clef+ " : "+ str(valeur),False,(0,0,0)) - - def showInfo(self,screen,rectangle): - i = 0 - for k,v in self.descripteurChamps.items(): - screen.blit(self.imageSurfaceinfo[k],(rectangle.x,rectangle.y + i)) - i += 30 - - def DeterminPourcentageFanage(self,montant): - self.probaFanage +=montant - - -class Buisson (Champs): - def __init__ (self, pos, prix = 10000): - super().__init__(0, 0, 0, pos, '../assets/Interface/buissonCadenas.png') - self.prix = prix - self.text = self.police.render("Champ disponible à l'achat : " + str(self.prix), False, (0,0,0)) - self.zoomText = self.text - - def showInfo (self, screen,rectangle): - screen.blit(self.text,(rectangle.x,rectangle.y)) - - def buyField (self): - return TerrainVide(self.pos) - - -class TerrainVide(Champs): - def __init__ (self, pos): - super().__init__(0, 0, 0, pos,'../assets/Plantation/champ.png') - self.text = self.police.render("Température : " + str(self.temperature), False, (0,0,0)) - self.zoomText = self.text - - - -class Houblon (Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/houblon.png'),(150,150)) - textStatic = police.render('Houblon',False, (0,0,0)) - textDescriptionStatic = police.render("Houblon sa marche bien",False,(0,0,0)) - montantAchat = 250 - montantVente = 600 - def __init__ (self, pos): - super().__init__(0, 0, 0, pos,'../assets/Plantation/champ.png') - self.text = self.police.render("Température : " + str(self.temperature), False, (0,0,0)) - self.zoomText = self.text - - self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) - - -class Ble (Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/wheat.png'),(150,150)) - textStatic = police.render('Ble',False, (0,0,0)) - textDescriptionStatic = police.render("Ble sa marche bien",False,(0,0,0)) - montantAchat = 250 - montantVente = 800 - def __init__ (self,pos): - super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') - - self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) - -class Malt (Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/malt.png'),(150,150)) - textStatic = police.render('Malt',False, (0,0,0)) - textDescriptionStatic = police.render("Malt sa marche bien",False,(0,0,0)) - montantAchat = 300 - montantVente = 800 - def __init__ (self,pos): - super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') - self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) - - -class Chanvre(Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/weed.png'),(150,150)) - textStatic = police.render("Chanvre",False, (0,0,0)) - textDescriptionStatic = police.render("Pour des spaces bières",False,(0,0,0)) - montantAchat = 1000 - montantVente = 5000 - def __init__ (self,pos): - super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') - self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) - - -class OrgeHiver(Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/orge.png'),(150,150)) - textStatic = police.render("Orge hiver",False, (0,0,0)) - textDescriptionStatic = police.render("Orge hiver sa marche bien",False,(0,0,0)) - montantAchat = 300 - montantVente = 800 - def __init__ (self,pos): - super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') - self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) - - -class OrgePrintemps(Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/OrgePrintemps.png'),(150,150)) - textStatic = police.render("Orge printemps",False, (0,0,0)) - textDescriptionStatic = police.render("Orge printemps sa marche bien",False,(0,0,0)) - montantAchat = 500 - montantVente = 1000 - def __init__ (self,pos): - super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') - - self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) - - -class Seigle(Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/seigle.png'),(150,150)) - textStatic = police.render("Seigle",False, (0,0,0)) - textDescriptionStatic = police.render("Seigle sa marche bien",False,(0,0,0)) - montantAchat = 200 - montantVente = 600 - def __init__ (self,pos): - super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') - self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) - - -class Pesticide(Champs): - iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/pesticide.png'),(150,150)) - textStatic = police.render("Pesticide",False, (0,0,0)) - textDescriptionStatic = police.render("Pour tuer les insectes",False,(0,0,0)) - montantAchat = 200 - def __init__ (self,pos): - super().__init__(0,0,0,pos,'../assets/Plantation/pesticide.png') - -#TODO : class Bussion, - -typePlantation = [Houblon,Ble,Malt,Chanvre,OrgeHiver,OrgePrintemps,Seigle,Pesticide] - +import pygame +import numpy as np +from Temps import * +from Image import transformImage + +listeImage = [pygame.transform.scale(pygame.image.load('../assets/Plantation/crop'+str(i)+'phase.png'),(120,120)) for i in range(1,5)] + + +#TODO : mettre une proba que les plantes meurent si il fait trop froid/chaud, et baisser cette proba de mourir avec une serre ou des torche pour l'hiver + +class Champs: + + iconInsecteStatic = pygame.transform.scale(pygame.image.load("../assets/Plantation/leech.png"),(90,90)) + def __init__ (self, temperature, humidite, tempsAvantMaturation, pos, image): + self.temperature = temperature + self.humidite = humidite + self.TAM = tempsAvantMaturation + self.pos = np.array(pos) + self.image = pygame.image.load(image) + self.imageSize = np.array(self.image.get_size()) + self.rect = pygame.rect.Rect(self.pos, self.image.get_rect().size) + self.rectScale = self.rect + self.police = pygame.font.SysFont("Alef", 22) #pygame.font.get_fonts() -> liste des fonts + self.imgZoom = pygame.transform.scale(self.image, self.imageSize) + self.indiceImage = 0 + self.champZoom = pygame.rect.Rect(self.pos,self.imgZoom.get_rect().size) + self.isInfeste = False + self.descripteurChamps = { + "Temperature" : None, + "Humidite" : None, + "Acidite" : None, + "Occupe" : None, + } + self.imageSurfaceinfo = { + "Temperature" : None, + "Humidite" : None, + "Acidite" : None, + "Occupe" : None, + } + self.setInformation("Temperature",self.temperature) + self.setInformation("Humidite", self.humidite) + self.setInformation("Acidite",0) + self.setInformation("Occupe", False) + + + + def plantationGrandit(self): + self.indiceImage +=1 + if self.indiceImage <4: + + self.imageChamp = listeImage[self.indiceImage] + else: + if(self.indiceImage == 4): + self.imageChamp =pygame.transform.scale(pygame.image.load('../assets/Plantation/damage.png'),(120,120)) + elif(self.indiceImage == 5): + self.isInfeste = False + self.imageChamp =pygame.transform.scale(pygame.image.load('../assets/Plantation/fanne.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()) + + + + screen.blit(self.imgZoom, camera.convertLocation(self.pos)) + if hasattr(self,'imageChamp'): + scaleChamp = camera.scaleImage(self.imageChamp) + if scaleChamp: + self.champZoom = scaleChamp + varlongueur = camera.convertLocation(self.pos) + self.rectChampScal = pygame.rect.Rect(varlongueur, self.champZoom.get_size()) + screen.blit( + self.champZoom, + ( + varlongueur[0] + + (self.rectScale.w-self.rectChampScal.w) + /2, + varlongueur[1] + + (self.rectScale.h-self.rectChampScal.h) + /2) + ) + self.setInformation("Occupe", True) + + if(self.isInfeste): + scaleInfecte = camera.scaleImage(Champs.iconInsecteStatic) + if scaleInfecte: + self.infecteZoom = scaleInfecte + varlongueur = camera.convertLocation(self.pos) + self.rectScalInfecte = pygame.rect.Rect(varlongueur, self.infecteZoom.get_size()) + screen.blit( + self.infecteZoom, + ( + varlongueur[0] + + (self.rectScale.w-self.rectScalInfecte.w) + /2, + varlongueur[1] + + (self.rectScale.h-self.rectScalInfecte.h) + /2) + ) + + + def changeText (self, camera): + scaleText = camera.scaleImage(self.text) + if scaleText: + self.zoomText = scaleText + + def setInformation(self,clef,valeur): + self.descr + + def setInformation(self,clef,valeur): + self.descripteurChamps[clef] = valeur + self.imageSurfaceinfo[clef] = police.render(clef+ " : "+ str(valeur),False,(0,0,0)) + + def showInfo(self,screen,rectangle): + i = 0 + for k,v in self.descripteurChamps.items(): + screen.blit(self.imageSurfaceinfo[k],(rectangle.x,rectangle.y + i)) + i += 30 + + def DeterminPourcentageFanage(self,montant): + self.probaFanage +=montant + + +class Buisson (Champs): + def __init__ (self, pos, prix = 10000): + super().__init__(0, 0, 0, pos, '../assets/Interface/buissonCadenas.png') + self.prix = prix + self.text = self.police.render("Champ disponible à l'achat : " + str(self.prix), False, (0,0,0)) + self.zoomText = self.text + + def showInfo (self, screen,rectangle): + screen.blit(self.text,(rectangle.x,rectangle.y)) + + def buyField (self): + return TerrainVide(self.pos) + + +class TerrainVide(Champs): + def __init__ (self, pos): + super().__init__(0, 0, 0, pos,'../assets/Plantation/champ.png') + self.text = self.police.render("Température : " + str(self.temperature), False, (0,0,0)) + self.zoomText = self.text + + + +class Houblon (Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/houblon.png'),(150,150)) + textStatic = police.render('Houblon',False, (0,0,0)) + textDescriptionStatic = police.render("Houblon sa marche bien",False,(0,0,0)) + montantAchat = 250 + montantVente = 600 + def __init__ (self, pos): + super().__init__(0, 0, 0, pos,'../assets/Plantation/champ.png') + self.text = self.police.render("Température : " + str(self.temperature), False, (0,0,0)) + self.zoomText = self.text + + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) + + +class Ble (Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/wheat.png'),(150,150)) + textStatic = police.render('Ble',False, (0,0,0)) + textDescriptionStatic = police.render("Ble sa marche bien",False,(0,0,0)) + montantAchat = 250 + montantVente = 800 + def __init__ (self,pos): + super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') + + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) + +class Malt (Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/malt.png'),(150,150)) + textStatic = police.render('Malt',False, (0,0,0)) + textDescriptionStatic = police.render("Malt sa marche bien",False,(0,0,0)) + montantAchat = 300 + montantVente = 800 + def __init__ (self,pos): + super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) + + +class Chanvre(Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/weed.png'),(150,150)) + textStatic = police.render("Chanvre",False, (0,0,0)) + textDescriptionStatic = police.render("Pour des spaces bières",False,(0,0,0)) + montantAchat = 1000 + montantVente = 5000 + def __init__ (self,pos): + super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) + + +class OrgeHiver(Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/orge.png'),(150,150)) + textStatic = police.render("Orge hiver",False, (0,0,0)) + textDescriptionStatic = police.render("Orge hiver sa marche bien",False,(0,0,0)) + montantAchat = 300 + montantVente = 800 + def __init__ (self,pos): + super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) + + +class OrgePrintemps(Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/OrgePrintemps.png'),(150,150)) + textStatic = police.render("Orge printemps",False, (0,0,0)) + textDescriptionStatic = police.render("Orge printemps sa marche bien",False,(0,0,0)) + montantAchat = 500 + montantVente = 1000 + def __init__ (self,pos): + super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') + + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) + + +class Seigle(Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/seigle.png'),(150,150)) + textStatic = police.render("Seigle",False, (0,0,0)) + textDescriptionStatic = police.render("Seigle sa marche bien",False,(0,0,0)) + montantAchat = 200 + montantVente = 600 + def __init__ (self,pos): + super().__init__(0,0,0,pos,'../assets/Plantation/champ.png') + self.imageChamp = pygame.transform.scale(pygame.image.load('../assets/Plantation/crop1phase.png'),(120,120)) + + +class Pesticide(Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Plantation/pesticide.png'),(150,150)) + textStatic = police.render("Pesticide",False, (0,0,0)) + textDescriptionStatic = police.render("Pour tuer les insectes",False,(0,0,0)) + montantAchat = 200 + def __init__ (self,pos): + super().__init__(0,0,0,pos,'../assets/Plantation/pesticide.png') + +#TODO : class Bussion, + +typePlantation = [Houblon,Ble,Malt,Chanvre,OrgeHiver,OrgePrintemps,Seigle,Pesticide] + \ No newline at end of file diff --git a/src/Game.py b/src/Game.py old mode 100755 new mode 100644 index d8836e22ca2d94ff8b443d756bd06a9fc95bb233..5c99bc9994d08e663c77b1e564057a265f4cda6e --- a/src/Game.py +++ b/src/Game.py @@ -1,309 +1,309 @@ -import pygame -import random -from Champs import Champs,Houblon,Buisson,TerrainVide,Pesticide,typePlantation -import numpy as np -from Camera import Camera -from Image import transformImage,Image -from Temps import Temps -from Infrastructure import Infrastructure,typeBatiment,Serre,Torche - -RAYON_MUR_INVISIBLE = 2000 -SAISONS = ["Printemps", "Été", "Automne", "Hiver"] -MOIS = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"] -police = pygame.font.SysFont("roboto", 30) - -class Game: - imagestaticplantation = pygame.image.load('../assets/Interface/imagePlantation.jpeg') - imagestaticbatiment = pygame.image.load('../assets/Interface/imageBatiment.jpeg') - imagestaticinfor = pygame.image.load('../assets/Interface/imageinfo.jpg') - def __init__ (self): - self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) - self.image = Image(self.screen) - self.screenSize = np.array(self.screen.get_size()) - self.score = 0 - self.money = 40000 - self.displayMoney = 40000 - self.month = 0 - - self.champs = [] - self.batiment = [] - - self.temps = Temps() - for i in range(12): - self.champs.append(Buisson(((i%4)*300-550,(i//4)*250-430))) - self.clock = pygame.time.Clock() - self.selectedChamp = None - - self.imageMoney = pygame.transform.scale(self.image.moneyImage, np.array(self.image.moneyImage.get_size())/2) - - self.camera = Camera(np.array(self.screen.get_size())/2) - - self.frame = 0 - self.buyFrame = -1000 - - self.tourSuivantOriginal = self.image.arrowNextImage - self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (100,100)) - self.coordonneeSuite = self.screenSize[0]-self.tourSuivantModif.get_width() - 120, self.screenSize[1] - self.tourSuivantModif.get_height() - 120 - self.suiteRectangle = pygame.rect.Rect(*self.coordonneeSuite, 100, 100) - - self.coordonne_info = pygame.rect.Rect(self.screen.get_width()*0.82,self.screen.get_height()*0.18,self.screen.get_width()*0.19,self.screen.get_height()*0.5) - self.recInformation = pygame.rect.Rect(self.coordonne_info) - self.rectPlantation = pygame.rect.Rect(0,0,self.temps.getImageSaison().get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height()) - self.recBatiment = pygame.rect.Rect(self.temps.getImageSaison().get_width(), self.screen.get_height() - self.temps.getImageSaison().get_height(), self.screen.get_width() * 0.65, self.temps.getImageSaison().get_height()) - - self.rectPlantationimage = pygame.transform.scale(Game.imagestaticplantation,(self.rectPlantation.w,self.rectPlantation.h)) - self.rectBatimentimage = pygame.transform.scale(Game.imagestaticbatiment,(self.recBatiment.w,self.recBatiment.h)) - self.rectinfoimage = pygame.transform.scale(Game.imagestaticinfor,(self.recInformation.w,self.recInformation.h)) - - self.recTourSuivant = pygame.rect.Rect( - self.recBatiment.x + self.recBatiment.w ,self.screen.get_height() - self.temps.getImageSaison().get_height(), - self.screen.get_width() - self.temps.getImageSaison().get_width() - self.recBatiment.w,self.temps.getImageSaison().get_height()) - - #DragAndDrop - self.dragBatiment = None - self.dragPlantation = None - - - - - def gameLoop (self): - while True: - - self.screen.blit(self.image.backgroundImage, (0,0)) - - #CHAMPS------------------ - # Affichage des champs - for champ in self.champs: - champ.draw(self.screen, self.camera) - - for bat in self.batiment: - bat.draw(self.screen, self.camera) - #DEBUT BOUCLE INTERFACE------------------------ - - #Onglet Information - #pygame.draw.rect(self.screen, (0, 127, 0), self.recInformation) - self.screen.blit(Game.imagestaticinfor,(self.coordonne_info.x,self.coordonne_info.y)) - - # Météo - self.screen.blit(self.temps.getImageSaison(), (0, self.screen.get_height() - 300)) - self.screen.blit(self.temps.iconSaison,(10,self.screen.get_height() - self.temps.iconSaison.get_height())) - self.screen.blit(self.temps.tempsaisonImage,(10,self.screen.get_height() - self.temps.iconSaison.get_height() - 50)) - - self.screen.blit(self.temps.nexticonSaison,(self.temps.getImageSaison().get_width() - self.temps.nexticonSaison.get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height() +20)) - self.screen.blit(self.temps.tempsaisonImageDeuxPosiiton,(self.temps.getImageSaison().get_width() - self.temps.nexticonSaison.get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height())) - - - print(self.rectPlantation.w) - print(self.rectPlantation.h) - #Onglet plantation - - self.screen.blit(self.rectPlantationimage,(0,0)) - #Onglet tour suivant - pygame.draw.rect(self.screen,(0, 127, 0),(self.recTourSuivant)) - self.screen.blit(self.tourSuivantModif, (self.recTourSuivant.x+ (self.recTourSuivant.w - self.tourSuivantModif.get_width())/2, - self.recTourSuivant.y+ (self.recTourSuivant.h - self.tourSuivantModif.get_height())/2)) - - for i,c in enumerate(typePlantation): - x = self.rectPlantation.x + ( 0 if i%2 else 170) - y = self.rectPlantation.y + (i//2) * 200 - r = pygame.rect.Rect(x,y,c.iconStatic.get_width(),c.iconStatic.get_height()+ 30 ) - self.screen.blit(c.textStatic, (x,y)) - self.screen.blit(c.iconStatic,(x,y+30 )) - if ( (r.collidepoint(pygame.mouse.get_pos()))): - pygame.draw.rect(self.screen,(138, 227, 237), r,1) - self.screen.blit(c.textDescriptionStatic,(self.recInformation.x,self.recInformation.y)) - #self.screen.blit(self.text,(screen.get_width()*0.85,screen.get_height()*0.18)) - - - - - #Onglet batiment - self.screen.blit(self.rectBatimentimage,(self.temps.getImageSaison().get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height())) - for i,c in enumerate(typeBatiment): - x = self.recBatiment.x + i* (c.iconStatic.get_width() + 30) +50 - y = self.recBatiment.y + 50 - r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) - self.screen.blit(c.textStatic, (x,y)) - self.screen.blit(c.iconStatic,(x,y + 30)) - if ( (r.collidepoint(pygame.mouse.get_pos()))): - pygame.draw.rect(self.screen,(138, 227, 237), r,1) - self.screen.blit(c.textDescriptionStatic,(self.recInformation.x,self.recInformation.y)) - - # FIN BOUCLE INTERFACE ------------------------ - - - isChamp = False - - # - - - if self.money < self.displayMoney: - self.displayMoney -= min(444, self.displayMoney - self.money) # Si quelque chose coûte moins que 100, changer par -= min(100, self.displayMoney - self.money) - elif self.money > self.displayMoney: - self.displayMoney+= min(444, self.money - self.displayMoney) # Si quelque chose coûte moins que 100, changer par -= min(100, self.money - self.displayMoney) - - - #self.displayMoney = self.money - - textMoney = police.render(str(self.displayMoney), True, (255,255,255)) - - self.CoRecArgent = pygame.rect.Rect(self.screen.get_width(), 0, 100, 100) - self.recArgent = pygame.draw.rect(self.screen,(255,0,0),(self.CoRecArgent)) - - self.screen.blit(textMoney, (self.screen.get_width() - self.imageMoney.get_width() - textMoney.get_width(),self.imageMoney.get_height()/2)) - self.screen.blit(self.imageMoney, (self.screen.get_width() - self.imageMoney.get_width() , 0)) - - - for event in pygame.event.get(): - if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: - exit() - - elif event.type == pygame.MOUSEMOTION: - - if event.buttons[2] == 1: #maintenir enfoncé clic droit - self.camera.setPosition(np.array(event.rel)) - if event.buttons[0] == 1:#maintenir enfoncé clic gauche - if self.dragBatiment == None and self.dragPlantation == None: - for i,c in enumerate(typeBatiment): - x = self.recBatiment.x + i* (c.iconStatic.get_width() + 30) +50 - y = self.recBatiment.y + 50 - r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) - if ( (r.collidepoint(event.pos))): - self.dragBatiment = c - if(self.dragBatiment): - self.screen.blit(self.dragBatiment.iconStatic, (event.pos)) - - - if self.dragPlantation == None and self.dragBatiment == None: - - for i,c in enumerate(typePlantation): - - x = self.rectPlantation.x + ( 0 if i%2 else 170) - y = self.rectPlantation.y + (i//2) * 200 - r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) - if ( (r.collidepoint(event.pos))): - self.dragPlantation = c - if(self.dragPlantation): - self.screen.blit(self.dragPlantation.iconStatic, (event.pos)) - - - else: - if self.dragPlantation: - for champ in self.champs: - if champ.rectScale.collidepoint(event.pos): - print(champ) - print(self.dragPlantation) - if self.dragPlantation == Pesticide: - print(champ.isInfeste) - champ.isInfeste = False - print(champ.isInfeste) - - elif isinstance(champ,TerrainVide): - self.champs.append(self.dragPlantation(champ.pos)) - self.champs.remove(champ) - #Perdre l'argent - variable = self.dragPlantation.montantAchat - self.moneyDefile(-variable) - - - - if self.dragBatiment: - for champ in self.champs: - if champ.rectScale.collidepoint(event.pos): - if isinstance(champ,TerrainVide): - self.batiment.append(self.dragBatiment(champ.pos)) - - #Perdre l'argent - variable = self.dragBatiment.montantAchat - self.moneyDefile(-variable) - - if self.dragBatiment not in [Torche,Serre]: - self.champs.remove(champ) - - - self.dragPlantation = None - self.dragBatiment = None - - - - for champ in self.champs + self.batiment: - if champ.rectScale.contains(event.pos[0],event.pos[1],0,0): - self.selectedChamp = champ - isChamp = True - - if not isChamp: - self.selectedChamp = None - - if (*event.pos,0,0) in self.recTourSuivant: - self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (200, 200)) - else: - self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (100, 100)) - - - - elif event.type == pygame.MOUSEWHEEL: - self.camera.zoomInOut(event.y) - - # Achat d'un champ - elif event.type == pygame.MOUSEBUTTONDOWN: - - if event.button == 1: - if(self.recTourSuivant.collidepoint(event.pos)): - self.temps.NextTurn() - - if(self.temps.currentSeason == "Hiver"): - self.AideEtat() - - - i = 0 - for champ in self.champs: - - if type(champ) in typePlantation: - if champ.isInfeste: - champ.indiceImage = 4 - champ.plantationGrandit() - if(random.random()< 0.10): - champ.isInfeste = True - - - for champ in self.champs: - if champ.rectScale.collidepoint(event.pos): - - if(champ.indiceImage > 3): - self.champs.append(TerrainVide(champ.pos)) - self.champs.remove(champ) - elif(champ.indiceImage == 3): - self.moneyDefile(champ.montantVente) - self.champs.append(TerrainVide(champ.pos)) - self.champs.remove(champ) - - - - if isinstance(champ, Buisson): - #if self.money >= champ.prix: - self.moneyDefile(-champ.prix) - self.champs.append(champ.buyField()) - self.champs.remove(champ) - - - - if self.frame < self.buyFrame + 20: - self.screen.blit(self.moneyChange, (self.screen.get_width() -200, (self.frame-self.buyFrame)*1.5)) - #self.screen.blit(self.moneyChange, (200, self.screen.get_height()-textMoney.get_height()*4+(self.frame-self.buyFrame)*1.5)) - - if self.selectedChamp: - self.selectedChamp.showInfo(self.screen,self.recInformation) - - - pygame.display.update() - self.clock.tick(50) - self.frame += 1 - - def moneyDefile(self,montant): - self.moneyChange = police.render(str(montant), True, (200,0,0) if montant < 0 else (0,250,0) ) - self.buyFrame = self.frame - self.money+= montant - - def AideEtat(self): - self.moneyDefile(5000) - +import pygame +import random +from Champs import Champs,Houblon,Buisson,TerrainVide,Pesticide,typePlantation +import numpy as np +from Camera import Camera +from Image import transformImage,Image +from Temps import Temps +from Infrastructure import Infrastructure,typeBatiment,Serre,Torche + +RAYON_MUR_INVISIBLE = 2000 +SAISONS = ["Printemps", "Été", "Automne", "Hiver"] +MOIS = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"] +police = pygame.font.SysFont("roboto", 30) + +class Game: + imagestaticplantation = pygame.image.load('../assets/Interface/imagePlantation.jpeg') + imagestaticbatiment = pygame.image.load('../assets/Interface/imageBatiment.jpeg') + imagestaticinfor = pygame.image.load('../assets/Interface/imageinfo.jpg') + def __init__ (self): + self.screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) + self.image = Image(self.screen) + self.screenSize = np.array(self.screen.get_size()) + self.score = 0 + self.money = 40000 + self.displayMoney = 40000 + self.month = 0 + + self.champs = [] + self.batiment = [] + + self.temps = Temps() + for i in range(12): + self.champs.append(Buisson(((i%4)*300-550,(i//4)*250-430))) + self.clock = pygame.time.Clock() + self.selectedChamp = None + + self.imageMoney = pygame.transform.scale(self.image.moneyImage, np.array(self.image.moneyImage.get_size())/2) + + self.camera = Camera(np.array(self.screen.get_size())/2) + + self.frame = 0 + self.buyFrame = -1000 + + self.tourSuivantOriginal = self.image.arrowNextImage + self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (100,100)) + self.coordonneeSuite = self.screenSize[0]-self.tourSuivantModif.get_width() - 120, self.screenSize[1] - self.tourSuivantModif.get_height() - 120 + self.suiteRectangle = pygame.rect.Rect(*self.coordonneeSuite, 100, 100) + + self.coordonne_info = pygame.rect.Rect(self.screen.get_width()*0.82,self.screen.get_height()*0.18,self.screen.get_width()*0.19,self.screen.get_height()*0.5) + self.recInformation = pygame.rect.Rect(self.coordonne_info) + self.rectPlantation = pygame.rect.Rect(0,0,self.temps.getImageSaison().get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height()) + self.recBatiment = pygame.rect.Rect(self.temps.getImageSaison().get_width(), self.screen.get_height() - self.temps.getImageSaison().get_height(), self.screen.get_width() * 0.65, self.temps.getImageSaison().get_height()) + + self.rectPlantationimage = pygame.transform.scale(Game.imagestaticplantation,(self.rectPlantation.w,self.rectPlantation.h)) + self.rectBatimentimage = pygame.transform.scale(Game.imagestaticbatiment,(self.recBatiment.w,self.recBatiment.h)) + self.rectinfoimage = pygame.transform.scale(Game.imagestaticinfor,(self.recInformation.w,self.recInformation.h)) + + self.recTourSuivant = pygame.rect.Rect( + self.recBatiment.x + self.recBatiment.w ,self.screen.get_height() - self.temps.getImageSaison().get_height(), + self.screen.get_width() - self.temps.getImageSaison().get_width() - self.recBatiment.w,self.temps.getImageSaison().get_height()) + + #DragAndDrop + self.dragBatiment = None + self.dragPlantation = None + + + + + def gameLoop (self): + while True: + + self.screen.blit(self.image.backgroundImage, (0,0)) + + #CHAMPS------------------ + # Affichage des champs + for champ in self.champs: + champ.draw(self.screen, self.camera) + + for bat in self.batiment: + bat.draw(self.screen, self.camera) + #DEBUT BOUCLE INTERFACE------------------------ + + #Onglet Information + #pygame.draw.rect(self.screen, (0, 127, 0), self.recInformation) + self.screen.blit(Game.imagestaticinfor,(self.coordonne_info.x,self.coordonne_info.y)) + + # Météo + self.screen.blit(self.temps.getImageSaison(), (0, self.screen.get_height() - 300)) + self.screen.blit(self.temps.iconSaison,(10,self.screen.get_height() - self.temps.iconSaison.get_height())) + self.screen.blit(self.temps.tempsaisonImage,(10,self.screen.get_height() - self.temps.iconSaison.get_height() - 50)) + + self.screen.blit(self.temps.nexticonSaison,(self.temps.getImageSaison().get_width() - self.temps.nexticonSaison.get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height() +20)) + self.screen.blit(self.temps.tempsaisonImageDeuxPosiiton,(self.temps.getImageSaison().get_width() - self.temps.nexticonSaison.get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height())) + + + print(self.rectPlantation.w) + print(self.rectPlantation.h) + #Onglet plantation + + self.screen.blit(self.rectPlantationimage,(0,0)) + #Onglet tour suivant + pygame.draw.rect(self.screen,(0, 127, 0),(self.recTourSuivant)) + self.screen.blit(self.tourSuivantModif, (self.recTourSuivant.x+ (self.recTourSuivant.w - self.tourSuivantModif.get_width())/2, + self.recTourSuivant.y+ (self.recTourSuivant.h - self.tourSuivantModif.get_height())/2)) + + for i,c in enumerate(typePlantation): + x = self.rectPlantation.x + ( 0 if i%2 else 170) + y = self.rectPlantation.y + (i//2) * 200 + r = pygame.rect.Rect(x,y,c.iconStatic.get_width(),c.iconStatic.get_height()+ 30 ) + self.screen.blit(c.textStatic, (x,y)) + self.screen.blit(c.iconStatic,(x,y+30 )) + if ( (r.collidepoint(pygame.mouse.get_pos()))): + pygame.draw.rect(self.screen,(138, 227, 237), r,1) + self.screen.blit(c.textDescriptionStatic,(self.recInformation.x,self.recInformation.y)) + #self.screen.blit(self.text,(screen.get_width()*0.85,screen.get_height()*0.18)) + + + + + #Onglet batiment + self.screen.blit(self.rectBatimentimage,(self.temps.getImageSaison().get_width(),self.screen.get_height() - self.temps.getImageSaison().get_height())) + for i,c in enumerate(typeBatiment): + x = self.recBatiment.x + i* (c.iconStatic.get_width() + 30) +50 + y = self.recBatiment.y + 50 + r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) + self.screen.blit(c.textStatic, (x,y)) + self.screen.blit(c.iconStatic,(x,y + 30)) + if ( (r.collidepoint(pygame.mouse.get_pos()))): + pygame.draw.rect(self.screen,(138, 227, 237), r,1) + self.screen.blit(c.textDescriptionStatic,(self.recInformation.x,self.recInformation.y)) + + # FIN BOUCLE INTERFACE ------------------------ + + + isChamp = False + + # + + + if self.money < self.displayMoney: + self.displayMoney -= min(444, self.displayMoney - self.money) # Si quelque chose coûte moins que 100, changer par -= min(100, self.displayMoney - self.money) + elif self.money > self.displayMoney: + self.displayMoney+= min(444, self.money - self.displayMoney) # Si quelque chose coûte moins que 100, changer par -= min(100, self.money - self.displayMoney) + + + #self.displayMoney = self.money + + textMoney = police.render(str(self.displayMoney), True, (255,255,255)) + + self.CoRecArgent = pygame.rect.Rect(self.screen.get_width(), 0, 100, 100) + self.recArgent = pygame.draw.rect(self.screen,(255,0,0),(self.CoRecArgent)) + + self.screen.blit(textMoney, (self.screen.get_width() - self.imageMoney.get_width() - textMoney.get_width(),self.imageMoney.get_height()/2)) + self.screen.blit(self.imageMoney, (self.screen.get_width() - self.imageMoney.get_width() , 0)) + + + for event in pygame.event.get(): + if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: + exit() + + elif event.type == pygame.MOUSEMOTION: + + if event.buttons[2] == 1: #maintenir enfoncé clic droit + self.camera.setPosition(np.array(event.rel)) + if event.buttons[0] == 1:#maintenir enfoncé clic gauche + if self.dragBatiment == None and self.dragPlantation == None: + for i,c in enumerate(typeBatiment): + x = self.recBatiment.x + i* (c.iconStatic.get_width() + 30) +50 + y = self.recBatiment.y + 50 + r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) + if ( (r.collidepoint(event.pos))): + self.dragBatiment = c + if(self.dragBatiment): + self.screen.blit(self.dragBatiment.iconStatic, (event.pos)) + + + if self.dragPlantation == None and self.dragBatiment == None: + + for i,c in enumerate(typePlantation): + + x = self.rectPlantation.x + ( 0 if i%2 else 170) + y = self.rectPlantation.y + (i//2) * 200 + r = pygame.rect.Rect(x,y,c.iconStatic.get_width() + 20 ,c.iconStatic.get_height()+ 30 ) + if ( (r.collidepoint(event.pos))): + self.dragPlantation = c + if(self.dragPlantation): + self.screen.blit(self.dragPlantation.iconStatic, (event.pos)) + + + else: + if self.dragPlantation: + for champ in self.champs: + if champ.rectScale.collidepoint(event.pos): + print(champ) + print(self.dragPlantation) + if self.dragPlantation == Pesticide: + print(champ.isInfeste) + champ.isInfeste = False + print(champ.isInfeste) + + elif isinstance(champ,TerrainVide): + self.champs.append(self.dragPlantation(champ.pos)) + self.champs.remove(champ) + #Perdre l'argent + variable = self.dragPlantation.montantAchat + self.moneyDefile(-variable) + + + + if self.dragBatiment: + for champ in self.champs: + if champ.rectScale.collidepoint(event.pos): + if isinstance(champ,TerrainVide): + self.batiment.append(self.dragBatiment(champ.pos)) + + #Perdre l'argent + variable = self.dragBatiment.montantAchat + self.moneyDefile(-variable) + + if self.dragBatiment not in [Torche,Serre]: + self.champs.remove(champ) + + + self.dragPlantation = None + self.dragBatiment = None + + + + for champ in self.champs + self.batiment: + if champ.rectScale.contains(event.pos[0],event.pos[1],0,0): + self.selectedChamp = champ + isChamp = True + + if not isChamp: + self.selectedChamp = None + + if (*event.pos,0,0) in self.recTourSuivant: + self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (200, 200)) + else: + self.tourSuivantModif = pygame.transform.scale(self.tourSuivantOriginal, (100, 100)) + + + + elif event.type == pygame.MOUSEWHEEL: + self.camera.zoomInOut(event.y) + + # Achat d'un champ + elif event.type == pygame.MOUSEBUTTONDOWN: + + if event.button == 1: + if(self.recTourSuivant.collidepoint(event.pos)): + self.temps.NextTurn() + + if(self.temps.currentSeason == "Hiver"): + self.AideEtat() + + + i = 0 + for champ in self.champs: + + if type(champ) in typePlantation: + if champ.isInfeste: + champ.indiceImage = 4 + champ.plantationGrandit() + if(random.random()< 0.10): + champ.isInfeste = True + + + for champ in self.champs: + if champ.rectScale.collidepoint(event.pos): + + if(champ.indiceImage > 3): + self.champs.append(TerrainVide(champ.pos)) + self.champs.remove(champ) + elif(champ.indiceImage == 3): + self.moneyDefile(champ.montantVente) + self.champs.append(TerrainVide(champ.pos)) + self.champs.remove(champ) + + + + if isinstance(champ, Buisson): + #if self.money >= champ.prix: + self.moneyDefile(-champ.prix) + self.champs.append(champ.buyField()) + self.champs.remove(champ) + + + + if self.frame < self.buyFrame + 20: + self.screen.blit(self.moneyChange, (self.screen.get_width() -200, (self.frame-self.buyFrame)*1.5)) + #self.screen.blit(self.moneyChange, (200, self.screen.get_height()-textMoney.get_height()*4+(self.frame-self.buyFrame)*1.5)) + + if self.selectedChamp: + self.selectedChamp.showInfo(self.screen,self.recInformation) + + + pygame.display.update() + self.clock.tick(50) + self.frame += 1 + + def moneyDefile(self,montant): + self.moneyChange = police.render(str(montant), True, (200,0,0) if montant < 0 else (0,250,0) ) + self.buyFrame = self.frame + self.money+= montant + + def AideEtat(self): + self.moneyDefile(5000) + diff --git a/src/T3.py b/src/T3.py old mode 100755 new mode 100644 index e01783088b332b05c52bfd24ee0f5ff190eaea6c..f9137f112dcb6998cd0ce44bc0085ed0e53f1c9a --- a/src/T3.py +++ b/src/T3.py @@ -1,52 +1,52 @@ -import pygame -pygame.init() - -from datetime import date -import Game - - -pygame.display.set_caption("Climate Simulator : Global Organization") -screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) - -#on récupère le mois actuelle pour le faire commencer à ce moment -class month: - def __init__ (self, str): - self.month = str - -current_month = month(date.today().strftime("%b")) - -#background (2è scène) -background = pygame.image.load('../assets/Interface/intro.webp') -background = pygame.transform.scale(background, (screen.get_width(), screen.get_height())) - -#bouton -play_button = pygame.image.load('../assets/Interface/button.png') -play_button = pygame.transform.scale(play_button,(400,150)) -play_button_rect = play_button.get_rect() -play_button_rect.x = screen.get_width() / 2 - play_button.get_width()/2 -play_button_rect.y = screen.get_height() / 2 - play_button.get_height()/2 - -#buisson -#bush = pygame.image.load('../assets/buisson.png') - -#cadenas -#lock = pygame.image.load('../assets/cadenas.png') - -screen.blit(background, (0,0)) -screen.blit(play_button, play_button_rect) - -#screen.blit(bush, (100,100)) -#screen.blit(lock, (bush.get_width()/2,bush.get_height()/2+40)) - -pygame.display.update() - -inMenu = True -while inMenu: - for event in pygame.event.get(): - if event.type == pygame.MOUSEBUTTONDOWN and play_button_rect.contains(*event.pos,0,0): - inMenu = False - elif event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: - exit(0) - -# à l'appui du bouton start +import pygame +pygame.init() + +from datetime import date +import Game + + +pygame.display.set_caption("Climate Simulator : Global Organization") +screen = pygame.display.set_mode((0,0), pygame.FULLSCREEN) + +#on récupère le mois actuelle pour le faire commencer à ce moment +class month: + def __init__ (self, str): + self.month = str + +current_month = month(date.today().strftime("%b")) + +#background (2è scène) +background = pygame.image.load('../assets/Interface/intro.webp') +background = pygame.transform.scale(background, (screen.get_width(), screen.get_height())) + +#bouton +play_button = pygame.image.load('../assets/Interface/button.png') +play_button = pygame.transform.scale(play_button,(400,150)) +play_button_rect = play_button.get_rect() +play_button_rect.x = screen.get_width() / 2 - play_button.get_width()/2 +play_button_rect.y = screen.get_height() / 2 - play_button.get_height()/2 + +#buisson +#bush = pygame.image.load('../assets/buisson.png') + +#cadenas +#lock = pygame.image.load('../assets/cadenas.png') + +screen.blit(background, (0,0)) +screen.blit(play_button, play_button_rect) + +#screen.blit(bush, (100,100)) +#screen.blit(lock, (bush.get_width()/2,bush.get_height()/2+40)) + +pygame.display.update() + +inMenu = True +while inMenu: + for event in pygame.event.get(): + if event.type == pygame.MOUSEBUTTONDOWN and play_button_rect.contains(*event.pos,0,0): + inMenu = False + elif event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: + exit(0) + +# à l'appui du bouton start Game.Game().gameLoop() \ No newline at end of file diff --git a/src/Temps.py b/src/Temps.py old mode 100755 new mode 100644 index 33046d08e985532314d8190c88490a54903368aa..cdcc5214b4f5e3080fb69a8a4860bbf75a90df9e --- a/src/Temps.py +++ b/src/Temps.py @@ -1,179 +1,184 @@ -import random -import pygame -from Image import transformImage -from random import triangular -police = pygame.font.SysFont("Alef", 30) -police2 = pygame.font.SysFont("Alef", 20) -class Temps: - - """ - climats = { - - "janvier" : { - "temp" : [2,7.8], - "humidité" : [78,90] - }, - "février" : { - "temp" : [4.5,11.8], - "humidité" : [60,85] - }, - "mars" : { - "temp" : [3.7,13.7], - "humidité" : [45,90] - }, - "avril" : { - "temp" : [15.4,4.7], - "humidité" : [42,76] - }, - "mai" : { - "temp" : [18.1,8.7], - "humidité" : [43,80] - }, - "juin" : { - "temp" : [24.5,14.6], - "humidité" : [60,84] - }, - "juillet" : { - "temp" : [24.9,15.5], - "humidité" : [45,84] - }, - "août" : { - "temp" : [24.6,14.8], - "humidité" : [64,81] - }, - "septembre" : { - "temp" : [24,14], - "humidité" : [58,90] - }, - "octobre" : { - "temp" : [18.3,8.6], - "humidité" : [70, 89] - }, - "novembre" : { - "temp" : [11.3,4.9], - "humidité" : [75,99] - }, - "décembre" : { - "temp" : [10.3,3.8], - "humidité" : [77,99] - } - - } - """ - - climats = { - "Automne" : { - "temp" : [4.8,13.3], - "humidité" : [70,95] - - }, - "Hiver" : { - "temp" : [-5,10.3], - "humidité" : [50,90] - }, - "Printemps" : { - "temp" : [13,27], - "humidité" : [40,90] - }, - "été" : { - "temp" : [25,40], - "humidité" : [40,96] - } - } - - def __init__(self): - self.indice = 2 - self.currentSeason = self.getSaisonName(self.indice) - self.globaltemp = self.tirageAuSortChiffreIntervalleTemp(self.currentSeason) - self.humidite = self.tirageAuSortChiffreIntervallehumidite(self.currentSeason) - self.temps = pygame.image.load(self.tempAAfficher(self.globaltemp,self.humidite)) - self.iconSaison = transformImage(self.temps,200,200) - - self.nextSaison = self.getSaisonName(self.indice+1) - self.nextglobalTemps = self.tirageAuSortChiffreIntervalleTemp(self.nextSaison) - self.nexthumidite = self.tirageAuSortChiffreIntervallehumidite(self.nextSaison) - self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps,self.nexthumidite)) - self.nexticonSaison = transformImage(self.nextTemps,100,100) - - self.tempsaisonImage = police.render(self.currentSeason +" : "+ str(round(self.globaltemp,1))+" °C",True,(0,0,0)) - - self.tempsaisonImageDeuxPosiiton = police2.render(self.nextSaison +" : "+ str(round(self.nextglobalTemps,1))+" °C",True,(0,0,0)) - for key,value in self.climats.items(): - self.climats.get(key)['image'] = transformImage(pygame.image.load("../assets/Saison/"+key+".png"),400,300) - - self.ListTemps = [] - - def NextTurn(self): - #Le next qui devien current - self.indice += 1 - self.currentSeason = self.nextSaison - self.globaltemp = self.nextglobalTemps - self.humidite = self.nexthumidite - self.temps = self.nextTemps - self.iconSaison = self.nexticonSaison - self.tempsaisonImage = police.render(self.currentSeason +" : "+ str(round(self.globaltemp,1))+" °C",True,(0,0,0)) - - #Nouveau turn - self.nextSaison = self.getSaisonName(self.indice+1) - self.nextglobalTemps = self.tirageAuSortChiffreIntervalleTemp(self.nextSaison) - self.nexthumidite = self.tirageAuSortChiffreIntervallehumidite(self.nextSaison) - self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps,self.nexthumidite)) - self.nexticonSaison = transformImage(self.nextTemps,100,100) - - - self.tempsaisonImageDeuxPosiiton = police2.render(self.nextSaison +" : "+ str(round(self.nextglobalTemps,1))+" °C",True,(0,0,0)) - - - def getSaisonName(self,indice:int)->str: - return list(self.climats.keys())[indice%4] - - def tirageAuSortChiffreIntervalleTemp(self,clef): - #tirage au sort pour avoir un nombre representatif dans son domaine; par exemple [0,10], la temp sera de 5 - - intervalle = self.getClimatTemp(clef) - """ - randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0] - return randomNombre - """ - return random.triangular(low = intervalle[0],high = intervalle[1]) - - def tirageAuSortChiffreIntervallehumidite(self,clef): - #tirage au sort pour avoir un nombre representatif dans son domaine; par exemple [0,10], la temp sera de 5 - intervalle = self.getClimatHumidite(clef) - - #randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0] - return random.triangular(low = intervalle[0],high = intervalle[1]) - - def tempAAfficher(self,temperature:float,humidite)-> str: - #Determination du temps a afficher - if( temperature < 0 and humidite >80): - return "../assets/Temps/neige.png" - elif (temperature < 10): - return "../assets/Temps/froid.png" - elif (temperature < 35): - return "../assets/Temps/chaud.png" - elif (temperature > 34): - if(humidite > 85): - return "../assets/Temps/orage.png" - - if(humidite < 65): - return "../assets/Temps/secheresse.png" - else: - return "../assets/Temps/canicule.png" - else: - pass - - def getClimatTemp(self,clef): - return self.climats[clef]["temp"] - - def getClimatHumidite(self,clef): - return self.climats[clef]["humidité"] - - def getcurrentSeason(self): - return self.currentSeason - - def getImageSaison(self): - return self.climats.get(self.currentSeason).get('image') - - - \ No newline at end of file +import random +import pygame +from Image import transformImage +from random import triangular +police = pygame.font.SysFont("Alef", 30) +police2 = pygame.font.SysFont("Alef", 20) +class Temps: + + """ + climats = { + + "janvier" : { + "temp" : [2,7.8], + "humidité" : [78,90] + }, + "février" : { + "temp" : [4.5,11.8], + "humidité" : [60,85] + }, + "mars" : { + "temp" : [3.7,13.7], + "humidité" : [45,90] + }, + "avril" : { + "temp" : [15.4,4.7], + "humidité" : [42,76] + }, + "mai" : { + "temp" : [18.1,8.7], + "humidité" : [43,80] + }, + "juin" : { + "temp" : [24.5,14.6], + "humidité" : [60,84] + }, + "juillet" : { + "temp" : [24.9,15.5], + "humidité" : [45,84] + }, + "août" : { + "temp" : [24.6,14.8], + "humidité" : [64,81] + }, + "septembre" : { + "temp" : [24,14], + "humidité" : [58,90] + }, + "octobre" : { + "temp" : [18.3,8.6], + "humidité" : [70, 89] + }, + "novembre" : { + "temp" : [11.3,4.9], + "humidité" : [75,99] + }, + "décembre" : { + "temp" : [10.3,3.8], + "humidité" : [77,99] + } + + } + """ + + climats = { + "Automne" : { + "temp" : [4.8,13.3], + "humidité" : [70,95] + + }, + "Hiver" : { + "temp" : [-5,10.3], + "humidité" : [50,90] + }, + "Printemps" : { + "temp" : [13,27], + "humidité" : [40,90] + }, + "été" : { + "temp" : [25,40], + "humidité" : [40,96] + } + } + + def __init__(self): + self.indice = 2 + self.currentSeason = self.getSaisonName(self.indice) + self.globaltemp = self.tirageAuSortChiffreIntervalleTemp(self.currentSeason) + self.humidite = self.tirageAuSortChiffreIntervallehumidite(self.currentSeason) + self.temps = pygame.image.load(self.tempAAfficher(self.globaltemp,self.humidite)) + self.iconSaison = transformImage(self.temps,200,200) + + self.nextSaison = self.getSaisonName(self.indice+1) + self.nextglobalTemps = self.tirageAuSortChiffreIntervalleTemp(self.nextSaison) + self.nexthumidite = self.tirageAuSortChiffreIntervallehumidite(self.nextSaison) + self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps,self.nexthumidite)) + self.nexticonSaison = transformImage(self.nextTemps,100,100) + + self.tempsaisonImage = police.render(self.currentSeason +" : "+ str(round(self.globaltemp,1))+" °C",True,(0,0,0)) + + self.tempsaisonImageDeuxPosiiton = police2.render(self.nextSaison +" : "+ str(round(self.nextglobalTemps,1))+" °C",True,(0,0,0)) + for key,value in self.climats.items(): + self.climats.get(key)['image'] = transformImage(pygame.image.load("../assets/Saison/"+key+".png"),400,300) + + self.ListTemps = [] + + def NextTurn(self): + #Le next qui devien current + self.indice += 1 + self.currentSeason = self.nextSaison + self.globaltemp = self.nextglobalTemps + self.humidite = self.nexthumidite + self.temps = self.nextTemps + self.iconSaison = self.nexticonSaison + self.tempsaisonImage = police.render(self.currentSeason +" : "+ str(round(self.globaltemp,1))+" °C",True,(0,0,0)) + + #Nouveau turn + self.nextSaison = self.getSaisonName(self.indice+1) + self.nextglobalTemps = self.tirageAuSortChiffreIntervalleTemp(self.nextSaison) + self.nexthumidite = self.tirageAuSortChiffreIntervallehumidite(self.nextSaison) + self.nextTemps = pygame.image.load(self.tempAAfficher(self.nextglobalTemps,self.nexthumidite)) + self.nexticonSaison = transformImage(self.nextTemps,100,100) + + + self.tempsaisonImageDeuxPosiiton = police2.render(self.nextSaison +" : "+ str(round(self.nextglobalTemps,1))+" °C",True,(0,0,0)) + + + def getSaisonName(self,indice:int)->str: + return list(self.climats.keys())[indice%4] + + def tirageAuSortChiffreIntervalleTemp(self,clef): + #tirage au sort pour avoir un nombre representatif dans son domaine; par exemple [0,10], la temp sera de 5 + + intervalle = self.getClimatTemp(clef) + """ + randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0] + return randomNombre + """ + return random.triangular(low = intervalle[0],high = intervalle[1]) + + def tirageAuSortChiffreIntervallehumidite(self,clef): + #tirage au sort pour avoir un nombre representatif dans son domaine; par exemple [0,10], la temp sera de 5 + intervalle = self.getClimatHumidite(clef) + + #randomNombre = random.random() * (intervalle[1]-intervalle[0]) + intervalle[0] + return random.triangular(low = intervalle[0],high = intervalle[1]) + + def tempAAfficher(self,temperature:float,humidite)-> str: + #Determination du temps a afficher + if( temperature < 0 and humidite >80): + return "../assets/Temps/neige.png" + elif (temperature < 10): + return "../assets/Temps/froid.png" + elif (temperature < 30): + if(humidite > 80): + return "../assets/Temps/pluie.png" + else: + return "../assets/Temps/nice_weather.png" + elif (temperature < 35): + return "../assets/Temps/chaud.png" + elif (temperature > 34): + + if(humidite > 85): + return "../assets/Temps/orage.png" + + if(humidite < 40): + return "../assets/Temps/secheresse.png" + else: + return "../assets/Temps/canicule.png" + else: + pass + + def getClimatTemp(self,clef): + return self.climats[clef]["temp"] + + def getClimatHumidite(self,clef): + return self.climats[clef]["humidité"] + + def getcurrentSeason(self): + return self.currentSeason + + def getImageSaison(self): + return self.climats.get(self.currentSeason).get('image') + +