graphics

Classes concerned with the screen and drawing things on it.

class graphics.Font(image, ink_key, paper_key)

The skool font.

Parameters:
  • image (pygame.Surface) – 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(images_dir, image_set, scale, images)

A container for all the images used in a game.

Parameters:
  • images_dir – The base directory for the images.
  • image_set – The name of the image set.
  • scale – The desired scale of the images.
  • images (dict) – Key-value pairs (image ID, path) from the Images section.
get_image(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.Screen(config, scale, gallery, title, icon_fname)

Represents the screen upon which everything is drawn.

Parameters:
  • config (dict) – Configuration parameters from the ini file.
  • scale – The scale at which the screen will be drawn.
  • gallery (Gallery) – The gallery of images to use for drawing.
  • title – The window title.
  • icon_fname – The filename of the Pyskool icon.
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, blackboards, cast, others, update)

Draw everything on the screen.

Parameters:
  • skool_images – The play area images.
  • blackboards – The blackboards (3-tuples, (x, y, image), where x and y are the coordinates, and image is an image of the blackboard).
  • cast – The cast (3-tuples, (x, y, image), where x and y are the coordinates, and image is an image of a cast member).
  • others – Anything else to be drawn (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 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 (a pygame.Surface), 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)

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.
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(initial_column, skool_width, eric_x)

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

Parameters:
  • initial_column – The initial leftmost column.
  • skool_width – The width of the entire play area (in pixels).
  • eric_x – Eric’s initial x-coordinate.
print_hi_score(hiscore)

Print the hi-score in the score box.

Parameter:hiscore – The hi-score.
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_lines(lines)

Print the lines total in the score box.

Parameter:lines – The lines total.
print_lines_bubble(x, y, message, ink, paper)

Print a lines message bubble.

Parameters:
  • x – The x-coordinate of the lines-giver’s head.
  • y – The y-coordinate of the top row of the bubble.
  • message (tuple) – The lines of text to write in the bubble.
  • ink (RGB triplet) – The ink colour of the bubble.
  • paper (RGB triplet) – The paper colour of the bubble.
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(score)

Print the score in the score box.

Parameter:score – The 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.
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.
ID of the logo 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