def __init__(self): self.window = Window() self.paddle = Paddle(self.window) self.bricks = Bricks(self.window) self.ball = Ball(self.window) self.running = True self.check = True
def build_imarray(im, x, y, wall): if wall: imarray = Bricks.build_grid_wall(x, y) pixels = im.load() for i in range(x * Config.WIDTH): for j in range((y * Config.HEIGHT) + Config.WIDTH): imarray[i,j] = pixels[i,j] # load method is faster than getpixel: im.getpixel((i,j)) return imarray else: imarray = Bricks.build_grid(x, y) pixels = im.load() for i in range(x * Config.WIDTH): for j in range(y * Config.HEIGHT): imarray[i,j] = pixels[i,j] # load method is faster than getpixel: im.getpixel((i,j)) return imarray
def build_imarray(im, x, y, wall): if wall: imarray = Bricks.build_grid_wall(x, y) pixels = im.load() for i in range(x * Config.WIDTH): for j in range((y * Config.HEIGHT) + Config.WIDTH): imarray[i, j] = pixels[ i, j] # load method is faster than getpixel: im.getpixel((i,j)) return imarray else: imarray = Bricks.build_grid(x, y) pixels = im.load() for i in range(x * Config.WIDTH): for j in range(y * Config.HEIGHT): imarray[i, j] = pixels[ i, j] # load method is faster than getpixel: im.getpixel((i,j)) return imarray
def update(grid, x, y, geracao): if (get_total(grid,x,y) < 30 or not(geracao % 300)): return Bricks.build_grid(x, y) updated_grid = Bricks.build_grid(x, y) for i in range(Config.WIDTH * x): for j in range(Config.HEIGHT * y): neighbors = get_neighbors(i, j, Config.WIDTH * x, Config.HEIGHT * y, grid) if(get_cell(i, j, Config.WIDTH * x, Config.HEIGHT * y, grid)): if(neighbors < 2): updated_grid[i,j] = Config.DEAD elif(neighbors > 3): updated_grid[i,j] = Config.DEAD else: updated_grid[i,j] = Config.LIVE else: if(neighbors == 3): updated_grid[i,j] = Config.LIVE else: updated_grid[i,j] = Config.DEAD return updated_grid
def loadMap(level, screen): GPIO.cleanup() Terrain = Entity.EntityGroup(screen) players = Entity.EntityGroup(screen) background = Entity.EntityGroup(screen) DarkBricks.build(0, 0, background) x = y = -48 samx = samy = 0 scullx = scully = 0 for row in level: for col in row: if col == "W": Bricks.build(x, y, Terrain) if col == "S": samx = x samy = y if col == "V": Bricks.build(x, y - 48, Terrain) if col == "O": scullx = x scully = y if col == "B": Bricks.build(x, y, background) x += 64 y += 64 x = -48 sam = Samurai.Samurai(samx, samy, Collider.Collider(Terrain)) sam.setDirection(directions.directions.LEFT) scull = Scull.build(scullx, scully, background) players.add(sam) return Terrain, players, background, sam, scullx, scully
class Engine: def __init__(self): self.window = Window() self.paddle = Paddle(self.window) self.bricks = Bricks(self.window) self.ball = Ball(self.window) self.running = True self.check = True def run(self): while self.running: # --- Inputs --- # self.window.getEvents() # --- Processing --- # self.ball.bounce() self.paddle.move(self.window.getKeyPressed()) self.ball.getBallPaddleCollision(self.paddle) for brick in self.bricks.getBricks( ): #Checks collision for all the brick if self.ball.getBallBrickCollision(brick): self.check = False self.bricks.getBricks().pop(self.check) self.ball.updateScore() print("Score:%s" % (self.ball.getScore())) if len(self.bricks.getBricks()) == 0: self.check = False exit() # --- Outputs --- # self.window.clearScreen() self.window.blitSprite(self.ball) self.window.blitSprite(self.paddle) self.bricks.blitBricks() self.window.updateScreen()
def showBricks(self): text = "Choose from: " font = ("Helvetica", "15") size = len(text) print(size) self.canvas.create_text(50, 560, text=text, font=font, anchor="nw") self.canvas.create_line(200, 600, 200, 800, width = 2) self.canvas.create_line(400, 600, 400, 800, width = 2) square_size = 20 #first brick my_brick = Bricks.chooseBrick() print("1 = ", my_brick) for i in range(len(my_brick.shape)): for j in range(len(my_brick.shape[i])): #print("i = ", i, " j = ", j) if my_brick.shape[i][j] == True: x_left = j*square_size + 75 x_right = j*square_size + 75 + square_size y_up = i*square_size + 640 y_down = i*square_size + 640 + square_size self.canvas.create_rectangle(x_left, y_up, x_right, y_down) #print("Up Left: (" + str(x_left) + ", " + str(y_up) + ")") #second brick my_brick_2 = Bricks.chooseBrick() print("2 = ", my_brick_2) for i in range(len(my_brick_2.shape)): for j in range(len(my_brick_2.shape[i])): #print("i = ", i, " j = ", j) if my_brick_2.shape[i][j] == True: x_left = j*square_size + 250 x_right = j*square_size + 250 + square_size y_up = i*square_size + 640 y_down = i*square_size + 640 + square_size self.canvas.create_rectangle(x_left, y_up, x_right, y_down) #print("Up Left: (" + str(x_left) + ", " + str(y_up) + ")") #third brick my_brick_3 = Bricks.chooseBrick() print("3 = ", my_brick_3) for i in range(len(my_brick_3.shape)): for j in range(len(my_brick_3.shape[i])): #print("i = ", i, " j = ", j) if my_brick_3.shape[i][j] == True: x_left = j*square_size + 425 x_right = j*square_size + 425 + square_size y_up = i*square_size + 640 y_down = i*square_size + 640 + square_size self.canvas.create_rectangle(x_left, y_up, x_right, y_down) #print("Up Left: (" + str(x_left) + ", " + str(y_up) + ")") shownBricks = [my_brick, my_brick_2, my_brick_3] return shownBricks
def __init__(self): Walls.Walls() Bricks.Bricks()
def __init__(self): ''' init function ''' Walls.Walls() Bricks.Bricks()
if (options.mode == "rand"): print "TODO" elif (options.mode == "im"): listing = glob.glob(options.folder) #print fig_list s = serial.Serial(Config.SERIAL_PORT, Config.SERIAL_BAUD_RATE, dsrdtr=True) s.open() if not options.wall: for infile in listing: fig = Figure.build_image(infile, options.x, options.y, options.wall) figarray = Figure.build_imarray(fig, options.x, options.y, options.wall) brick_list = Bricks.build_bricklist(options.x, options.y, figarray) fig_list.append(brick_list) turn = 0 while True: #if (True): for fig in fig_list: #Bricks.writetofile(fig) Bricks.sendserial(fig, s) turn = turn + 1 print turn time.sleep(0.1) else: print "modo wall" for infile in listing: fig = Figure.build_image(infile, options.x, options.y, options.wall)
optParser.add_option("-f", "--folder", action="store", dest= "folder", type="string", help="name of the folder containing the images") options, remainingArgs = optParser.parse_args() if (options.mode == "rand"): print "TODO" elif (options.mode == "im"): listing = glob.glob(options.folder) #print fig_list s = serial.Serial(Config.SERIAL_PORT, Config.SERIAL_BAUD_RATE, dsrdtr=True) s.open() if not options.wall: for infile in listing: fig = Figure.build_image(infile, options.x, options.y, options.wall) figarray = Figure.build_imarray(fig, options.x, options.y, options.wall) brick_list = Bricks.build_bricklist(options.x, options.y,figarray) fig_list.append(brick_list) turn = 0 while True: #if (True): for fig in fig_list: #Bricks.writetofile(fig) Bricks.sendserial(fig, s) turn = turn + 1 print turn time.sleep(0.1) else: print "modo wall" for infile in listing: fig = Figure.build_image(infile, options.x, options.y, options.wall) figarray = Figure.build_imarray(fig, options.x, options.y, options.wall)