Esempio n. 1
0
	def on_load_font(self):
		"""Chargement des polices du jeu"""
		# Gestion des polices
		if not pygame.font: print("Attention, les polices sont désactivees !")
		else:
			self.font       = pygame.font.Font(None, 24)
			self.font_score = pygame.font.Font(None, 22)
			
			self.text_screen = self.font.render("SCORE", 1, (255,255,255))
			self.text_screen_pos = self.text_screen.get_rect(centerx=self.fen.get_width()/2, centery=(self.fen.get_height()/2)-100)
			self.text_quit = self.font.render("QUITTER", 1, (255,255,255))
			self.text_quit_pos = self.text_quit.get_rect(centerx=(self.fen.get_width()/2)+105, centery=(self.fen.get_height()/2)+95)
			self.text_reset = self.font.render("RESET", 1, (255,255,255))
			self.text_reset_pos = self.text_reset.get_rect(centerx=(self.fen.get_width()/2)-105, centery=(self.fen.get_height()/2)+95)
			self.text_easy = self.font.render("Easy :", 1, (255,255,255))
			self.text_easy_pos = self.text_easy.get_rect(centerx=(self.fen.get_width()/2)-130, centery=(self.fen.get_height()/2)-40)
			self.text_medium = self.font.render("Medium :", 1, (38,200,33))
			self.text_medium_pos = self.text_medium.get_rect(centerx=(self.fen.get_width()/2)-6, centery=(self.fen.get_height()/2)-40)
			self.text_hard = self.font.render("Hard :", 1, (227,42,58))
			self.text_hard_pos = self.text_hard.get_rect(centerx=(self.fen.get_width()/2)+92, centery=(self.fen.get_height()/2)-40)
			
			# Chargement des scores
			self.get_score()
			
			self.lst_easy = []
			self.lst_medium = []
			self.lst_hard = []
			for i, item in enumerate(self.score_easy): # EASY
				text = self.font_score.render(str(i+1) + ".  " + fonctions.render_score(item), 1, (255,255,255))
				text_pos = (7, (13*i)+95)
				
				self.lst_easy.append((text, text_pos))
				
			for i, item in enumerate(self.score_medium): # MEDIUM
				text = self.font_score.render(str(i+1) + ".  " + fonctions.render_score(item), 1, (38,200,33))
				text_pos = (117, (13*i)+95)
				
				self.lst_easy.append((text, text_pos))
				
			for i, item in enumerate(self.score_hard): # HARD
				text = self.font_score.render(str(i+1) + ".  " + fonctions.render_score(item), 1, (227,42,58))
				text_pos = (230, (13*i)+95)
				
				self.lst_easy.append((text, text_pos))
Esempio n. 2
0
	def on_load_font(self):
		"""Chargement des polices du jeu"""
		# Gestion des polices
		if not pygame.font: print("Attention, les polices sont désactivees !")
		else:
			self.font = pygame.font.Font(None, 24)
			self.text_score = self.font.render("Score : {}" .format(fonctions.render_score(self.score)), 1, (255,255,255))
			self.text_score_pos = (5,5)
			
			self.font_game_over = pygame.font.Font(None, 32)
			self.text_game_over = self.font_game_over.render("Game 0ver", 1, (255,255,255))
			self.text_game_over_pos = self.text_game_over.get_rect(centerx=(self.fen.get_width()/2)-50, centery=(self.fen.get_height()/2)-20)
Esempio n. 3
0
	def on_run(self):
		"""Programme principal"""
		old  = 0
		old2 = 0
		old3 = 0
		
		while 1:
			event_code = self.on_event()
			# Arrêt du programme
			if event_code == -1:
				break
			elif event_code == "dead":
				self.code = "dead"
				break
			
			# GESTION ECRAN
			# Gestion position écran haut/bas
			if self.movey_pos <= -self.limy:
				self.limy = randrange(5, 20)
				self.movey = "down"
			elif self.movey_pos >= self.limy:
				self.limy = randrange(5, 20)
				self.movey = "up"
			
			# Gestion position écran gauche/droite
			if self.movex_pos <= -self.limx:
				self.limx = randrange(5, 20)
				self.movex = "right"
			elif self.movex_pos >= 0:
				self.limx = randrange(5, 20)
				self.movex = "left"
			
			# Récupération temps actuel
			current = pygame.time.get_ticks()
			
			# Timer d'avancement du perso
			if (current > old+self.timer and not self.game_over): 
				self.list_pos.pop(0)
				self.list2_pos.pop(0)
				self.score += 1
				
				old = current
			
			# Timer de mouvement d'écran
			if (current > old2+self.timer_move and not self.game_over): 
				if self.movey == "up":
					self.movey_pos -= 1
				elif self.movey == "down":
					self.movey_pos += 1
					
				if self.movex == "left":
					self.movex_pos -= 1
				elif self.movex == "right":
					self.movex_pos +=1
					
				old2 = current
			
			# Timer de mouvement du score
			if (current > old3+self.timer_score and self.game_over):
				centerx = self.text_game_over.get_rect(centerx=(self.fen.get_width()/2))[0]
				centery = self.text_game_over.get_rect(centery=(self.fen.get_height()/2))[1]
				if (self.text_score_pos[0] < centerx+20):
					self.text_score_pos = (self.text_score_pos[0]+1, self.text_score_pos[1]+1)
				elif (self.text_score_pos[1] < centery):
					self.text_score_pos = (self.text_score_pos[0], self.text_score_pos[1]+1)
			
			# Rendu du score en haut à gauche
			self.text_score = self.font.render("Score : {}" .format(fonctions.render_score(self.score)), 1, (255,255,255))
			
			# Rendu de l'écran
			self.on_render()
			pygame.display.flip()
			
		print("Home screen")