Previous topic

cast

Next topic

debug

character

Defines the Character class, which determines how characters are animated and how they behave.

class pyskool.character.Character(character_id, name, head_xy=None, flags='')

Base class for anything in the game that moves.

Parameters:
  • character_id – Unique ID.
  • name – Display name.
  • head_xy – The coordinates of the character’s head within his sprite when he’s standing upright (used for collision detection).
  • flags – Character flags.
add_blackboard_message(message)

Add a blackboard message to the character’s repertoire.

Parameters:message – The message to add.
add_command(command)

Add a command to the character’s command list. The command will become the character’s current command (that is, it will be executed the next time the character is moved).

Parameters:command (Command) – The command to add.
add_command_list(lesson_id, command_list_id)

Add a command list ID to the character’s personal timetable.

Parameters:
  • lesson_id – The ID of the lesson in which the command list will be used.
  • command_list_id – The command list ID.
add_lesson_message(message, condition)

Add a lesson message to the character’s collection. A lesson message is something like ‘START READING AT THE NEXT CHAPTER IN YOUR BOOKS’, which will be used by a teacher during class if he’s not teaching Eric, or he has decided not to have a question-and-answer session with the swot.

Parameters:
  • message – The lesson message.
  • condition – The condition identifier; the lesson message will be used only if this condition is true.
add_lines(lines)

Add lines to Eric’s total.

Parameters:lines – The number of lines to add.
add_lines_message(message_id, message_lines)

Add a lines message to the character’s collection of lines messages that he is authorised to utter.

Parameters:
  • message_id – The lines message ID.
  • message_lines – A 2-element tuple containing the lines of text of the message.
add_sit_down_message(message)

Add a sit-down message to the character’s repertoire.

Parameters:message – The message to add.
adds_to_lines_total()

Return whether any lines the character gets are added to Eric’s total.

adds_to_score()

Return whether any lines the character gets are added to Eric’s score.

aim_catapult()

Make the character finish raising his catapult (to firing height).

aim_water_pistol()

Make the character aim his water pistol.

build_images()

Build the animatory state images for the character. This method is called after rescaling the screen or loading a saved game.

can_drop_stinkbomb()

Return whether the character can drop a stinkbomb. The answer will be True if and only if all of the following conditions are met:

  • the character has an ARM_UP sprite
  • the character can drop stinkbombs
  • the character’s stinkbomb cloud sprite is not currently visible
can_fire_catapult()

Return whether the character can fire a catapult. The answer will be True if and only if all of the following conditions are met:

  • the character has CATAPULT0 and CATAPULT1 sprites
  • the character has a catapult pellet
  • the catapult pellet is not currently airborne
can_fire_water_pistol()

Return whether the character can fire a water pistol. The answer will be True if and only if all of the following conditions are met:

  • the character has a WATERPISTOL sprite
  • the character has a water pistol
  • the character’s water/sherry sprite is not currently visible
can_give_lines()

Return whether the character can give lines.

can_give_lines_message(message_id)

Return whether the character is authorised to utter a given lines message.

Parameters:message_id – The ID of the lines message to check.
can_give_lines_now()

Return whether the character is in an animatory state and location that are amenable to him giving lines.

can_kiss_eric()

Return whether the character can kiss Eric. The answer is True if the character has a KISSING_ERIC sprite defined.

can_open_door(door)

Return whether the character can open a door.

Parameters:door – The door.
can_open_doors()

Return whether the character can open doors and windows.

can_receive_lines()

Return whether the character can be given lines.

can_see_special_answer()

Return whether the character can see his special answer written on a blackboard.

can_sit_on_stairs()

Return whether the character can sit on the stairs.

can_smell_stinkbomb(stinkbomb)

Return whether the character can smell a given stinkbomb. The answer will be true if the character:

  • can smell stinkbombs generally, and
  • is standing up, and
  • is on the same floor as and within smelling range of the stinkbomb
Parameters:stinkbomb – The stinkbomb to check.
can_smell_stinkbombs()

Return whether the character can smell stinkbombs (and will be compelled to open a nearby window if he smells one).

chair(check_dir=True)

Return the chair that is beside the character.

