Exemple #1
0
def run():	
	while True:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:	#Quit if you leave the window
				pygame.quit()
				quit()				
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)	#Clear buffer
				
		output2d.draw_images()
		output2d.draw_inv_text()
				
		
		if pygame.key.get_pressed()[pygame.K_UP]:
			if hallway_type not in [Hallways.LEFT, Hallways.RIGHT, Hallways.BIFURC]:
				step(Directions.FORWARDS, pygame.K_UP)

		elif pygame.key.get_pressed()[pygame.K_DOWN] and maze.position.adjacent[Directions.BACKWARDS] != None:
			step(Directions.BACKWARDS,pygame.K_DOWN)
			
		elif pygame.key.get_pressed()[pygame.K_LEFT]:
			if hallway_type not in [Hallways.STRAIGHT, Hallways.RIGHT, Hallways.RIGHT_BIFURC]:
				step(Directions.LEFT, pygame.K_LEFT)
				
		elif pygame.key.get_pressed()[pygame.K_RIGHT]:
			if hallway_type not in [Hallways.STRAIGHT, Hallways.LEFT, Hallways.LEFT_BIFURC]:
				step(Directions.RIGHT, pygame.K_RIGHT)
		
		hallway_type = maze.current_type()
		
		GLComponents.hallway(hallway_type, True, maze.position.colours)
			
		pygame.display.flip()	#Refresh screen
		pygame.time.wait(25)
Exemple #2
0
	def draw_inv_text(self):	#Box around the text here
		PERCENT_UP = 0.95	#How far up is the text?
		FONT = GLUT_BITMAP_9_BY_15
		LOADING_WIDTH = 40
		LOADING_HEIGHT = 10
		TEXT_LOADINGBAR_GAP = 10
		
		text_top = PERCENT_UP * SCREEN_SIZE[1] #Text starts from here
		
		GLComponents.glEnable2D()
		max_length = 0
		for item_num in range(len(self.inventory.inventory)):	#Longest sentence
			key = self.inventory.inventory.keys()[item_num]
			
			cap = ReadFile.read_caps()[item_num]
			if cap:
				message = "{0}: {1:.2f}%".format(key, self.inventory.inventory[key]/cap * 100.0)
			else:
				message = "{0}: {1:.2f}".format(key, self.inventory.inventory[key])
			
			width = self.str_width(message, FONT)
			
			if width > max_length:
				max_length = width
			GLComponents.write_str(message, 0, text_top - item_num * 15, FONT)
			if cap:	#Only capped values get loading bars
				GLComponents.loading_bar(max_length + TEXT_LOADINGBAR_GAP, text_top - 15 * item_num, 
					self.inventory.inventory[key]/cap * 100, LOADING_WIDTH, LOADING_HEIGHT)
		
		GLComponents.draw_rect(0, max_length + LOADING_WIDTH + TEXT_LOADINGBAR_GAP + 2, 
			text_top + 15, text_top - len(self.inventory.inventory) * 15)
		
		GLComponents.glDisable2D()
Exemple #3
0
def display():
	output2d.draw_images()
	output2d.draw_inv_text()
	
	hallway_type = maze.current_type()

	GLComponents.hallway(hallway_type, True, maze.position.colours)
	pygame.display.flip()	#Refresh screen
		
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)	#Clear buffer
Exemple #4
0
def display_straight(delay, winning_spot):
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
	
	if winning_spot and maze.give_prize(inventory):	#Note the use of short circuit operators here. Be careful
		output2d.winning_message()
		#GLComponents.prize_picture(maze.position.prize[0]) #can add this for images I think??????not quite sure what it does, only seems to work sometimes (maybe its selecting nones sometimes)
	
	#GLComponents.prize_picture('food')
	output2d.draw_inv_text()  
	GLComponents.hallway(Hallways.STRAIGHT, True, MazeComponent.generate_colours(Hallways.STRAIGHT)) 

	pygame.display.flip() 
	time.mri_delay(delay)		#Show first hallway		
Exemple #5
0
def display_straight(delay, winning_spot):
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
	
	GLComponents.hallway(Hallways.STRAIGHT, True, MazeComponent.generate_colours(Hallways.STRAIGHT))

	if winning_spot and maze.give_prize(inventory):	#Note the use of short circuit operators here. Be careful
		output2d.winning_message()
		#GLComponents.prize_picture(maze.position.prize[0])
	
	#GLComponents.prize_picture('food')
	output2d.draw_inv_text()
	pygame.display.flip()
	time.mri_delay(delay)		#Show first hallway		
