def newLevel(self): # TODO Make this better self.killChildren() self.manager = layer.ScrollingManager() self.newMap(30, 30) self.map = tiles.load('tilemap.xml')['map0'] self.checkSpawnPoint() self.carLayer = layer.ScrollableLayer() self.carLayer.add(self.player) self.manager = layer.ScrollingManager() self.manager.add(self.map) self.manager.add(self.carLayer) self.add(self.manager)
def main(): global keyboard, scroller from cocos.director import director director.init(width=800, height=600, autoscale=False, resizable=True) car_layer = layer.ScrollableLayer() car = cocos.sprite.Sprite('car.png') car_layer.add(car) car.position = (200, 100) car.max_forward_speed = 200 car.max_reverse_speed = -100 car.do(DriveCar()) scroller = layer.ScrollingManager() test_layer = tiles.load('road-map.tmx')['map0'] scroller.add(test_layer) scroller.add(car_layer) main_scene = cocos.scene.Scene(scroller) keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) def on_key_press(key, modifier): if key == pyglet.window.key.Z: if scroller.scale == .75: scroller.do(actions.ScaleTo(1, 2)) else: scroller.do(actions.ScaleTo(.75, 2)) elif key == pyglet.window.key.D: test_layer.set_debug(True) director.window.push_handlers(on_key_press) director.run(main_scene)
def main(): global keyboard, scroller from cocos.director import director director.init(width=960, height=640, autoscale=False, resizable=True) scroller = layer.ScrollingManager() test_layer = tiles.load('road-map.tmx')['map0'] scroller.add(test_layer) main_scene = cocos.scene.Scene(scroller) keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) def on_key_press(key, modifier): if key == pyglet.window.key.Z: if scroller.scale == .75: scroller.do(actions.ScaleTo(1, 2)) else: scroller.do(actions.ScaleTo(.75, 2)) elif key == pyglet.window.key.D: test_layer.set_debug(True) director.window.push_handlers(on_key_press) director.run(main_scene)
def __init__(self): super(World, self).__init__() self.player = Car(self) self.newMap(30, 20) self.map = tiles.load('tilemap.xml')['map0'] self.checkSpawnPoint() self.exitPoint = self.checkExitPoint() self.blockKeys = 0.0 self.blockKeysFull = 0.3 self.bindings = { key.LEFT: 'left', key.RIGHT: 'right', key.UP: 'up', key.DOWN: 'down', key.E: 'down_level', key.Z: 'scale', } buttons = {} for k in self.bindings: buttons[self.bindings[k]] = 0 self.buttons = buttons self.overlaidCells = [] #self.overlay = layer.util_layers.ColorLayer(0, 0, 0, 128, 20*128, 30*128) #self.map.add(self.overlay) self.carLayer = layer.ScrollableLayer() self.carLayer.add(self.player) self.manager = layer.ScrollingManager() self.manager.add(self.map) self.manager.add(self.carLayer) self.add(self.manager) self.schedule(self.update)
def __init__(self): self.list = MenuListLayer() self.backgrounds = map.generate_cover() self.scroller = ccly.ScrollingManager() for i in range(1, len(self.backgrounds)): self.scroller.add(self.backgrounds[i]) self.scroller.scale = 0.7 self.scene = ccsc.Scene(self.backgrounds[0], self.scroller, self.list)
def main(): global keyboard, tilemap, scroller from cocos.director import director director.init(width=800, height=600, autoscale=False) print(description) # create a layer to put the player in player_layer = layer.ScrollableLayer() # NOTE: the anchor for this sprite is in the CENTER (the cocos default) # which means all positioning must be done using the center of its rect player = cocos.sprite.Sprite('witch-standing.png') player_layer.add(player) player.do(PlatformerController()) # add the tilemaps and the player sprite layer to a scrolling manager scroller = layer.ScrollingManager() fullmap = tiles.load('platformer-map.xml') tilemap_walls = fullmap['walls'] scroller.add(tilemap_walls, z=0) tilemap_decoration = fullmap['decoration'] scroller.add(tilemap_decoration, z=1) scroller.add(player_layer, z=2) # set the player start using the player_start token from the map start = tilemap_decoration.find_cells(player_start=True)[0] r = player.get_rect() # align the mid bottom of the player with the mid bottom of the start cell r.midbottom = start.midbottom # player image anchor (position) is in the center of the sprite player.position = r.center # give a collision handler to the player mapcollider = mapcolliders.RectMapCollider(velocity_on_bump='slide') player.collision_handler = mapcolliders.make_collision_handler( mapcollider, tilemap_walls) # construct the scene with a background layer color and the scrolling layers platformer_scene = cocos.scene.Scene() platformer_scene.add(layer.ColorLayer(100, 120, 150, 255), z=0) platformer_scene.add(scroller, z=1) # track keyboard presses keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) # allow display info about cells / tiles def on_key_press(key, modifier): if key == pyglet.window.key.D: tilemap_walls.set_debug(True) director.window.push_handlers(on_key_press) # run the scene director.run(platformer_scene)
def main(): global keyboard global scroller # This variable is going to become a scrolling manager to enable us to scroll along the map # Initialize director director.init(width=800, height=600, caption="In the beginning everything was Kay-O", autoscale=True, resizable=True) # Create player layer and add player onto it # This time make it a ScrollableLayer type rather than simply Layer player_layer = layer.ScrollableLayer() player = sprite.Sprite('images/mr-saturn.png') player_layer.add(player) # Sets initial position and velocity of player player.position = (750, 1200) player.velocity = (0, 0) # Set the sprite's movement class player.do(Player()) # Create a new ScrollingManager object so we can scroll the view along with the player # The ScrollingManager object lets us separate "world" coordinates and "screen" coordinates # In this way, we can keep track of where the player is across the entire map but keep the viewport local #(http://python.cocos2d.org/doc/api/cocos.layer.scrolling.html#cocos.layer.scrolling.ScrollingManager) scroller = layer.ScrollingManager() # Now we will create a map layer based on our TMX file # I called the ground layer "Ground" in the tmx file, which is what we specify here as an identifier # This is located in the <layer> tags in map.tmx # We do the same thing for TopLayer # See README in this folder for more information ground_layer = tiles.load('tiles/map.tmx')['Ground'] top_layer = tiles.load('tiles/map.tmx')['TopLayer'] # Creates a text layer and adds an instance of BigText() to it text_layer = BigText() # Add player sprite and player_layer to the ScrollingManager # We have also added a second argument to the add() calls # This is the z-index, which explicity determines the order of layers. # Here, the player has a z-index of 1 and the text has an index of 2 so it will overlay the player. # And 0 will be the background scroller.add(ground_layer, z = 0) scroller.add(top_layer, z = 1) scroller.add(player_layer, z = 1) # Here we initialize the scene with initial layer "scroller" which holds all of the layers main_scene = scene.Scene(scroller) # Here we add the text_layer containing the instance of BigText() to the main scene main_scene.add(text_layer, z = 2) keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) # Run the scene we've built in the window director.run(main_scene)
def main(): global keyboard, walls, scroller from cocos.director import director director.init(width=800, height=600, autoscale=False) print(description) # create the scrolling manager that will hold all game entities scroller = layer.ScrollingManager() # load the map layer of interest and add to the level walls = tiles.load('tmx_collision.tmx')['walls'] assert isinstance(walls, tiles.TmxObjectLayer) scroller.add(walls, z=0) # create a layer to put the player in; it will care for player scroll player_layer = layer.ScrollableLayer() # NOTE: the anchor for this sprite is in the CENTER (the cocos default) # which means all positioning must be done using the center of its rect player = cocos.sprite.Sprite('witch-standing.png') player_layer.add(player) player.do(PlatformerController2()) scroller.add(player_layer, z=1) # set the player start using the object with the 'player_start' property player_start = walls.find_cells(player_start=True)[0] # for convenience the player start was give the same dimensions as player, # so put player.center over player start center player.position = player_start.center # set focus so the player is in view scroller.set_focus(*player.position) # extract the player_start, which is not a wall walls.objects.remove(player_start) # give a collision handler to the player mapcollider = mapcolliders.TmxObjectMapCollider() mapcollider.on_bump_handler = mapcollider.on_bump_slide player.collision_handler = mapcolliders.make_collision_handler( mapcollider, walls) # construct the scene with a background layer color and the scrolling layers platformer_scene = cocos.scene.Scene() platformer_scene.add(layer.ColorLayer(100, 120, 150, 255), z=0) platformer_scene.add(scroller, z=1) # track keyboard presses keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) # run the scene director.run(platformer_scene)
def team_mode_game(): """returns the game scene""" scene = Scene() game = Game() table = RectMapLayer('Table', HOR_MAP_SIZE, VER_MAP_SIZE, game.cells, origin=(0, 0, 0)) table.debug = True player = MainPlayerPane(game.players[0]) adversary1 = OtherPlayerPane(game.players[1], PlayerPosition.LEFT) adversary2 = OtherPlayerPane(game.players[2], PlayerPosition.RIGHT) adversary3 = OtherPlayerPane(game.players[3], PlayerPosition.TOP) game.deal_cards() game.players[0].show_cards() player.update_card_positions() adversary1.update_card_positions() adversary2.update_card_positions() adversary3.update_card_positions() background = layer.util_layers.ColorLayer(107, 142, 35, 255) background.add(player, z=3, name='player area') background.add(adversary1, z=4, name='adversary 1') background.add(adversary2, z=5, name='adversary 2') background.add(adversary3, z=6, name='adversary 3') # im = pyglet.image.load('res/textures/wood3.png') # for i in range(HOR_MAP_SIZE): # for j in range(VER_MAP_SIZE): # s = Sprite(im) # background.add(s, z=1) # s.position = table.cells[i][j].center scroller = layer.ScrollingManager() scroller.add(table, z=2, name='table') fx = card_size * HOR_MAP_SIZE // 2 fy = card_size * VER_MAP_SIZE // 2 scroller.set_focus(fx, fy, True) ctrl = GameCtrl(game, player, table, scroller) scene.add(background, z=0, name='background') scene.add(ctrl, z=7, name='controller') scene.add(scroller, z=8, name='scroller') # scene.add(player, z=3, name='player area') # scene.add(adversary1, z=4, name='adversary 1') # scene.add(adversary2, z=5, name='adversary 2') # scene.add(adversary3, z=6, name='adversary 3') return scene
def main(): global keyboard, walls, scroller from cocos.director import director director.init(width=800, height=600, autoscale=False) print(description) # add the tilemap and the player sprite layer to a scrolling manager scroller = layer.ScrollingManager() walls = tiles.load('tmx_collision.tmx')['walls'] assert isinstance(walls, tiles.TmxObjectLayer) scroller.add(walls, z=0) # make the function to handle collision between actors and walls mapcollider = TmxObjectMapCollider() mapcollider.on_bump_handler = mapcollider.on_bump_bounce fn_collision_handler = mapcolliders.make_collision_handler( mapcollider, walls) # make the function to set visual focus at position fn_set_focus = scroller.set_focus # create a layer to put the player in actors_layer = layer.ScrollableLayer() ball = Ball((300, 300), (600, 600), fn_collision_handler, fn_set_focus, (255, 0, 255)) actors_layer.add(ball) scroller.add(actors_layer, z=1) # set the player start using the object with the 'player_start' property player_start = walls.find_cells(player_start=True)[0] ball.position = player_start.center # set focus so the player is in view scroller.set_focus(*ball.position) # extract the player_start, which is not a wall walls.objects.remove(player_start) # construct the scene with a background layer color and the scrolling layers platformer_scene = cocos.scene.Scene() platformer_scene.add(layer.ColorLayer(100, 120, 150, 255), z=0) platformer_scene.add(scroller, z=1) # track keyboard presses keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) # run the scene director.run(platformer_scene)
def __init__(self): super(TestScene, self).__init__() scroller = layer.ScrollingManager() scrollable = tiles.load('road-map.tmx')['map0'] scroller.add(scrollable) self.add(scroller) template_action = (CallFunc(scroller.set_focus, 0, 0) + Delay(1) + CallFunc(scroller.set_focus, 768, 0) + Delay(1) + CallFunc(scroller.set_focus, 768, 768) + Delay(1) + CallFunc(scroller.set_focus, 1500, 768) + Delay(1) + ScaleTo(0.75, 1) + Delay(1) + CallFunc(scrollable.set_debug, True) + Delay(1) + CallFunc(director.window.set_size, 800, 600)) scroller.do(template_action)
def main(): from cocos.director import director director.init(width=800, height=600, autoscale=False, resizable=True) glClearColor(255, 255, 255, 255) scroller = layer.ScrollingManager() maploaded = tiles.load('obj.tmx') test_layer = maploaded["tiles_layer_1"] scroller.add(test_layer) object_layer = maploaded['test_object_layer'] scroller.add(object_layer) main_scene = cocos.scene.Scene(scroller) print(test_layer.px_width, test_layer.px_height) scroller.set_focus(test_layer.px_width // 2, test_layer.px_height // 2) director.run(main_scene)
def main(): global keyboard, walls, scroller from cocos.director import director director.init(width=800, height=600, autoscale=False) print(description) car_layer = layer.ScrollableLayer() car = cocos.sprite.Sprite('car.png') car_layer.add(car) car.position = (200, 100) car.max_forward_speed = 200 car.max_reverse_speed = -100 worker_action = car.do(DriveCar()) # add the map and the player sprite layer to a scrolling manager scroller = layer.ScrollingManager() walls = tiles.load('tmx_collision.tmx')['walls'] assert isinstance(walls, tiles.TmxObjectLayer) worker_action.walls = walls scroller.add(walls, z=0) scroller.add(car_layer, z=1) player_start = walls.find_cells(player_start=True)[0] # extract the player_start, which is not a wall walls.objects.remove(player_start) # give car access to the walls so it can change colors car.walls = walls # construct the scene with a background layer color and the scrolling layers platformer_scene = cocos.scene.Scene() platformer_scene.add(layer.ColorLayer(100, 120, 150, 255), z=0) platformer_scene.add(scroller, z=1) # track keyboard presses keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) # run the scene director.run(platformer_scene)
def main(): global keyboard, tilemap, scroller from cocos.director import director director.init(width=800, height=600, do_not_scale=True) print description # create a layer to put the player in player_layer = layer.ScrollableLayer() # NOTE: the anchor for this sprite is in the CENTER (the cocos default) # which means all positioning must be done using the center of its rect player = cocos.sprite.Sprite('witch-standing.png') player_layer.add(player) player.do(PlatformerController()) # add the tilemap and the player sprite layer to a scrolling manager scroller = layer.ScrollingManager() tilemap = tiles.load('platformer-map.xml')['level0'] scroller.add(tilemap, z=0) scroller.add(player_layer, z=1) # set the player start using the player_start token from the tilemap start = tilemap.find_cells(player_start=True)[0] r = player.get_rect() # align the mid bottom of the player with the mid bottom of the start cell r.midbottom = start.midbottom # player image anchor (position) is in the center of the sprite player.position = r.center # construct the scene with a background layer color and the scrolling layers platformer_scene = cocos.scene.Scene() platformer_scene.add(layer.ColorLayer(100, 120, 150, 255), z=0) platformer_scene.add(scroller, z=1) # track keyboard presses keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) # run the scene director.run(platformer_scene)
def __init__(self, w, h): self.size = (w, h) self.focus = list(resolution_2) self.layers = map.generate_map(w, h) self.scroller = ccly.ScrollingManager() self.scroller.add(name="bg", child=self.layers[0]) self.scroller.add(name="path", child=self.layers[1]) self.scroller.add(name="item", child=self.layers[2]) self.scroller.add(name="chess", child=self.layers[3]) self.origin = ((0, 12), (29, 12)) chesses_loc_dict = { "ChessArcher": (-1, -1), "ChessAssassin": (-1, -1), "ChessSwordman": (-1, -1), "ChessKnight": (-1, -1), "ChessFriar": (-1, -1), "ChessMage": (-1, -1), "ChessProphet": (-1, -1), "ChessWitch": (-1, -1) } self.chesses_loc = (chesses_loc_dict.copy(), chesses_loc_dict.copy())
def main(): # Declare these as global so they can be accessed within class methods. global keyboard global scroller # Initialize the window. director.init(width=800, height=600, do_not_scale=True, resizable=True) # Create a layer and add a sprite to it. player_layer = layer.ScrollableLayer() me = sprite.Sprite('human-female.png') player_layer.add(me) # Set initial position and velocity. me.position = (100, 100) me.velocity = (0, 0) # Set the sprite's movement class. me.do(Me()) # Create scroller object and load tiles. scroller = layer.ScrollingManager() map_layer = tiles.load('tiles/map.xml')['map0'] # Add map and player layers. scroller.add(map_layer) scroller.add(player_layer) # Create a scene and set its initial layer. main_scene = scene.Scene(scroller) # Attach a KeyStateHandler to the keyboard object. keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) # Play the scene in the window. director.run(main_scene)
def __init__(self, *children): super().__init__(*children) self.scrollManager = layer.ScrollingManager() self.scrollBar = ScrollBar(self.scrollManager) self.scrollLayer = ScrollLayer(reswidth / 2, resheight, reswidth, resheight, self.scrollBar) self.scrollLayer.x = 0 self.scrollLayer.y = 0 self.scrollBar.x = reswidth - (self.scrollBar.width / 2) self.scrollBar.y = (resheight - (resheight * 0.02)) - (self.scrollBar.img.height / 2) self.title = text.Label("Controls", font_name=resources.font[1], font_size=50, anchor_y="top", anchor_x="center") self.title.x = reswidth / 2 self.title.y = resheight * 0.85 self.add(self.title) blackLayer = layer.ColorLayer(0, 0, 0, 255) blackLayer.width = reswidth blackLayer.height = int(resheight * 0.35) blackLayer.x = 0 blackLayer.y = int(resheight - (blackLayer.height / 2)) self.add(blackLayer, z=-1) backButton = elements.mediumButton( "BACK", events.mainmenuevents.onSettingsButtonClick) backButton.x = reswidth * 0.065 backButton.y = resheight * 0.89 backButton.show(0.0001) self.add(backButton) controlElements = [] i = 1 for control, value in cfg.configuration["Controls"].items(): lbl = text.Label(str(control).capitalize(), font_size=25, anchor_x="left", anchor_y="center", color=(255, 255, 255, 255)) lbl.x = reswidth * 0.1 lbl.y = resheight * (0.6 - (0.15 * (i - 1))) txtBx = ControlTextBox(control) txtBx.x = reswidth * 0.9 txtBx.y = resheight * (0.6 - (0.15 * (i - 1))) self.scrollLayer.add(lbl) self.scrollLayer.add(txtBx) controlElements.append([lbl, txtBx]) i += 1 self.scrollManager.add(self.scrollLayer) self.scrollLayer.calculate() self.scrollManager.set_focus(reswidth / 2, resheight / 2) self.add(self.scrollManager, z=-2) self.add(self.scrollBar) self.add(messagePopup, z=1)
def main(): global keyboard, tilemap, scroller, player_direction, player_right, player_left, my_start_x, ground_list, start_point from cocos.director import director director.init(width=BG_WD, height=BG_HT, autoscale=False) print(description) # create a layer to put the player in player_layer = layer.ScrollableLayer(1) # NOTE: the anchor for this sprite is in the CENTER (the cocos default) # which means all positioning must be done using the center of its rect player = cocos.sprite.Sprite('block_man.png') player.x = -2850 player.y = 120 dragon_keep_bg = cocos.sprite.Sprite('DragonKeepPNG.png') player_layer.add(dragon_keep_bg, z=1) player_layer.add(player, z=2) #test tmx object collision - no really good examples #points = [(3232, 2400), (4232, 2400), (4232, 2300), (3232, 2300)] #t = cocos.tiles.TmxObject('polygon', 'dragon', 3232, 2400, 1000, 10, None, None, None, 1, points) #lay = cocos.tiles.TmxObjectLayer('layer', (255, 0, 0, 255), [t], 1, 1, (3232, 2400)) #i = 0 #pdb.set_trace() #while (i < 10): # player.x += 10 # player.y -= 10 # rect = player.get_rect() # if (lay.collide(rect, 'layer')): # print("True!") # i+=1 #tbd player.do(PlatformerController()) scroller = layer.ScrollingManager() scroller.add(player_layer, z=2) # construct the scene with a background layer color and the scrolling layers platformer_scene = cocos.scene.Scene() platformer_scene.add(layer.ColorLayer(0, 0, 0, 255), z=0) platformer_scene.add(scroller, z=1) # track keyboard presses keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) my_start_x = 0 ground_list = [] start_point = [] # allow display info about cells / tiles def on_key_press(key, modifier): #pdb.set_trace() global player_direction if key == pyglet.window.key.LEFT: player.x -= 100 if key == pyglet.window.key.RIGHT: player.x += 100 if key == pyglet.window.key.UP: player.y += 100 if key == pyglet.window.key.DOWN: player.y -= 100 if key == pyglet.window.key.E: print(ground_list) scroller.set_focus(player.position[0], player.position[1]) print(player.position) print("x{}, y{}".format(player.x, player.y)) def on_mouse_release(x, y, buttons, modifiers): global my_start_x, start_point, ground_list t = scroller.screen_to_world(x, y) print("mouse x{}, y{}".format(x, y)) print("mouse x{}, y{}".format(t[0], t[1])) if (my_start_x == 0): print("start_x = 0") my_start_x = 1 start_point = t else: print("start_x = 1") my_start_x = 0 ground_list.append([start_point, t]) director.window.push_handlers(on_key_press) director.window.push_handlers(on_mouse_release) scroller.set_focus(player.position[0], player.position[1]) # run the scene director.run(platformer_scene)
for x in range(len(self.squares_matrix)): if self.squares_matrix[x][y] is None: row += ' |' else: row += '*|' s = row + '\n' + s if label is not None: s = label + '\n' + s return s class ShouldntHappenError(UserWarning): pass #=============================================================================== #=========== MAIN SCRIPT ================ #=============================================================================== if __name__ == '__main__': director.init(resizable=True) tetris_board = TetrisBoardLayer('tetris.xml') scroller = layer.ScrollingManager() scroller.set_focus(100, 200) scroller.add(tetris_board) s = layer.ScrollableLayer() scroller.add(s) director.run(scene.Scene(scroller))
def main(): global keyboard, scroller, old_ij, old_cell, old_highlighted_color from cocos.director import director director.init(width=600, height=300, autoscale=False, resizable=True) car_layer = layer.ScrollableLayer() car = cocos.sprite.Sprite('car.png') car_layer.add(car) car.position = (200, 100) car.max_forward_speed = 200 car.max_reverse_speed = -100 car.do(DriveCar()) scroller = layer.ScrollingManager() map_loaded = tiles.load('hexmap.tmx') # In Tiled we named 'tile_layer_1' our sample layer test_layer = map_loaded['tile_layer_1'] tint_green_hexmap_borders(test_layer) scroller.add(test_layer) scroller.add(car_layer) old_ij = 'nonexist' old_highlighted_color = None old_cell = None main_scene = cocos.scene.Scene(scroller) keyboard = key.KeyStateHandler() director.window.push_handlers(keyboard) def on_key_press(key, modifier): if key == pyglet.window.key.Z: if scroller.scale == .75: scroller.do(actions.ScaleTo(1, 2)) else: scroller.do(actions.ScaleTo(.75, 2)) elif key == pyglet.window.key.D: test_layer.set_debug(True) elif key == pyglet.window.key.Q: tint_red_hexmap_borders(test_layer) director.window.push_handlers(on_key_press) def on_mouse_motion(x, y, dx, dy): global scroller, old_ij, old_cell, old_highlighted_color #vh, vy = director.get_virtual_coordinates(x, y) vx, vy = scroller.screen_to_world(x, y) ij = test_layer.get_key_at_pixel(vx, vy) if ij == old_ij: return # restore color if old_cell: p, q = old_ij if old_highlighted_color is None: test_layer.set_cell_color(p, q, (255, 255, 255)) del old_cell.properties['color4'] else: test_layer.set_cell_color(p, q, old_highlighted_color[:3]) # record info and set color old_ij = ij i, j = ij print(i, j) old_cell = test_layer.get_cell(i, j) if old_cell is None: return old_highlighted_color = old_cell.properties.get('color4', None) test_layer.set_cell_color(i, j, (255, 0, 0)) director.window.push_handlers(on_mouse_motion) director.run(main_scene)
def main(): global keyboard, scroller from cocos.director import director director.init(width=800, height=600, autoscale=False, resizable=True) global startAction, doTask, isPack, cel, ruch, isPicked, packAdres scroller = layer.ScrollingManager() test_layer = tiles.load('mapaSZI.tmx')['Warstwa Kafelków 1'] obj = tiles.load('mapa.tmx')['GameObjects'] poi = tiles.load('mapa.tmx')['Points'] scroller.add(test_layer) #0=start, 1=up, 2=bottom 3=bottom1, #0=wojtyniaka, 1=mickiewicza, 2=kopernika, 3=orlicza, 4= kuchnia, 5=borsuka kelner_layer = layer.ScrollableLayer() kelner = cocos.sprite.Sprite('kelner.png') kelner_layer.add(kelner) miejsca = {} startX = poi.objects[0].x startY = poi.objects[0].y miejsca['start'] = (startX, startY) upX = poi.objects[1].x upY = poi.objects[1].y miejsca['up'] = (upX, upY) bottomX = poi.objects[2].x bottomY = poi.objects[2].y miejsca['bottom'] = (bottomX, bottomY) bottom1X = poi.objects[3].x bottom1Y = poi.objects[3].y miejsca['bottom1'] = (bottom1X, bottom1Y) stacjaX = obj.objects[0].x stacjaY = obj.objects[0].y miejsca['stacja'] = (stacjaX, stacjaY) micX = obj.objects[1].x micY = obj.objects[1].y miejsca['mickiewicza'] = (micX, micY) kopX = obj.objects[2].x kopY = obj.objects[2].y miejsca['kopernika'] = (kopX, kopY) orlX = obj.objects[3].x orlY = obj.objects[3].y miejsca['orlicza'] = (orlX, orlY) pasX = obj.objects[4].x pasY = obj.objects[4].y miejsca['pascala'] = (pasX, pasY) borX = obj.objects[5].x borY = obj.objects[5].y miejsca['borsuka'] = (borX, borY) G = Graf() G.add_vertex('start') G.add_vertex('mickiewicza') G.add_vertex('up') G.add_vertex('borsuka') G.add_vertex('bottom1') G.add_vertex('stacja') G.add_vertex('pascala') G.add_vertex('orlicza') G.add_vertex('bottom') G.add_vertex('kopernika') G.add_edge('start', 'mickiewicza', 9) G.add_edge('mickiewicza', 'up', 2) G.add_edge('up', 'borsuka', 2) G.add_edge('borsuka', 'bottom1', 4) G.add_edge('bottom1', 'stacja', 1) G.add_edge('bottom1', 'pascala', 3) G.add_edge('pascala', 'orlicza', 5) G.add_edge('orlicza', 'bottom', 3) G.add_edge('bottom', 'kopernika', 3) G.add_edge('kopernika', 'start', 3) G.add_edge('mickiewicza', 'start', 9) G.add_edge('up', 'mickiewicza', 2) G.add_edge('borsuka', 'up', 2) G.add_edge('bottom1', 'borsuka', 4) G.add_edge('stacja', 'bottom1', 1) G.add_edge('pascala', 'bottom1', 3) G.add_edge('orlicza', 'pascala', 5) G.add_edge('bottom', 'orlicza', 3) G.add_edge('kopernika', 'bottom', 3) G.add_edge('start', 'kopernika', 3) print(shortest_path(G, 'mickiewicza', 'pascala')) short = shortest_path(G, 'mickiewicza', 'pascala') kelner.position = miejsca['start'] kelner.rotation = 90 ruch = MoveTo(miejsca['start'], 0) for i in short: ruch += MoveTo(miejsca[i], 2) kelner.do(ruch) scroller.add(kelner_layer) main_scene = cocos.scene.Scene(scroller) director.run(main_scene)