Example #1
0
    def __init__(self, mapfile):
        self._move_queue = []
        self.running = False
        self.last_position_update = 0
        map = load_pygame(mapfile)

        self.layer = map.layers[1]

        map_data = pyscroll.data.TiledMapData(map)

        w, h = screen.get_size()

        self.map_layer = pyscroll.BufferedRenderer(map_data,
                                                   screen.get_size(),
                                                   clamp_camera=True)

        self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer,
                                            default_layer=2)
        self.map_layer.zoom = .5

        self.player = Player(PLAYER_IMAGE)
        self.player.position = self.map_layer.map_rect.center

        self.group.add(self.player)

        self.mesh = Pathfinder(map)
Example #2
0
    def setup(self):
        pygame.init()
        init_spritesheet()
        from src.spritesheet import RougeSheet
        self.screen_size = (960, 600)

        self.screen = pygame.display.set_mode(self.screen_size)
        pygame.display.set_caption("Scroller Game")

        self.clock = pygame.time.Clock()

        self.map_data = load_map("map4")
        self.map = pyscroll.TiledMapData(self.map_data)
        self.map_layer = pyscroll.BufferedRenderer(self.map, self.screen_size)
        self.map_layer.zoom = 3

        self.walls = create_walls(self.map_data)
        self.player = basic_player(self, RougeSheet)
        self.enemies = pygame.sprite.Group()
        add_mobs(self, self.map_data)

        self.all_sprites = pyscroll.PyscrollGroup(map_layer=self.map_layer)
        self.all_sprites.add(self.player)
        self.all_sprites.add(self.enemies)
        self.all_sprites.center(self.player.rect.center)
Example #3
0
    def __init__(self, filename, renderer):
        # Load TMX data
        self.tmx_data = load_pysdl2(filename=filename, renderer=renderer)

        # Make data source for the map
        self.map_data = pyscroll.TiledMapData(self.tmx_data)

        # Make the scrolling layer
        screen_size = (400, 400)
        map_layer = pyscroll.BufferedRenderer(self.map_data, screen_size)

        # make the pygame SpriteGroup with a scrolling map
        group = pyscroll.PyscrollGroup(map_layer=map_layer)

        # Add sprites to the group
        group.add(sprite)

        # Center the layer and sprites on a sprite
        group.center(sprite.rect.center)

        # Draw the layer
        # If the map covers the entire screen, do not clear the screen:
        # Clearing the screen is not needed since the map will clear it when drawn
        # This map covers the screen, so no clearing!
        group.draw(screen)

        # adjust the zoom (out)
        map_layer.zoom = .5

        # adjust the zoom (in)
        map_layer.zoom = 2.0
Example #4
0
    def map_change(self, map, target=False):  # Does what it says on the tin
        mapfile = get_map(map)
        tmx_data = load_pygame(mapfile)
        self.tmx_data = tmx_data
        map_data = pyscroll.data.TiledMapData(tmx_data)
        self.walls = list()
        for object in tmx_data.objects:
            self.walls.append(
                pygame.Rect(object.x, object.y, object.width, object.height))

        # creates new 'camera'
        self.map_layer = pyscroll.BufferedRenderer(map_data, screen.get_size())
        self.map_layer.zoom = 2
        self.group = PyscrollGroup(map_layer=self.map_layer, default_layer=4)

        #creates a new Hero to go on our new camera
        self.hero = Hero('Tiles/hero/character_still.png')
        try:
            self.hero.position = (target)
        except TypeError:
            self.hero.position = self.map_layer.map_rect.center
        self.map = stats['map'][:-4].lower()
        self.map = self.map.lstrip(
            "m")  # Fix that stupid bug that changes "maze1" to "ze1"
        self.map = self.map.lstrip("aps/")
Example #5
0
 def __init__(self, event_manager, world):
     """
     :param event_manager: event Manager
     :type event_manager: events.EventManager
     :param world: game world
     :type world: gameWorld.GameWorld
     """
     self.world = world
     self.event_manager = event_manager
     self.event_manager.register_listener(self)
     #Set game screen
     self.screen = world.screen
     w, h = world.screen.get_size()
     #Create new renderer (camera)
     self.map_layer = pyscroll.BufferedRenderer(self.world.level.map_data,
                                                (w, h),
                                                clamp_camera=False)
     #The sprite should to be on top of layer named "decoration behind"
     #Find layer number of the layer named "decoration behind"
     self.render_layer = 0
     for layer_index in range(len(self.world.level.tmx_data.layers)):
         if self.world.level.tmx_data.layers[layer_index].name == "decoration behind":
             self.render_layer = layer_index
     self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer,
                                         default_layer=self.render_layer)
