graphics

Classes concerned with the screen and drawing things on it.

class graphics.Font(image, ink_key, paper_key)

The skool font.

Parameters:
  • image (Image) – The font image.
  • ink_key (RGB triplet) – The ink colour in font.png (used to create transparency).
  • paper_key (RGB triplet) – The paper colour in font.png (used to create transparency).
add_character(char, offset, width)

Define the location and width of a font character bitmap in the font image.

Parameters:
  • char – The font character.
  • offset – The offset (in pixels) of the font character bitmap from the left edge of the font image.
  • width – The width of the font character bitmap.
has_char(char)

Return whether the skool font contains a bitmap for a given character.

Parameter:char – The character to look for.
render(words, ink, paper)

Return an image (a pygame.Surface) of a text message written in the skool font.

Parameters:
  • words – The message.
  • ink – RGB triplet
  • ink – The desired ink colour.
  • paper – RGB triplet
  • paper – The desired paper colour.
class graphics.Gallery(config, scale, images)

A container for all the images used in a game.

Parameters:
  • config (dict) – Configuration parameters from the ini file.
  • scale – The desired scale of the images; if None, the Scale configuration parameter will be used to set the scale.
  • images (dict) – Key-value pairs (image ID, path) from the Images section.
get_image(image_id)

Return an Image from the gallery, or None if there is no image in the gallery with the given ID. The image will be scaled up as necessary.

Parameter:image_id – The ID of the image.
get_surface(image_id)

Return an image (a pygame.Surface) from the gallery, or None if there is no image in the gallery with the given ID. The image will be scaled up as necessary.

Parameter:image_id – The ID of the image.
class graphics.Image(gallery, image_id, surface, top_left=None, flipped=False)

A container for a pygame.Surface. This is used to handle the saving and restoring of images, because a pygame.Surface cannot be pickled directly.

Parameters:
  • gallery (Gallery) – The gallery of images.
  • image_id – The ID of the image (the parent image) from which this image is derived.
  • surface (pygame.Surface) – The image itself.
  • top_left – The coordinates of the top-left corner of this image inside the parent image.
  • flipped – If True, the image will be flipped before use.
blit(*args)

Blit a pygame.Surface onto this image.

Parameter:args – Arguments passed to pygame.Surface.blit().
copy()
Return a copy of the image.
flip()
Return a flipped copy of the image.
get_height()
Return the width of the image.
get_size()
Return the size (width, height) of the image.
get_width()
Return the width of the image.
set_colorkey(colorkey)

Set the colour key of the image.

Parameter:colorkey – The colour key.
subsurface(coords, size)

Return a subsurface of the image.

Parameters:
  • coords – The coordinates of the top-left corner of the subsurface.
  • size – The size of the subsurface.
class graphics.Screen(config, gallery, title_prefix)

Represents the screen upon which everything is drawn.

Parameters:
  • config (dict) – Configuration parameters from the ini file.
  • gallery (Gallery) – The gallery of images to use for drawing.
  • title_prefix – The window title prefix.
add_font_character(char, offset, width)

Define the location and width of a font character bitmap in the font image.

Parameters:
  • char – The font character.
  • offset – The offset (in pixels) of the font character bitmap from the left edge of the font image.
  • width – The width of the font character bitmap.
contains(character, full=True)

Return whether a character is on-screen.

Parameters:
  • character (Character) – The character to check.
  • full – If True, return whether the character’s entire sprite is on-screen; if False, return whether any part of the character’s sprite is on-screen.
draw(skool_images, cast, speech_bubbles, update)

Draw everything on the screen.

Parameters:
  • skool_images – The play area images.
  • cast – The cast (3-tuples, (x, y, image), where x and y are the coordinates, and image is an image of a cast member).
  • speech_bubbles – Speech bubbles (3-tuples, (x, y, image)).
  • update – Whether to update the screen after drawing.
get_bubble(words, lip_pos, shift)

Create a speech bubble displaying a portion of a message.

