From 6c867df7bbd312f3245b594bb2601651ff322351 Mon Sep 17 00:00:00 2001 From: rcoh Date: Wed, 31 Aug 2011 15:55:42 -0400 Subject: fixed the renderer :). --- renderer.py | 30 +++++++++++++++++++----------- tetris.py | 6 +++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/renderer.py b/renderer.py index db929e5..a950447 100644 --- a/renderer.py +++ b/renderer.py @@ -138,12 +138,13 @@ class LedRenderer(Renderer): Renderer for the LEDs. Based heavily on IndoorRenderer in Smootlight and general Smootlight abstraction patterns """ - POWER_SUPPLY_IPS = ['10.32.97.17',0,0,0] #TODO: Fill in + POWER_SUPPLY_IPS = ['10.32.0.32','10.32.0.32', '10.32.0.31', '10.32.0.31',0,0] #TODO: Fill in SOCK_PORT = 6038 sockets = {} def render_game(self, game_board): packets = self.map_to_packets(game_board) + packets_with_destinations = zip(self.POWER_SUPPLY_IPS, packets) for (ip, (port, packet)) in packets_with_destinations: if not ip in self.sockets: @@ -155,7 +156,11 @@ class LedRenderer(Renderer): except: print 'failure sending packet' def color_deref(self, color): - return (255, 0, 0) + return Color(color)[0:3] + def fake_map_to_packets(self, game_board): + strip = zeros((50,3), 'ubyte') + strip[:] = (255,255,0) + return [(1, strip), (2, strip)] * 4 def map_to_packets(self, game_board): """ Performs the mapping between a game_board and a list of (port,packet) pairs. The port,packet @@ -164,19 +169,22 @@ class LedRenderer(Renderer): #This is hardcoded, mostly because I'm curious of the complexity packets = [] board_x_min = 0 - board_x_max = 10 + board_x_max = 9 section_width = 10 section_height = 5 - for board_x_min in [0, 10]: - packet = [] - for board_y_min in [20, 15, 10, 5]: + for board_x_min in [0, 10]: #for each board: + for board_y_min in [0, 5, 10, 15]: strip = zeros((50,3),'ubyte') index = 0 - for y in range(board_y_min, board_y_min-section_height, -1): - for x in range(board_x_min+section_width, board_x_min, -1): + for y in range(board_y_min, board_y_min+section_height, 1): + strand_dir = 1 if y % 5 % 2 == 0 else -1 + left_x = board_x_min+section_width-1 if strand_dir < 0 else board_x_min + right_x = board_x_min-1 if strand_dir < 0 else board_x_min+section_width + for x in range(left_x, right_x, strand_dir): + print (x,y), index + #strip[index] = (x*10,0,y*10) if (x,y) in game_board: strip[index] = self.color_deref(game_board[(x,y)]) - packet.append((1+len(packet), strip)) - index += 1 - packets += packet + index += 1 + packets.append((1+(len(packets) % 2), strip)) return packets diff --git a/tetris.py b/tetris.py index 4b85798..e88e4a7 100644 --- a/tetris.py +++ b/tetris.py @@ -20,7 +20,7 @@ from ddrinput import DdrInput from ddrinput import DIRECTIONS import pygame -TIME_LIMIT = 2 * 60 #seconds +TIME_LIMIT = 5 * 60 #seconds LINES_TO_ADVANCE = 8 #num lines needed to advance to next level LEVEL_SPEEDS = [400,300,400,250,560,520] @@ -295,8 +295,8 @@ class TetrisGame(object): p.handle_move(DOWN) def update_gui(self): - #[gui.render_game(self.to_dict()) for gui in self.gui] - self.gui[0].render_game(self.to_gui_dict()) + [gui.render_game(self.to_dict()) for gui in self.gui] + #self.gui[0].render_game(self.to_gui_dict()) def end_game(self): if self.gameState.winner!=None: -- cgit v1.2.3