Example #6
0
    def __init__(self,
                 mapName="WorldMap",
                 nameInZone="StartPointWorld",
                 screenSize=(SCREEN_WIDTH, SCREEN_HEIGHT)):

        self.nameMap = mapName

        self.tmxData = pytmx.util_pygame.load_pygame(
            self.reqImageName(self.nameMap))
        self.tiledMapData = pyscroll.data.TiledMapData(self.tmxData)
        self.cameraPlayer = pyscroll.BufferedRenderer(self.tiledMapData,
                                                      screenSize,
                                                      clamp_camera=True)

        self.cameraPlayer
        # self.soundController = soundPlayerController()

        self.allSprites = pygame.sprite.Group()
        self.enemyGroup = pygame.sprite.Group()
        self.itemGroup = pygame.sprite.Group()
        self.friendlyBullet = pygame.sprite.Group()
        self.friendlyExplosion = pygame.sprite.Group()
        self.enemyBullet = pygame.sprite.Group()
        self.spritesHUD = pygame.sprite.Group()

        eFactory = EnemyFactory()
        iFactory = ItemFactory()

        for obj in self.tmxData.objects:
            if obj.type == "enemy":
                enemy = eFactory.create(obj, self)
                self.allSprites.add(enemy)
                self.enemyGroup.add(enemy)

            # if obj.type == "item":
            #     item = iFactory.create(obj)
            #     self.allSprites.add(item)
            #     self.itemGroup.add(item)

        # Put camera in mapData
        self.camera = pyscroll.PyscrollGroup(map_layer=self.cameraPlayer,
                                             default_layer=SPRITE_LAYER)
        self.camera.add(self.allSprites)

        # Spawn point of the player
        valBool = False
        for obj in self.tmxData.objects:
            if obj.name == "InZone":
                if obj.StartPoint == nameInZone:

                    self.spawmPointPlayerx = obj.x
                    self.spawmPointPlayery = obj.y
                    valBool = True
                else:
                    print('No starting point')

        # The game is not complete?
        if valBool == False:

            quitGame()
Example #7
0
    def __init__(self):

        # true while running
        self.running = False

        # load data from pytmx
        tmx_data = load_pygame(self.filename)

        # setup level geometry with simple pygame rects, loaded from pytmx
        self.walls = list()
        for object in tmx_data.objects:
            self.walls.append(
                pygame.Rect(object.x, object.y, object.width, object.height))

        # create new data source for pyscroll
        map_data = pyscroll.data.TiledMapData(tmx_data)

        # create new renderer (camera)
        self.map_layer = pyscroll.BufferedRenderer(map_data, screen.get_size())
        self.map_layer.zoom = 2

        # pyscroll supports layered rendering.  our map has 3 'under' layers
        # layers begin with 0, so the layers are 0, 1, and 2.
        # since we want the sprite to be on top of layer 1, we set the default
        # layer for sprites as 2
        self.group = PyscrollGroup(map_layer=self.map_layer, default_layer=2)

        self.hero = Hero()

        # put the hero in the center of the map
        self.hero.position = self.map_layer.map_rect.center

        # add our hero to the group
        self.group.add(self.hero)
 def __init__(self, event_manager, world):
     """
     :param event_manager: event Manager
     :type event_manager: events.EventManager
     :param world: game world
     :type world: gameWorld.GameWorld
     """
     self.world = world
     self.event_manager = event_manager
     self.event_manager.register_listener(self)
     self.screen = world.screen
     w, h = world.screen.get_size()
     #Create new renderer/camera
     self.map_layer = pyscroll.BufferedRenderer(self.world.level.map_data,
                                                (w, h),
                                                clamp_camera=False,
                                                colorkey=None,
                                                alpha=True)
     #The player, enemies, items etc. should to be on top of
     #layer named in TMX "decoration behind"
     #Find layer number of the layer named "decoration behind"
     self.render_layer = 0
     for layer_index in range(len(self.world.level.tmx_data.layers)):
         if self.world.level.tmx_data.layers[layer_index].name == "walls":
             self.render_layer = layer_index  #content will be drawn on top of walls layer
     self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer,
                                         default_layer=self.render_layer)
     #Players image position is actually camera position
     player_image_position = self.world.appearance[self.world.player].rect
     #Parallax background
     self.star_field = parallaxStarfield.ParallaxStarfield(
         w, h, player_image_position.x, player_image_position.y)
