Exemple #1
0
    def switch(self, name):
        """Switch to a new screen by saving the current state, and then
            restoring the specified state."""

        State.save(State.name)
        State.prev_name = State.name
        State.restore(name)
Exemple #2
0
    def create_screens(self):
        """Create all of the game screens specified in the game
            configuration."""

        for name in State.game['screens']:
            State.screen = Screen(name)
            State.save(name)
Exemple #3
0
 def __init__(self, name):
     State.name = name
     State.screen = self
     State.controls = State.screens[State.name]['controls']
     State.groups = {}
     self.layers = LayeredDirty()
     self.add_all()
     State.save(State.name)
Exemple #4
0
    def add_object(self, screen, object, amount=1, pos=None, group=None):
        """Add one or more instances of an object to a screen."""

        # Switch the game state to the desired screen first.
        State.restore(screen)

        # Create the specified amount of instances of this object.
        for i in range(0, amount):
            State.screen.add_object(object, group, pos)
Exemple #5
0
    def run(self, screen):
        """Main game loop."""

        State.running = True
        State.restore(screen)
        while State.running:
            State.clock.tick()
            if State.clock.update_ready():
                self.update()
            if State.clock.frame_ready():
                self.draw()
Exemple #6
0
    def create_screen(self, name):
        """Create a new screen and save it to a state of the same name for
            retrieval."""

        State.screen = Screen(name)
        State.save(name)
Exemple #7
0
    def add_object(self, screen, object, amount=1, pos=None):
        """Add one or more instances of an object to a screen."""

        State.restore(screen)
        State.screen.add_object(object, amount, pos)
        State.save(screen)