Exemple #1
0
def is_game_over(state):
    return not state['bricks'] or state['ball']['y'] > state['display']['height']


def controller(state):
    if state['status'] in (GAME_NOT_STARTED, GAME_OVER)\
            and state['joystick']['clicked']:
        state = get_initial_game_state(state)
    elif state['status'] == GAME_ACTIVE:
        state['paddle'] = update_paddle(state['paddle'], state['joystick'],
                                        state['display']['width'])
        state = update_ball(state)
        if is_game_over(state):
            state['status'] = GAME_OVER
    return state


initial_state = {'status': GAME_NOT_STARTED}
breakout = Game(display=Display(pinout={'sda': 'Y10',
                                    'scl': 'Y9'},
                                height=64,
                                external_vcc=False),
                joystick=Joystick('X1', 'X2', 'X3'),
                initial_state=initial_state,
                view=view,
                controller=controller)

if __name__ == '__main__':
    breakout.run()
Exemple #2
0
                state['ball'],
                state['player'],
                state['ai'],
                state['display']['height'])
        state['player'] = update_player(state['player'],
                                        state['joystick'],
                                        state['display']['height'])
        state['ai'] = update_ai(state['ai'],
                                state['ball'],
                                state['display']['height'])
        state['state'] = update_game_state(state['ball'],
                                           state['display']['width'])
    elif state['joystick']['clicked']:
        state.update(get_new_game_state(state['display']['width'],
                                        state['display']['height']))
        state['state'] = GAME_ACTIVE
    return state


pong = Game(display=Display(pinout={'sda': 'Y10',
                                    'scl': 'Y9'},
                            height=64,
                            external_vcc=False),
            joystick=Joystick('X1', 'X2', 'X3'),
            initial_state={'state': GAME_NOT_STARTED},
            view=view,
            controller=controller)

if __name__ == '__main__':
    pong.run()
Exemple #3
0
    if state['state'] == GAME_ACTIVE:
        state['ball'] = update_ball(state['ball'], state['player'],
                                    state['ai'], state['display']['height'])
        state['player'] = update_player(state['player'], state['joystick'],
                                        state['display']['height'])
        state['ai'] = update_ai(state['ai'], state['ball'],
                                state['display']['height'])
        state['state'] = update_game_state(state['ball'],
                                           state['display']['width'])
    elif state['joystick']['clicked']:
        state.update(
            get_new_game_state(state['display']['width'],
                               state['display']['height']))
        state['state'] = GAME_ACTIVE
    return state


pong = Game(display=Display(pinout={
    'sda': 'Y10',
    'scl': 'Y9'
},
                            height=64,
                            external_vcc=False),
            joystick=Joystick('X1', 'X2', 'X3'),
            initial_state={'state': GAME_NOT_STARTED},
            view=view,
            controller=controller)

if __name__ == '__main__':
    pong.run()
Exemple #4
0
        'bricks'] or state['ball']['y'] > state['display']['height']


def controller(state):
    if state['status'] in (GAME_NOT_STARTED, GAME_OVER)\
            and state['joystick']['clicked']:
        state = get_initial_game_state(state)
    elif state['status'] == GAME_ACTIVE:
        state['paddle'] = update_paddle(state['paddle'], state['joystick'],
                                        state['display']['width'])
        state = update_ball(state)
        if is_game_over(state):
            state['status'] = GAME_OVER
    return state


initial_state = {'status': GAME_NOT_STARTED}
breakout = Game(display=Display(pinout={
    'sda': 'Y10',
    'scl': 'Y9'
},
                                height=64,
                                external_vcc=False),
                joystick=Joystick('X1', 'X2', 'X3'),
                initial_state=initial_state,
                view=view,
                controller=controller)

if __name__ == '__main__':
    breakout.run()