Example #9
0
    def __init__(self,
                 screen_size: Tuple[int, int],
                 tmx: pytmx.TiledMap,
                 collision_layers: List[str] = []) -> None:
        """Create scroll map object.

        Args:
            screen_size (Tuple[int, int]): screen resolution will be used to the map rendering
            tmx (pytmx.TiledMap): loaded `pytmx.TiledMap` object
            collision_layers (List[str], optional): List of `pytmx.TiledMap` layer names will be used for tiles collision detection. Defaults to [].
        """
        self._tmx = tmx

        # create new data source for pyscroll
        map_data = pyscroll.data.TiledMapData(self._tmx)

        # create new renderer (camera)
        self.map_layer = pyscroll.BufferedRenderer(map_data,
                                                   screen_size,
                                                   clamp_camera=False,
                                                   tall_sprites=1)
        self.map_layer.zoom = 1

        # pyscroll supports layered rendering.  our map has 3 'under' layers
        # layers begin with 0, so the layers are 0, 1, and 2.
        # since we want the sprite to be on top of layer 1, we set the default
        # layer for sprites as 2
        self._map_group = PyscrollGroup(map_layer=self.map_layer,
                                        default_layer=2)

        self._map_collision_obj: List[pygame.Rect] = []

        self.add_collision_layers(collision_layers)
Example #10
0
    def __init__(self,
                 mapName="WorldMap",
                 nameInZone="StartPointWorld",
                 screenSize=(SCREEN_WIDTH, SCREEN_HEIGHT)):
        super().__init__()

        # Beginning MAP DATA
        self.nameMap = mapName

        # A set-up to shut down the logger 'orthographic' in pyscroll
        logger = logging.getLogger('orthographic')
        logger.setLevel(logging.ERROR)

        self.tmxData = pytmx.util_pygame.load_pygame(
            self.reqImageName(self.nameMap))
        self.tiledMapData = pyscroll.data.TiledMapData(self.tmxData)
        self.cameraPlayer = pyscroll.BufferedRenderer(self.tiledMapData,
                                                      screenSize,
                                                      clamp_camera=True)
        self.camera = pyscroll.PyscrollGroup(map_layer=self.cameraPlayer,
                                             default_layer=SPRITE_LAYER)

        # Spawn point of the player
        valBool = False
        for obj in self.tmxData.objects:
            if obj.name == "InZone":
                if obj.StartPoint == nameInZone:
                    self.spawmPointPlayerx = obj.x
                    self.spawmPointPlayery = obj.y
Example #11
0
    def __init__(self):
        super(Intro, self).__init__()

        tmx_data = load_pygame(MAP['intro'])

        map_data = pyscroll.data.TiledMapData(tmx_data)
        self.map_layer = pyscroll.BufferedRenderer(map_data, SCREEN_SIZE)
        self.map_layer.zoom = 0.5

        self.group = PyscrollGroup(map_layer=self.map_layer, default_layer=2)

        self.animations = pg.sprite.Group()
        self.labels = pg.sprite.Group()
        self.letters = pg.sprite.Group()
        self.surface = GFX['intro'].convert_alpha()
        self.cheat = False


        timespan = 3000
        midbottom = (SCREEN_RECT.centerx, SCREEN_RECT.bottom - 20)
        font = FONTS["UbuntuMono-B"]
        self.prompt = Blinker("Press Enter key to continue", {"midbottom": midbottom},
                              500, text_color=(255, 255, 255), font_path=font,
                              font_size= 25)
        Label('UP-UP-DOWN-DOWN-LEFT-RIGHT-LEFT-RIGHT-B-A',{"topleft": (50, 0)},self.labels,font_path=font,font_size = 7)
        task = Task(self.labels.add, timespan, args=(self.prompt,))
        self.animations.add(task)
