Example #1
0
def main():

    global keyboard

    #  initialzing the director. the director creates the window for the game
    director.init(width=400, height= 600, autoscale=True, resizable = True)

    #  creating a layer using the cocos2d platform
    #  different layers are used for each aspect of the game, i.e. the main character or background
    game_layer = layer.Layer()

    #creating a Sprite for the main character
    heroimage = pyglet.resource.image('hero.png')
    player = HeroShip(heroimage)
    #heroShip.cshape = cm.AARectShape(eu.Vector2(heroShip.position), 32, 32)

    #adding the main character to the 'player_layer' layer
    game_layer.add(player)

    #initializing the main character's position and velocity
    #heroShip.position = (100, 100)
    #heroShip.velocity = (0, 0)

    #creating a background layer
    background_layer = layer.Layer()
    background = sprite.Sprite('space_wallpaper.png')

    #adding backgound image to background layer
    background_layer.add(background)


    AsteroidImage = pyglet.resource.image('asteroid.png')

    asteroid = Asteroid(AsteroidImage, (200, 400))


    #adding asteroids to game layer
    game_layer.add(asteroid)

    game_layer.add(CollisionManager(player, asteroid))






    #initializing pyglet, which allows for keyboard import for character movement

    keyboard = key.KeyStateHandler()
    director.window.push_handlers(keyboard)

    #assigning the movement class to the heroShip sprite
    player.do(HeroShipMovement())

    #asteroid_1.do(actions.MoveBy( (0, -600), 4) )
    #asteroid_2.do(actions.MoveBy( (100, -600), 8) )

    main_scene = scene.Scene(background_layer, game_layer)

    director.run(main_scene)
Example #2
0
def main():
  global keyboard # Declare this as global so it can be accessed within class methods.
  
  # Initialize the window.
  director.init(width=500, height=300, do_not_scale=True, resizable=True)
  
  # Create a layer and add a sprite to it.
  player_layer = layer.Layer()
  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 a scene and set its initial layer.
  main_scene = scene.Scene(player_layer)

  # 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)
Example #3
0
def main():
    director.director.init(width=640, height=480)

    layer_ = layer.Layer()

    # Try animation sprite.
    explosion = image.load('explosion.png')
    explosion_seq = image.ImageGrid(explosion, 1, 8)
    explosion_animation = image.Animation.from_image_sequence(
        explosion_seq, 0.1)
    explosion_sprite = sprite.Sprite(
        explosion_animation,
        position=(320, 240),
    )
    layer_.add(explosion_sprite)

    # Try move action.
    # [NOTE]: Can overwrite `on_animation_end` method to implement the same thing.
    def move_sprite(_):
        explosion_sprite.position = (random.randint(0, 640),
                                     random.randint(0, 480))

    explosion_sprite.schedule_interval(move_sprite, 0.1 * 8)

    director.director.run(scene.Scene(layer_))
Example #4
0
    def step(self, dt):

        super(Me, self).step(dt)  # Run step function on the parent class.

        # Determine velocity based on keyboard inputs.
        if keyboard[key.RIGHT] > keyboard[key.LEFT]:
            direction = 0
            print("up here dummy")
        else:
            direction = 1

        velocity_x = 100 * (keyboard[key.RIGHT] - keyboard[key.LEFT])
        velocity_y = 100 * (keyboard[key.UP] - keyboard[key.DOWN])

        # Set the object's velocity.
        self.target.velocity = (velocity_x, velocity_y)

        player_layer = layer.Layer()
        if direction == 0:
            print("0")
            me = sprite.Sprite('standing.png', scale=1.0)
        else:
            print('1')
            me = sprite.Sprite('standingleft.png', scale=2.0)
        player_layer.add(me)
Example #5
0
def _test():
    director.director.init()

    main_layer = layer.Layer()
    main_layer.add(center_label('Click Me!', ActiveLabel))

    main_scene = scene.Scene(main_layer)

    director.director.run(main_scene)
