core.tools module

core.tools.calc_dialog_rect(screen_rect)[source]

Return a rect that is the area for a dialog box on the screen

Parameters:screen_rect
Returns:
core.tools.check_parameters(parameters, required=0, exit=True)[source]

Checks to see if a given list has the required number of items

core.tools.convert_alpha_to_colorkey(surface, colorkey=(255, 0, 255))[source]

Convert image with perpixel alpha to normal surface with colorkey

This is a crude hack that only works well with images that do not have alpha blended antialiased edges. Using this function on such images will result in discoloration of edges.

Parameters:
  • surface (pygame.Surface) – Some image to change
  • colorkey (Sequence or pygame.Color) – Colorkey to use for transparency
Returns:

Modified surface

Return type:

pygame.Surface

core.tools.cursor_from_image(image)[source]

Take a valid image and create a mouse cursor.

core.tools.get_cell_coordinates(rect, point, size)[source]

Find the cell of size, within rect, that point occupies.

core.tools.load_and_scale(filename)[source]

Load an image and scale it according to game settings

  • Filename will be transformed to be loaded from game resource folder
  • Will be converted if needed.
  • Scale factor will match game setting.
Parameters:filename
Return type:pygame.Surface
core.tools.load_image(filename)[source]

Load image from the resources folder

  • Filename will be transformed to be loaded from game resource folder
  • Will be converted if needed.

This is a “smart” loader, and will convert files in the best way, but is slightly slower than just loading. Its important that this is not called too often (like once per draw!)

Parameters:filename – String
Return type:pygame.Surface
core.tools.load_sound(filename)[source]

Load a sound from disk

The required path will be appended to the filename

Parameters:filename (basestring) – filename to load
Return type:core.platform.mixer.Sound
core.tools.load_sprite(filename, **rect_kwargs)[source]

Load an image from disk and return a pygame sprite

Image name will be transformed and converted Rect attribute will be set

Any keyword arguments will be passed to the get_rect method of the image for positioning the rect.

Parameters:filename – Filename to load
Return type:core.components.sprite.Sprite
core.tools.new_scaled_rect(*args, **kwargs)[source]

Create a new rect and scale it

Parameters:
  • args – Normal args for a Rect
  • kwargs – Normal kwargs for a Rect
Return type:

pygame.rect.Rect

core.tools.open_dialog(game, text)[source]

Open a dialog with the standard window size

Parameters:
  • game
  • text – list of strings
Returns:

core.tools.scale(number)[source]

Scale the thing

Parameters:number – int
Return type:int
core.tools.scale_rect(rect, factor=5)[source]

Scale a rect. Returns a new object.

Parameters:
  • rect – pygame Rect
  • factor – int
Return type:

pygame.rect.Rect

core.tools.scale_sequence(sequence)[source]

Scale the thing

Parameters:sequence
Return type:list
core.tools.scale_sprite(sprite, ratio)[source]

Scale a sprite’s image in place

Parameters:ratio – amount to scale by
Return type:core.components.sprite.Sprite
core.tools.scale_surface(surface, factor)[source]

Scale a surface. Just a shortcut.

Returns:Scaled surface
Return type:pygame.Surface
core.tools.scale_tile(surface, tile_size)[source]

Scales a map tile based on resolution.

Return type:pygame.Surface
core.tools.smart_convert(image)[source]

Given an unconverted file, determine if it has transparent pixels and return a converted image, with per-pixel alpha if needed.

Parameters:image – pygame.Surface
Return type:pygame.Surface
core.tools.strip_coords_from_sheet(sheet, coords, size)[source]

Strip specific coordinates from a sprite sheet.

core.tools.strip_from_sheet(sheet, start, size, columns, rows=1)[source]

Strips individual frames from a sprite sheet given a start location, sprite size, and number of columns and rows.

core.tools.transform_resource_filename(filename)[source]

Appends the resource folder name to a filename

Parameters:filename – String
Return type:basestring