Example #1
0
    def __init__(self, warrior1, warrior2):
        GameController.__init__(self, warrior1, warrior2)
        pygame.init()
        config.Screen()

        self.screen = pygame.Surface((320, 240), 0, 32)
        self.warrior_ui1 = WarriorUi(warrior1.state, self.screen, '../res/Char/Rick/Rick.png')
        self.warrior_ui2 = WarriorUi(warrior2.state, self.screen, '../res/Char/Ken/Ken.png')
    
        self.config = config.OptionConfig()
        self.clock = pygame.time.Clock()
        self.color = (0,0,0,0)
        self.input_reader = InputReader(self.config.keysP1, self.config.keysP2)

        self.background = Background('../res/Background/Bckgrnd4.png')
        self.background.position = Point(-160, 0)
Example #2
0
class GameUiController(GameController):

    def __init__(self, warrior1, warrior2):
        GameController.__init__(self, warrior1, warrior2)
        pygame.init()
        config.Screen()

        self.screen = pygame.Surface((320, 240), 0, 32)
        self.warrior_ui1 = WarriorUi(warrior1.state, self.screen, '../res/Char/Rick/Rick.png')
        self.warrior_ui2 = WarriorUi(warrior2.state, self.screen, '../res/Char/Ken/Ken.png')
    
        self.config = config.OptionConfig()
        self.clock = pygame.time.Clock()
        self.color = (0,0,0,0)
        self.input_reader = InputReader(self.config.keysP1, self.config.keysP2)

        self.background = Background('../res/Background/Bckgrnd4.png')
        self.background.position = Point(-160, 0)


    def apply_action(self, action1, state1, action2, state2):
        
        a1 = self.prev_action1.combine(action1)
        a2 = self.prev_action2.combine(action2)

        self.debug(state1, a1)
        self.debug(state2, a2)

        GameController.apply_action(self, action1, state1, action2, state2)


    def debug(self, state1, action1):
        if isinstance(action1, LightAttackAction) or isinstance(action1, HardAttackAction):
            rect = action1.hit_rect(state1)
            pygame.draw.rect(self.screen, (0,0,255), rect.value(), 1)
        rect = state1.get_rect()
        pygame.draw.rect(self.screen, (0,255,0), rect.value(), 1)
        position = state1.position
        pygame.draw.circle(self.screen, (255, 0, 0), position.value(), 1)

    def mainloop(self):
        done = False
        while not done:
            stick_inputs_p1, btn_inputs_P1, stick_inputs_p2, btn_inputs_P2, special = self.input_reader.getInputs()
            
            if special == 'QUIT':
                return 'QUIT'

            self.screen.fill((0,0,0))
            self.background.print_me(self.screen)
            
            self.warrior1.set_inputs(stick_inputs_p1, btn_inputs_P1)
            self.warrior2.set_inputs(stick_inputs_p2, btn_inputs_P2)

            self.warrior_ui1.print_me()
            self.warrior_ui2.print_me()
            
            action1 = self.warrior1.next_action(self.warrior2.state)
            action2 = self.warrior2.next_action(self.warrior1.state)

            self.apply_action(action1, warrior1.state, action2, warrior2.state)

            config.Screen().display_update(self.screen)
            
            if warrior1.state.health <= 0 or warrior2.state.health <= 0:
                done = True
            self.clock.tick(12)

        for i in range(10):
            self.clock.tick(12)