Example #6
0
    def __init__(self):
        super().__init__()

        pole = cocos.sprite.Sprite('pole.png', position=(300,240))
        pole.scale = 1/3.2
        pole.scale_x = 1.0365
        # pole.scale_y = 0.936

        background = layer.Layer()
        midle = layer.Layer()
        foreground = MouseInput()

        from cocos.text import Label

        self.lbl = Label('0', (50, 440), color=(255, 255, 255, 255))

        background.add(pole)
        background.add(self.lbl)
        self.add(background)

        blue_prived = Object(2 + j, 50, 'blue.png', 50, kuda1)
        blue_prived.sprite.scale = 1 / 14
        privedenia.append(blue_prived)

        for complex_number in graf.keys():
            dots.append(cocos.sprite.Sprite('dot.png', position=(complex_number.real * coef + left_offset, complex_number.imag * coef + down_offset)))
            dots[-1].scale = 1 / 2
            midle.add(dots[-1])
            dots_graf.update({complex_number: dots[-1]})
            dots_to_graf.update({dots[-1]: complex_number})


        def callback(dt, *args, **kwargs):
            global Pack_c
            blue_prived.moving(dt, self)
            foreground.pacman.moving(dt, self, collide = True, pacman=True)
            Pack_c = foreground.pacman.vert

        midle.add(blue_prived.sprite)
        self.add(midle)
        self.add(foreground)
        self.schedule(callback)
Example #7
0
def main():
    path = os.path.join(os.path.dirname(__file__), '../Map/assets/img')
    resource.path.append(path)
    resource.reindex()

    director.director.init(width=640, height=480)

    layer_ = layer.Layer()

    layer_.add(
        MultipleSprite(
            Sprite('grossini.png', position=(50, 40)),
            Sprite('sky.gif', position=(-60, -30)),
            position=(320, 240),
        ))

    director.director.run(scene.Scene(layer_))
Example #8
0
def main():
    global keyboard  # This is declared as global so that it can be accessed by all class methods

    # Initialize director and create scene.
    # Arguments passed set the size of the window.
    # autoscale allows the graphics to be scaled according to the window being resized.
    # Caption sets window title. Have some fun with that!
    # (http://python.cocos2d.org/doc/api/cocos.director.html)
    director.init(width=800,
                  height=600,
                  caption="In the beginning everything was Kay-O",
                  autoscale=True,
                  resizable=True)

    # Create a layer and add a sprite to the layer.
    # Layers help to separate out different parts of a scene.
    # Typically, the highest layer will go to dialogue boxes and menus
    # Followed by the player layer with the background on the bottom
    player_layer = layer.Layer()  # Creates an instance of a new layer
    player = sprite.Sprite(
        'images/mr-saturn.png'
    )  #initializes a sprite object and includes a path to default image.
    player_layer.add(
        player)  # Adds player to instance of layer we just created

    # Sets initial position and velocity of player
    player.position = (250, 150)
    player.velocity = (0, 0)

    # Set the sprite's movement class
    player.do(Player())

    # Create a scene and set its initial layer
    main_scene = scene.Scene(player_layer)

    # Creates a KeyStateHandler on the keyboard object so we can accept input from the keyboard (KeyStateHandler is part of the pyglet library)
    # And pushes it to director
    keyboard = key.KeyStateHandler()
    director.window.push_handlers(keyboard)

    # Run the scene we've built in the window
    director.run(main_scene)
Example #9
0
def main():
  global keyboard # Declare this as global so it can be accessed within class methods.
  # Initialize the window
  director.init(width=size[0], height=size[1], autoscale=True, resizable=True)

  # Create a layer and add a sprite to it.
  player_layer = layer.Layer()
  molecule = sprite.Sprite('sprites/molecule.png')
  molecule.scale = 2
  player_layer.add(molecule, z=1)
  scale = actions.ScaleBy(3, duration=2)

  # Add a Label, because we can.
  label = cocos.text.Label('Hello, world@' + str(deltaTime), font_name='Times New Roman', font_size=32, anchor_x='left', anchor_y='center')
  label.position = 0, size[1]/2
  label.velocity = 0, 0
  player_layer.add(label)

  # Set initial position and velocity.
  molecule.position = (size[0]/2, size[1]/2)
  molecule.velocity = (0, 0)

  # Set the sprite's movement class and run some actions.
  molecule.do(actions.Repeat(scale + actions.Reverse(scale)))

  label.do(Me())

  # Rotate the entire player_layer (includes ALL nodes, will rotate ONCE)
  player_layer.do(actions.RotateBy(360, duration=10))

  # Create a scene and set its initial layer.
  main_scene = scene.Scene(player_layer)

  # Set the sprite's movement class.
  keyboard = key.KeyStateHandler()
  director.window.push_handlers(keyboard)

  # Play the scene in the window.
  director.run(main_scene)
