def create_Brick(self): screen_w = 800 screen_h = 600 screen_tilew = math.ceil(screen_w / self.tile_width) screen_tileh = math.ceil(screen_h / self.tile_height) start_y = -(self.camera_pos[1] % self.tile_height) start_x = -(self.camera_pos[0] % self.tile_width) start_tile_x = max(0, int(self.camera_pos[0] / self.tile_width)) start_tile_y = max(0, int(self.camera_pos[1] / self.tile_height)) end_tile_x = min(start_tile_x + screen_tilew, self.world_width - 1) end_tile_y = min(start_tile_y + screen_tileh, self.world_height - 1) for layer_num in range(len(self.tile_layers)): layer = self.tile_layers[layer_num] y = start_y for row_num in range(start_tile_y, end_tile_y + 1): row = layer[row_num] x = start_x for col_num in range(start_tile_x, end_tile_x + 1): code = row[col_num] if code != 0: if code == 6 or code == 7: self.bricks.append(bricks.Brick([x,y],(8, 8),code, toughscore = 2)) else: self.bricks.append(bricks.Brick([x,y],(8, 8),code)) x += self.tile_width y += self.tile_height
def setUp(self): self.pipe = collider.Pipe(1, 2) self.brick = bricks.Brick(1, 2, 'coin') self.step = collider.Step(1, 2) self.pipe = collider.Pipe(1, 2) self.goomba = enemies.Goomba(1, 2) self.koopa = enemies.Koopa(1, 2)
__author__ = 'kartikn' import random import pygame import sys from pygame.locals import * import bricks WINDOW_WIDTH = 300 WINDOW_HEIGHT = 300 pygame.init() window_surface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32) brick_list = [] for i in range(0, 5): brick = bricks.Brick(random.randrange(50, 250), random.randrange(50, 250), random.randrange(50), random.randrange(50), WINDOW_WIDTH, WINDOW_HEIGHT) brick.x_vel = random.randrange(-1, 2) brick.y_vel = random.randrange(-1, 2) brick.color = ([ random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255) ]) brick.line_width = (random.randrange(0, 10)) brick.warp = random.randrange(0, 2) brick_list.append(brick) while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit()
colors = [ORANGE, RED, GREEN, BLUE, YELLOW] number_bricks = 9 pygame.init() main_Surface = pygame.display.set_mode((500, 250), 0, 32) pygame.display.set_caption("Brick Pyramid") WIDTH = (500 - (number_bricks * SPACE)) / number_bricks x = 0 y = 250 - HEIGHT for c in range(5): x = ( WIDTH + SPACE ) * c # this add a space + height to add a row of new bricks on the x row color = colors[c] for b in range(number_bricks): my_brick = bricks.Brick(WIDTH, HEIGHT, color, main_Surface) my_brick.draw_brick(x, y) x += WIDTH + SPACE number_bricks = number_bricks - 2 y = y - HEIGHT - SPACE # This subtracts the height - space to take 2 bricks away # from the row above the previous row and makes a new row of bricks while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit()
backround_c = (255, 255, 255) # sets number of brick in row in pyramid numberofB = 9 SPACE_BETWEEN_BRICKS = 5 pygame.init() # made variable to pass width of screen size W = 650 # creates surface in pygame, sets caption, and fills the screen color mainSurface = pygame.display.set_mode((W, 500)) pygame.display.set_caption("Bricks") mainSurface.fill(backround_c) # calculates the width of the brick pyramid width = (W - ((numberofB + 1) * SPACE_BETWEEN_BRICKS))/numberofB brick = bricks.Brick(mainSurface, width) # sets red green and blue for brick color to a set ammount r = 255 g = 10 b = 12 # starting y position ypos = 470 # starting x position xpos = SPACE_BETWEEN_BRICKS # height of brick height = 25 # loop that updated the number of brick, x-y position and color for each row of bricks for q in range(5): # loop that creates a row of bricks for x in range(numberofB): brick.drawbrick(xpos, ypos, r, g, b)