Example #12
0
    def load(self, data):
        #loading map to creating group
        tmx_data = load_pygame(
            path.join(self.game.dir, "data",
                      self.datahelper.maps[data["mapname"]]["file"]))
        map_data = pyscroll.data.TiledMapData(tmx_data)
        self.map_layer = pyscroll.BufferedRenderer(
            map_data, self.screen.surface.get_size(),
            clamp_camera=False)  #tall_sprites=1)
        self.map_layer.zoom = 2
        self.group = PyscrollGroup(map_layer=self.map_layer,
                                   default_layer=5)  #data["layer"])
        #setting up player
        self.mapname = data["mapname"]
        self.hero.position = [data["player"]["x"], data["player"]["y"] - 8]
        if data["player"]["walking"] == 1:
            self.hero.walking = True
            self.hero.movingx, self.hero.movingy = data["player"][
                "walkingx"], data["player"]["walkingy"]
            self.hero.steps = 16
        self.group.add(self.hero)
        self.hero.rect.topleft = self.hero.position

        #colliditon
        self.collidable = {}
        self.interactable = {}
        self.warps = {}
        self.npcs = {}
        i = j = k = l = 0
        for id in tmx_data.objects_by_id:
            #print(tmx_data.objects_by_id[id].name)
            if tmx_data.objects_by_id[id].name in self.datahelper.interactable:
                self.interactable[j] = tmx_data.objects_by_id[id]
                j += 1
            if tmx_data.objects_by_id[id].name in self.datahelper.collidable:
                self.collidable[i] = (tmx_data.objects_by_id[id].x,
                                      tmx_data.objects_by_id[id].y)
                i += 1
            if "Warp" in tmx_data.objects_by_id[id].name:
                self.warps[k] = tmx_data.objects_by_id[id]
                k += 1
            if "npc" in tmx_data.objects_by_id[id].name:
                self.npcs[l] = self.scriptengine.load_npc(
                    tmx_data.objects_by_id[id])
                #self.npcs[l] = NPC(tmx_data.objects_by_id[id].name)
                #self.npcs[l].position = [tmx_data.objects_by_id[id].x, tmx_data.objects_by_id[id].y-8]
                self.group.add(self.npcs[l])
                self.npcs[l].map = self
                #self.npcs[l].rect.topleft = self.npcs[l].position
                #if "dir" in tmx_data.objects_by_id[id].properties.keys():
                #self.npcs[l].dir = tmx_data.objects_by_id[id].properties["dir"]
                #self.scriptengine.load(self.npcs[l])
                #self.npcs[l].map = self
                l += 1
        #animations
        #print(self.warps)
        self.timer = 0
        self.warping = False
        self.nextmap = {}
Example #13
0
 def init_group(self):
     map_data = pyscroll.data.TiledMapData(self.tmx_data)
     self.map_layer = pyscroll.BufferedRenderer(map_data,
                                                screen.get_size(),
                                                clamp_camera=True)
     self.map_layer.zoom = 0.3
     self.zoomchange = 1
     self.group = PyscrollGroup(map_layer=self.map_layer, default_layer=1)
Example #14
0
def load_world_map(map_file, screen):
    tmx_data = load_pygame(map_file)
    map_data = pyscroll.data.TiledMapData(tmx_data)
    w, h = screen.get_size()
    map_renderer = pyscroll.BufferedRenderer(
        map_data, (int(w * 0.65), int(h * 0.65)))  # map renderer
    map_group = pyscroll.PyscrollGroup(map_layer=map_renderer,
                                       default_layer=5)  # Sprite group for map
    return tmx_data, map_renderer, map_group
Example #15
0
 def load_world(self, world: World):
     w, h = self.screen.get_size()
     self.map_layer = pyscroll.BufferedRenderer(world.map_data,
                                                (w / SCREEN_SCALE, h / SCREEN_SCALE),
                                                clamp_camera=True)
     self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer, default_layer=4)
     self.group.add(world.player)
     self.group.add(world.lemons)
     self.group.add(world.juice, layer=5)