Parameters:check_dir – If True, return the chair only if the character is facing the correct way to sit in it; otherwise, return the chair whichever way the character is facing.
Returns:The chair, or None if there is none.
change_command_list(command_list_id)

Make the character switch to a different command list immediately.

Parameters:command_list_id – The ID of the command list to switch to.
check_door_status(barrier_id, shut)

Return whether a door or window is in a given state (open or closed).

Parameters:
  • barrier_id – The ID of the door or window.
  • shutTrue to check whether the door or window is closed, False to check whether it’s open.
check_mouse(mouse)

Make the character respond appropriately to a mouse. The character will start jumping up and down if he:

  • is scared of mice, and
  • is on the same floor as the mouse, and
  • is facing it, and
  • is close enough to see it, and
  • is not doing anything else that precludes jumping up and down
Parameters:mouse – The mouse to check.
check_shields_at(x, y)

Return whether there is a shield at a given location.

Parameters:
  • x – The x-coordinate to check.
  • y – The y-coordinate to check.
complete_action()

Restore the character’s animatory state after completing an action (such as firing a catapult or water pistol).

deck(paralyse=False)

Knock the character to the floor (as when struck by a fist or catapult pellet).

Parameters:paralyse – If True, the character will be rendered unconscious until shortly before the bell is due to ring (as when Albert is struck by a falling conker).
dethrone()

Knock the character out of his seat.

down()

Move the character downwards.

drop_stinkbomb()

Make the character drop a stinkbomb. A stinkbomb cloud will appear as a result.

end_game()

End the game.

eric_understood()

Return whether Eric has acknowledged understanding of a message delivered to him.

expand_names(message)

Return a message with character name macros expanded. A character name macro takes the form $WACKER (for example), which expands to the name of the character whose ID is WACKER.

Parameters:message – The message that may contain unexpanded name macros.
fall_off_plant()

Make the character fall off a plant that has just died. This method adds a FallToFloor command to the character’s command list. It is not currently used by any non-player characters, because they never climb onto plants.

fall_to_floor()

Make the character sit on the floor for a bit (as after falling off a plant that has just died, or upon landing after jumping from the saddle of a bike). This method is not currently used by any non-player characters, because they never climb onto plants or ride bikes.

finish_kiss()

Restore the character’s animatory state after kissing Eric.

finished_speaking()

Called by the swot or the teacher when he’s finished speaking.

fire_catapult()

Make the character launch his catapult pellet.

fire_water_pistol(liquid=None)

Make the character fire his water pistol. A stream of water or sherry will begin its trajectory as a result.

Parameters:liquid – The ID of the liquid.
freeze_eric()

Freeze Eric (as when he is being spoken to by a little boy, or by Mr Wacker for having exceeded the lines limit).

get_GoTo_destination()

Return the character’s destination, or None if he is not under the control of a GoTo command.

get_assembly_message()

Return a message to deliver during assembly (with verb and noun randomly chosen).

get_blackboard()

Return the blackboard in the room in which the character is located, or None if there is none.

get_blackboard_backtrack()

Return the distance a teacher should walk back after wiping a blackboard.

get_blackboard_message()

Return a blackboard message randomly chosen from the character’s collection.

get_blackboard_pace_distance()

Return the distance a teacher should pace up and down in front of the blackboard during a lesson without a question-and-answer session.

get_come_along_message_id()

Return the ID of the message for Eric’s teacher to use next as he encourages him to stop playing truant.

Returns:COME_ALONG1, COME_ALONG2, or COME_ALONG3.
get_command_list_id(lesson_id)

Return a command list ID from the character’s personal timetable.

Parameters:lesson_id – The ID of the lesson to retrieve the command list for.
get_destination(character_id)

Return the destination of another character.

Parameters:character_id – The ID of the character to get the destination of.
get_floor(thing=None)

Return the floor that the character (or some other object) is on (or None if the character or object is not on a floor).

Parameters:thing – If not None, return the floor that thing is on; otherwise return the floor that the character is on.
get_image()

Return the image (a pygame.Surface) corresponding to the character’s current animatory state.

get_lesson_message()

Return a lesson message randomly chosen from the character’s collection.

get_location()

Return the on-floor location that is closest to the character.

get_location_of_eric()

Return the on-floor location closest to Eric.

