The procgame.game submodule contains the core building blocks of a pyprocgame-based game. See pyprocgame Manual for a discussion on how to create a pyprocgame game.
A collection of procgame.game.GameItem objects.
Returns a list of items with the given tag.
Represents a driver in a pinball machine, such as a lamp, coil/solenoid, or flasher.
Subclass of GameItem.
Disables (turns off) this driver.
Enables this driver indefinitely.
Warning
Never use this method with high voltage drivers such as coils and flashers! Instead, use time-limited methods such as pulse() and schedule().
Enables this driver for milliseconds at P-ROC timestamp: timestamp.
If no parameter is provided for milliseconds, default_pulse_time is used. If no parameter is provided or timestamp, 0 is used. ValueError will be raised if milliseconds is outside of the range 0-255.
The last time that this driver’s state was modified.
Enables a pitter-patter sequence.
It starts by activating the driver for original_on_time milliseconds. Then it repeatedly turns the driver on for on_time milliseconds and off for off_time milliseconds.
Enables this driver for milliseconds.
If no parameters are provided or milliseconds is None, default_pulse_time is used. ValueError will be raised if milliseconds is outside of the range 0-255.
Enables a pitter-patter sequence that runs for run_time milliseconds.
Until it ends, the sequence repeatedly turns the driver on for on_time milliseconds and off for off_time milliseconds.
Schedules this driver to be enabled according to the given schedule bitmask.
Returns a dictionary representing this driver’s current configuration state.
Core object representing the game itself. Usually a game developer will create a new game by subclassing this class. Consider subclassing BasicGame instead, as it makes use of several helpful modes and controllers.
The number of the current ball. A value of 1 represents the first ball; 0 indicates game over.
Called by the game framework when the current ball has ended.
Called by the game framework when a new ball is starting.
Number of balls per game.
An AttrCollection of Driver objects. Populated by load_config().
YAML game configuration loaded by load_config().
Instantiates and returns the class to use as the P-ROC device. This method is called by GameController‘s init method to populate proc.
Checks config for the key path pinproc_class. If that key path exists the string is used as the fully qualified class name to instantiate. The class is then instantiated with one initializer argument, machine_type.
If that key path does not exist then this method returns an instance of pinproc.PinPROC.
Instantiates and returns a new instance of the Player class with the name name. This method is called by add_player(). This can be used to supply a custom subclass of Player.
Returns the current Player as described by current_player_index.
Called by the GameController when a DMD event has been received.
Enables or disables the flippers AND bumpers.
Called by the implementor to notify the game that the current ball has ended.
Called by the implementor to mark notify the game that the game has ended.
Called by the programmer when he wants the run_loop to end
Contains high score and audit information. That is, transient information specific to one game installation.
Called by the GameController when the current game has ended.
Called by the GameController when a new game is starting.
Called by run_loop() once per cycle to get the events to process during this cycle of the run loop.
An AttrCollection of Driver objects. Populated by load_config().
Reads the YAML machine configuration file into memory. Configures the switches, lamps, and coils members. Enables notifyHost for the open and closed debounced states on each configured switch.
Reads the YAML machine configuration in stream form (string or opened file) into memory. Configures the switches, lamps, and coils members. Enables notifyHost for the open and closed debounced states on each configured switch.
Loads the YAML game data configuration file. This file contains transient information such as audits, high scores and other statistics. The template_filename provides default values for the game; user_filename contains the values set by the user.
See also: save_game_data()
Loads the YAML game settings configuration file. The game settings describe operator configuration options, such as balls per game and replay levels. The template_filename provides default values for the game; user_filename contains the values set by the user.
See also: save_settings()
Logger object instance; instantiated in __init__() with the logger name “game”.
A pinproc.PinPROC instance, created in the initializer with machine type machine_type.
Called by load_config() and load_config_stream() to process the values in config.
Reset the game state as a slam tilt might.
Called by the programmer to read and process switch events until interrupted.
Writes the game data to filename. See load_game_data().
Writes the game settings to filename. See load_settings().
Called by the game framework when a new ball is starting which was the result of a stored extra ball (Player.extra_balls). The default implementation calls ball_starting(), which is not called by the framework in this case.
Called by the implementor to notify the game that (usually the first) ball should be started.
Called by the implementor to notify the game that the game has started.
An AttrCollection of Switch objects. Populated by load_config().
Start time.time of the game program. I.e., the time of power-up.
Called by the GameController once per run loop.
Contains local game configuration, such as the volume.
Base class for Driver and Switch. Contained in an instance of AttrCollection within the GameController.
GameController to which this item belongs.
Display name of this item.
String name of this item.
Integer value for this item providing a mapping to the hardware.
List of string tags used to group this item.
Number string from YAML config file
Abstraction of a game mode to be subclassed by the game programmer.
Modes are essentially a collection of switch even thandlers. Active modes are held in GameController.modes, an instance of ModeQueue, which dispatches event notifications to modes in order of priority (highest to lowest). If a higher priority mode’s switch event handler method returns SwitchStop, the event is not passed down to lower modes.
Switch event handlers are detected when the Mode initializer is called by the subclass. Various switch event handler formats are recognized:
Example variants of the above:
def sw_switchName_closed_for_2s(self, sw):
pass
def sw_switchName_closed_for_100ms(self, sw):
pass
def sw_switchName_open_for_500ms(self, sw):
pass
Note
Presently only switch names with the characters a-z, A-Z, and 0-9 are recognized. If a switch name has an underscore in it, the switch handler will not be recognized.
Modes can be programatically configured using add_switch_handler().
Add mode as a child of the receiver. Child modes are added and removed from the game’s mode queue when mode_started() and mode_stopped() are called, respectively.
If this mode is already on the mode queue (is_started() == True), then mode will be added (started) immediately.
Sets mode‘s parent_mode to the receiver.
| Returns: | mode |
|---|
Programatically configure a switch event handler.
Keyword arguments:
Removes the given named delays from the delayed list, cancelling their execution.
Schedule the run loop to call the given handler at a later time.
Keyword arguments:
If param is None, handler’s signature must be handler(self). Otherwise, it is handler(self, param) to match the switch method handler pattern.
Returns the name of the delay, which may later be used with cancel_delayed().
Example usage for delayed method invocation:
def delayed_handler(self):
print 'thatButton was pressed 2 seconds ago!'
def sw_thatButton_active(self):
# After 2 seconds, call delayed_handler() above.
self.delayed_name = self.delay(delay=2.0, handler=self.delayed_handler)
# Store name to cancel the delay later: self.cancel_delayed(self.delayed_name)
Called by the GameController to dispatch any delayed events.
Returns True if this mode is on the mode queue (mode_started() has already been called).
Notifies the mode that it is now active on the mode queue.
This method should not be invoked directly; it is called by the GameController run loop.
Notifies the mode that it has been removed from the mode queue.
This method should not be invoked directly; it is called by the GameController run loop.
Called by the GameController run loop during each loop when the mode is running.
Notifies the mode that it is now the topmost mode on the mode queue.
This method should not be invoked directly; it is called by the GameController run loop.
The parent mode for this mode. Set by add_child_mode() and cleared in remove_child_mode().
Remove mode as a child of the receiver. See add_child_mode() for a description of child modes. If this mode is already on the mode queue, the mode will be removed (stopped) immediately.
Sets mode‘s parent_mode to None.
See also: add_child_mode().
Called by the GameController re-apply active lamp schedules
Represents a player in the game. The game maintains a collection of players in GameController.players.
Number of extra balls that this player has earned.
Number of seconds that this player has had the ball in play.
This player’s name.
This player’s score.
Represents a switch in a pinball machine.
Switches are accessed using GameController.switches.
Subclass of GameItem.
True indicates switch events should only change the state when they are debounced events.
Hardware timestamp of the last state change of this switch. None until an event is received.
True if the ball is activating this switch, or if this switch is somehow being activated. If seconds is not None (the default), only returns True if the switch has been active for that number of seconds.
True if the ball is not activating this switch If seconds is not None (the default), only returns True if the switch has not been active for that number of seconds.
time of the last state change of this switch. None if the GameController has not yet initialized this switch’s state.
Resets the value returned by time_since_change() to 0.0. Normally this is called by the GameController, but it can be triggered manually if needed.
False indicates open, True is closed. In most applications the is_active() and is_inactive() methods should be used to determine a switch’s state.
Number of seconds that this switch has been in its current state. This value is reset to 0 by the GameController after the switch event has been processed by the active Mode instances.
'NO' (normally open) or 'NC' (normally closed). Mechanical switches are usually NO, while opto switches are almost always NC. This is used to determine whether a switch is active (“in contact with the ball”) without ruleset code needing to be concerned with the details of the switch hardware.
BasicGame is a subclass of GameController that includes and configures various useful helper classes to provide:
It is a recommended base class to build your game upon, or use as a template if your game has special requirements.
Updates the DMD via DisplayController.
Overriding GameController’s implementation in order to append keyboard events.
Calls super’s reset and adds the ScoreDisplay mode to the mode queue.
Convenience method to add points to the current player.
Called once per run loop.
Displays the last-received DMD frame on the desktop.