Example #16
0
    def __init__(self,
                 mapName="WorldMap",
                 nameInZone="StartPointWorld",
                 screenSize=(SCREEN_WIDTH, SCREEN_HEIGHT)):

        self.nameMap = mapName

        self.tmxData = pytmx.util_pygame.load_pygame(
            self.reqImageName(self.nameMap))
        self.tiledMapData = pyscroll.data.TiledMapData(self.tmxData)
        self.cameraPlayer = pyscroll.BufferedRenderer(self.tiledMapData,
                                                      screenSize,
                                                      clamp_camera=True)
        # self.soundController = soundPlayerController()

        self.allSprites = pygame.sprite.Group()
        self.enemyGroup = pygame.sprite.Group()
        self.itemGroup = pygame.sprite.Group()
        self.friendlyBullet = pygame.sprite.Group()
        self.enemyBullet = pygame.sprite.Group()
        self.spritesHUD = pygame.sprite.Group()
        self.notifySet = weakref.WeakSet(
        )  #Set of all object that needs to be notified of events. Weak references are used to prevent this set from keeping objects alive

        eFactory = EnemyFactory()
        iFactory = ItemFactory()

        for obj in self.tmxData.objects:
            if obj.type == "enemy":
                enemy = eFactory.create(obj, self)
                if enemy is not None:
                    self.allSprites.add(enemy)
                    self.enemyGroup.add(enemy)

            # if obj.type == "item":
            #     item = iFactory.create(obj)
            #     self.allSprites.add(item)
            #     self.itemGroup.add(item)

        # Put camera in mapData
        self.camera = pyscroll.PyscrollGroup(map_layer=self.cameraPlayer,
                                             default_layer=SPRITE_LAYER)
        self.camera.add(self.allSprites)

        # Spawn point of the player
        valBool = False
        for obj in self.tmxData.objects:
            if obj.name == "InZone":
                if obj.StartPoint == nameInZone:
                    self.spawmPointPlayerx = obj.x
                    self.spawmPointPlayery = obj.y
                    valBool = True

        # The game is not complete?
        if valBool == False:
            quitGame()
Example #17
0
    def initialize_renderer(self):
        """ Initialize the renderer for the map and sprites

        :rtype: pyscroll.BufferedRenderer
        """
        visual_data = pyscroll.data.TiledMapData(self.data)
        # TODO: Tuxemon will not work with clamp_camera=True
        return pyscroll.BufferedRenderer(visual_data,
                                         prepare.SCREEN_SIZE,
                                         clamp_camera=False)
Example #18
0
 def __init__(self, game, filename):
     self.game = game
     self.tmx_data = load_pygame('assets/maps/' + filename)
     self.map_data = pyscroll.TiledMapData(self.tmx_data)
     self.size = [
         self.map_data.map_size[0] * self.map_data.tile_size[0],
         self.map_data.map_size[1] * self.map_data.tile_size[1]
     ]
     self.map_layer = pyscroll.BufferedRenderer(self.map_data, self.size)
     self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer)
Example #19
0
    def __init__(self):
        tmx_data = load_pygame(self.filename)

        self.make_walls(tmx_data.get_layer_by_name('collision'))
        self.make_trees(tmx_data.get_layer_by_name('tree'))
        self.make_ground(tmx_data.get_layer_by_name('ground'))

        map_data = pyscroll.data.TiledMapData(tmx_data)
        self.map_layer = pyscroll.BufferedRenderer(
            map_data,
            pygame.display.get_surface().get_size())
Example #20
0
    def __init__(self, fileName):
        #Создать объект карты из PyTMX
        self.mapObject = pytmx.load_pygame(fileName)

        ##Настройка геометрии уровня с простыми pygame прямоугольниками, загруженными из pytmx
        self.walls = list()
        self.npcs = list()
        self.stairs = list()
        for map_object in self.mapObject.objects:
            if map_object.type == "wall":
                print("wall загрузка не удалась: переопределение wall")
                #self.walls.append(Wall(map_object))
            elif map_object.type == "stair":
                print("stair загрузка не удалась: переопределение stair")
                #self.stairs.append(Wall(map_object))
            elif map_object.type == "guard":
                print("npc загрузка не удалась: переопределение npc")
                #self.npcs.append(Npc(map_object))
            elif map_object.type == "hero":
                print("hero загрузка не удалась: переопределение hero")
                #self.hero = Hero(map_object)

        ##Создать новый источник данных для pyscroll
        map_data = pyscroll.data.TiledMapData(self.mapObject)

        ##Создать новый рендер (камера)
        screen = init_screen(SCREEN_WIDTH, SCREEN_HEIGHT)
        self.map_layer = pyscroll.BufferedRenderer(map_data,
                                                   screen.get_size(),
                                                   clamp_camera=True,
                                                   tall_sprites=1)
        self.map_layer.zoom = 2

        ##pyscroll поддерживает многоуровневую визуализацию. наша карта имеет 3 нижних слоя
        ##Слои начинаются с 0, поэтому это 0, 1 и 2.
        ##Так как мы хотим, чтобы спрайт был на вершине слоя 1, мы устанавливаем значение по умолчанию
        ##слой для спрайтов как 2
        self.group = PyscrollGroup(map_layer=self.map_layer, default_layer=3)

        ##Добавить нашего героя в группу объектов для рендеринга
        ##self.group.add(self.hero)
        ##for npc in self.npcs:
        ##    self.group.add(npc)

        #Создать список слоев для карты
        self.layers = []

        #Число сдвига уровня влево/вправо
        self.levelShift = 0

        #Создайте слои для каждого слоя на карте тайлов
        for layer in range(len(self.mapObject.layers)):
            self.layers.append(Layer(index=layer, mapObject=self.mapObject))