get_nearby_adults()

Return a list of adults who are close enough to the character (and are facing the right way) to be able to see him.

get_next_chair(move_along, go_to_back)

Return the next chair that the character should find and sit on (at the start of a lesson, or after being dethroned).

Parameters:
  • move_alongTrue if the character should proceed to the next seat along (as after being dethroned), False if he should re-take the seat he was pushed out of (as the swot does).
  • go_to_backTrue if the character should proceed to the back seat (as at the start of a lesson), False otherwise.
Returns:

A 2-tuple containing the target chair and the direction it faces.

get_next_staircase(destination)

Return the next staircase the character must ascend or descend in order to reach his destination.

Parameters:destination (Location) – The character’s destination.
get_punchee(offset)

Return the first punchable character in front of this one.

Parameters:offset (number) – The distance in front of this character to check for punchees.
Returns:A punchable character, or None if there is none at the given distance.
get_qa_generator()

Return a QAGenerator for the character to use during this lesson.

get_random_destination()

Return a location randomly chosen from the character’s collection.

Returns:An (x, y) tuple.
get_sit_down_message()

Return a sit-down message randomly chosen from the character’s collection.

get_tell_eric_delay()

Return the time to wait for Eric to respond before repeating a message.

get_title()

Return the name the swot should use when addressing this character.

get_up()

Make a character get up from a sitting position. If the character was sitting in a chair, the chair will be marked vacant.

get_walk_state_index()

Return the index of the character’s current animatory state in his collection of walking sprites.

Returns:0, 1, 2, or 3 (or -1 if the character is not standing or walking).
give_lines(recipient_id, message_id, now=False)

Add a lines message to the character’s buffer.

Parameters:
  • recipient_id – The ID of the character receiving the lines.
  • message_id – The ID of the reprimand message.
  • now – If True, the lines message box will be printed immediately; if False, it will be printed on the next pass through the main loop (after the screen has been updated for the character’s current animatory state and location).
give_lines_now()

Print the lines message that is in the character’s buffer (if there is one) immediately.

go_fast()

Ensure that this character runs continuously.

go_slow()

Ensure that this character does not run.

got_signal(signal)

Return whether a signal has been raised.

Parameters:signal – The signal to check.
has_arm_raised()

Return whether the character has his arm raised (as when writing on a blackboard or opening a door).

has_bike_secret()

Return whether the character holds a bike combination digit.

has_line_of_sight_to(character)

Return whether the character has a line of sight to another character (that is, there are no walls between them).

Parameters:character (Character) – The other character.
has_safe_key()

Return whether the character holds the key to the safe.

has_safe_secret()

Return whether the character holds a safe combination letter.

has_storeroom_secret()

Return whether the character holds a storeroom combination letter.

head_at(x, y)

Return whether the character’s head is at a given location.

Parameters:
  • x – The x-coordinate of the location.
  • y – The x-coordinate of the location.
hide()

Hide the character. This is used mostly by inanimate objects (such as the desk lid) or non-human characters (such as mice) that are not always in the play area.

impeded(bottom_y, top_y)

Return whether the character is blocked by an object (such as a wall).

Parameters:
  • bottom_y – The y-coordinate of the bottom of the object.
  • top_y – The y-coordinate of the top of the object.
initialise_animatory_state(initial_as, direction)

Set the character’s initial animatory state and direction.

Parameters:
  • initial_as – The animatory state.
  • direction – The direction.
initialise_bike_secret()

Set and return a bike combination digit (chosen at random) for the character to hold.

initialise_safe_secret()

Set and return a safe combination letter (chosen at random) for the character to hold.

initialise_special_answer()

Initialise the character’s special answer (if he has one). A special answer is something that the character must see written on a blackboard before he will reveal his safe combination letter.

initialise_storeroom_secret()

Set and return a storeroom combination letter (chosen at random) for the character to hold.

is_adult()

Return whether the character is an adult. The answer is used in various situations where the difference between an adult and a child is significant, as when placing a speech bubble, or being knocked over or knocked out by a catapult pellet.

is_beside_eric()

Return whether the character is beside Eric.

is_conkerable()

Return whether the character can be knocked over by a falling conker.

is_deckable()

