def draw(self): print "" board = self.board for line in range(len(board)): print board[len(board)-(line+1)] #Draw to panel if self.paneldisplay: colors = self.COLORS if self.BOARDSIZE > 4: for x in range(len(board)): for y in range(len(board[0])): #sp.set_pixel_color(sp.matrix((x+1),14-(y+1)), colors[board[x][y]]) self.panel[7-x][13-y] = colors[board[x][y]] else: for x in range(len(board)): for y in range(len(board[0])): self.panel[6-(x*2)][12-(y*2)] = colors[board[x][y]] self.panel[6-(x*2)][12-(y*2-1)] = colors[board[x][y]] self.panel[6-(x*2-1)][12-(y*2)] = colors[board[x][y]] self.panel[6-(x*2-1)][12-(y*2-1)] = colors[board[x][y]] #sp.set_pixel_color(sp.matrix(((x+1)*2),(15-(y+1)*2)), colors[board[x][y]]) #sp.set_pixel_color(sp.matrix(((x+1)*2),(15-(y+1)*2)-1), colors[board[x][y]]) #sp.set_pixel_color(sp.matrix(((x+1)*2-1),(15-((y+1)*2))), colors[board[x][y]]) #sp.set_pixel_color(sp.matrix(((x+1)*2)-1,(15-((y+1)*2)-1)), colors[board[x][y]]) sp.set_panel_memory_from_matrix(self.panel)
def show(self): matrix = self.build_matrix() if panel_available: svetelny_panel.set_panel_memory_from_matrix(matrix) else: self.print_to_console(matrix)
def play(self, wi): import time while self.playing: direction = self.getdirection(wi) if direction == "R": self.right() time.sleep(0.23) elif direction == "L": self.left() time.sleep(0.3) elif direction == "U": self.up() time.sleep(0.3) elif direction == "D": self.down() time.sleep(0.3) if self.checkboard(): self.playing = False print "You win" text, textwidth = self.textHandler.make_text("YOU WIN!", 16,1, color="00ff00") engine =matrixHandler.MatrixEngine(text) for i in range(textwidth+16): engine.shift_left() matrix = engine.get_matrix(cycle=True, cycle_size_col = textwidth+16) sp.set_panel_memory_from_matrix(matrix) return for _ in range(5): sp.set_panel_color("003000") time.sleep(1) sp.panel_clear() time.sleep(1)
def draw(self): print "" board = self.board for line in range(len(board)): print board[len(board) - (line + 1)] #Draw to panel if self.paneldisplay: colors = self.COLORS if self.BOARDSIZE > 4: for x in range(len(board)): for y in range(len(board[0])): #sp.set_pixel_color(sp.matrix((x+1),14-(y+1)), colors[board[x][y]]) self.panel[7 - x][13 - y] = colors[board[x][y]] else: for x in range(len(board)): for y in range(len(board[0])): self.panel[6 - (x * 2)][12 - (y * 2)] = colors[board[x][y]] self.panel[6 - (x * 2)][12 - (y * 2 - 1)] = colors[board[x][y]] self.panel[6 - (x * 2 - 1)][12 - (y * 2)] = colors[board[x][y]] self.panel[6 - (x * 2 - 1)][12 - (y * 2 - 1)] = colors[board[x][y]] #sp.set_pixel_color(sp.matrix(((x+1)*2),(15-(y+1)*2)), colors[board[x][y]]) #sp.set_pixel_color(sp.matrix(((x+1)*2),(15-(y+1)*2)-1), colors[board[x][y]]) #sp.set_pixel_color(sp.matrix(((x+1)*2-1),(15-((y+1)*2))), colors[board[x][y]]) #sp.set_pixel_color(sp.matrix(((x+1)*2)-1,(15-((y+1)*2)-1)), colors[board[x][y]]) sp.set_panel_memory_from_matrix(self.panel)
def show( self, cords, ): col = self.color print cords, matrix = self.matrix cord = self.pohl.warp(cords[0], cords[1]) x, y = int(round(cord[0])), int(round(cord[1])) print cord if x < 0: return x = 0 elif x >= self.BOARDX: return x = self.BOARDX - 1 if y < 0: return y = 0 elif y >= self.BOARDY: return y = self.BOARDY - 1 if x == 0 and y != 8: self.color = self.COLORS[y] matrix[8][0] = self.color sp.set_panel_memory_from_matrix(matrix) return #matrix = [["000000" for _ in range(self.BOARDX)] for __ in range(self.BOARDY)] matrix[y][x] = col sp.set_panel_memory_from_matrix(matrix)
def show(self, cords, ): col = self.color print cords, matrix = self.matrix cord =self. pohl.warp(cords[0],cords[1]) x, y = int(round(cord[0])), int(round(cord[1])) print cord if x < 0: return x = 0 elif x >= self.BOARDX: return x = self.BOARDX - 1 if y < 0: return y = 0 elif y >= self.BOARDY: return y = self.BOARDY - 1 if x == 0 and y != 8: self.color = self.COLORS[y] matrix[8][0] = self.color sp.set_panel_memory_from_matrix(matrix) return #matrix = [["000000" for _ in range(self.BOARDX)] for __ in range(self.BOARDY)] matrix[y][x] = col sp.set_panel_memory_from_matrix(matrix)
def loaddrawing(self, name): filetoload = open(name+"-paneldrawing.txt", "r") read = filetoload.read() filetoload.close() newmatrix = [] for i in read.split("\n"): newmatrix.append(i.rstrip().split(" ")) self.matrix = newmatrix sp.set_panel_memory_from_matrix(self.matrix)
def showtext( inputtext, inputcolor="0000ff", times=1): for _ in range(times): text, textwidth = textHandler.make_text(inputtext, 16,1, color=inputcolor) engine =matrixHandler.MatrixEngine(text) for i in range(textwidth+16): engine.shift_left() matrix = engine.get_matrix(cycle=True, cycle_size_col = textwidth+16) sp.set_panel_memory_from_matrix(matrix)
def draw(self, wi): running = True for i in range(len(self.COLORS)): self.matrix[i][0] = self.COLORS[i] sp.set_panel_memory_from_matrix(self.matrix) while running: cord = self.getcord(wi) if cord == None: running = False break self.show(cord) buttons = wi.state["buttons"] if buttons & 4: running = False
def show(self): render_board = self.get_blank_board(15, 9) self.addToBoard(SPRITE_SHAPE, render_board, self.sprite.color, self.sprite.x, self.sprite.y) for bullet in self.bullets: render_board[bullet.y][bullet.x] = bullet.color for baddie in self.baddies: render_board[baddie.y][baddie.x] = baddie.color if panel_available: svetelny_panel.set_panel_memory_from_matrix(render_board)
def show(self): render_board = self.get_blank_board(PANEL_WIDTH, PANEL_HEIGHT) for board in self.boards: for x, y in [[board.column, y] for y in range(board.y, board.y + board.height)]: render_board[y][x] = board.color render_board[self.player[1]][self.player[0]] = colors.RED1 if panel_available: svetelny_panel.set_panel_memory_from_matrix(render_board) else: self.print_to_console(render_board)
def checkforlost(self): self.oldboard = copy.deepcopy(self.board) self.shiftleft() self.leftcount() if self.board == self.oldboard: #cannot move left self.shiftright() self.rightcount() if self.board == self.oldboard: #cannot move right self.shiftup() self.upcount() if self.board == self.oldboard: #cannot move up self.shiftdown() self.downcount() if self.board == self.oldboard: #cannot move down #you lose! self.playing = False print "Game over" text, textwidth = self.textHandler.make_text("GAME OVER!", 16,1, color="ff0000") engine =matrixHandler.MatrixEngine(text) for i in range(textwidth+16): engine.shift_left() matrix = engine.get_matrix(cycle=True, cycle_size_col = textwidth+16) sp.set_panel_memory_from_matrix(matrix) return if self.paneldisplay: for _ in range(5): sp.set_panel_color("300000") time.sleep(1) sp.panel_clear() time.sleep(1) else: self.board = self.oldboard else: self.board = self.oldboard else: self.board = self.oldboard else: self.board = self.oldboard
def checkforlost(self): self.oldboard = copy.deepcopy(self.board) self.shiftleft() self.leftcount() if self.board == self.oldboard: #cannot move left self.shiftright() self.rightcount() if self.board == self.oldboard: #cannot move right self.shiftup() self.upcount() if self.board == self.oldboard: #cannot move up self.shiftdown() self.downcount() if self.board == self.oldboard: #cannot move down #you lose! self.playing = False print "Game over" text, textwidth = self.textHandler.make_text( "GAME OVER!", 16, 1, color="ff0000") engine = matrixHandler.MatrixEngine(text) for i in range(textwidth + 16): engine.shift_left() matrix = engine.get_matrix( cycle=True, cycle_size_col=textwidth + 16) sp.set_panel_memory_from_matrix(matrix) return if self.paneldisplay: for _ in range(5): sp.set_panel_color("300000") time.sleep(1) sp.panel_clear() time.sleep(1) else: self.board = self.oldboard else: self.board = self.oldboard else: self.board = self.oldboard else: self.board = self.oldboard
def show(self): #print "" Y = self.BOARDY X = self.BOARDX board = self.board #for line in self.board: # print line for y in range(Y): for x in range(X): if board[y][x] == "p": self.matrix[(Y - 1) - y][x] = "00FF00" else: self.matrix[(Y - 1) - y][x] = "000000" if self.bird < 0: self.bird = 0 elif self.bird >= self.BOARDY: self.bird = self.BOARDY - 1 self.matrix[self.BOARDY - (self.bird + 1)][0] = "0000FF" sp.set_panel_memory_from_matrix(self.matrix)
def show_text(text, text_color, delay=0.1): text, width = textHandler.make_text(text, x_shift=16, y_shift=1, color=text_color) engine = MatrixEngine(text) last = time.time() for i in range(width + 16): engine.shift_left() matrix = engine.get_matrix(cycle_x=False) #Moving text #Wait unit time delay reached while True: if time.time() - last > delay: last = time.time() break svetelny_panel.set_panel_memory_from_matrix(matrix)
def show(self): #print "" Y = self.BOARDY X = self.BOARDX board = self.board #for line in self.board: # print line for y in range(Y): for x in range(X): if board[y][x] == "p": self.matrix[(Y-1)-y][x]="00FF00" else: self.matrix[(Y-1)-y][x]="000000" if self.bird < 0: self.bird = 0 elif self.bird >= self.BOARDY: self.bird = self.BOARDY-1 self.matrix[self.BOARDY-(self.bird+1)][0] = "0000FF" sp.set_panel_memory_from_matrix(self.matrix)
def init(self, wi=None, panel=True): global board global oldboard global pane self.board = [[0 for _ in range(self.BOARDSIZE)] for _ in range(self.BOARDSIZE)] self.oldboard = copy.deepcopy(self.board) self.panel = [["101010" for _ in range(15)] for _ in range(9)] self.addtile() if panel: self.paneldisplay = True else: self.paneldisplay = False if self.paneldisplay: sp.panel_clear() self.playing=True """if self.BOARDSIZE > 4 and self.paneldisplay: sp.rectangle(0, 15-(self.BOARDSIZE+2), self.BOARDSIZE+1, 14, "ffffff") else: sp.rectangle(0,15-((self.BOARDSIZE+2)*2-2), ((self.BOARDSIZE+1)*2)-1, 14, "656565")""" if self.paneldisplay: for i in range(len(self.COLORS)-2): #sp.set_pixel_color(sp.matrix(i,0), self.COLORS[i+1]) #sp.set_pixel_color(sp.matrix(i,1), self.COLORS2[i+1]) self.panel[8-i][0] = self.COLORS[i+1] sp.set_panel_memory_from_matrix(self.panel) time.sleep(0.1) print i self.draw() self.play(wi)
def init(self, wi=None, panel=True): global board global oldboard global pane self.board = [[0 for _ in range(self.BOARDSIZE)] for _ in range(self.BOARDSIZE)] self.oldboard = copy.deepcopy(self.board) self.panel = [["101010" for _ in range(15)] for _ in range(9)] self.addtile() if panel: self.paneldisplay = True else: self.paneldisplay = False if self.paneldisplay: sp.panel_clear() self.playing = True """if self.BOARDSIZE > 4 and self.paneldisplay: sp.rectangle(0, 15-(self.BOARDSIZE+2), self.BOARDSIZE+1, 14, "ffffff") else: sp.rectangle(0,15-((self.BOARDSIZE+2)*2-2), ((self.BOARDSIZE+1)*2)-1, 14, "656565")""" if self.paneldisplay: for i in range(len(self.COLORS) - 2): #sp.set_pixel_color(sp.matrix(i,0), self.COLORS[i+1]) #sp.set_pixel_color(sp.matrix(i,1), self.COLORS2[i+1]) self.panel[8 - i][0] = self.COLORS[i + 1] sp.set_panel_memory_from_matrix(self.panel) time.sleep(0.1) print i self.draw() self.play(wi)
def draw(self): svetelny_panel.set_panel_memory_from_matrix(self.get_matrix())
def show(self): render_board = copy.deepcopy(self.board) xshift = 1 yshift = 0 render_board = self.get_blank_board( 15, 9) #Render board is bigger than tetris board for r, row in enumerate(self.board): for c, cell in enumerate(row): if self.isOnBoard(c, r): xabs = xshift + c yabs = yshift + r if (xabs < 15 and xabs >= 0 and yabs < 9 and yabs >= 0): render_board[yabs][xabs] = self.board[r][c] #----boarders----- board_left = xshift - 1 board_right = xshift + BOARDWIDTH board_down = yshift + BOARDHEIGHT board_up = yshift - 1 #Vertical boarder for y in range(9): yabs = y + yshift if yabs >= 0 and yabs < 9: if board_left >= 0 and board_left < 15: render_board[yabs][board_left] = BOARDER_COLOR #Left edge if board_right >= 0 and board_right < 15: render_board[yabs][ board_right] = BOARDER_COLOR #Right edge #Horizontal boarder for x in range(9 + 2): xabs = x + xshift - 1 if xabs >= 0 and xabs < 15: if board_up >= 0 and board_up < 9: render_board[board_up][xabs] = BOARDER_COLOR #Left edge if board_down >= 0 and board_down < 9: render_board[board_down][xabs] = BOARDER_COLOR #Right edge for magnitude, digit in enumerate(str(self.score)[::-1]): for r in range(int(digit)): xabs = 13 - magnitude + xshift yabs = r + yshift if (xabs < 15 and xabs >= 0 and yabs < 9 and yabs >= 0): render_board[yabs][xabs] = MAGNITUDE_COLORS[magnitude] self.addToBoard(self.fallingPiece, render_board, xshift, yshift) if not panel_available: self.print_board(render_board) print render_board else: svetelny_panel.set_panel_memory_from_matrix(render_board)
import svetelny_panel, colors, time from textHandler import * from matrixHandler import * #Moving text demo svetelny_panel.setup() textHandler = TextHandler() textToView = raw_input("Text to view:") text, textwidth = textHandler.make_text( textToView, x_shift=16, y_shift=1, color=colors.PURPLE ) #Text is shifted 16 pixels horizonataly to right at the very beggining engine = MatrixEngine( text) #Creates Engine object with text from 'textToView' variable while True: engine.shift_left() matrix = engine.get_matrix(cycle_x=True, cycle_size_x=textwidth + 16) #Moving text svetelny_panel.set_panel_memory_from_matrix(matrix) time.sleep(0.05) #engine.print_matrix() #Prints matrix to console