# This will save the this instance to state machine BaseState.__init__(self, 'Intro') # All draw code goes here def draw(self, surface): surface.fill((0, 0, 40)) surface.blit(self.text, self.text_rect) class Intro(BaseState): def __init__(self): # This will save the this instance to state machine BaseState.__init__(self, 'Game') # All draw code goes here def draw(self, surface): surface.fill((0, 40, 0)) surface.blit(self.text, self.text_rect) if __name__ == '__main__': pygame.init() StateMachine.screen_center() # Create the state machine StateMachine('Example Flip', 800, 600) # Create states Game() # Create Intro and set it to first state StateMachine.main_loop(Intro()) pygame.quit()
import pygame from machine import StateMachine, State class Example(State): def __init__(self): # This will save the this instance to state machine State.__init__(self) # All draw code goes here def draw(self, surface): surface.fill((0, 40, 0)) # Process all event here def event(self, event): if event.type == pygame.QUIT: # call state machine self.state.machine.quit() if __name__ == '__main__': pygame.init() StateMachine.screen_center() # Create the state machine StateMachine('Example', 800, 600) # Create Example and set it to first state StateMachine.main_loop(Example()) pygame.quit()
def main(): pygame.init() StateMachine.screen_center() StateMachine("Test", 800, 600) Test2() StateMachine.main_loop(Test())