Example #21
0
    def initialize_renderer(self):
        """ Initialize the renderer for the map and sprites

        :rtype: pyscroll.BufferedRenderer
        """
        # TODO: Use self.edges == "stitched" here when implementing seamless maps
        visual_data = pyscroll.data.TiledMapData(self.data)
        clamp = (self.edges == "clamped")
        self.renderer = pyscroll.BufferedRenderer(visual_data,
                                                  prepare.SCREEN_SIZE,
                                                  clamp_camera=clamp,
                                                  tall_sprites=2)
Example #22
0
    def __init__(self):
        self.score = 0
        self.start_screen = True
        self.start_screen_obj = StartScreen()
        self.game_over = False
        self.pause = False
        self.game_over_music_enabled = False
        self.fps = 0.0
        self.font = pygame.font.Font(os.path.join('fonts', 'PressStart2P.ttf'),
                                     8)

        self.all_sprites_list = pygame.sprite.Group()
        self.player_object_list = pygame.sprite.Group()
        #it contains all enemy sprites including bullets
        self.enemy_object_list = pygame.sprite.Group()
        #it contains only ships and monsters
        self.enemy_list = pygame.sprite.Group()

        Player.containers = self.all_sprites_list, self.player_object_list
        EnemySmallSpaceship.containers = self.all_sprites_list, self.enemy_object_list, self.enemy_list
        Whale.containers = self.all_sprites_list, self.enemy_object_list, self.enemy_list
        Bullet.containers = self.all_sprites_list, self.enemy_object_list
        BulletPlayer.containers = self.all_sprites_list, self.player_object_list

        self.last_time_enemy_killed = pygame.time.get_ticks()
        self.milliseconds_per_kill = 1500

        # Create the player
        self.player = Player()

        self.interval_spawn_enemy = 1500
        self.last_time_spawn_enemy = pygame.time.get_ticks()

        self.max_score = 0

        # Test boss
        #add_whale()

        self.start_screen_obj.play_music()

        # Load TMX data
        tmx_data = load_pygame(os.path.join('maps', 'mapcorridor.tmx'))

        # Make data source for the map
        map_data = pyscroll.TiledMapData(tmx_data)

        # Make layer
        self.map_layer = pyscroll.BufferedRenderer(
            map_data, (SCREEN_WIDTH, SCREEN_HEIGHT))
        self.center_map = [
            self.map_layer.map_rect.width // 2,
            self.map_layer.map_rect.height - SCREEN_HEIGHT // 2
        ]
Example #23
0
 def init_graphics(self):
     pygame.display.set_caption('Dinos äventyr')
     self.screen = pygame.display.set_mode(self.size, pygame.RESIZABLE)
     self.background = pygame.Surface(self.screen.get_size())
     self.tmx_data = pytmx.load_pygame("real_map.tmx")
     # Make data source for the map
     self.map_data = pyscroll.TiledMapData(self.tmx_data)
     # Make the scrolling layer
     screen_size = (self.width, self.height)
     self.map_layer = pyscroll.BufferedRenderer(self.map_data, screen_size, clamp_camera=True, tall_sprites=1)
     self.map_layer.zoom = 2
     # make the PyGame SpriteGroup with a scrolling map
     self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer)
Example #24
0
    def loadTiledMap(self,
                     screen_w=800,
                     screen_h=600,
                     path='maps/testmap2.tmx'):
        self.tiled_map = load_pygame(path)
        self.map_data = pyscroll.TiledMapData(self.tiled_map)
        (w, h) = self.map_data.map_size
        self.rect = Rect(0, 0, w * 64, h * 64)
        self.map_layer = pyscroll.BufferedRenderer(self.map_data,
                                                   (screen_w, screen_h),
                                                   clamp_camera=True)

        return self.map_layer