Parameters:
  • words – The text of the message.
  • lip_pos – The offset (in tiles) from the left edge of the speech bubble at which to place the lip.
  • shift – The offset (in tiles) by which to shift the text image before displaying it in the bubble; if negative, leading spaces will be displayed.
Returns:

A 2-tuple, (bubble, done), where bubble is the speech bubble image (an Image), and done is True if the entire message has been spoken, False otherwise.

get_scroll_increment(x)

Return the direction in which the screen should be scrolled when Eric is at a given x-coordinate.

Parameter:x – Eric’s x-coordinate.
Returns:-1 if the screen should scroll right, 1 if it should scroll left, or 0 if it should not scroll.
get_text(words, ink, paper, transparent=True)

Return a pygame.Surface displaying some text in the skool font.

Parameters:
  • words – The text.
  • ink – The ink colour to use.
  • paper – The paper colour to use.
  • transparent – Whether the paper colour should be transparent.
has_font_char(char)

Return whether the skool font contains a bitmap for a given character.

Parameter:char – The character to look for.
initialise_column(skool_width, eric_x)

Set the leftmost column of the play area that will appear on the screen when the game starts.

Parameters:
  • skool_width – The width of the entire play area (in pixels).
  • eric_x – Eric’s initial x-coordinate.
print_inventory(item_images=())

Print the inventory. If no inventory is defined, nothing happens.

Parameter:item_images – A sequence of item images to draw in the inventory box.
print_lesson(*text_lines)

Print some text in the lesson box.

Parameter:text_lines – The lines of text to print.
print_message_box(x, y, message, ink, paper)

Print a message box.

Parameters:
  • x – The x-coordinate of the messenger’s head.
  • y – The y-coordinate of the messenger’s head.
  • message (tuple) – The lines of text to write in the box.
  • ink (RGB triplet) – The ink colour of the box.
  • paper (RGB triplet) – The paper colour of the box.
print_mice(count=0, mouse_image=None)

Print the mouse inventory. If no mouse inventory is defined, nothing happens.

Parameters:
  • count – The number of mice to draw.
  • mouse_image – An image of a captured mouse.
print_score_box(score, lines, hi_score)

Print the score, lines total and hi-score in the score box.

Parameters:
  • score – The score.
  • lines – The lines total.
  • hi_score – The hi-score.
reinitialise()
Reinitialise the screen for a new game.
scale_coords(coords)

Scale up a pair of coordinates and return them.

Parameter:coords – The coordinates.
scroll(inc, skool, clock)

Scroll the skool a number of columns across the screen.

Parameters:
  • inc – The scroll increment (-1 to scroll one column at a time rightwards, 1 to scroll one column at a time leftwards).
  • skool (Skool) – The skool.
  • clock (pygame.time.Clock) – The clock to use to time the scrolling.
scroll_skool(skool, clock)

Scroll the skool across the entire width of the screen from right to left.

Parameters:
  • skool (Skool) – The skool.
  • clock (pygame.time.Clock) – The clock to use to time the scrolling.
setup(set_mode=False)

Set up the following things:

  • the window title and icon
  • the screen background
  • the logo image
  • the score box
  • (optionally) the size of the screen
Parameter:set_mode – If True, the size of the screen will be set.
take_screenshot(filename)

Take a screenshot and save it to a file.

Parameter:filename – The name of the file.
graphics.FONT
ID of the font image.
graphics.INVENTORY
ID of the inventory items image.
graphics.LESSON_BOX
ID of the lesson box image.
ID of the logo image.
graphics.MESSAGE_BOX
ID of the message box image.
graphics.MUTABLES
ID of the mutables image.
graphics.MUTABLES_INK
ID of the ink-only mutables image.
graphics.MUTABLES_PAPER
ID of the paper-only mutables image.
graphics.SCOREBOX
ID of the score box image.
graphics.SKOOL
ID of the play area image.
graphics.SKOOL_INK
ID of the ink-only play area image.
graphics.SKOOL_PAPER
ID of the paper-only play area image.
graphics.SPEECH_BUBBLE
ID of the speech bubble image.
graphics.SPRITES
ID of the sprites image.

Previous topic

game

Next topic

input