Exemple #6
0
def wait_key_up(key):
	
	if maze.give_prize(inventory):
			output2d.winning_message()
	
	GLComponents.hallway(maze.current_type(), True, maze.position.colours)							
	pygame.display.flip()
	
	
	while pygame.key.get_pressed()[key]:
		for event in pygame.event.get():
			if event.type == pygame.QUIT:	#Quit if you leave the window
				pygame.quit()
				quit()
Exemple #7
0
	def draw_images(self):
		width = self.camera.display[0]
		if self.maze.position.is_choice_room:
			inv_types = self.maze.position.prize_order
			if inv_types[0] != None:
				GLComponents.inventory_img(((0, 0), (0, 100), (100, 100), (100, 0)), inv_types[0] + IMAGE_EXT)
			if inv_types[1] != None:
				GLComponents.inventory_img(((width/2 - 50, 0), (width/2 - 50, 100), (width/2 + 50, 100), (width/2 + 50, 0)), inv_types[1] + IMAGE_EXT)
			if inv_types[2] != None:
				GLComponents.inventory_img(((width - 100, 0), (width - 100, 100), (width, 100), (width, 0)), inv_types[2] + IMAGE_EXT)
Exemple #8
0
	def draw_images(self):
		width = SCREEN_SIZE[1]
		if self.maze.position.prize_order != [None, None, None]:
			inv_types = [x[2] if x else x for x in self.maze.position.prize_infos]
			if inv_types[0] != None:
				GLComponents.image_2d(((0, 0), (0, 100), (100, 100), (100, 0)), inv_types[0])
			if inv_types[1] != None:
				GLComponents.image_2d(((width/2 - 50, 0), (width/2 - 50, 100), (width/2 + 50, 100), (width/2 + 50, 0)), inv_types[1])
			if inv_types[2] != None:
				GLComponents.image_2d(((width - 100, 0), (width - 100, 100), (width, 100), (width, 0)), inv_types[2])
Exemple #9
0
	def draw_inv_text(self):	#Box around the text here
		PERCENT_UP = 0.95	#How far up is the text?
		FONT = GLUT_BITMAP_9_BY_15
		text_top = PERCENT_UP * self.camera.display[1] #Text starts from here
		
		GLComponents.glEnable2D()
		max_length = 0
		for item_num in range(len(self.inventory.inventory)):
			key = self.inventory.inventory.keys()[item_num]
			message = key + ': ' + str(self.inventory.inventory[key])
			
			width = self.str_width(message, FONT)
			
			if width > max_length:
				max_length = width
			GLComponents.write_str(message, 0, text_top - item_num * 15, FONT)
		
		GLComponents.draw_rect(0, max_length, text_top + 15, text_top - len(self.inventory.inventory) * 15)
		
		GLComponents.glDisable2D()
Exemple #10
0
	def draw_centred(self, message, side_padding = 1, up_padding = 1):
		GLComponents.glEnable2D()
		if up_padding == 1 and side_padding == 1:	#Might as well clear all
			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
			glDisable(GL_DEPTH_TEST)
		FONT = GLUT_BITMAP_HELVETICA_18
		
		width = self.str_width(message, FONT)	#For centering

		#Centered text
		GLComponents.write_str(message, SCREEN_SIZE[0]/2 - width/2, SCREEN_SIZE[1]/2, FONT)
		
		if up_padding != 1 or side_padding != 1:
			GLComponents.draw_rect(SCREEN_SIZE[0]/2 * (1 - side_padding), SCREEN_SIZE[0]/2 * (1 + side_padding), 
				SCREEN_SIZE[1]/2 * (1 - up_padding), SCREEN_SIZE[1]/2 * (1 + up_padding))
		
		self.draw_inv_text()

		GLComponents.glDisable2D()
		
		pygame.display.flip()
		
		glEnable(GL_DEPTH_TEST)
Exemple #11
0
	def winning_message(self):
		glDisable(GL_DEPTH_TEST)
		FONT = GLUT_BITMAP_HELVETICA_18
		WAIT = 2000 #How long is the message showing? In ms.
		
		message = 'You just got ' + str(self.maze.position.prize[1]) + ' ' + self.maze.position.prize[0] + '!'
		width = self.str_width(message, FONT)	#For centering
		
		GLComponents.glEnable2D()
		
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
		
		#Centered text
		GLComponents.write_str(message, self.camera.display[0]/2 - width/2, self.camera.display[1]/2, FONT)
		
		#GLComponents.draw_rect(0, self.camera.display[0], 0, self.camera.display[1])
		GLComponents.glDisable2D()
		
		pygame.display.flip()
		pygame.time.wait(WAIT)
		
		glEnable(GL_DEPTH_TEST)