Example #10
0
 def __init__(self):
     self.clickable_list = []
     self.misc_layer = ccly.Layer()
     self.misc_layer.add(name="stdout",
                         child=cc.text.Label(
                             text="",
                             font_size=18,
                             bold=True,
                             color=(255, 255, 255, 180),
                             anchor_x="left",
                             anchor_y="top",
                             position=(gui_paras["stdout-x"],
                                       gui_paras["stdout-y"]),
                             width=gui_paras["stdout-width"],
                             multiline=True))
     self.stdout = collections.deque()
     enemy_cardback_sprite = ccsp.Sprite(sprite_path + "CardBacks.png", \
             position = (resolution[0]/2,
                 resolution[1]-gui_paras["margin-top"]-0.5*gui_paras["enemy-cardbacks-size"]))
     self.enemy_cardnum_label = cc.text.Label(text="4",
                                              font_size=50,
                                              bold=True,
                                              anchor_x="center",
                                              anchor_y="center")
     enemy_cardback_sprite.add(self.enemy_cardnum_label)
     self.misc_layer.add(enemy_cardback_sprite)
     action_scale = gui_paras["action-button-size"] / 200
     base_height = gui_paras["margin-bottom"] + 2*gui_paras["hud-chess-size"] + \
             gui_paras["battle-button-margin"] + gui_paras["battle-button-size"] + \
             gui_paras["action-button-margin"]
     self.misc_layer.add(
         name="OK",
         child=ccsp.Sprite(sprite_path + "OK.png",
                           scale=action_scale,
                           anchor=(0, 0),
                           position=(resolution[0] -
                                     3 * gui_paras["action-button-margin"] -
                                     2 * gui_paras["action-button-size"],
                                     base_height)))
     self.misc_layer.add(
         name="cancel",
         child=ccsp.Sprite(
             sprite_path + "Cancel.png",
             scale=action_scale,
             anchor=(0, 0),
             position=(resolution[0] - gui_paras["action-button-margin"] -
                       gui_paras["action-button-size"], base_height)))
     self.misc_layer.add(
         name="end",
         child=ccsp.Sprite(
             sprite_path + "Turn.png",
             scale=action_scale,
             anchor=(0, 0),
             position=(resolution[0] - gui_paras["action-button-margin"] -
                       gui_paras["action-button-size"],
                       base_height + gui_paras["action-button-size"] +
                       2 * gui_paras["action-button-margin"])))
     self.cards_layer = ccly.Layer()
     self.card_sprites = []
     self.enemy_card_sprites = []
     self.chesses_layer = ccly.Layer()
     self.chesses_sprites = []
     self.enemy_chesses_layer = ccly.Layer()
     self.enemy_chesses_sprites = []
     self.battle_button_layer = ccly.Layer()
     self.battle_button_sprites = []
Example #11
0

if __name__ == "__main__":

    global keyboard

    # director init takes the same arguments as pyglet.window
    # cocos.director.director.init()
    director.init(width=640, height=480, autoscale=True, resizable=True)

    #initializing pyglet, which allows for keyboard import for character movement
    keyboard = key.KeyStateHandler()
    director.window.push_handlers(keyboard)

    #creating a background layer
    background_layer = layer.Layer()
    background = sprite.Sprite('space_wallpaper.jpeg')
    background.position = (350, 300)
    background_layer.add(background)

    game_layer = GameLayer()

    # A scene that contains the layer hello_layer
    # main_scene = cocos.scene.Scene(hello_layer, game_layer)
    main_scene = cocos.scene.Scene(background_layer, game_layer)

    # And now, start the application, starting with main_scene
    cocos.director.director.run(main_scene)

    # or you could have written, without so many comments:
    #      director.run( cocos.scene.Scene( HelloWorld() ) )
Example #12
0
def main():
  director.init(width=WIN_WIDTH,height=WIN_HEIGHT)
  game_layer = layer.Layer()
  game_scene = scene.Scene(BackgroundLayer())
  director.run(game_scene)