graphics

Classes concerned with the screen and drawing things on it.

class graphics.Font(image)

The skool font.

Parameter:image (pygame.Surface) – The font image.
add_character_offset(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 – The desired ink colour.
  • 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) – The images (keyed by image ID).
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) – Screen configuration parameters (from the Screen section of 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.
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)

Draw everything on the screen.

Parameters:
  • skool_images – The play area images.
  • blackboards – The blackboards (3-tuples, (x, y, text), where x and y are the coordinates, and text is a list of images of the blackboard contents).
  • cast – The cast (3-tuples, (x, y, sprite), where x and y are the coordinates, and sprite is an image of a cast member).
  • others – Anything else to be drawn (3-tuples, (x, y, image)).
draw_blackboard(surface, x, y, text)

Draw the contents of a blackboard.

Parameters:
  • surface (pygame.Surface) – The surface on which to draw the blackboard contents.
  • x – The x-coordinate of the leftmost column of the blackboard.
  • y – The y-coordinate of the top row of the blackboard.
  • text (pygame.Surface) – A list of images of the blackboard contents.
draw_image(surface, x, y, image)

Draw an image on a surface.

Parameters:
  • surface (pygame.Surface) – The surface on which to draw the image.
  • x – The x-coordinate of the image.
  • y – The y-coordinate of the image.
  • image (pygame.Surface) – The image.
draw_skool(surface, skool)

Draw the skool.

Parameters:
  • surface (pygame.Surface) – The surface on which to draw the skool.
  • skool (pygame.Surface) – An image of the play area.
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_ink_and_paper(attribute)

Return the ink and paper colour derived from an attribute byte. The ink colour is taken from bits 6 (BRIGHT) and 0-2; the paper colour is taken from bits 3-6.

Parameter:attribute – The attribute byte.
Returns:A 2-tuple containing the ink and paper colours.
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.
initialise_colours()
Initialise the colour palette.
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 tiles).
  • 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_colour, paper_colour)

Print a lines message bubble.

Parameters:
  • x – The x-coordinate of the leftmost column of the bubble.
  • y – The y-coordinate of the top row of the bubble.
  • message – The message to write in the bubble.
  • ink_colour – The ink colour of the bubble.
  • paper_colour – 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_number(number, y_offset)

Print a number (the score, lines total, or hi-score) in the score box.

Parameters:
  • number – The number.
  • y_offset – The vertical offset from the top of the score box at which to print the number.
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.
update()
Update the screen.
graphics.BLACK
RGB triplet for black.
graphics.BLUE
RGB triplet for blue.
graphics.BRIGHT_BLACK
RGB triplet for bright black.
graphics.BRIGHT_BLUE
RGB triplet for bright blue.
graphics.BRIGHT_CYAN
RGB triplet for bright cyan.
graphics.BRIGHT_GREEN
RGB triplet for bright green.
graphics.BRIGHT_MAGENTA
RGB triplet for bright magenta.
graphics.BRIGHT_RED
RGB triplet for bright red.
graphics.BRIGHT_WHITE
RGB triplet for bright white.
graphics.BRIGHT_YELLOW
RGB triplet for bright yellow.
graphics.CYAN
RGB triplet for cyan.
graphics.FONT
ID of the font image.
graphics.FONT_INK
Ink colour in font.png (used to create transparency).
graphics.FONT_PAPER
Paper colour in font.png (used to create transparency).
graphics.GREEN
RGB triplet for green.
graphics.HISCORE_Y_OFFSET
Offset used to position printing of the hi-score.
graphics.INVENTORY
ID of the inventory items image.
graphics.INVENTORY_SIZE
Size of the inventory (width and height in tiles).
graphics.LESSON_BOX_SIZE
Size of the lesson box (width and height in tiles).
graphics.LINES_BUBBLE_SIZE
Size of a lines bubble (width and height in tiles).
graphics.LINES_Y_OFFSET
Offset used to position printing of the lines total.
ID of the logo image.
graphics.MAGENTA
RGB triplet for magenta.
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.OPEN_LIP_BYTE
Bit pattern used to open the lip of the speech bubble.
graphics.RED
RGB triplet for red.
graphics.SCOREBOX
ID of the score box image.
graphics.SCORE_Y_OFFSET
Offset used to position printing of the score.
graphics.SKOOL
ID of the play area image.
graphics.SKOOL_COLORKEY
Transparent colour used in the skool ink 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.SPEECH_BUBBLE_COLORKEY
Transparent colour used in the speech bubble.
graphics.SPEECH_BUBBLE_INSET_X
Inset (in pixels) of the text window from the left and right edges of a speech bubble.
graphics.SPEECH_BUBBLE_INSET_Y
Inset (in pixels) of the text window from the top edge of a speech bubble.
graphics.SPEECH_BUBBLE_SIZE
Size of the bounding rectangle of a speech bubble (width and height in tiles).
graphics.SPRITES
ID of the sprites image.
graphics.WHITE
RGB triplet for white.
graphics.YELLOW
RGB triplet for yellow.

Previous topic

game

Next topic

input