Example #25
0
    def __init__(self):
        Scene.__init__(self)

        # Set window caption
        pygame.display.set_caption(WINDOW_CAPTION)

        # TODO: rewrite scenes class to allow resizing of screen globally.
        # See end paragraph of this article:https://nerdparadise.com/programming/pygame/part7
        screen_size = [SCREEN_WIDTH, SCREEN_HEIGHT]

        # List variable for layers - 0 = background color; 1 = scenery; 2 = level; 3 = player; 4 = foreground
        # Each layer is a seperate surface.
        self.layers = [pygame.Surface(screen_size) for i in range(4)]

        # Create a sprite group of active sprites, which are all rendered in draw() function
        self.active_sprite_list = pygame.sprite.Group()

        # Create instance of player
        self.player_one = Player(150, 50, self)

        # Add player to list of active sprites, so it gets rendered in draw() function
        self.active_sprite_list.add(self.player_one)

        # Time to load our TMX level map.
        self.lvl1_tmx_data = pytmx.load_pygame(LEVEL_01_TMX)

        # Create new data source for pyscroll
        self.map_data = pyscroll.data.TiledMapData(self.lvl1_tmx_data)

        # Create new renderer (camera)
        # Clamp_camera is used to prevent the map from scrolling past the edge
        # TODO: remove screen width/height constants once we get dynamic screen sizes figured out
        self.map_layer = pyscroll.BufferedRenderer(self.map_data,
                                                   screen_size,
                                                   clamp_camera=True)
        self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer)

        # TODO: Figure out how to center player in map.
        # TODO: uncomment the following lines of code, and remove/rewrite active_sprite_list
        # For that, see https://github.com/bitcraft/pyscroll/wiki/Tutorial-(WIP)

        # Add our player to the group
        self.group.add(self.player_one)

        # Can be switched on with F10 key, for that see events()
        self.debug_mode = False

        self.jump_key_pressed = False

        self.platforms = self.get_solid_platforms(
            self.lvl1_tmx_data.get_layer_by_name("Collision Mask"))
Example #26
0
    def __init__(self, mapfile):
        self._move_queue = []
        self.running = False
        self.last_position_update = 0
        map = load_pygame(mapfile)
        self.mapp = load_pygame(mapfile)
        self.objectlist = list(self.mapp.get_tile_locations_by_gid(20))
        self.objectlist2 = list(self.mapp.get_tile_locations_by_gid(20))
        self.moveCounter = 0
        self.layer = map.layers[1]
        self.objectlayer = map.layers[3]
        self.charizardLayer = map.layers[4]
        self.blastoiseLayer = map.layers[5]
        self.ironLayer = map.layers[6]
        self.venusaurLayer = map.layers[7]
        self.snorlaxLayer = map.layers[8]
        self.blastoiseLayer.visible = 0
        self.ironLayer.visible = 0
        self.venusaurLayer.visible = 0
        self.snorlaxLayer.visible = 0
        self.objectType = ["pokemon", "item"]
        self.rarity = [1, 2, 3, 4, 5, 6, 8]
        self.type = ["fire", "grass", "water", "normal"]
        self.itemType = ["heal", "upgrade"]
        self.catchableOrShiny = ["y", "n"]
        self.itemUseless = [0]
        self.apdp = [10, 15, 20, 25, 30, 35, 40, 50]
        self.hpOfPokemonAndPlayer = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
        self.pokemonCounter = 0
        self.itemCounter = 0
        self.moveHelper = self.objectlist[0]
        self.moveCounter2 = 0
        self.itemActive = 0
        self.screenHelper = 1
        self.hpPlayer = 100



        map_data = pyscroll.data.TiledMapData(map)

        w, h = screen.get_size()

        self.map_layer = pyscroll.BufferedRenderer(map_data, screen.get_size(), clamp_camera=True)
        self.group = pyscroll.PyscrollGroup(map_layer=self.map_layer, default_layer=4)
        self.map_layer.zoom = 1.5
        self.player = Player(PLAYER_IMAGE)
        self.player.position = self.map_layer.map_rect.center
        self.group.add(self.player)
        self.mesh = Pathfinder(map)
Example #27
0
    def loadMap(self, fname):
        self.tmx_data = load_pygame(fname)

        # Make data source for the map
        self.map_data = pyscroll.TiledMapData(self.tmx_data)

        # Make the scrolling layer
        self.map_layer = pyscroll.BufferedRenderer(self.map_data,
                                                   Config.screen_size,
                                                   alpha=False,
                                                   clamp_camera=True)

        # here, we know the space of our world, so store it in the class
        h = self.tmx_data.height * self.tmx_data.tileheight
        w = self.tmx_data.width * self.tmx_data.tilewidth
        Config.world_size = (w, h)
