def first_generate_platforms(): platformss = [] platformss.append(classes.PlatformFirst(710, 1000)) platformss.append(classes.Platform(1210, 600)) platformss.append(classes.Platform(210, 600)) platformss.append(classes.Platform(710, 200)) return platformss
def create_level(level): sprite_group = sprite.Group() platforms = [] #chests = [] x = 0 y = 0 for row in level: for col in row: if col == "-": pf = classes.Platform(x, y) platforms.append(pf) sprite_group.add(pf) if col == "c": ch = classes.Chest(x, y) #chests.append (ch) sprite_group.add(ch) if col == "m": mn = classes.Monster(x, y, text.zombitext) sprite_group.add(mn) x += 45 x = 0 y += 45 x = 0 y = 0 return platforms, sprite_group
def initPlatforms(): """Populates the world with plaforms and walls """ # Create holes holes = [0, 0, 300, 500, 900, 1200, 1500, 1900, varbs.stageW] # Create the floor res = [ classes.Platform(x=holes[2 * i + 1], w=holes[2 * i + 2] - holes[2 * i + 1]) for i in range(len(holes) // 2) ] # Create left wall res += [classes.Wall()] # Create right wall res += [classes.Wall(x=varbs.stageW)] # Create platforms res += [classes.Platform(x=200, y=300, openBottom=True)] return res
screen.fill(CONSTS.GREY) cl.heros.draw(screen) cl.plats.draw(screen) cl.borders.draw(screen) pg.display.flip() running = True pg.init() width, height = size = [1080, 720] screen = pg.display.set_mode(size) hero = cl.Hero([0, 0], cl.heros) platform = cl.Platform([0, 640], CONSTS.plat, cl.plats) ADDEVENT = 10 pg.time.set_timer(ADDEVENT, 40) pg.mouse.set_visible(True) screen.fill(CONSTS.WHITE) pg.display.flip() clock = pg.time.Clock() speed = 10
def build_level(*args): """ build level passed in :param args: :return: """ # unpackage arguments current_level, level, enemies, enemy_sprites, platforms, blocks, entities,\ Platform, block_types, collision_blocks,\ collision_block_sprites, indestructibles, coins, coin_sprites = (x for x in args) # unpackage block_types Unbreakable1, Unbreakable2, BaigeBlock,\ NeonRedBlock, NeonWhiteBlock, NeonBlueBlock, NeonYellowBlock, NeonOrangeBlock, NeonGreenBlock,\ BlueBlock, GrayBlock, BrightBlueBlock, BrownBlock,\ CollisionBlock, CornerPatrolBlock = (x for x in block_types) enemy = None x, y = 0, 0 # build the level for row in level: for col in row: if col != " ": if col == "F": p = classes.BlueCoin(x, y) entities.add(p) coins.append(p) coin_sprites.add(p) elif col == "c": p = classes.Coin(x, y) entities.add(p) coins.append(p) coin_sprites.add(p) elif col == "G": p = classes.GreenCoin(x, y) entities.add(p) coins.append(p) coin_sprites.add(p) elif col == "p": p = classes.PurpleCoin(x, y) entities.add(p) coins.append(p) coin_sprites.add(p) elif col == "E": which_block = BaigeBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "C": which_block = BrownBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "A": which_block = BlueBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "B": which_block = BrightBlueBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "D": which_block = GrayBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "r": which_block = NeonRedBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "w": which_block = NeonWhiteBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "b": which_block = NeonBlueBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "y": which_block = NeonYellowBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "o": which_block = NeonOrangeBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "g": which_block = NeonGreenBlock p = classes.Platform(x, y, which_block) platforms, blocks, entities = InsertPlatform(p, platforms, blocks, entities) elif col == "n": which_block = Unbreakable1 # add indestructible manually to sprite lists p = classes.Platform(x, y, which_block) indestructibles.add(p) entities.add(p) platforms.append(p) elif col == "m": which_block = Unbreakable2 # add indestructible manually to sprite lists p = classes.Platform(x, y, which_block) indestructibles.add(p) entities.add(p) platforms.append(p) elif col == "O": which_block = CollisionBlock # add collision block manually to sprite lists p = classes.BlankPlatform(x, y, which_block, False) collision_blocks.append(p) collision_block_sprites.add(p) entities.add(p) elif col == "Q": which_block = CornerPatrolBlock p = classes.BlankPlatform(x, y, which_block, True) collision_blocks.append(p) collision_block_sprites.add(p) entities.add(p) elif col == "X" or col == "Y": # add exit block manually to sprite lists p = classes.ExitBlock(x, y, col) collision_blocks.append(p) collision_block_sprites.add(p) entities.add(p) # spawn enemies elif col in list('12345678'): if col == "1": enemy = classes.GarbageCollector(x-32, y-64) elif col == "2": enemy = classes.GreenPysnake(x-32, y-64) elif col == "3": enemy = classes.RedPysnake(x-32, y-64) elif col == "4": enemy = classes.BluePysnake(x-32, y-64) elif col == "5": enemy = classes.PurplePysnake(x-32, y-64) elif col == "6": enemy = classes.RedGhost(x, y) elif col == "7": enemy = classes.WhiteGhost(x, y) elif col == "8": enemy = classes.Dragon(x-32, y-64) entities.add(enemy) enemies.append(enemy) enemy_sprites.add(enemy) x += 32 # index by 32 bits y += 32 x = 0 #for enemy in get_enemies(current_level): # # re-calls enemy's constructor # enemy = type(enemy)(enemy.rect.x, enemy.rect.y) # entities.add(enemy) # enemy_sprites.add(enemy) # enemies.append(enemy) return platforms, blocks, entities, enemies,\ enemy_sprites, collision_block_sprites, indestructibles, collision_blocks,\ coins, coin_sprites
def add_plat(): a = get_rand_plat() x = a[0] w = a[1] platforms.append(cl.Platform(x, 150, "platform.png", 0, w, 25))
pygame.display.set_caption("THE GAME") font = pygame.font.Font('freesansbold.ttf', 32) ### OBJECTS ######################################################################################### y = 150 x = 0 for i in range(3): w = random.randrange(min_width,max_width,rand_step) x = random.randrange(x-300,x+300,rand_step) if x < 0: x = 0 if x > screen_width-w: x = screen_width-w platforms.append(cl.Platform(x, y, "platform.png", 0, w, 25)) y += space_between player1 = cl.Player(x, y-30, "bola.png", False, False, -1*speed) player1.resize_image(60, 60) player1.count_plat = 3 player1.last_plat = x ### FUNCTIONS ######################################################################################## def get_pressed_keys(event, end): if event.type == pygame.QUIT: end = True elif event.type == pygame.KEYDOWN: pressed = pygame.key.get_pressed()
def create_addition_wall(self, i, addition, image): wall_up = (classes.Platform(i.rect.x, i.rect.y - 45)) wall_up.image = image addition.append(wall_up)