def draw(self, colour): printval = abs(self.value % 10) serialprint.setColor(colour) for y in range(5): for x in range(3): if constants.DIGITS[printval][y][x] == "X": serialprint.print_at(self.position.y + y, self.position.x + x, " ")
def draw(): serialprint.setColor(constants.COLOURS["Net"]) net.draw() bat1.draw(constants.COLOURS["BlueBat"]) score1.draw(constants.COLOURS["BlueScore"]) bat2.draw(constants.COLOURS["RedBat"]) score2.draw(constants.COLOURS["RedScore"]) serialprint.setColor(constants.COLOURS["Reset"]) ball.erase() ball.draw()
def checkWinner(): global is_winner if score1.value >= constants.WINNER_SCORE: #printing function message = constants.WINNER[1] is_winner = True elif score2.value >= constants.WINNER_SCORE: #printing function message = constants.WINNER[0] is_winner = True if (is_winner): if score1.value == constants.WINNER_SCORE: serialprint.setColor(constants.COLOURS["BlueScore"]) else: serialprint.setColor(constants.COLOURS["RedScore"]) for y in range(5): for x in range(len(message[0])): if message[y][x] == "X": serialprint.print_at(9 + y, 24 + x, " ")
def draw(self, colour): serialprint.setColor(constants.COLOURS["Reset"]) for y in range(self.position.y): serialprint.print_at(y, self.position.x, " ") serialprint.setColor(colour) for y in range(self.position.y, self.position.y + self.length): serialprint.print_at(y, self.position.x, " ") serialprint.setColor(constants.COLOURS["Reset"]) for y in range(self.position.y + self.length, constants.ROWS): serialprint.print_at(y, self.position.x, " ")
for y in range(5): for x in range(len(message[0])): if message[y][x] == "X": serialprint.print_at(9 + y, 24 + x, " ") bat1 = Bat(3, 3) bat2 = Bat(77, 3) net = Net(int(ceil(constants.COLUMNS / 2)), constants.ROWS) ball = Ball(40, 6) score1 = Score(29, 2, 0) score2 = Score(49, 2, 0) LEDDisplay.init() inputs.init() serialprint.setColor(constants.COLOURS["Reset"]) draw() if constants.showcountdown: LEDDisplay.countdown7seg() #Three second timer setup_serve() while is_winner == False: inputarr = [game_state, player_serving] inputs.update(bat1, bat2, inputarr) game_state = inputarr[0] if game_state == constants.STATE_IN_PLAY: update_game() elif game_state == constants.STATE_SERVE: update_serve()