def __init__(self, path, filename, mediatype) :

		self.path = path

		self.filename = filename

		self.key = os.path.join(path, filename)

		self.mediatype = mediatype

		if (cmp(self.mediatype, "image") == 0) :
			(self.imgtype, self.width, self.height) = ui.get_image_info(self.key)

			self.imgtype = self.imgtype["name"]

		self.size = os.path.getsize(self.key)

		self.size_light = ""
		self.width_light = ""
		self.height_light = ""

		filename_light = common.light_name(self.key)

		if (os.path.isfile(filename_light)) :
			self.size_light = os.path.getsize(filename_light)

			if (cmp(self.mediatype, "image") == 0) :
				(foo, self.width_light, self.height_light) = ui.get_image_info(filename_light)
Beispiel #2
0
	def update(self) :
		
		ui.Page.update(self)

		(image_type, width, height) = ui.get_image_info(self.puzzle_file)

	
	
		self.game_area_width = self.screen.get_width()
		self.game_area_height = (self.screen.get_height()*self.height_percent_puzzle) // 100
	
		self.start_posy_puzzle = (self.start_posy_puzzle_percent * self.screen.get_height()) // 100
	
		max_width = self.game_area_width
		max_height = self.game_area_height	
	
		if ((width < max_width) and (height < max_height)) :
			ratio = (height*1.0) / width
			
			width = max_width
			height = ratio * width	
			
		amount_pieces = 0
	
		while (amount_pieces < self.pieces_amount_x * self.pieces_amount_y) :
			max_width = max_width * 0.97
			max_height = max_height * 0.98
			
			if (width > max_width) :
				# we must keep proportions so we have to change the height...
				new_height = (height * max_width) // width
				new_width = max_width
						
			elif (height > max_height) :
				# we must keep proportions so we have to change the width...
				new_width = (width * max_height) // height
				new_height = max_height	
		
			else :
				new_width = width
				new_height = height
			
		
			# puzzle looks like this :
			#
			#  OOO PPPPP OOO
			#  OOO PPPPP OOO
			#  OOO PPPPP OOO
			#  OOOOOOOOOOOOO
			#  OOOOOOOOOOOOO
			#
			# O = a piece
			# P = the puzzle itself
			
			piece_space_x = (new_width * self.ratio_spacing_pieces_x) // self.pieces_amount_x
			piece_space_y = (new_height * self.ratio_spacing_pieces_y) // self.pieces_amount_y
			
			usable_x_top = (self.game_area_width - new_width)//2
			amount_x_pieces_top = usable_x_top // piece_space_x
			
			#print "amount_x_pieces_top " + str(amount_x_pieces_top)	
			
			usable_y_top = new_height
			amount_y_pieces_top = usable_y_top // piece_space_y
	
			#print "amount_y_pieces_top " + str(amount_y_pieces_top)	
	
			usable_x_bottom = self.game_area_width
			amount_x_pieces_bottom = usable_x_bottom // piece_space_x
			
			#print "amount_x_pieces_bottom " + str(amount_x_pieces_bottom)		
			
			usable_y_bottom = self.game_area_height - new_height
			amount_y_pieces_bottom = usable_y_bottom // piece_space_y
			
			#print "amount_y_pieces_bottom " + str(amount_y_pieces_bottom)
			
			amount_pieces = (2 * (amount_x_pieces_top * amount_y_pieces_top)) + (amount_x_pieces_bottom * amount_y_pieces_bottom)
			
			#print "amount_pieces " + str(amount_pieces)
		
		
		(resized_bitmap, foo) = ui.load_image(self.puzzle_file, (new_width, new_height))
		
		new_width = resized_bitmap.get_width()
		new_height = resized_bitmap.get_height()
	
		if (amount_y_pieces_top == 0) :
			amount_x_pieces_top = 0
			
		if (amount_x_pieces_top == 0) :
			amount_y_pieces_top = 0
	
		
		self.puzzle_image = ui.Image_Absolute(self, ((self.screen.get_width()-new_width) // 2, self.start_posy_puzzle), (new_width, new_height), resized_bitmap)	
		
		piece_size_x = new_width  // self.pieces_amount_x
		piece_size_y = new_height // self.pieces_amount_y
			
		rel_x = -1
		rel_y = 1
		
		delta_x = (piece_space_x - piece_size_x) // 2
		
		delta_y = (piece_space_y - piece_size_y) // 2

		self.puzzle_pieces = []
		self.tuxes = []		
		self.empty_locations = []
		
		for x in range(self.pieces_amount_x) :
			x_pos = x * piece_size_x
			for y in range(self.pieces_amount_y) :
				y_pos = y * piece_size_y
				
				size_x = piece_size_x
				size_y = piece_size_y
	
				if ((x == self.pieces_amount_x - 1) and (x_pos + piece_size_x > self.puzzle_image.surface.get_width())) :
					size_x = self.puzzle_image.surface.get_width() - x_pos
						
				if ((y == self.pieces_amount_y - 1) and (y_pos + piece_size_y > self.puzzle_image.surface.get_height())) :
					size_y = self.puzzle_image.surface.get_height() - y_pos
						
				if (rel_y <= amount_y_pieces_top) :
					# we are in the top part, on the left and right of the finished puzzle
					if (rel_x < 0) :
						# on the left of the finished puzzle
						x_piece_pos = self.puzzle_image.rect.centerx + rel_x * piece_space_x - self.puzzle_image.surface.get_width() // 2
					else :
						# on the right of the finished puzzle
						x_piece_pos = self.puzzle_image.rect.centerx + (rel_x - 1) * piece_space_x + self.puzzle_image.surface.get_width() // 2
					
					y_piece_pos = self.puzzle_image.rect.bottom - (rel_y  * piece_space_y)
				
				else :
					# we are below the finished puzzle
					if (rel_x < 0) :
						if (amount_x_pieces_bottom % 2 == 0) :
							x_piece_pos = self.puzzle_image.rect.centerx + (rel_x  * piece_space_x)
						else :
							x_piece_pos = self.puzzle_image.rect.centerx + ((rel_x+0.5)  * piece_space_x)
					else :
						if (amount_x_pieces_bottom % 2 == 0) :
							x_piece_pos = self.puzzle_image.rect.centerx + ((rel_x-1)  * piece_space_x) 
						else :
							x_piece_pos = self.puzzle_image.rect.centerx + ((rel_x-0.5)  * piece_space_x) 
					
					y_piece_pos = self.puzzle_image.rect.bottom + ((rel_y - 1 - amount_y_pieces_top) * piece_space_y)				
					
					
					
	
				
				if (rel_x < 0) :
					rel_x = -rel_x
	
					if ((amount_x_pieces_bottom % 2 == 1) and (rel_x > amount_x_pieces_bottom // 2) and (rel_y > amount_y_pieces_top)) :
						rel_x = -1
						rel_y = rel_y + 1
	
				else :
					rel_x = - (rel_x + 1)
					
					if (((rel_y <= amount_y_pieces_top) and (rel_x < -amount_x_pieces_top)) or ((amount_x_pieces_bottom % 2 == 0) and (rel_x < -(amount_x_pieces_bottom // 2)) and (rel_y > amount_y_pieces_top))) :	
							rel_y = rel_y + 1
							rel_x = -1
				
						

						
						
				empty_location = ui.Empty_Box_Absolute(self, (x_pos + self.puzzle_image.rect.left, y_pos + self.puzzle_image.rect.top), (size_x, size_y), constants.line_color, constants.line_alpha)
				
				self.append_back(empty_location)
				
				self.empty_locations.append(empty_location)
				
				
				
				((tux_x_percent, tux_y_percent), (tux_width_percent, tux_height_percent)) = ( \
				(self.x_px2pc(x_pos + self.puzzle_image.rect.left), self.y_px2pc(y_pos + self.puzzle_image.rect.top)), \
				(self.x_px2pc(size_x), self.y_px2pc(size_y)))



				
				tux = ui.Image(self, (tux_x_percent, tux_y_percent), (tux_width_percent, tux_height_percent), self.game.goal_image_file, self.alpha_tux, self.tux_size_ratio_percent)
				
				self.append_back(tux)
				
				self.tuxes.append(tux)
				
				
				
				piece_image = ui.Image_Absolute(self, (x_piece_pos + delta_x, y_piece_pos + delta_y), (size_x, size_y), resized_bitmap.subsurface(Rect((x_pos, y_pos), (size_x, size_y))))
				
				piece_image.set_associated_object(empty_location)
				
				self.append(piece_image)
								
				self.puzzle_pieces.append(piece_image)
				

		common.randomize_rects(self.puzzle_pieces)

		common.center_vert_absolute(self.puzzle_pieces + self.tuxes + self.empty_locations, self.start_posy_puzzle, self.game_area_height)

		if (cmp(self.puzzle.text, "") == 0) :

			text = self.puzzle.game.get_title(self.language)
			
		else :
			text = self.puzzle.text


		self.draw_back()
Beispiel #3
0
    def init_background(self):

        # the background of the igloo is indeed a part of the menu background image

        common.info("Init igloo background - start")

        (surface, dim) = ui.load_image(constants.main_menu_back)

        (surface_x_pc, surface_y_pc) = constants.igloo_pos

        surface_x = int((surface_x_pc * surface.get_width()) / 100)
        surface_y = int((surface_y_pc * surface.get_height()) / 100)

        (surface_width_pc, surface_height_pc) = constants.igloo_size

        surface_width = int((surface_width_pc * surface.get_width()) / 100)
        surface_height = int((surface_height_pc * surface.get_height()) / 100)

        self.surface_to_zoom_rect = Rect(surface_x, surface_y, surface_width,
                                         surface_height)

        surface_to_zoom = surface.subsurface(self.surface_to_zoom_rect)

        self.background = pygame.transform.scale(
            surface_to_zoom,
            (self.screen.get_width(), self.screen.get_height()))

        # now let's go back to screen dimensions :
        surface_x = int(self.x_pc2px(surface_x_pc))
        surface_y = int(self.y_pc2px(surface_y_pc))

        surface_width = int(self.x_pc2px(surface_width_pc))
        surface_height = int(self.y_pc2px(surface_height_pc))

        self.surface_to_zoom_rect = Rect(surface_x, surface_y, surface_width,
                                         surface_height)

        # adding the igloo
        self.igloo = ui.Image(self, (0, 0), (100, 100), constants.igloo_file,
                              255, 100, "TOPLEFT")

        self.append_back(self.igloo)

        # not clean, but same trick as used in ui.Page.draw_back()
        save_screen = self.screen
        self.screen = self.background
        self.igloo.draw()
        self.screen = save_screen

        (foo, initial_width,
         initial_height) = ui.get_image_info(constants.igloo_file)
        coord_convert_igloo = ui.Coordinates_converter(
            self, Rect((0, 0), (initial_width, initial_height)),
            self.igloo.rect)

        # not very clean: as the limit is the height
        # we assume width could be three times as big (for instance !)
        self.tux_size = coord_convert_igloo.get_coords_px2pc(
            (3 * constants.tux_height, constants.tux_height))

        self.tux_initial_pos = coord_convert_igloo.get_coords_px2pc(
            constants.tux_initial_pos)

        (self.flag_mast_pos_x,
         self.flag_mast_pos_y) = coord_convert_igloo.get_coords_px2pc(
             (constants.flag_mast_pos_x_px, 0))

        common.info("Init igloo background - before reducing")

        self.igloo_reduced_surface = pygame.transform.scale(
            self.background, self.surface_to_zoom_rect.size)

        common.info("Init igloo background - end")
Beispiel #4
0
	def init_background(self) :

		# the background of the igloo is indeed a part of the menu background image

		common.info("Init igloo background - start")

 		(surface, dim) = ui.load_image(constants.main_menu_back)

		(surface_x_pc, surface_y_pc) = constants.igloo_pos

		surface_x = int((surface_x_pc * surface.get_width()) / 100)
		surface_y = int((surface_y_pc * surface.get_height()) / 100)

		(surface_width_pc, surface_height_pc) = constants.igloo_size

		surface_width = int((surface_width_pc * surface.get_width()) / 100)
		surface_height = int((surface_height_pc * surface.get_height()) / 100)


		self.surface_to_zoom_rect = Rect(surface_x, surface_y, surface_width, surface_height)

		surface_to_zoom = surface.subsurface(self.surface_to_zoom_rect)

		self.background = pygame.transform.scale(surface_to_zoom, (self.screen.get_width(), self.screen.get_height()))
		
		# now let's go back to screen dimensions :
		surface_x = int(self.x_pc2px(surface_x_pc))
		surface_y = int(self.y_pc2px(surface_y_pc))

		surface_width = int(self.x_pc2px(surface_width_pc))
		surface_height = int(self.y_pc2px(surface_height_pc))

		self.surface_to_zoom_rect = Rect(surface_x, surface_y, surface_width, surface_height)

		
		# adding the igloo
		self.igloo = ui.Image(self, (0,0), (100,100), constants.igloo_file, 255, 100, "TOPLEFT")
		
		self.append_back(self.igloo)

		# not clean, but same trick as used in ui.Page.draw_back()
		save_screen = self.screen
		self.screen = self.background
		self.igloo.draw()
		self.screen = save_screen

		(foo, initial_width, initial_height) = ui.get_image_info(constants.igloo_file)
		coord_convert_igloo = ui.Coordinates_converter(self, Rect((0,0), (initial_width, initial_height)), self.igloo.rect)
		
		# not very clean: as the limit is the height
		# we assume width could be three times as big (for instance !)
		self.tux_size = coord_convert_igloo.get_coords_px2pc((3 * constants.tux_height, constants.tux_height))

		self.tux_initial_pos = coord_convert_igloo.get_coords_px2pc(constants.tux_initial_pos)

		(self.flag_mast_pos_x, self.flag_mast_pos_y) = coord_convert_igloo.get_coords_px2pc((constants.flag_mast_pos_x_px, 0))


		common.info("Init igloo background - before reducing")

		self.igloo_reduced_surface = pygame.transform.scale(self.background, self.surface_to_zoom_rect.size)

		common.info("Init igloo background - end")