def initializeSurface(self, p1, p2): fieldHeight = 40 goalHeight = 100 postHeight = 30 self.player = playerObject.Player(self, p1) self.AI = soccerAI.AI(self, p2) self.playerChar = self.player.player self.aiPlayerChar = self.AI.player self.playerImageList = self.player.playerL self.playerImageListFlipped = self.player.playerFlippedL self.aiImageList = self.AI.playerL self.aiImageListFlipped = self.AI.playerFlippedL self.ball = sprites.Ball(self) self.field = sprites.Field(0, HEIGHT - fieldHeight, WIDTH, fieldHeight) self.gP1 = sprites.Goalpost(0, HEIGHT - fieldHeight - goalHeight, PLAYER_r * 2, goalHeight) self.gP2 = sprites.Goalpost(WIDTH - PLAYER_r * 2, HEIGHT - fieldHeight - goalHeight, PLAYER_r * 2, goalHeight) self.wall1 = sprites.Wall(0, 0, PLAYER_r * 3, HEIGHT - 140) self.wall2 = sprites.Wall(WIDTH - PLAYER_r * 3, 0, PLAYER_r * 3 + 10, HEIGHT - 140) self.banner = sprites.Banner(70, 199, 560, 50) self.scoreBoard = sprites.ScoreBoard(WIDTH * 2 // 6, 0, WIDTH // 3, HEIGHT // 4) self.sky = sprites.Wall(0, -200, WIDTH, 200)
def init_level(self, level): # Sprite groups self.exits = pygame.sprite.Group() self.magic = pygame.sprite.Group() self.walls = pygame.sprite.Group() self.generators = pygame.sprite.Group() self.doors = pygame.sprite.Group() # Create the level and set current_level to its level list (used for camera movement) self.current_level = self.create_level(level) # Level borders self.left_border = sprites.Wall(-1, 0, 1, settings.display_height) self.walls.add(self.left_border) self.right_border = sprites.Wall( len(self.current_level[0]) * 32, 0, 1, settings.display_height) self.walls.add(self.right_border) # We blit surfaces to the world surface, then blit the world surface to the game display self.world_surface = pygame.Surface( (len(self.current_level[0]) * 32, settings.display_height)) # Camera variables self.cam_x_offset = 0 # Screen shake variables self.shake_amount = 10
def create_level(self, level, solid=True, bg=False): level_x = 0 # Make the bottom-left tile aligned with the bottom-left of the screen if len(level) <= 20: level_y = 0 else: level_y = 0 - (32 * (len(level) - 20)) for rows in level: for cols in rows: if cols == -1: w = sprites.Wall(level_x, level_y, 32, 32, color=settings.green) self.exits.add(w) if "d" in str(cols): w = sprites.Door(level_x, level_y, int(cols[1:])) self.walls.add(w) self.doors.add(w) if "g" in str(cols): w = sprites.Generator(level_x, level_y, int(cols[1:]), self.doors) self.generators.add(w) if cols == 1: w = sprites.Wall(level_x, level_y, 32, 32) self.walls.add(w) level_x += 32 level_x = 0 level_y += 32 return level
def transitRoom(game, group, dungeon, room_number): #deletes all instances in the group and adds new ones #based on the room data matching the given room number for i in range(len(dungeon.room_map)): for j in range(len(dungeon.room_map)): if dungeon.room_map[i][j] == room_number: index = [i, j] dungeon.room_index = index data = dungeon.rooms[index[0]][index[1]].layout try: group.empty() for i in range(len(data)): for j in range(len(data[i])): if data[i][j] == 1: group.add( spr.Wall(game, (j * st.TILESIZE, i * st.TILESIZE), (st.TILESIZE, st.TILESIZE))) dungeon.rooms[dungeon.room_index[0]][ dungeon.room_index[1]].visited = True return group except Exception: #if something goes wrong, return an empty group traceback.print_exc() return group
def new(self): #SPAWN DAS SPRITES self.all_sprites = py.sprite.Group() self.walls = py.sprite.Group() self.colisao = py.sprite.Group() for row, tiles in enumerate(self.map_data): for col, tile in enumerate(tiles): if tile == '1': #SPAWN DO MURO sprites.Wall(self, col, row) # if tile == 'L': #SPAWN DO PORTAL LARANJA DE CIMA # sprites.Portal_L(self, col, row) # if tile == 'l': #SPAWN DO PORTAL LARANJA DE BAIXO # sprites.Portal_l(self, col, row) # # if tile == 'R': #SPAWN DO PORTAL ROXO DE CIMA # sprites.Portal_R(self, col, row) # if tile == 'r': #SPAWN DO PORTAL ROXO DE BAIXO # sprites.Portal_r(self, col, row) if tile == '!': #SPAWN DO PLAYER 1 / AZUL / ÁGUA self.player_agua = sprites.Player(self, col, row) self.players_agua = py.sprite.Group() self.players_agua.add(self.player_agua) if tile == '@': #SPAWN DO PLAYER 2 / AMARELO / FOGO self.player_fogo = sprites.Player2(self, col, row) self.players_fogo = py.sprite.Group() self.players_fogo.add(self.player_fogo)
def initializeSurface(self): fieldHeight = 40 goalHeight = 100 postHeight = 30 self.player = sprites.Player(self) self.AI = sprites.AI(self, self.player) self.ball = sprites.Ball(self) self.field = sprites.Field(0, HEIGHT - fieldHeight, WIDTH, fieldHeight) self.gP1 = sprites.Goalpost(0, HEIGHT - fieldHeight - goalHeight, PLAYER_length * 2, goalHeight) self.gP2 = sprites.Goalpost(WIDTH - PLAYER_length * 2, HEIGHT - fieldHeight - goalHeight, PLAYER_length * 2, goalHeight) # self.gPframe1 = sprites.Wall(0, HEIGHT-fieldHeight-goalHeight-postHeight, PLAYER_length*5,postHeight) # self.gPframe2 = sprites.Wall(WIDTH-PLAYER_length*5,HEIGHT-fieldHeight-goalHeight-postHeight,PLAYER_length*5,postHeight) self.wall1 = sprites.Wall(0, -10000, PLAYER_length * 3 + 10, HEIGHT - 140 + 10000) self.wall2 = sprites.Wall(WIDTH - PLAYER_length * 3 - 10, -10000, PLAYER_length * 3 + 10, HEIGHT - 140 + 10000)
def create_level(self, level, solid=True, bg=False): level_x = 0 # Make the bottom-left tile aligned with the bottom-left of the screen if len(level) <= 20: level_y = 0 else: level_y = 0 - (32 * (len(level) - 20)) for rows in level: for cols in rows: for tilesets in tiles.tileset_list: if int(cols) == tilesets.id: for tile in tilesets.all_tiles: if cols == tile["id"]: # If the tile ID is divisible by 5, top solid is true if int(cols) % 5 == 0: w = sprites.Wall(level_x, level_y, 32, 32, image=tile["image"], top_solid=True) else: w = sprites.Wall(level_x, level_y, 32, 32, image=tile["image"]) if solid: self.walls.add(w) elif bg: self.background_details.add(w) else: self.details.add(w) level_x += 32 level_x = 0 level_y += 32 return level
def new(self): self.all_sprites = py.sprite.Group() self.walls = py.sprite.Group() for row, tiles in enumerate(self.map_data): for col, tile in enumerate(tiles): if tile == '1': sprites.Wall(self, col, row) if tile == 'S': self.player_agua = sprites.Player(self, col, row) if tile == 'L': self.player_fogo = sprites.Player2(self, col, row)
def new(self): self.all_sprites = pygame.sprite.Group() self.player_sprites = pygame.sprite.Group() self.all_enemies = pygame.sprite.Group() self.walls = pygame.sprite.Group() # Initialize Map Objects for tile_object in self.map.tmxdata.objects: if tile_object.name == 'player': self.player = player.Player(self, tile_object.x, tile_object.y) if tile_object.name == 'enemy': enemies.Enemy(self, tile_object.x, tile_object.y) if tile_object.name == 'wall': sprites.Wall(self, tile_object.x, tile_object.y, tile_object.width, tile_object.height)
def Layout(self): x_offset = (BLOCK_SIZE / 2) y_offset = (BLOCK_SIZE / 2) for y in xrange(self.image.get_height()): self.y = y for x in xrange(self.image.get_width()): self.x = x """Get the center point for the rects""" color = self.get_at(self.x, self.y) pos = ((self.x * 4 + x_offset), (self.y * 4 + y_offset)) print self.x, self.y, color if color == self.WALL: wall = sprites.Wall(dataFiles.wallIm, pos) sGroups.staticSprites.add(wall) print sGroups.staticSprites
def build_walls(level): # X and y positions to feed into Wall() x = 0 y = 0 # Each string (row) in the list (level)... for row in level: # Each column (letter in string), move the X by the tile size. Spawn sprite instances according to letters (see level.py for key). for column in row: if column == "W": s.Wall(x, y) if column == "H": s.Door(x, y, "hor") if column == "V": s.Door(x, y, "ver") x += i.tileWidth # Each row (string in list), reset the X to 0 and increase the Y by the tile size. x = 0 y += i.tileHeight
def generate_walls(self): corner_floors = [] for floor in self.game.layers["FLOOR"]: for y in range(int(floor.pos.y - 1), int(floor.pos.y + 2)): for x in range(int(floor.pos.x - 1), int(floor.pos.x + 2)): if not (x == int(floor.pos.x) and y == int(floor.pos.y)): if not self.get_sprites_at( [self.game.layers["WALLS"]], x, y) and not self.get_sprites_at( [self.game.layers["FLOOR"]], x, y): sprites.Wall(self.game, x, y, self.wall_type) a, b, c, d = self.get_neighbours( self.game.layers["FLOOR"], x, y) if a + b + c + d: corner_floors.append((x, y)) for wall in self.game.layers["WALLS"]: top, right, bottom, left = self.get_neighbours( self.game.layers["WALLS"], wall.pos.x, wall.pos.y) if not self.place_exit(wall, (top, right, bottom, left)): wall.update_sprite(top + right * 2 + bottom * 4 + left * 8) return corner_floors
def startup(self): # Sprite groups self.background_details = pygame.sprite.Group() self.walls = pygame.sprite.Group() self.projectiles = pygame.sprite.Group() self.fires = pygame.sprite.Group() self.dust = pygame.sprite.Group() self.animals = pygame.sprite.Group() self.details = pygame.sprite.Group() self.clouds = pygame.sprite.Group() # Creating an instance of the player self.player = sprites.Player(self.walls) # Creating Animals self.bird_1 = sprites.Bird(120, 400, self.walls) self.bird_2 = sprites.Bird(550, 200, self.walls) self.bird_3 = sprites.Bird(900, 200, self.walls) self.animals.add(self.bird_1) self.animals.add(self.bird_2) self.animals.add(self.bird_3) self.butterfly_1 = sprites.Butterfly(120, 120, self.walls) self.butterfly_2 = sprites.Butterfly(650, 350, self.walls) self.butterfly_3 = sprites.Butterfly(1450, 280, self.walls) self.animals.add(self.butterfly_1) self.animals.add(self.butterfly_2) self.animals.add(self.butterfly_3) # Create the background details layer self.create_level(levels.level_background_details, solid=False, bg=True) # Create the level and set current_level to its level list (used for camera movement) self.current_level = self.create_level(levels.level) # Create the details Layer self.create_level(levels.level_details, solid=False) # Level borders self.left_border = sprites.Wall(-1, 0, 1, settings.display_height) self.walls.add(self.left_border) self.right_border = sprites.Wall( len(self.current_level[0]) * 32, 0, 1, settings.display_height) self.walls.add(self.right_border) # We blit surfaces to the world surface, then blit the world surface to the game display self.world_surface = pygame.Surface( (len(self.current_level[0]) * 32, settings.display_height)) self.background = pygame.Surface( (settings.display_width, settings.display_height)) self.background.blit(resources.sky_background, (0, 0)) # Camera variables self.cam_x_offset = 0 # fireball variables self.previous_fireball = 0 # Screen shake variables self.shake_amount = 10
def makeWall(self, pos, size, scale=1, offset=vector.Vector(0, 0)): sprite = sprites.Wall(self.game, pos * scale + offset, size * scale) self.game.all.add(sprite) self.game.walls.add(sprite) return sprite
def init_map(self): for row in range(self.level_map.map_height): for column in range(self.level_map.map_width): if self.level_map.level_data[row][column] == '#': sprites.Wall(self, column * self.level_map.rect_size, row * self.level_map.rect_size)