def handle_events(self): """ Loop through all events. """ for event in pymlgame.get_events(): if event.type == pymlgame.E_NEWCTLR: if len(self.players) < 2: self.construct_player(event.uid) elif event.type in [pymlgame.E_KEYDOWN, pymlgame.E_KEYPRESSED]: if event.button == pymlgame.CTLR_UP: self.players[event.uid].move_up() elif event.button == pymlgame.CTLR_DOWN: self.players[event.uid].move_down() elif event.type == pymlgame.E_PING: print('ping from', event.uid)
def handle_events(self): """ Loop through all events. """ for event in pymlgame.get_events(): if event.type == E_NEWCTLR: #print(datetime.now(), '### new player connected with uid', event.uid) self.players[event.uid] = {'name': 'alien_{}'.format(event.uid), 'score': 0} elif event.type == E_DISCONNECT: #print(datetime.now(), '### player with uid {} disconnected'.format(event.uid)) self.players.pop(event.uid) elif event.type == E_KEYDOWN: #print(datetime.now(), '###', self.players[event.uid]['name'], 'pressed', event.button) if event.button == 9: self.init_game_board() else: self.colors.append(self.colors.pop(0)) elif event.type == E_PING: #print(datetime.now(), '### ping from', self.players[event.uid]['name']) pass
def handle_events(self): """ Loop through all events. """ for event in pymlgame.get_events(): if event.type == pymlgame.E_NEWCTLR: print('new ctlr with uid:', event.uid) elif event.type == pymlgame.E_KEYDOWN: if event.button == pymlgame.CTLR_UP: if self.snake.direction != DOWN: self.snake.direction = UP elif event.button == pymlgame.CTLR_DOWN: if self.snake.direction != UP: self.snake.direction = DOWN elif event.button == pymlgame.CTLR_LEFT: if self.snake.direction != RIGHT: self.snake.direction = LEFT elif event.button == pymlgame.CTLR_RIGHT: if self.snake.direction != LEFT: self.snake.direction = RIGHT elif event.type == pymlgame.E_PING: print('ping from', event.uid)
def handle_events(self): """ Loop through all events. """ for event in pymlgame.get_events(): if event.type == E_NEWCTLR: #print(datetime.now(), '### new player connected with uid', event.uid) self.players[event.uid] = { 'name': 'alien_{}'.format(event.uid), 'score': 0 } elif event.type == E_DISCONNECT: #print(datetime.now(), '### player with uid {} disconnected'.format(event.uid)) self.players.pop(event.uid) elif event.type == E_KEYDOWN: #print(datetime.now(), '###', self.players[event.uid]['name'], 'pressed', event.button) if event.button == 9: self.init_game_board() else: self.colors.append(self.colors.pop(0)) elif event.type == E_PING: #print(datetime.now(), '### ping from', self.players[event.uid]['name']) pass
def handle_events(self): """ Loop through all events. """ for event in pymlgame.get_events(): if event.type == E_NEWCTLR: print('new ctlr with id:', event.id) elif event.type == E_KEYDOWN: if event.button == CTLR_UP: if self.snake.direction != DOWN: self.snake.direction = UP elif event.button == CTLR_DOWN: if self.snake.direction != UP: self.snake.direction = DOWN elif event.button == CTLR_LEFT: if self.snake.direction != RIGHT: self.snake.direction = LEFT elif event.button == CTLR_RIGHT: if self.snake.direction != LEFT: self.snake.direction = RIGHT elif event.type == E_PING: #print('ping from', event.id) pass
def handle_events(self): for event in pymlgame.get_events(): if event.type == E_PING: print(datetime.now(), '# ping from', event.uid) else: print(datetime.now(), '# unknown event', event.uid, event.type)