Example #28
0
    def switch_map(self, map_name='monestary', spawn=True):
        """
        Switches to input map
        """
        self.current_map = map_name
        # Pyscroll
        tm = pytmx.load_pygame(path.join(self.maps_folder,
                                         '{}.tmx'.format(map_name)),
                               pixelalpha=True)
        self.map_data = pyscroll.TiledMapData(tm)
        screen_size = (WIDTH, HEIGHT)
        self.map_layer = pyscroll.BufferedRenderer(self.map_data, screen_size)
        # Instantiate all_sprites group
        self.all_sprites = pyscroll.PyscrollGroup(map_layer=self.map_layer)

        for tile_object in tm.objects:
            obj_center = vector(tile_object.x + tile_object.width / 2,
                                tile_object.y + tile_object.height / 2)
            if tile_object.name == 'player':
                if spawn:
                    self.player = Player(self, obj_center.x, obj_center.y)
            elif not spawn:
                self.all_sprites.add(self.player)
            if tile_object.name == 'mob':
                Mob(self, obj_center.x, obj_center.y, tile_object.type)
            if tile_object.name == 'npc':
                Npc(self, obj_center.x, obj_center.y, tile_object.type)
            if tile_object.name == 'wall':
                Obstacle(self, tile_object.x, tile_object.y, tile_object.width,
                         tile_object.height)
            if tile_object.name == 'portal':
                Portal(self, obj_center.x, obj_center.y, tile_object.width,
                       tile_object.height, tile_object.type)
            if tile_object.name == 'spawn':
                Spawn(self, obj_center.x, obj_center.y, tile_object.width,
                      tile_object.height, tile_object.type)
            if tile_object.name == 'readable':
                Readable(self, obj_center.x, obj_center.y, tile_object.width,
                         tile_object.height, tile_object.type)
            if tile_object.name in POTION_ITEMS:
                Potion(self, obj_center, tile_object.name)
            if tile_object.name in SPELL_ITEMS:
                Spell(self, obj_center, tile_object.name)
        self.paused = False
        self.night = False
        self.inventory = False
        self.effect_sounds['level_start'].play()
Example #29
0
	def __init__(self, game):
		screen = game.screen
		(w,h) = (screen.get_width(), screen.get_height())

		tmx_data = load_pygame(getFilePath(game.levelName))
		map_data = pyscroll.data.TiledMapData(tmx_data)

		self.map_layer = pyscroll.BufferedRenderer(map_data, (w,h), padding=1, clamp_camera=True)
		self.group = PyscrollGroup(map_layer=self.map_layer)

		self.center = [self.map_layer.rect.width/2, self.map_layer.rect.height/2]

		self.camera_acc = [0, 0, 0]
		self.camera_vel = [0, 0, 0]
		self.last_update = 0

		self.screen = screen
Example #30
0
    def __init__(self, state):
        if state == False:
            self.fullscreen = False
            # true while running.
            self.running = False
            self.clock = pygame.time.Clock()
            # create all the directio variables
            self.direction = "still"
            self.EntityDirection = "still"
            self.EntityDirection1, self.EntityDirection2 = "still", "still"
            self.fps = 1000

            self.bypass = False

            entityPos1, heroPos1 = False, False

            # load data from pytmx
            tmx_data = load_pygame(self.filename)
            self.tmx_data = tmx_data

            mapPlay = load_pygame(get_map(stats['map']))
            # create new data source for pyscroll
            map_data = pyscroll.data.TiledMapData(mapPlay)
            # setup level geometry with simple pygame rects, loaded from pytmx.
            self.walls = list()
            for object in mapPlay.objects:
                self.walls.append(
                    pygame.Rect(object.x, object.y, object.width,
                                object.height))

            # create new renderer (camera)
            self.map_layer = pyscroll.BufferedRenderer(map_data,
                                                       screen.get_size())
            self.map_layer.zoom = 2

            self.group = PyscrollGroup(map_layer=self.map_layer,
                                       default_layer=4)
            self.hero = Hero('Tiles/hero/character_still.png')
            self.entity = Entity('Tiles/hero/character_still.png')
            self.hero.position = stats['pos']
            self.entity.position = stats['pos']
            # add our hero to the group
            self.group.add(self.hero)
            #self.group.add(self.entity)

            self.entVel = (0, 0)