def createLevel(self): # Set x and y coordinates to 0 x = y = 0 for line in self.layout.split(): # Go through each line for brick in line: # Go through each character in each line and create a color brick or a space according to the character if brick == "w": self.brick_list.append(Brick(x, y, constants.WHITE)) elif brick == "b": self.brick_list.append(Brick(x, y, constants.BLUE)) elif brick == "g": self.brick_list.append(Brick(x, y, constants.GREEN)) elif brick == "r": self.brick_list.append(Brick(x, y, constants.RED)) elif brick == "_": pass else: print brick + " is not a valid character" raw_input("<press enter>") pygame.quit sys.exit() x += 38 + constants.BRICK_MARGIN x = 0 y += 13 + constants.BRICK_MARGIN
def create_brick(bj_settings, screen, bricks, brick_number, Last): bricknew = Brick(bj_settings, screen) bricknew.rect.y -= brick_number * bricknew.rect.height if Last: bricknew.image = pygame.image.load('images/redbrick753.bmp') bricknew.pickedbrick = False bricks.add(bricknew)
def __add_bricks(self): self.__make_poss_array() for i in range(self.no_bricks): brick = Brick() self.empty = brick.place_brick(np.asarray(self.empty)) x, y = brick.get_coord() self.board = render.make_brick(self.board, x, y)
def printLayout(bricks,grid,layout,xgap=0,ygap=1,yoffset=0,custom=None): '''prints the initial brick layout, based on input Layout list''' obj_brick = Brick() br_xlen,br_ylen = obj_brick.getLength() rows = [ lay.split() for lay in layout ] for (rind,row) in enumerate(rows): for (cind,char) in enumerate(row): # print("rind",rind, " cind",cind) brick = None if char == 'A': #rainbow brick = RainbowBrick(grid, cind * (br_xlen+xgap), rind*(br_ylen+ygap)+3+yoffset) elif char == 'G': #green brick = GreenBrick(grid, cind * (br_xlen+xgap), rind*(br_ylen+ygap)+3+yoffset) elif char == 'R': #red brick = RedBrick(grid, cind * (br_xlen+xgap), rind*(br_ylen+ygap)+3+yoffset) elif char == 'C': #cyan brick = CyanBrick(grid, cind * (br_xlen+xgap), rind*(br_ylen+ygap)+3+yoffset) elif char == 'Y': #gold brick = GoldBrick(grid, cind * (br_xlen+xgap), rind*(br_ylen+ygap)+3+yoffset) elif char == 'E': # exploding if custom != None: brick = ExplodingBrick(grid, cind * (br_xlen+xgap), rind*(br_ylen+custom)+3+yoffset) else: brick = ExplodingBrick(grid, cind * (br_xlen+xgap), rind*(br_ylen+ygap)+3+yoffset) if brick!=None: bricks.append(brick)
def generate_ground(self, settings, screen, objects): for x in range(17): objects.add( Brick(settings, screen, settings.brick_lenth * x, settings.ground_level, 5)) objects.add( Brick(settings, screen, settings.brick_lenth * x, settings.ground_level + settings.brick_lenth, 5))
def __init__(self): self.y_pos = STARTING_Y_POS for _ in range(0, WALL_HEIGHT): self.y_pos += 20 for x_pos in range(-350, 450, 100): new_brick = Brick() new_brick.goto(x=x_pos, y=self.y_pos) self.brick_list.append(new_brick)
def fillBricks(self, num): array = [] array2 = [] if num == 1: a = 0 for i in range(0, 18, 3): for j in range(0, 144, 8): stren = random.randint(1, 5) hl = int(j / 8) whbrick = np.random.choice(2, 1, p=[0.9, 0.1]) if whbrick: stren = 3 if (hl == a or hl == a + 1 or hl == 17 - a or hl == 17 - a - 1) and int(i / 3) != 5: stren = 6 whbrick = 0 array.append( Brick(9 + i, 30 + j, 3, 8, 0, 0, stren, whbrick)) if (stren == 3 or stren == 4): array2.append( PowerUp(9 + i, 30 + j, 1, 1, 0, 0, random.choice(POWERUPS))) a += 2 if num == 2: a = 10 for i in range(0, 18, 3): for j in range(0, 144, 8): stren = random.randint(1, 5) hl = int(j / 8) whbrick = np.random.choice(2, 1, p=[0.9, 0.1]) if whbrick: stren = 3 if (hl == a or hl == a + 1 or hl == 17 - a or hl == 17 - a - 1) and int(i / 3) != 0: stren = 6 whbrick = 0 if not ((int(i / 3) == 0 and int(j / 8) == 0) or (int(i / 3) == 0 and int(j / 8) == 17)): array.append( Brick(9 + i, 30 + j, 3, 8, 0, 0, stren, whbrick)) if (stren == 3 or stren == 4): array2.append( PowerUp(9 + i, 30 + j, 1, 1, 0, 0, random.choice(POWERUPS))) a -= 2 if num == 3: array.append(Boss(0, int(FRAMEWIDTH / 2), 7, 33, 0, 1, 20, 0)) for i in range(9, 18, 3): for j in range(0, 144, 8): stren = random.randint(1, 5) if stren == 5: array.append(Brick(9 + i, 30 + j, 3, 8, 0, 0, stren, 0)) return array, array2
def spawn_brick(self) -> bool: """Spawns a random new brick. Returns true on collision (game over).""" if self.__next_brick is None: shape_num = randint(1, 7) self.__next_brick = Brick(shape_num) self.__brick = self.__next_brick shape_num = randint(1, 7) self.__next_brick = Brick(shape_num) collision = self.__brick.collision(self.__matrix) return collision
def draw_bricks(self): h = 0 for j in [25, 75]: for i in range(65, self.width - 65, self.width / 5): self.bricks.append(Brick(self, i, j, h)) h += 1 for k in [self.height - 25, self.height - 75]: for i in range(65, self.width - 65, self.width / 5): self.bricks.append(Brick(self, i, k, h)) h += 1
def spawn_brick(self): """ Spawns a new (random) brick. """ if self.next_brick is None: shape_num = randint(1, 7) self.next_brick = Brick(shape_num) self.brick = self.next_brick shape_num = randint(1, 7) self.next_brick = Brick(shape_num) collision = self.brick.collision(self.matrix) return collision
def ready_game(): global gameState gameState = GAMESTATE_READY game_world.remove_objects_at_layer(game_world.layer_obstacle) game_world.remove_objects_at_layer(game_world.layer_item) global stage_number, max_stage_number try: f = open('stage_' + str(stage_number) + '.json', 'r') data = json.load(f) f.close() if max_stage_number <= stage_number: max_stage_number = stage_number + 1 except IOError: data = None global stage if data == None: bricks = [] stage['bricks'] = [] else: stage = data wall.bg_index = data['bg_pattern'] bricks = data['bricks'] global ball ball.x, ball.y, ball.angle, ball.speed = tuple(stage['ball']) bricks = list(map(lambda d: Brick(d["x"], d["y"], d["t"]), bricks)) bricks.sort(key=lambda b: b.orderValue()) for b in bricks: game_world.add_object(b, game_world.layer_obstacle) global scoreStatic, scoreLabel, nameLabel if 'label_s1' in stage: color = tuple(stage['label_s1']) scoreStatic.color = color nameStatic.color = color if 'label_s2' in stage: color = tuple(stage['label_s2']) scoreLabel.color = color nameLabel.color = color if 'designer' in stage: nameLabel.text = stage['designer'] global brick brick = Brick(0, 0, 1, True) update_score() update_stage_label() update_bg_index()
def setUp(self): """Common bricks, positions, and rotations for testing the designspace functionality from many angles""" self.design = designspace.DesignSpace() self.b1 = Brick('1') self.b2 = Brick('2') self.pos1 = [1, 2, 3] self.pos2 = [4, 5, 6] self.rot1 = [7, 8, 9] self.rot2 = [10, 11, 12]
def create_area(): brick_count = 0 pattern = choice(patterns) # Looks at the pattern array and creates a grid of bricks. for row, num in enumerate(pattern): color = choice(brick_colors) start_x = (432 - (num * 32) - ((num - 1) * 16)) // 2 start_y = 32 for i in range(num): brick = Brick(game_area, color, brick_count) brick.create_brick(start_x + (i * 48), start_y + (row * 32)) bricks.append(brick) brick_count += 1
def create_bricks(screen, sett, briks): '''Создаёт поле кирпичей''' brick = Brick(screen, sett) available_space_x = sett.W - brick.rect.width number_bricks = available_space_x // brick.rect.width #print(f"width = {number_bricks*brick.rect.width}") for row_brick in range(1, 6): for col_brick in range(1, number_bricks): brick = Brick(screen, sett) brick.rect.x = brick.rect.width*col_brick brick.rect.y = brick.rect.height*row_brick briks.add(brick)
def fill(self): if(self.parity == 0): for b in range(self.capacity): print(b) self.bricks[b] = Brick(Type.big,self.num,b) else: print(0) self.bricks[0] = Brick(Type.small,self.num,0) for k in range(1,self.capacity-1): print(k) self.bricks[k] = Brick(Type.big,self.num,k) print(self.capacity-1) self.bricks[self.capacity-1] = Brick(Type.small,self.num,self.capacity-1)
def generate_ground(self, settings, screen, objects): for x in range(70): objects.add( Brick(settings, screen, settings.brick_lenth * x, settings.ground_level, 2)) objects.add( Brick(settings, screen, settings.brick_lenth * x, settings.ground_level + settings.brick_lenth, 2)) for x in range(72, 87): objects.add( Brick(settings, screen, settings.brick_lenth * x, settings.ground_level, 2)) objects.add( Brick(settings, screen, settings.brick_lenth * x, settings.ground_level + settings.brick_lenth, 2)) for x in range(90, 154): objects.add( Brick(settings, screen, settings.brick_lenth * x, settings.ground_level, 2)) objects.add( Brick(settings, screen, settings.brick_lenth * x, settings.ground_level + settings.brick_lenth, 2)) for x in range(156, 213): objects.add( Brick(settings, screen, settings.brick_lenth * x, settings.ground_level, 2)) objects.add( Brick(settings, screen, settings.brick_lenth * x, settings.ground_level + settings.brick_lenth, 2))
def setup(self): pygame.init() # create window self.screen = Window(self.window_size) self.draw_dot = Dot(self.screen) # create game board self.screen.create_game_board() # create brick ## brick type value is from 0 to 6 ## should be set to 0 in default self.brick = Brick(self.screen, 0, 0, 0, 1)
def create_bricks(self): w = c.brick_width h = c.brick_height brick_count = c.screen_width // (w + 1) offset_x = (c.screen_width - brick_count * (w + 1)) // 2 bricks = [] for row in range(c.row_count): for col in range(brick_count): effect = None brick_color = c.brick_color index = random.randint(0, 10) if index < len(special_effects): brick_color, start_effect_func, reset_effect_func = list(special_effects.values())[index] effect = start_effect_func, reset_effect_func brick = Brick(offset_x + col * (w + 1), c.offset_y + row * (h + 1), w, h, brick_color, effect) bricks.append(brick) self.objects.append(brick) self.bricks = bricks
def ready_game(): global gameState gameState = GAMESTATE_READY game_world.remove_objects_at_layer(game_world.layer_obstacle) game_world.remove_objects_at_layer(game_world.layer_item) f = open('stage_' + str(stage_number) + '.json', 'r') data = json.load(f) f.close() global stage stage = data wall.bg_index = data['bg_pattern'] bricks = data['bricks'] global ball ball.x, ball.y, ball.angle, ball.speed = tuple(data['ball']) for d in bricks: brick = Brick(d["x"], d["y"], d["t"]) game_world.add_object(brick, game_world.layer_obstacle) global scoreStatic, scoreLabel if 'label_s1' in data: scoreStatic.color = tuple(data['label_s1']) if 'label_s2' in data: scoreLabel.color = tuple(data['label_s2']) # player.init(Life.LIFE_AT_START) update_score()
def create_brick(self, x, y, num): self.brick = Brick(self.screen, self.settings, num) self.brick.rect.x = x self.brick.rect.y = y self.bricks.add(self.brick) if num == 4: # + self.ground.add(self.brick) # +
def draw_field(self): bricks = [] for j, row in enumerate(self.world.field): for i, el in enumerate(row): brick_color = colors.YELLOW1 if el.predators: brick_color = colors.INDIANRED elif el.herbivores: brick_color = colors.LIGHTBLUE elif el.plant: brick_color = colors.GREEN w = c.brick_width h = c.brick_height brick = Brick(i * (w + 1), j * (h + 1), w, h, brick_color, None) bricks.append(brick) self.objects.append(brick) self.dots = bricks
def update(self): if self.is_jump: self.y = (2 * self.t ** 2 - 3 * self.t + 1) * self.y1 + (-4 * self.t ** 2 + 4 * self.t) * self.y2 + ( 2 * self.t ** 2 - self.t) * self.y3 self.t += game_framework.frame_time if self.t >= 1: self.t = 0 self.is_jump = False if self.is_collide_brick: self.is_collide_to_brick = True brick = Brick() self.y = brick.y + 80 if self.x < brick.x - 50 or self.x > brick.x + 50: self.is_collide_brick = False if not self.is_collide_brick: while (self.y == 130): self.y -= game_framework.frame_time * 200 self.cur_state.do(self) if len(self.event_que) > 0: event = self.event_que.pop() self.cur_state.exit(self, event) self.cur_state = next_state_table[self.cur_state][event] self.cur_state.enter(self, event) pass
def update(self): if self.is_collide_item_box: self.is_jump = False self.is_collide_item_box = False # 점프 if self.is_jump: self.y = (2 * self.t**2 - 3 * self.t + 1) * self.y1 + ( -4 * self.t**2 + 4 * self.t) * self.y2 + (2 * self.t**2 - self.t) * self.y3 self.t += game_framework.frame_time if self.t >= 1: self.t = 0 self.is_jump = False # 벽돌 위 올라감 if self.is_collide_brick: brick = Brick() self.y = brick.y + 80 if self.x < brick.x - 50 or self.x > brick.x + 45: self.is_collide_brick = False if not self.is_collide_brick: self.y -= game_framework.frame_time * 100 self.cur_state.do(self) if len(self.event_que) > 0: event = self.event_que.pop() self.cur_state.exit(self, event) self.cur_state = next_state_table[self.cur_state][event] self.cur_state.enter(self, event) pass
def enter(): global mario, map, enemy, object, fire_ball, chimney, mario_life global mario_life2, mario_life3, mario_life4 global item_box, brick, item, coin_box, turtle, coin, balls mario = Mario() map = Map() enemy = Enemy() object = Object() fire_ball = Ball() chimney = Chimney() mario_life = Mario_Life() mario_life2 = Mario_Life2() mario_life3 = Mario_Life3() mario_life4 = Mario_Life4() item_box = Object_Item() brick = Brick() item = Item() coin_box = Coin_Box() turtle = Turtle() coin = Coin() game_world.add_object(map, 0) game_world.add_object(object, 1) game_world.add_object(mario, 0) game_world.add_object(enemy, 1) #game_world.add_object(chimney, 0) game_world.add_object(mario_life, 1) game_world.add_object(mario_life2, 0) game_world.add_object(mario_life3, 1) game_world.add_object(mario_life4, 0) game_world.add_object(item_box, 1) game_world.add_object(brick, 0) game_world.add_object(coin_box, 1) #game_world.add_object(turtle, 0) pass
def enter(): global mario, map, enemy, object, fire_ball, chimney, mario_life global mario_life2, mario_life3, mario_life4 global item_box, brick mario = Mario() map = Map() enemy = Enemy() object = Object() fire_ball = Ball() chimney = Chimney() mario_life = Mario_Life() mario_life2 = Mario_Life2() mario_life3 = Mario_Life3() mario_life4 = Mario_Life4() item_box = Object_Item() brick = Brick() game_world.add_object(map, 0) game_world.add_object(object, 1) game_world.add_object(mario, 0) game_world.add_object(enemy, 1) game_world.add_object(chimney, 0) game_world.add_object(mario_life, 1) game_world.add_object(mario_life2, 0) game_world.add_object(mario_life3, 1) game_world.add_object(mario_life4, 0) game_world.add_object(item_box, 1) game_world.add_object(brick, 0) pass
def create_bricks(self): w = c.brick_width h = c.brick_height brick_count = c.screen_width // (w + 1) offset_x = (c.screen_width - brick_count * (w + 1)) // 2 bricks = [] effects = random.sample([i for i in range(c.row_count * brick_count)], 24) random.shuffle(effects) for row in range(c.row_count): for col in range(brick_count): index = row * brick_count + col effect = None brick_color = c.brick_color if index in effects: brick_color, start_effect_func, reset_effect_func = list( special_effects.values())[effects.index(index) // 4] effect = start_effect_func, reset_effect_func brick = Brick(offset_x + col * (w + 1), c.offset_y + row * (h + 1), w, h, brick_color, effect) bricks.append(brick) self.objects.append(brick) self.bricks = bricks
def append_brick(self, column, row, color_id, type_id): self.bricks.append( Brick( constants.SCREEN_MARGIN + column * (self.brick_width + constants.BRICK_DISTANCE), constants.SCREEN_MARGIN + row * (self.brick_height + constants.BRICK_DISTANCE), self.brick_width, self.brick_height, color_id, type_id))
def init_game(): hand_x = WIDTH * 0.45 # initial x hand_y = HEIGHT - 100 # initial y newHand = Hand(hand_x, hand_y, 0) # o 0 eh a velocidade, pois a mao comeca parada myBrick = Brick(random.randrange(0, WIDTH - 60), -600, 5) brickList.append(myBrick) return newHand
def levelTwo(self): x1 = 20 y1 = 20 x2 = 78 y2 = 60 self.bricks_list = [] for i in range(4): for j in range(10): brick = Brick(Point(x1, y1), Point(x2, y2), self.win) x1 += 58 x2 += 58 brick.color_brick() self.bricks_list.append(brick) x1 = 20 x2 = 78 y1 += 40 y2 += 40
def collision(self, ball_object: ball.Ball, brick_object: brick.Brick): try: self.screen.blit( brick_object.draw(), (int(brick_object.pos.x), int(brick_object.pos.y))) if (brick_object.pos.x - 5) < ball_object.pos.x < (brick_object.pos.x + 69) and ( ball_object.pos.y > brick_object.pos.y - 10) and ball_object.pos.y < brick_object.pos.y + 74: assets.Assets.brick_collision_sound.play() ball_object.move_y *= -1 ball_object.move_x *= -1 brick_object.bool = False self.score += 1 except TypeError: raise Exception("Type Error in collision") except: raise Exception("Collision function error")
def main(): screen = display.set_mode(WIN_SIZE) display.set_caption('ARCANOID') bg = Surface(WIN_SIZE) bg.fill((100,100,200)) win = image.load('Spr/win.png') boll = Boll(500, 300) pl = Platform(500, 500) bricks = [ [0, 1, 2, 3, 0, 1, 2, 3, 0, 1], [1, 2, 3, 0, 1, 2, 3, 0, 1, 2], [2, 3, 0, 1, 2, 3, 0, 1, 2, 3], [3, 0, 1, 2, 3, 0, 1, 2, 3, 0], [0, 1, 2, 3, 0, 1, 2, 3, 0, 1], [1, 2, 3, 0, 1, 2, 3, 0, 1, 2], [2, 3, 0, 1, 2, 3, 0, 1, 2, 3], [3, 0, 1, 2, 3, 0, 1, 2, 3, 0], [0, 1, 2, 3, 0, 1, 2, 3, 0, 1], [1, 2, 3, 0, 1, 2, 3, 0, 1, 2], ] left = right = reboot =False timer = pygame.time.Clock() count = True while count: timer.tick(60) for e in event.get(): if e.type == QUIT: count = False if e.type == KEYDOWN and e.key == K_LEFT: left = True if e.type == KEYDOWN and e.key == K_RIGHT: right = True if e.type == KEYUP and e.key == K_LEFT: left = False if e.type == KEYUP and e.key == K_RIGHT: right = False if e.type == KEYDOWN and e.key == K_r: reboot = True bricks = [ [0, 1, 2, 3, 0, 1, 2, 3, 0, 1], [1, 2, 3, 0, 1, 2, 3, 0, 1, 2], [2, 3, 0, 1, 2, 3, 0, 1, 2, 3], [3, 0, 1, 2, 3, 0, 1, 2, 3, 0], [0, 1, 2, 3, 0, 1, 2, 3, 0, 1], [1, 2, 3, 0, 1, 2, 3, 0, 1, 2], [2, 3, 0, 1, 2, 3, 0, 1, 2, 3], [3, 0, 1, 2, 3, 0, 1, 2, 3, 0], [0, 1, 2, 3, 0, 1, 2, 3, 0, 1], [1, 2, 3, 0, 1, 2, 3, 0, 1, 2], ] if e.type == KEYUP and e.key == K_r: reboot = False screen.blit(bg, (0, 0)) win_count = 0 x = y = 0 for row in bricks: for col in row: if col != 4: br = Brick(x+BOLL_D, y+BOLL_D, col) br.draw(screen) win_count = 1 x += BRICK_WIDTH y += BRICK_HEIGHT x = 0 boll.update(bricks, pl, reboot) if not win_count: boll.dx = 0 boll.dy = 0 boll.draw(screen) if not win_count: screen.blit(win, (0, 0)) pl.update(left, right, reboot) pl.draw(screen) display.update()