Return whether the character is in an animatory state and location that are amenable to him being knocked over.

is_door()

Return whether the character is a door.

Returns:False.
is_eric()

Return whether the character is Eric.

Returns:False.
is_eric_absent()

Return whether Eric is absent from a classroom or other region he should be present in right now.

is_eric_expelled()

Return whether Eric is due to be or is in the process of being expelled.

is_facing(thing)

Return whether the character is facing something or somebody else.

Parameters:thing – The thing (such as a blackboard or another character) to check.
is_facing_eric()

Return whether the character is facing Eric.

is_firing_catapult()

Return whether the character is firing his catapult.

is_home(x)

Return whether the character is on the ‘home’ side of a given x-coordinate. For male characters, the home side is the left side; for female characters, it is the right side.

Parameters:x – The x-coordinate to check.
is_interruptible()

Return whether the character’s current command can be interrupted.

is_kissing_eric()

Return whether the character is kissing Eric.

is_knocked_out()

Return whether the character has been knocked out.

is_knocked_over()

Return whether the character has been knocked over.

is_lowering_catapult()

Return whether the character is lowering his catapult.

is_lowering_fist()

Return whether the character is lowering his fist.

is_pelletable()

Return whether the character can be knocked over by a catapult pellet.

is_punchable()

Return whether the character can be knocked over by a punch.

is_punchable_now()

Return whether the character is amenable to being punched at this exact moment.

is_punching()

Return whether the character is punching.

is_raising_catapult()

Return whether the character is raising his catapult.

is_raising_fist()

Return whether the character is raising his fist.

is_riding_bike()

Return whether the character is riding a bike.

is_scared_of_mice()

Return whether the character is scared of mice.

is_sitting()

Return whether the character is sitting down (on the floor or on a chair).

is_sitting_on_chair()

Return whether the character is sitting on a chair.

is_sitting_on_floor()

Return whether the character is sitting on the floor.

is_sitting_on_stairs()

Return whether the character is sitting on a staircase.

is_standing()

Return whether the character is upright (in a walking animatory state).

is_stopping_eric(eric)

Return whether this character is preventing Eric from escaping.

is_teaching_eric()

Return whether the character is teaching Eric this period.

is_time_to_move()

Return whether the character should be moved on this pass.

is_time_to_start_lesson()

Return whether enough time has passed to start the lesson. This is used, for example, to check whether a teacher should tell the kids to sit down, or continue pacing up and down outside the classroom doorway.

is_time_to_wake()

Return whether it is time for the character to regain consciousness after being struck by a falling conker.

is_touching_eric()

Return whether the character is in the same location as Eric.

is_trippable()

Return whether the character can be tripped up by a stampeding kid.

is_very_conkerable()

Return whether the character will be rendered unconscious for a while if struck by a falling conker.

is_visible()

Return whether the character is somewhere in the play area. The answer is generally True for human characters, but may be False for inanimate objects (such as the desk lid) or non-human characters (such as mice, which occasionally hide).

join_lesson(qa_group)

Called by the teacher to join the lesson started by the swot.

Parameters:qa_group – The Q&A group from which to choose questions and answers for the teacher and the swot; if None, the Q&A group will be chosen at random from those available each time a question and answer is generated.
jump_if_open(door_id, offset)

Jump forwards (or backwards) in the character’s command list if a given door is open.

Parameters:
  • door_id – The ID of the door to check.
  • offset (number) – The offset by which to jump in the command list.
jump_if_shut(door_id, offset)

Jump forwards (or backwards) in the character’s command list if a given door is shut.

Parameters:
  • door_id – The ID of the door to check.
  • offset (number) – The offset by which to jump in the command list.
keep_seat()

Indicate that the character should return to the same seat if he’s knocked out of it. This is used by the swot during lessons. (The swot must return to the same seat so that he remains underneath his speech bubble.)

kiss_eric()

Make the character kiss Eric.

knock_over()

Knock the character over (as when hit by a catapult pellet).

left()

Move the character leftwards.

lower_arm()

Make the character lower his arm.

lower_catapult()

Make the character start lowering his catapult.

lower_fist()

Make the character start lowering his fist.

midstride()

Return whether the character is midstride.

move()

