diff --git a/src/Champs.py b/src/Champs.py index d16688615eb5786e72299d2e07e52e06f9a3e384..5cc2832696c9d24aaf4b81da5b984ae4f471d6ed 100755 --- a/src/Champs.py +++ b/src/Champs.py @@ -2,19 +2,40 @@ import pygame import numpy as np from Temps import * + class Champs: - def __init__ (self, tempature, humidite, tempsAvantMaturation, pos, image): - self.temperature = tempature + + def __init__ (self, temperature, humidite, tempsAvantMaturation, pos, image): + self.temperature = temperature self.humidite = humidite self.TAM = tempsAvantMaturation self.pos = np.array(pos) - self.image = image + 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.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 draw (self, screen, camera): scaleImage = camera.scaleImage(self.image) @@ -29,31 +50,79 @@ class Champs: if scaleText: self.zoomText = scaleText -class Houblon (Champs): - def __init__ (self, pos): - super().__init__(0, 0, 0, pos, pygame.image.load('../assets/champ.png')) - self.text = self.police.render("Température : " + str(self.temperature), False, (0,0,0)) - self.zoomText = self.text + 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, camera): - #pygame.draw.rect(screen, (255, 255, 255), pygame.rect.Rect(camera.convertLocation(self.pos), np.array(self.rect.size)*0.75*abs(camera.zoom))) - self.changeText(camera) + 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 - screen.blit(self.zoomText, camera.convertLocation(self.pos)) class Buisson (Champs): def __init__ (self, pos, prix = 10000): - super().__init__(0, 0, 0, pos, pygame.image.load('../assets/buissonCadenas.png')) + super().__init__(0, 0, 0, pos, '../assets/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 Houblon(self.pos) - def showInfo (self, screen, camera): - #pygame.draw.rect(screen, (255, 255, 255), pygame.rect.Rect(camera.convertLocation(self.pos), np.array(self.rect.size)*0.75*abs(camera.zoom))) - self.changeText(camera) - screen.blit(self.zoomText, camera.convertLocation(self.pos)) +class Houblon (Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/neige.png'),(150,150)) + textStatic = police.render('Houblon',False, (0,0,0)) + textDescriptionStatic = police.render("Houblon sa marche bien",False,(0,0,0)) + def __init__ (self, pos): + super().__init__(0, 0, 0, pos,'../assets/champ.png') + self.text = self.police.render("Température : " + str(self.temperature), False, (0,0,0)) + self.zoomText = self.text + + +class Ble (Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Automne.png'),(150,150)) + textStatic = police.render('Ble',False, (0,0,0)) + textDescriptionStatic = police.render("Ble sa marche bien",False,(0,0,0)) + def __init__ (self,pos,icon): + super().__init__(0,0,0,pos,'../assets/champ.png') - def buyField (self): - # Clique sur buisson -> Pop up "Êtes-vous certain ?" -> Oui ? -> Supprime le buisson de la liste et ajoute un Houblon aux mêmes coordonnées - return Houblon(self.pos) \ No newline at end of file +class Malt (Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Hiver.png'),(150,150)) + textStatic = police.render('Malt',False, (0,0,0)) + textDescriptionStatic = police.render("Malt sa marche bien",False,(0,0,0)) + def __init__ (self,pos,icon): + super().__init__(0,0,0,pos,'../assets/champ.png') + + +class OrgeHiver(Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/canicule.png'),(150,150)) + textStatic = police.render("Orge d'hiver",False, (0,0,0)) + textDescriptionStatic = police.render("Orge Hiver sa marche bien",False,(0,0,0)) + def __init__ (self,pos,icon): + super().__init__(0,0,0,pos,'../assets/champ.png') + +class OrgePrintemps(Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/canicule.png'),(150,150)) + textStatic = police.render("Orge printemps",False, (0,0,0)) + textDescriptionStatic = police.render("Orge printemps sa marche bien",False,(0,0,0)) + def __init__ (self,pos,icon): + super().__init__(0,0,0,pos,'../assets/champ.png') + +class Seigle(Champs): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/orage.png'),(150,150)) + textStatic = police.render("Seigle",False, (0,0,0)) + textDescriptionStatic = police.render("Seigle sa marche bien",False,(0,0,0)) + def __init__ (self,pos,icon): + super().__init__(0,0,0,pos,'../assets/champ.png') + + + +typePlantation = [Houblon,Ble,Malt,OrgeHiver,OrgePrintemps,Seigle] + + \ No newline at end of file diff --git a/src/Game.py b/src/Game.py index d592835c4ad9aae3a467f732b077ebfb07b3d4a3..ea5a5383b357ed82b7ee2f4ff3308ef140db8932 100755 --- a/src/Game.py +++ b/src/Game.py @@ -1,14 +1,15 @@ import pygame -from Champs import Champs,Houblon,Buisson +from Champs import Champs,Houblon,Buisson,typePlantation import numpy as np from Camera import Camera -from Image import Image +from Image import transformImage,Image from Temps import Temps +from Infrastructure import Infrastructure,typeBatiment 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("Alef", 30) +police = pygame.font.SysFont("calibri", 30) class Game: def __init__ (self): @@ -16,101 +17,131 @@ class Game: self.image = Image(self.screen) self.screenSize = np.array(self.screen.get_size()) self.score = 0 - self.money = 10000 - self.displayMoney = 10000 + self.money = 20000 + self.displayMoney = 20000 self.month = 0 self.champs = [] self.temps = Temps() for i in range(12): - self.champs.append(Buisson(((i%4)*300-550,(i//4)*200-300))) + 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())/3) - + self.camera = Camera(np.array(self.screen.get_size())/2) - self.pluie = pygame.transform.scale(self.image.rainImage, (200,200)) self.frame = 0 self.buyFrame = -1000 - - self.flecheChangementdroite = self.image.arrowImage1 - self.flecheChangementgauche = self.image.arrowImage2 - self.flecheChangementdroite = pygame.transform.scale(self.flecheChangementdroite, (100,100)) - self.flecheChangementgauche = pygame.transform.scale(self.flecheChangementgauche, (100,100)) - self.coordonnee_image_droite = self.screenSize[0]-self.flecheChangementdroite.get_width() - 10, self.screenSize[1]/2 - self.coordonnee_image_gauche = 10, self.screenSize[1]/2 - self.rectangle_button_fleche = pygame.rect.Rect(*self.coordonnee_image_droite,100,100) - self.rectangle_button_fleche_gauche = pygame.rect.Rect(*self.coordonnee_image_gauche,100,100) self.tourSuivant = self.image.arrowNextImage self.tourSuivant = pygame.transform.scale(self.tourSuivant, (100,100)) self.coordonneeSuite = self.screenSize[0]-self.tourSuivant.get_width() - 120, self.screenSize[1] - self.tourSuivant.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.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() + ) + + + def gameLoop (self): while True: - self.screen.blit(self.image.backgroundImage, (0,0)) - # Bouton suite - self.screen.blit(self.tourSuivant, (self.screen.get_width() - 120, self.screen.get_height() - 120)) + self.screen.blit(self.image.backgroundImage, (0,0)) - # Météo - pygame.draw.rect(self.screen, (127, 127, 127), (0, self.screen.get_height() - 200, 200, 200)) - self.screen.blit(self.temps.Temps, (0, self.screen.get_height() - 200)) - #self.screen.blit(self.pluie, (0, self.screen.get_height() - 200)) - #self.screen.blit(police,self.temps.getcurrentSeason(),(500,500)) - self.screen.blit(self.temps.temperatureImage,(10,self.screen.get_height() - self.temps.temperatureImage.get_height())) - # Saison - """ - surface = police.render(SAISONS[self.month%4], False, (0,0,0)) - self.screen.blit(surface, (0, self.screen.get_height() - surface.get_height())) - """ - #isChamp = False + #CHAMPS------------------ # Affichage des champs for champ in self.champs: champ.draw(self.screen, self.camera) - champ.showInfo(self.screen, self.camera) - # Affiche les fps - fpsText = police.render(("%.0f fps" %(self.clock.get_fps())), True, (180,180,180)) - self.screen.blit(fpsText, (self.screen.get_width() - fpsText.get_width(), 0)) + + #DEBUT BOUCLE INTERFACE------------------------ + + #Onglet Information + pygame.draw.rect(self.screen, (0, 127, 0), self.recInformation) + + # Météo + self.screen.blit(self.temps.getImageSaison(), (0, self.screen.get_height() - 300)) + self.screen.blit(self.temps.image,(10,self.screen.get_height() - self.temps.image.get_height())) + self.screen.blit(self.temps.temperatureImage,(10,self.screen.get_height() - self.temps.image.get_height() - 50)) + + + #Onglet plantation + pygame.draw.rect(self.screen, (0, 127, 127), self.rectPlantation) + + #Onglet tour suivant + pygame.draw.rect(self.screen,(0, 127, 0),(self.recTourSuivant)) + self.screen.blit(self.tourSuivant, (self.screen.get_width() - 120, self.screen.get_height() - 120)) + + 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 + pygame.draw.rect(self.screen, (127, 127, 127), (self.recBatiment)) + 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 -= 500 # Si quelque chose coûte moins que 100, changer par -= min(100, self.displayMoney - self.money) elif self.money > self.displayMoney: self.displayMoney += 500 # Si quelque chose coûte moins que 100, changer par -= min(100, self.money - self.displayMoney) + textMoney = police.render(str(self.displayMoney), True, (255,255,255)) pygame.draw.rect(self.screen, (0,0,0), (200, self.screen.get_height() - 50, 100, 50)) self.screen.blit(textMoney, (200, self.screen.get_height()-30)) self.screen.blit(self.imageMoney, (300, self.screen.get_height()-self.imageMoney.get_height())) - self.screen.blit(self.flecheChangementdroite, self.coordonnee_image_droite) 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.MOUSEBUTTONDOWN and (*event.pos,0,0) in self.rectangle_button_fleche: - self.gameLoopSecondScreen() - elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT: - self.gameLoopSecondScreen() elif event.type == pygame.MOUSEMOTION: if event.buttons[2] == 1: #maintenir enfoncé clic droit self.camera.setPosition(np.array(event.rel)) - """for champ in self.champs: + for champ in self.champs: if champ.rectScale.contains(event.pos[0],event.pos[1],0,0): self.selectedChamp = champ isChamp = True if not isChamp: - self.selectedChamp = None""" + self.selectedChamp = None if (*event.pos,0,0) in self.suiteRectangle: self.tourSuivant = pygame.transform.scale(self.tourSuivant, (120, 120)) else: self.tourSuivant = pygame.transform.scale(self.tourSuivant, (100, 100)) + elif event.type == pygame.MOUSEWHEEL: self.camera.zoomInOut(event.y) @@ -123,9 +154,7 @@ class Game: if champ.rectScale.contains(event.pos[0],event.pos[1],0,0): if self.money >= champ.prix: self.moneyChange = police.render(str(-champ.prix), True, (255,0,0)) - self.buyFrame = self.frame - self.champs.append(champ.buyField()) self.champs.remove(champ) self.money -= champ.prix @@ -134,24 +163,10 @@ class Game: if self.frame < self.buyFrame + 20: 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.camera)""" + if self.selectedChamp: + self.selectedChamp.showInfo(self.screen,self.recInformation) + pygame.display.update() self.clock.tick(50) - self.frame += 1 - - def gameLoopSecondScreen (self): - while True: - self.screen.blit(self.image.barnImage, (0,0)) - self.screen.blit(self.flecheChangementgauche, self.coordonnee_image_gauche) - - 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.KEYDOWN and event.key == pygame.K_LEFT: - return - elif event.type == pygame.MOUSEBUTTONDOWN and (*event.pos,0,0) in self.rectangle_button_fleche_gauche: - self.gameLoop() - pygame.display.update() - self.clock.tick(50) \ No newline at end of file + self.frame += 1 \ No newline at end of file diff --git a/src/Infrastructure.py b/src/Infrastructure.py index 80db74033bf35b7d62316ffd31eb07afdbc02cad..6431cf9edee287b6a813da39ba59d34adb62e283 100644 --- a/src/Infrastructure.py +++ b/src/Infrastructure.py @@ -1,6 +1,72 @@ import numpy as np import pygame +police = pygame.font.SysFont("Alef", 22) #pygame.font.get_fonts() -> liste des fonts + class Infrastructure: - def __init__ (self): - \ No newline at end of file + + 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.descripteurInfrastructure = { + "CoutProd" : None, + + } + self.imageSurfaceinfo = { + "CoutProd" : None, + } + self.setInformation("CoutProd",2000) + + + + 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)) + + def changeText (self, camera): + scaleText = camera.scaleImage(self.text) + if scaleText: + self.zoomText = scaleText + + 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 + + +class Puit (Infrastructure): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/money.png'),(150,150)) + textStatic = police.render('Puits',False, (0,0,0)) + textDescriptionStatic = police.render("C'est un puit",False,(0,0,0)) + def __init__ (self,pos,icon): + super().__init__(0,0,0,pos,'../assets/champ.png') + +class Capteur (Infrastructure): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Hiver.png'),(150,150)) + textStatic = police.render('Capteur eau de pluie',False, (0,0,0)) + textDescriptionStatic = police.render("Permet de capturer l'eau de pluit",False,(0,0,0)) + def __init__ (self,pos,icon): + super().__init__(0,0,0,pos,'../assets/champ.png') + +class Irrigation (Infrastructure): + iconStatic = pygame.transform.scale(pygame.image.load('../assets/Printemps.png'),(150,150)) + textStatic = police.render('Irrigation goute à goute',False, (0,0,0)) + textDescriptionStatic = police.render("Permet d'arroser les plantes en économisant l'eau",False,(0,0,0)) + def __init__ (self,pos,icon): + super().__init__(0,0,0,pos,'../assets/champ.png') + +typeBatiment = [Puit,Capteur,Irrigation] \ No newline at end of file diff --git a/src/Plantation.py b/src/Plantation.py new file mode 100644 index 0000000000000000000000000000000000000000..33cc37437b8317930471bf166758248dd7cdeb27 --- /dev/null +++ b/src/Plantation.py @@ -0,0 +1,3 @@ +class Plantation: + + def __init__ (self): \ No newline at end of file diff --git a/src/Temps.py b/src/Temps.py index 221318b6783844d4cde2d911aad8906bf031f77e..ab4f7d9a00b40daf8258c3a4df012bad3ad7787f 100755 --- a/src/Temps.py +++ b/src/Temps.py @@ -4,8 +4,10 @@ from Image import transformImage police = pygame.font.SysFont("Alef", 30) class Temps: # "humidité" est un pourcentage moyen + + """ climats = { - """ + "janvier" : { "temp" : [2,7.8], "humidité" : [78,90] @@ -54,7 +56,11 @@ class Temps: "temp" : [10.3,3.8], "humidité" : [77,99] } - """ + + } + """ + + climats = { "Automne" : { "temp" : [5.8,13.3], "humidité" : [72,94] @@ -68,24 +74,21 @@ class Temps: "temp" : [8,35], "humidité" : [44,80] }, - "Été" : { + "été" : { "temp" : [15,27], "humidité" : [56,85] } } def __init__(self): - self.currentSeason = "Hiver" + self.currentSeason = "Printemps" self.globaltemp = self.tirageAuSortChiffreIntervalleTemp(self.currentSeason) self.humidite = self.tirageAuSortChiffreIntervallehumidite(self.currentSeason) - self.Temps = pygame.image.load(self.tempAAfficher()) self.image = transformImage(self.Temps,200,200) self.temperatureImage = police.render(self.currentSeason +" : "+ str(round(self.globaltemp,1))+" °C",True,(0,0,0)) - """ - for key,value in climats.items(): - climats.get(key)['image'] = pygame.image.load("../assets/"+key+".png") - """ + for key,value in self.climats.items(): + self.climats.get(key)['image'] = transformImage(pygame.image.load("../assets/"+key+".png"),400,300) @@ -129,5 +132,8 @@ class Temps: def getcurrentSeason(self): return self.currentSeason + def getImageSaison(self): + return self.climats.get(self.currentSeason).get('image') + \ No newline at end of file