def create(self): self.player = Player(self.controller) self.hunger = Hunger(self.player) wall_x = 38 wall_y = [10, 11, 12] walls = [ Wall(wall_x, wall_y[0]), Wall(wall_x, wall_y[1]), Wall(wall_x, wall_y[2]), ] food_x = [43, 43, 40] food_y = [10, 12, 12] food_list = [ Food(food_x[0], food_y[0]), Food(food_x[1], food_y[1]), Food(food_x[2], food_y[2]), ] entities = [ self.player, self.hunger, ] entities.extend(food_list) entities.extend(walls) self.updater = Updater(entities) self.collider = Collider(entities) self.render = Render(entities)
def main(): terminal.open() terminal.refresh() controller = Controller() player = Player(controller) hunger = Hunger(player) walls = [ Wall(WALL_X, WALL_Y[0]), Wall(WALL_X, WALL_Y[1]), Wall(WALL_X, WALL_Y[2]), ] food_list = [ Food(FOOD_X[0], FOOD_Y[0]), Food(FOOD_X[1], FOOD_Y[1]), Food(FOOD_X[2], FOOD_Y[2]), ] entities = [ player, hunger, ] entities.extend(food_list) entities.extend(walls) updater = Updater(entities) collider = Collider(entities) render = Render(entities) while True: controller.update() if controller.is_exit: break if player.is_game_over: render_game_over() else: terminal.refresh() updater.update() collider.update() render.update() terminal.close()
def available_actions(self) -> List[Union[ActionPlaceWall, ActionMovePawn]]: player = self.pawn result = [ActionMovePawn(player.coord, x) for x in player.valid_moves] if not player.walls: # Out of walls? return result k = self.board.state[1 + 4 * len(self.board.pawns):] try: return result + core.MEMOIZED_WALLS[k] except KeyError: pass color = self.board[0][0].wall_color tmp: List[Union[ActionPlaceWall, ActionMovePawn]] = [] for i in range(self.board.rows - 1): for j in range(self.board.cols - 1): for horiz in (False, True): wall = Wall(self.board.screen, self.board, color, Coord(i, j), horiz) if self.board.can_put_wall(wall): tmp.append(ActionPlaceWall(wall)) core.MEMOIZED_WALLS[k] = tmp return result + tmp
def set_walls(self, walls): wall_array = [] for x in range(int(WIDTH / TILESIZE)): for y in range(int(HEIGHT / TILESIZE)): if walls[y][x] == w: wall_array.append(Wall(self.gsm, x, y)) return wall_array
def convertMap(self, m): walls = [] x, y = 0, 0 for line in m: for column in line: if column in ["+", "|", "-"]: walls.append(Wall(x, y)) x += CELL_SIZE y += CELL_SIZE x = 0 return walls
def read_state(file_path, player_key): with open(file_path, 'r') as state_file: js = json.load(state_file) game_state = GameState() for player in js['RegisteredPlayerEntities']: if not player['Killed']: game_state.players.append( Player(player['Name'], player['Key'], player['Points'], player['Killed'], player['BombBag'], player['BombRadius'], location_to_tuple(player['Location']))) game_state.current_player = filter(lambda player: player.key == player_key, game_state.players)[0] for _singleEntity in js['GameBlocks']: for singleEntity in _singleEntity: if singleEntity['Entity']: if singleEntity['Entity'][ '$type'] != 'Domain.Entities.PlayerEntity, Domain': wall = singleEntity['Entity'] game_state.walls.append( Wall(wall['$type'], location_to_tuple(wall['Location']))) if singleEntity['Bomb']: bomb = singleEntity['Bomb'] game_state.bombs.append( Bomb(bomb['Owner']["Key"], bomb['BombRadius'], bomb['BombTimer'], bomb['IsExploding'], location_to_tuple(bomb['Location']))) if singleEntity['PowerUp']: pUp = singleEntity['PowerUp'] game_state.power_ups.append( PowerUp(pUp['$type'], location_to_tuple(pUp['Location']))) game_state.map = [['.' for j in range(js['MapWidth'])] for i in range(js['MapHeight'])] for wall in game_state.walls: if wall.destructible: game_state.set_map(wall.location, '+') else: game_state.set_map(wall.location, '#') return game_state
def load_to_game(): walls = [ Wall(pygame.Rect(-100, -200, 300, 100), renderer), Wall(pygame.Rect(100, 200, 300, 100), renderer), Wall(pygame.Rect(-300, -500, 500, 200), renderer), Wall(pygame.Rect(600, -200, 400, 100), renderer), Wall(pygame.Rect(-500, -800, 300, 600), renderer), Wall(pygame.Rect(-1600, -1600, 200, 1000), renderer), Wall(pygame.Rect(-1600, 1600, 1000, 200), renderer), Wall(pygame.Rect(1600, 1600, 1000, 200), renderer), Wall(pygame.Rect(1600, -1600, 1000, 200), renderer), Wall(pygame.Rect(-2000, -3700, 300, 1000), renderer), Wall(pygame.Rect(-2000, 3700, 300, 1000), renderer), Wall(pygame.Rect(2000, 3700, 300, 1000), renderer), Wall(pygame.Rect(2000, -3700, 300, 1000), renderer), Wall(pygame.Rect(4300, -4300, 100, 100), renderer), Wall(pygame.Rect(-2000, -2900, 100, 100), renderer), Wall(pygame.Rect(4500, -900, 100, 100), renderer), Wall(pygame.Rect(400, -500, 100, 100), renderer), Wall(pygame.Rect(-1400, 4500, 100, 100), renderer), Wall(pygame.Rect(3800, -2900, 100, 100), renderer), Wall(pygame.Rect(-1900, 3100, 100, 100), renderer), Wall(pygame.Rect(-4700, 4400, 100, 100), renderer), Wall(pygame.Rect(-4300, 2300, 100, 100), renderer), Wall(pygame.Rect(-2300, 2000, 100, 100), renderer), Wall(pygame.Rect(-1200, -4800, 100, 100), renderer), Wall(pygame.Rect(1100, -3000, 100, 100), renderer), Wall(pygame.Rect(1500, -3400, 100, 100), renderer), Wall(pygame.Rect(3600, 4600, 100, 100), renderer), Wall(pygame.Rect(3700, 800, 100, 100), renderer), Wall(pygame.Rect(-4500, -3400, 100, 100), renderer), Wall(pygame.Rect(2000, 2000, 100, 100), renderer), Wall(pygame.Rect(4800, -4700, 100, 100), renderer), Wall(pygame.Rect(-1500, 3000, 100, 100), renderer), Wall(pygame.Rect(-1700, 2700, 100, 100), renderer), Wall(pygame.Rect(4300, 3600, 100, 100), renderer), Wall(pygame.Rect(4600, 2300, 100, 100), renderer), Wall(pygame.Rect(2700, 3700, 100, 100), renderer), Wall(pygame.Rect(-1400, 3700, 100, 100), renderer), Wall(pygame.Rect(500, -1100, 100, 100), renderer), Wall(pygame.Rect(3900, -4100, 100, 100), renderer), Wall(pygame.Rect(2900, -4900, 100, 100), renderer), Wall(pygame.Rect(4600, -1300, 100, 100), renderer), Wall(pygame.Rect(4300, 2000, 100, 100), renderer), Wall(pygame.Rect(3700, -1200, 100, 100), renderer), # Boundaries Wall(pygame.Rect(-5000, -5000, 100, 10000), renderer), Wall(pygame.Rect(-5000, -5000, 10000, 100), renderer), Wall(pygame.Rect(-5000, 4900, 10000, 100), renderer), Wall(pygame.Rect(4900, -5000, 100, 10000), renderer) ] # This dictionary contains all the paths of the picture assets s_paths = { "Circle": "Assets\\Sprites\\Circle.png", "Rect": "Assets\\Sprites\\Rectangle.png", "Smoke 1": "Assets\\Sprites\\Smoke 1.png", "Wall": "Assets\\Sprites\\Wall.png", "Rock 1": "Assets\\Sprites\\Rock 1.png", "Coin 1": "Assets\\Sprites\\Coin 1.png", "Coin 2": "Assets\\Sprites\\Coin 2.png", "Coin 3": "Assets\\Sprites\\Coin 3.png", "Coin 4": "Assets\\Sprites\\Coin 4.png", "Boss Bar": "Assets\\Sprites\\Boss Bar.png", "Boss Bar Sides": "Assets\\Sprites\\Boss Bar Sides.png", "Boss Bar Part": "Assets\\Sprites\\Boss Bar Part.png", "Heart": "Assets\\Sprites\\Heart.png", "Empty Heart": "Assets\\Sprites\\Empty Heart.png", "Onion": "Assets\\Sprites\\Onion.png", "Durian": "Assets\\Sprites\\Durian.png", "Mirror": "Assets\\Sprites\\Mirror.png", "Entity Shadow": "Assets\\Sprites\\Entity Shadow.png", "Enemy Spawner": "Assets\\Sprites\\Enemy Spawner.png", "Player": "Assets\\Sprites\\Player.png", "Alien Ammo": "Assets\\Sprites\\Alien Ammo.png", "Alien Ammo Burst": "Assets\\Sprites\\Alien Ammo Burst.png", "Squishy Enemy": "Assets\\Sprites\\Squishy Enemy.png", "Crimson 1": "Assets\\Sprites\\Crimson 1.png", "Crimson 2": "Assets\\Sprites\\Crimson 2.png", "Crimson 3": "Assets\\Sprites\\Crimson 3.png", "Angry Enemy 1": "Assets\\Sprites\\Angry Enemy 1.png", "Angry Enemy 2": "Assets\\Sprites\\Angry Enemy 2.png", "Slimy Enemy": "Assets\\Sprites\\Slimy Enemy.png", "Yummy Enemy 1": "Assets\\Sprites\\Yummy Monster F1.png", "Yummy Enemy 2": "Assets\\Sprites\\Yummy Monster F2.png", "Alien Launcher": "Assets\\Sprites\\Alien Launcher.png", "Tile 1": "Assets\\Sprites\\Grass Tile 1.png", "Tile 2": "Assets\\Sprites\\Grass Tile 2.png", "Blood 1": "Assets\\Sprites\\Blood 1.png", "Blood 2": "Assets\\Sprites\\Blood 2.png", } game_loading_scene.start_loading(audio_manager, s_paths, start_game, renderer, text_fonts[1], clock, walls)