Move the character. The steps taken are:

  1. make the character give lines (if he has a lines message buffered)
  2. check whether it’s time to move the character, and abort if not
  3. move the character from the midstride position (if he is midstride), or
  4. hand control of the character over to the current command in his command list
move_door(barrier_id, shut)

Make the character open or close a door or window.

Parameters:
  • barrier_id – The ID of the door or window.
  • shutTrue if the door or window should be closed, False if it should be opened.
next_swot_action()

Return the next command to be executed by the swot (which may be None).

next_teacher_action()

Return the next command to be executed by the teacher (which may be None).

on_stairs()

Return whether the character is on one of the steps of a staircase.

open_door()

Return an OpenDoor command for the door or window in front of the character.

open_window(window)

Make the character take a detour to a window and open it.

Parameters:window (Window) – The window to open.
pause()

Add a Pause command to the character’s command list. This is used to temporarily suspend a character’s command list while kissing Eric.

print_lines_message(recipient_id, message_id)

Make the character give lines to someone. First display the recipient’s name and the number of lines being given, accompanied by a sound effect. Then display the reprimand message, accompanied by another sound effect.

Parameters:
  • recipient_id – The ID of the character receiving the lines.
  • message_id – The ID of the reprimand message.
print_message_box(message, ink, paper, sound_id, prev_coords=False, pre_resume=None, pre_resume_args=None)

Print a message box above the character’s head.

Parameters:
  • message – The text to display in the message box.
  • ink (number) – The ink colour of the message box.
  • paper (number) – The paper colour of the message box.
  • sound_id – The ID of the sound effect to play.
  • prev_coords – If True, print the message box at the same coordinates as the last one; otherwise calculate the coordinates afresh.
  • pre_resume – A method to execute after the sound effect has finished playing.
  • pre_resume_args – The arguments for the pre_resume method.
punch()

Make the character finish raising his fist (to punching height).

raise_alarm(message, alertee_id, command_list_id)

Make this character raise the alarm that Eric is escaping.

Parameters:
  • message – The alarm message.
  • alertee_id – The ID of the character to alert.
  • command_list_id – The ID of the command list that the alerted character should switch to.
raise_arm()

Make the character raise his arm.

raise_catapult()

Make the character start raising his catapult.

raise_fist()

Make the character start raising his fist.

reinitialise()

Reinitialise the character after a game has ended or restarted. In particular:

  • restore the initial animatory state and location
  • remove any speech bubble
  • create a new, empty command list
remove_bubble()

Remove the character’s speech bubble.

reprimand()

Make the character give lines to the nearest lines recipient for knocking him over.

reset_come_along_index()

Reset the index of the teacher’s COME_ALONG* messages for this lesson.

reset_walk_delay()

Reset the delay before the character is moved again (if he is walking).

resolve_location_id(location_id)

Return the location with a given ID.

Parameters:location_id – The ID of the location.
Returns:The appropriate Location.
restart_command_list()

Restart the character’s command list.

resume()

Resume the character’s command list after being suspended by a Pause command (see pause()). This is used to indicate to the Pause command that it should terminate.

reveal_bike_secret()

Make the character reveal his bike combination digit (if he has one, and he is on-screen).

reveal_safe_secret(decked)

Make the character reveal his safe combination letter if certain conditions are met. The conditions are:

  • the character is on-screen
  • the character holds a safe combination letter
  • the safe has not been opened yet
  • the character can see his special answer on a blackboard, or the character has no special answer and all the shields are flashing
Parameters:decked – Whether the character has been knocked over.
reveal_storeroom_secret()

Make the character reveal his storeroom combination letter (if he has one, and he is on-screen).

right()

Move the character rightwards.

say(words, shift)

Make the character start or continue saying something.

Parameters:
  • words (string) – The words to speak.
  • shift (number) – The amount by which the words should be shifted in the text window of the speech bubble.
Returns:

True if the character has finished speaking, False otherwise.

set_animatory_states(as_dict_L, as_dict_R)

Set the character’s animatory states (sprite collection). These are organised into a collection of left-facing sprites keyed by animatory state name (such as WALK0), and a corresponding collection of right-facing sprites.

Parameters:
  • as_dict_L (dict) – The left-facing sprites.
  • as_dict_R (dict) – The right-facing sprites.
set_command_list_template(template)

Set the character’s command list template. This method is called to change a character’s command list (for example, after the bell rings).

set_components(cast, skool, screen, config)

Set the character up with access to essential objects.

Parameters:
  • cast (Cast) – The cast.
  • skool (Skool) – The skool.
  • screen (Screen) – The screen.
  • config (dict) – Configuration parameters from the ini file.
set_controlling_command(command)

Set the controlling command on the character’s command list. See pyskool.ai.CommandList.set_controlling_command() for more details.

Parameters:command (Command) – The controlling command.
set_home_room()

Set Eric’s home room for the current period. The home room is the place Eric should be in by now; if he’s not, and he’s spotted by a teacher, he will be given lines.

set_initial_location(x, y)

Set the character’s initial location.

Parameters:
  • x – Initial x-coordinate.
  • y – Initial y-coordinate.
set_random_locations(locations)

Set the character’s collection of random locations.

Parameters:locations – Sequence of (x, y) tuples.
set_restart_point()

Discard the current and all previous commands in the character’s command list. Any command that restarts the command list from now on will see the next command as the first.

set_subcommand(command_name, args)

Set a subcommand on the character’s command list. See pyskool.ai.CommandList.set_subcommand() for details.

should_chase_eric(chase_x)

Return whether the character should start chasing Eric away. The answer will be True if all of the following conditions are met:

  • it is not playtime
  • Eric’s x-coordinate is greater than chase_x
  • Eric is on the same floor as the character
Parameters:chase_x – The x-coordinate beyond which Eric must be for the monitor to start chasing Eric.
should_stop_eric(escape_x, danger_zone)

Return whether this character should try to prevent Eric from escaping.

Parameters:
  • escape_x – The x-coordinate beyond which Eric should be regarded as trying to escape.
  • danger_zone – The minimum and maximum distance to the left of the watcher that Eric must be for him to raise the alarm.
signal(signal)

Raise a signal.

Parameters:signal (string) – The signal to raise.
sit()

Make the character sit in a chair or on the floor (if he is standing up), or stand up (if he is sitting or lying down).

sit_on_floor()

Make the character sit on the floor.

sometimes_runs()

Return whether the character sometimes runs instead of walking (as the kids do).

stalk(character_id)

Set the character’s destination equal to that of another character’s destination (if they are both under the control of a GoTo command).

stand_up()

Make the character stand up.

start_clock(ticks)

Restart the skool clock at a given time. (See stop_clock().)

Parameters:ticks – The number of ticks until the end of the period.
start_lesson()

Called by the swot to start a lesson.

stop_clock()

Stop the skool clock. This is used to prevent the bell from ringing before a certain event happens. (See start_clock().)

trigger_speed_change()

Make it so that the character will consider a change of walking speed the next time he is moved.

trip_people_up()

Make the character trip people up at his current location.

turn()

Make the character turn round.

unfreeze_eric()

Unfreeze Eric (see freeze_eric()).

unset_home_room()

Unset Eric’s home room for the current period. This is used when assembly is finished (so that Eric is not told off for being outside the assembly hall after Mr Wacker has finished speaking).

unsignal(signal)

Lower a signal.

Parameters:signal (string) – The signal to lower.
up()

Move the character upwards.

wait_at_door(door_id)

Return whether the characters are on the ‘home’ side of the given door.

walk(on_stairs=False)

Make a character take one step in the direction he’s facing. The character’s y-coordinate will be adjusted appropriately if he’s going up or down a staircase.

Parameters:on_stairsTrue if the character is on a staircase, False otherwise.
will_fire_catapult()

Return whether the character wants to fire a catapult now.

will_hit()

Return whether the character wants to throw a punch now.

will_kiss_eric()

Return whether the character will kiss Eric (if he tries).

will_write_on_board()

Return whether the character will write on a blackboard. The answer is used by teachers who are conducting a class without Eric.

wipe_board(column)

Wipe a bit of a blackboard clean.

Parameters:column – The column of the blackboard to wipe.
write_on_board(message, index)

Make this character start or continue writing on a blackboard.

Parameters:
  • message – The message being written.
  • index – The index of the next character in the message to write.