Example #1
0
    def __init__(self):
        Scene.__init__(self)
        self.add(
            Sprite(image=pyglet.resource.image('background.png'),
                   position=(self.anchor_x,
                             self.anchor_y)))  # Background Image

        black_fade = ColorLayer(0, 0, 0, 0)
        black_fade.opacity = 120
        self.add(black_fade)

        menu = Menu("TETRIS")
        menu.position = (0, -60)
        menu.font_title["font_name"] = "Tetrominoes"
        menu.font_title["color"] = (214, 178, 152, 255)
        menu.font_item["font_name"] = "Ravie"
        menu.font_item_selected["font_name"] = "Ravie"

        menu_items = [
            MenuItem('Start Game',
                     game_controller.game_controller.init_new_game),
            MenuItem('Ranking', self.show_ranking),
            MenuItem('Quit', game_controller.game_controller.close_scene)
        ]
        menu.menu_hmargin = 10
        menu.create_menu(menu_items)

        menu.on_quit = self.on_quit

        self.menu_lyr = Layer()
        self.menu_lyr.add(menu)
        self.rank = Ranking()
        self.multi_layer = MultiplexLayer(self.menu_lyr, self.rank)
        self.add(self.multi_layer)
Example #2
0
 def _load_background(self):
     background = Sprite(
         self.gallery.content["display"]["worldmap_minitrain"])
     self.optimal_scale = (self.config.window_width * self.display_pos_size[
         "display_worldmap_minitrain"]["W"]) / background.width
     background.image_anchor = 0, 0
     background.scale = self.optimal_scale
     background.x = self.config.window_width * self.display_pos_size[
         "display_worldmap_minitrain"]["X"]
     background.y = self.config.window_height * self.display_pos_size[
         "display_worldmap_minitrain"]["Y"]
     self.left_margin = background.x
     self.bottom_margin = background.y
     self.optimal_width = background.width
     self.optimal_height = background.height
     #self.add(background)
     white_base = ColorLayer(255,
                             255,
                             255,
                             255,
                             width=background.width * 6,
                             height=background.height + 10)
     white_base.x = background.x - (background.width * 3)
     white_base.y = background.y + self.bottom_margin
     self.add(white_base)
Example #3
0
    def set_slide(self, slide, change="normal"):
        self.get("clock").clock_shown(slide.show_clock)

        out_layer = self.get("slide")
        in_layer = self.__get_slide_layer(slide)
        try:
            self.remove("temp")
        except Exception:
            pass  # no transition running.
        try:
            self.remove("temp_col")
        except Exception:
            pass  # no transition running.
        self.remove("slide")

        self.add(out_layer, z=1, name="temp")
        self.add(in_layer, z=0, name="slide")

        transition = config.effect_mapping[change][slide.effect]
        logger.debug("Changing slide with transition: %s", transition)
        if transition == "tile_swipe":
            out_layer.do(FadeOutBLTiles(grid=(16, 9), duration=1) + Hide() + StopGrid())
        elif transition == "crossfade":
            out_layer.do(FadeOut(duration=1))
        elif transition == "fade_red":
            col_layer = ColorLayer(255, 0, 0, 0)
            self.add(col_layer, z=1.1, name="temp_col")
            col_layer.do(FadeIn(duration=0.3) + Delay(0.5) + FadeOut(duration=1.5))
            out_layer.do(Delay(0.3) + Hide())
        else:
            out_layer.do(Hide())
    def __init__(self):
        super().__init__()

        ws = director.get_window_size()

        color_fill = ColorLayer(0, 191, 255, 255, height = 800, width = 800)
        color_fill.position = (250, 0)
        self.add(color_fill)

        self.add(Label("REPORT OF THE NEXT WAVE", font_size = 34, x = 320, y = 700))
        self.add(Label("Vagabonds: ", color = (255, 255, 255, 255), font_size = 32, x = 400, y = 600))
        self.add(Label("Militiars: ", color = (255, 255, 255, 255), font_size = 32, x = 400, y = 550))
        self.add(Label("Looters: ", color = (255, 255, 255, 255), font_size = 32, x = 400, y = 500))
        self.add(Label("Defendors: ", color = (255, 255, 255, 255), font_size = 32, x = 400, y = 450))
        self.add(Label("Agressors: ", color = (255, 255, 255, 255), font_size = 32, x = 400, y = 400))
        self.add(Label("Champions: ", color = (255, 255, 255, 255), font_size = 32, x = 400, y = 350))

        self.vaga_count = Label("0",  font_size = 32, x = 750, y = 600)
        self.mili_count = Label("0",  font_size = 32, x = 750, y = 550)
        self.loot_count = Label("0",  font_size = 32, x = 750, y = 500)
        self.defe_count = Label("0",  font_size = 32, x = 750, y = 450)
        self.agre_count = Label("0",  font_size = 32, x = 750, y = 400)
        self.cham_count = Label("0",  font_size = 32, x = 750, y = 350)

        self.add(self.vaga_count)
        self.add(self.mili_count)
        self.add(self.loot_count)
        self.add(self.defe_count)
        self.add(self.agre_count)
        self.add(self.cham_count)
Example #5
0
    def __init__(self):
        super().__init__()

        ws = director.get_window_size()

        color_fill = ColorLayer(0, 191, 255, 255, height=800, width=800)
        color_fill.position = (250, 0)
        self.add(color_fill)

        self.add(Label("REPORT OF THE NEXT WAVE", font_size=34, x=320, y=700))
        self.add(
            Label("Vagabonds: ",
                  color=(255, 255, 255, 255),
                  font_size=32,
                  x=400,
                  y=600))
        self.add(
            Label("Militiars: ",
                  color=(255, 255, 255, 255),
                  font_size=32,
                  x=400,
                  y=550))
        self.add(
            Label("Looters: ",
                  color=(255, 255, 255, 255),
                  font_size=32,
                  x=400,
                  y=500))
        self.add(
            Label("Defendors: ",
                  color=(255, 255, 255, 255),
                  font_size=32,
                  x=400,
                  y=450))
        self.add(
            Label("Agressors: ",
                  color=(255, 255, 255, 255),
                  font_size=32,
                  x=400,
                  y=400))
        self.add(
            Label("Champions: ",
                  color=(255, 255, 255, 255),
                  font_size=32,
                  x=400,
                  y=350))

        self.vaga_count = Label("0", font_size=32, x=750, y=600)
        self.mili_count = Label("0", font_size=32, x=750, y=550)
        self.loot_count = Label("0", font_size=32, x=750, y=500)
        self.defe_count = Label("0", font_size=32, x=750, y=450)
        self.agre_count = Label("0", font_size=32, x=750, y=400)
        self.cham_count = Label("0", font_size=32, x=750, y=350)

        self.add(self.vaga_count)
        self.add(self.mili_count)
        self.add(self.loot_count)
        self.add(self.defe_count)
        self.add(self.agre_count)
        self.add(self.cham_count)
Example #6
0
    def __init__(self, text_list, text_source, map, w, h, info,
                 size=200, callback=None, **kwargs):

        super().__init__(text_list, text_source)
        self.map = map
        self.w, self.h = w, h
        self.size = size
        self.callback = callback
        self.kwargs = kwargs
        self.info = info # dict of persons that stands for V or E

        # add background

        self.background = Sprite(map.scene, position=(w // 2, h // 2))
        self.text_back = ColorLayer(0,0,200,255,w,h//3)
        self.add(self.background)
        self.add(self.text_back)

        # add img
        self.left = Sprite('ring.png', position=(w // 6, h // 2), opacity=0)
        self.right = Sprite('ring.png', position=(w * 5 // 6, h // 2), opacity=0)
        self.add(self.left)
        self.add(self.right)

        # add label
        self.label = Text(text=' ', position=(w // 6, h // 3), font_size=24)
        self.text_back.add(self.label)

        # add text
        self.text = Text(text=' ', position=(w // 2, h // 6), font_size=30)
        self.text_back.add(self.text)
class FadeTransition(TransitionScene):
    """Fade out the outgoing scene and then fade in the incoming scene.

    Optionally supply the color to fade to in-between as an RGB color tuple.
    """

    def __init__(self, *args, **kwargs):
        color = kwargs.pop("color", (0, 0, 0)) + (0,)
        super(FadeTransition, self).__init__(*args, **kwargs)

        self.fadelayer = ColorLayer(*color)

        self.in_scene.visible = False
        self.add(self.fadelayer, z=2)

    def on_enter(self):
        super(FadeTransition, self).on_enter()
        self.fadelayer.do(
            FadeIn(duration=self.duration / 2.0)
            + CallFunc(self.hide_out_show_in)
            + FadeOut(duration=self.duration / 2.0)
            + CallFunc(self.finish)
        )

    def on_exit(self):
        super(FadeTransition, self).on_exit()
        self.remove(self.fadelayer)
Example #8
0
def main():
    # initialize the director
    director.init(800, 600, resizable=True)
    # create the scene switch layer
    switch_layer = SwitchScene()    

    # define the scene switch layer


    red = ColorLayer(255, 0, 0, 255)
    green = ColorLayer(0, 255, 0, 255)
    blue = ColorLayer(0, 0, 255, 255)

    # place all scenes in a scene list
    scenes = [
        Scene(Title('Cocos2D tutorial'), switch_layer),
        Scene(Animals(), switch_layer),
        Scene(SwitchLayer(red, green, blue), switch_layer),
        Scene(PythonInterpreterLayer(), switch_layer),
        Scene(Mouse(), switch_layer),
        Scene(ColorLayer(150, 0, 0, 255), switch_layer),
        Scene(OptionsMenu(), switch_layer),
        Scene(ColorLayer(0, 150, 0, 255), switch_layer),
        Scene(ActionMenu(actions), switch_layer),
        Scene(EffectMenu(effects), switch_layer),
        Scene(TransitionMenu(transitions), switch_layer)
        ]

    # give the scene list to the switch layer
    switch_layer.scenes = scenes
    
    # run the first scene
    cocos.director.director.run(scenes[0]) 
Example #9
0
	def set_slide(self, slide, change='normal'):
		self.get('clock').clock_shown(slide.show_clock)
		
		out_layer=self.get('slide')
		in_layer=self.__get_slide_layer(slide)
		try:
			self.remove('temp')
		except Exception:
			pass # no transition running.
		try:
			self.remove('temp_col')
		except Exception:
			pass # no transition running.
		self.remove('slide')

		self.add(out_layer, z=1, name='temp')
		self.add(in_layer, z=0, name='slide')

		transition=config.effect_mapping[change][slide.effect]
		logger.debug("Changing slide with transition: %s", transition)
		if transition == 'tile_swipe':
			out_layer.do(FadeOutBLTiles(grid=(16, 9), duration=1) + Hide() + StopGrid())
		elif transition == 'crossfade':
			out_layer.do(FadeOut(duration=1))
		elif transition == 'fade_red':
			col_layer=ColorLayer(255, 0, 0, 0)
			self.add(col_layer, z=1.1, name='temp_col')
			col_layer.do(FadeIn(duration=0.3)+Delay(0.5)+FadeOut(duration=1.5))
			out_layer.do(Delay(0.3) + Hide())
		else:
			out_layer.do(Hide())
Example #10
0
    def __init__(self, *args, **kwargs):
        color = kwargs.pop('color', (0, 0, 0)) + (0, )
        super(FadeTransition, self).__init__(*args, **kwargs)

        self.fadelayer = ColorLayer(*color)

        self.in_scene.visible = False
        self.add(self.fadelayer, z=2)
Example #11
0
    def __init__(self):
        super().__init__()

        self.recap_labels = []

        red_bar = ColorLayer(*BAR_COLOR, width=WINDOW_WIDTH, height=BAR_HEIGHT)
        red_bar.y = WINDOW_HEIGHT / 2 - BAR_HEIGHT / 2
        self.add(red_bar, z=-1)
    def __init__(self):
        super(HelloScene, self).__init__()
        my_layer = ColorLayer(171, 75, 100, 1000)
        text = Label('Hello Everyone',
                     font_name='Times New Roman',
                     font_size=32,
                     anchor_x='center',
                     anchor_y='center')

        text.position = GameObj.my_director._window_virtual_width / 2, GameObj.my_director._window_virtual_height / 2
        my_layer.add(text)
Example #13
0
	def __init__(self, player_score, player2_score):
		super(GameOver, self).__init__()
		gameover_layer = ColorLayer(0,0,0,255)
		size = director.get_window_size()
		game_over = Label("Game Over", (size[0] / 2,size[1] / 2), font_name = "David", font_size = 32)
		p1_score = Label("Player 1 score: " + str(player_score), (size[0] / 2,size[1] / 4), font_name = "David", font_size = 32)
		p2_score = Label("Player 2 score: " + str(player2_score), (size[0] / 2,size[1] / 6), font_name = "David", font_size = 32)
		gameover_layer.add(game_over)
		gameover_layer.add(p1_score)
		gameover_layer.add(p2_score)
		self.add(gameover_layer)
Example #14
0
    def draw_overlays(self):
        """Draws black, semi-transparent overlays over the lights to simulate
           a light that is turned off."""
        self.overlays = []

        width = self.image.width / TrafficLights.NUM_LIGHTS
        height = self.image.height

        for i in range(-2, TrafficLights.NUM_LIGHTS / 2):
            overlay = ColorLayer(0, 0, 0, 125, width, height)
            overlay.x = i * width
            self.add(overlay, z=2)
            self.overlays.append(overlay)
Example #15
0
    def __init__(self, list, *args, **kwargs):
        super(TransitionMenu, self).__init__(list, title='Transitions', *args, *kwargs)

        # Define three different sprites
        s0 = Sprite('animals/cow-icon.png', position=(400, 300), scale=2)
        s1 = Sprite('animals/bird-icon.png', position=(400, 300), scale=2)
        s2 = Sprite('animals/parrot-icon.png', position=(400, 300), scale=2)

        # Define three different scenes
        scene0 = Scene(ColorLayer(100, 0, 0, 255), s0, self)
        scene1 = Scene(ColorLayer(0, 100, 0, 255), s1, self)
        scene2 = Scene(ColorLayer(0, 0, 100, 255), s2, self)
        
        self.scenes = [scene0, scene1, scene2]
        self.scene_index = 0
Example #16
0
    def build(self, width, height):
        self.width, self.height = width, height
        self.x, self.y = (director.window.width - width) // 2, (director.window.height - height) // 2

        title_label = Label(self.popup_ctrl.title,
                            font_name='Calibri',
                            color=rgba_colors["black"],
                            font_size=23,
                            anchor_x='center', anchor_y='center')

        title_label.x = width // 2
        title_label.y = height - 50

        self.add(title_label)

        message_label = Label(self.popup_ctrl.message,
                              font_name='Calibri',
                              color=rgba_colors["black"],
                              font_size=16,
                              anchor_x='center', anchor_y='center')

        message_label.x = width // 2
        message_label.y = height - 100

        self.add(message_label)

        for i, button in enumerate(self.popup_ctrl.buttons):
            padding = 20
            button_container = ColorLayer(*rgba_colors["popup_button_background"],
                                          width=(width - padding) // len(self.popup_ctrl.buttons) - padding,
                                          height=40)

            button_container.position = padding * (i + 1) + button_container.width * i, 30

            self.add(button_container)
            self.buttons_container.append(button_container)

            button_text = Label(button.text,
                                font_name='Calibri',
                                color=rgba_colors["white"],
                                font_size=18,
                                anchor_x='center', anchor_y='center')

            button_text.position = button_container.x + button_container.width / 2, button_container.y + button_container.height / 2 + 3

            self.add(button_text)

        director.window.push_handlers(self.popup_ctrl)
Example #17
0
def default_pause_scene():
    w, h = director.window.width, director.window.height
    texture = pyglet.image.Texture.create_for_size(
        GL_TEXTURE_2D, w, h, GL_RGBA)
    texture.blit_into(pyglet.image.get_buffer_manager().get_color_buffer(), 0, 0, 0)
    return PauseScene(texture.get_region(0, 0, w, h),
                      ColorLayer(25, 25, 25, 205), PauseLayer())
Example #18
0
 def create_layers(self):
     '''Creates scene layers.'''
     # layers
     lr.back = ColorLayer(*my.layout['color']['back window'])
     lr.instruction = MessageLayerStyled('instruction')
     lr.end = MessageEnd()
     lr.gui = GUIBase()
Example #19
0
    def __init__(self, model, hud):
        super(GameView, self).__init__()

        width, height = director.get_window_size()

        aspect = width / float(height)
        self.grid_size = (int(20 * aspect), 20)
        self.duration = 8

        self.position = (width // 2 - COLUMNS * SQUARE_SIZE // 2, 0)
        self.transform_anchor = (COLUMNS * SQUARE_SIZE // 2,
                                 ROWS * SQUARE_SIZE // 2)

        # background layer to delimit the pieces visually
        cl = ColorLayer(112,
                        66,
                        20,
                        50,
                        width=COLUMNS * SQUARE_SIZE,
                        height=ROWS * SQUARE_SIZE)
        self.add(cl, z=-1)

        self.model = model
        self.hud = hud

        self.model.push_handlers(
                                    self.on_up_character, \
                                    self.on_level_complete, \
                                    self.on_new_level, \
                                    self.on_game_over, \
                                    self.on_win, \
                                    )

        self.hud.show_message('GET READY', self.model.start)
Example #20
0
def get_dance(index):
    d = dances[index]
    layer = ColorLayer(0, 255, 0, 100)
    s = Scene(FontLayer(title=d[0], subtitle=d[1]), d[2](index))
    s.add(layer)
    # return Scene(FontLayer(title=d[0], subtitle=d[1]), d[2](index))
    return s
Example #21
0
    def __init__(self, *args, **kwargs):
        super(Transitions, self).__init__(transitions, wrap=True, *args, *kwargs)
        w, h = director.get_window_size()

        # Define three different sprites
        s0 = Sprite('cow-icon.png', position=(w//2, h//2), scale=2)
        s1 = Sprite('bird-icon.png', position=(w//2, h//2), scale=2)
        s2 = Sprite('parrot-icon.png', position=(w//2, h//2), scale=2)

        # Define three different scenes
        scene0 = Scene(ColorLayer(100, 0, 0, 255), s0, self)
        scene1 = Scene(ColorLayer(0, 100, 0, 255), s1, self)
        scene2 = Scene(ColorLayer(0, 0, 100, 255), s2, self)
        
        self.scenes = [scene0, scene1, scene2]
        self.scene_index = 0
Example #22
0
def default_pause_scene():
    x, y = director.get_window_size()
    texture = pyglet.image.Texture.create_for_size(GL_TEXTURE_2D, x, y,
                                                   GL_RGBA)
    texture.blit_into(pyglet.image.get_buffer_manager().get_color_buffer(), 0,
                      0, 0)
    return PauseScene(texture, ColorLayer(25, 25, 25, 205), PauseLayer())
Example #23
0
def main():
    print(description)
    director.init(resizable=True)
    main_scene = Scene()

    red = ColorLayer(255, 0, 0, 128)

    sprite = SpriteLayer()

    red.scale = 0.75

    main_scene.add(red, z=0)
    main_scene.add(sprite, z=1)

    sprite.do(Waves3D(duration=2) + Flip(duration=2))
    director.run(main_scene)
def main():
    print description
    director.init( resizable=True )
    main_scene = Scene()

    red = ColorLayer(255,0,0,128)

    sprite = SpriteLayer()

    red.scale = 0.75

    main_scene.add( red, z=0 )
    main_scene.add( sprite, z=1 )

    sprite.do( Waves3D(duration=2) + Flip(duration=2) )
    director.run (main_scene)
Example #25
0
    def __init__( self, *args, **kwargs ):
        super(FadeTransition, self ).__init__( *args, **kwargs)

        self.fadelayer = ColorLayer(0,0,0,0)

        self.in_scene.visible = False
        self.add( self.fadelayer, z=2 )
Example #26
0
    def __init__(self):
        w, h = director.get_window_size()
        super(ScoreLayer, self).__init__()

        # transparent layer
        self.add(ColorLayer(32, 32, 32, 32, width=w, height=48), z=-1)

        self.position = (0, h - 48)

        self.score = Label('Score:',
                           font_size=36,
                           font_name='Arial',
                           color=(255, 255, 255, 255),
                           anchor_x='left',
                           anchor_y='bottom')
        self.score.position = (0, 0)
        self.add(self.score)

        self.lvl = Label('Lvl:',
                         font_size=36,
                         font_name='Arial',
                         color=(255, 255, 255, 255),
                         anchor_x='left',
                         anchor_y='bottom')

        self.lvl.position = (450, 0)
        self.add(self.lvl)
Example #27
0
    def __init__(self):
        """initializer"""
        Scene.__init__(self)
        self.config = Config()
        self.gallery = Gallery()
        # creating map
        raw_map = tiles.load("{}/{}.{}".format(self.config.resources, "combat", self.config.map_format) )
        self.tw = self.config.tile_width = raw_map.contents["combat"].tw

    
        snow_base = ColorLayer( 250, 250, 250, 255, director.window.width, director.window.height)
        self.add(snow_base, name="display_worldmap_snow")
        cz = 1
        self.add(DisplayCombatMapscroll(0), z=cz, name="display_combat_mapscroll")
        cz +=1
        padding_x, padding_y = self.get_initial_padding(raw_map)
        print('e')
        for layer_name in [ "combat"]:  # TODO remove this hardcoded stuff, where is the Z value?
            cz += 1
            self.get("display_combat_mapscroll").add(raw_map.contents[layer_name], z=cz, name=layer_name) #z=len(self.children), name=layer_name)
            self.get("display_combat_mapscroll").get(layer_name).set_view(padding_x, padding_y, director.window.width + padding_x, director.window.height + padding_y)
        print('e')
        cz +=1
        self.get("display_combat_mapscroll").init_tactical_map()
        print('e')
#        self.add(DisplayWorldmapLauncher(), z=cz, name="display_worldmap_launcher")
#        cz +=1
        self.MapInZoom=True
        print('e')
        self.display_combat_mapscroll=self.get("display_combat_mapscroll")    
        print('e')
Example #28
0
    def __init__(self, hud):
        super().__init__()

        try:
            fullmap = load("mario-world1-1.tmx")
        except Exception as e:
            raise SystemExit(e)

        bg_map = fullmap["Background"]
        fg_map = fullmap["Foreground"]
        ob_map = fullmap["Objects"]
        tileset = fullmap["Mario"]

        fg_map.do(BlinkBricks())
        fg_map.set_cell_opacity(64, 5, 0)

        scroller = ScrollingManager()
        scroller.add(bg_map, z=0)
        scroller.add(fg_map, z=2)
        scroller.add(GameLayer(hud, fg_map, ob_map, tileset), z=1)

        scroller.scale = 2.5

        self.add(ColorLayer(107, 140, 255, 255), z=0)
        self.add(scroller, z=1)
        self.add(hud, z=10)
Example #29
0
 def _load_background(self):
     background = Sprite(self.gallery.content["display"]["worldmap_hud"])
     self.optimal_scale = (self.config.window_width *
                           self.display_pos_size["display_worldmap_hud"]
                           ["W"]) / background.width
     background.image_anchor = 0, 0
     background.scale = self.optimal_scale
     background.x = self.config.window_width * self.display_pos_size[
         "display_worldmap_hud"]["X"]
     background.y = self.config.window_height * self.display_pos_size[
         "display_worldmap_hud"]["Y"]
     self.left_margin = background.x
     self.bottom_margin = background.y
     self.optimal_width = background.width
     self.optimal_height = background.height
     black_base = ColorLayer(0,
                             0,
                             0,
                             255,
                             width=background.width,
                             height=background.height)
     black_base.x = background.x
     black_base.y = background.y
     self.add(black_base)
     self._load_button_gen("button", "engine", events.emit_show_engine,
                           "button_engine", 0, 1, 0.9)
     self._load_button_gen("button", "quarters", events.emit_show_quarters,
                           "button_quarters", 0, 1, 0.9)
     self._load_button_gen("button", "cnc", events.emit_show_cnc,
                           "button_cnc", 0, 1, 0.9)
     self._load_button_gen("button", "minimap", events.emit_show_minimap,
                           "button_minimap", 0, 1, 0.9)
     self._load_button_gen("button", "find_engine", events.emit_find_engine,
                           "button_find_engine", 0, 1, 0.9)
     self._load_button_gen("button", "arrow_left",
                           events.emit_scroll_minitrain,
                           "button_arrow_left", 0, 0.4, 0.95)
     self._load_button_gen("button", "arrow_right",
                           events.emit_scroll_minitrain,
                           "button_arrow_right", 0, 0.4, 0.95)
     #self._load_button_direction()
     self._load_button_gen("button", "break_on", events.emit_switch_break,
                           "button_break", 0, 1, 0.95)
     self._load_button_gen("button", "direction_for",
                           events.emit_switch_direction, "button_direction",
                           0, 1, 0.95)
     self.add(background)
Example #30
0
    def __init__(self, title, choices, callback, explanation=None, width=400):
        super(ChoiceLayer, self).__init__()
        self.callback = callback
        self.add(ColorLayer(20, 20, 20, 150), z=-2)
        w, h = director.get_window_size()

        y = h - 256
        but = Label(title,
                    color=(0, 0, 0, 255),
                    position=(w // 2, y),
                    anchor_x='center',
                    anchor_y='top',
                    font_size=24)
        x1 = w // 2 - but.element.content_width // 2
        x2 = w // 2 + but.element.content_width // 2
        y2 = y
        self.add(but)
        y -= but.element.content_height + 10

        if explanation:
            but = Label(explanation,
                        multiline=True,
                        color=(0, 0, 0, 255),
                        position=(w // 2, y),
                        width=width,
                        anchor_x='center',
                        anchor_y='top',
                        font_size=14,
                        align='center',
                        font_name='Prototype')
            self.add(but)
            x1 = min(w // 2 - width // 2, x1)
            x2 = max(w // 2 + width // 2, x2)
            y -= but.element.content_height + 10

        y -= 32

        self.choice_buts = []
        for choice in choices:
            but = Label(choice,
                        color=(0, 0, 0, 255),
                        position=(w // 2, y),
                        anchor_x='center',
                        anchor_y='bottom',
                        font_size=20,
                        font_name='Prototype')
            self.add(but, z=1)
            self.choice_buts.append(but)
            x = w // 2 - but.element.content_width // 2
            x1 = min(x, x1)
            x2 = max(w // 2 + but.element.content_width // 2, x2)
            but.rect = Rect(x, y, but.element.content_width,
                            but.element.content_height)
            y1 = y
            y -= but.element.content_height

        self.patch_dimensions = (x1, y1, x2 - x1, y2 - y1)

        self.ninepatch = NinePatch(pyglet.resource.image('border-9p.png'))
Example #31
0
 def show_rect(self):
     if self.sprite_rect:
         self.remove(self.sprite_rect)
     rect = self.sprite1.get_rect()
     self.sprite_rect = ColorLayer(255, 255, 255, 255,
                                   width=rect.width, height=rect.height)
     self.sprite_rect.position = rect.position
     self.add(self.sprite_rect, z=1)
    def __init__(self, *args, **kwargs):
        color = kwargs.pop("color", (0, 0, 0)) + (0,)
        super(FadeTransition, self).__init__(*args, **kwargs)

        self.fadelayer = ColorLayer(*color)

        self.in_scene.visible = False
        self.add(self.fadelayer, z=2)
 def __init__(self):
     super(GameScene, self).__init__()
     GameObj.my_director.window.push_handlers(GameObj.keyboard)
     GameObj.scroller.add(GameObj.map_layer, z=0)
     GameObj.scroller.add(SpriteLayer(), z=1)
     bg_color = ColorLayer(155, 155, 255, 1000)
     self.add(GameObj.scroller, z=1)
     self.add(bg_color)
Example #34
0
    def __init__(self):
        self.title = ""
        self.description = ""
        self.buttons = []

        self.shadow = ColorLayer(0, 0, 0, 100)
        self.view = PopupView(self)

        self.parent_ctrl = None
Example #35
0
 def __init__(self):
     super(ShowCollision, self).__init__()
     self.collision_view = []
     for i in range(10):
         self.collision_view.append(
             ColorLayer(255, 0, 0, 255, width=64, height=64))
     for e in self.collision_view:
         self.add(e)
     signal = blinker.signal("collider cells")
     signal.connect(self.on_collision_changed)
Example #36
0
def main():
    # initialize the director
    director.init(800, 600, resizable=True)
    # create the scene switch layer
    switch_layer = SwitchScene()

    # define the scene switch layer

    red = ColorLayer(255, 0, 0, 255)
    green = ColorLayer(0, 255, 0, 255)
    blue = ColorLayer(0, 0, 255, 255)

    # Goal: adding class name and docstring
    # 1 using on_enter:
    # get parent().__name__
    # get parent().__doc__

    # place all scenes in a scene list
    scenes = [
        Scene(Title('Cocos2D tutorial'), switch_layer),
        Scene(HelloWorld(), switch_layer),
        Scene(AddActor(), switch_layer),
        Scene(AddAction(), switch_layer),
        Scene(Mouse(), switch_layer),
        Scene(Cat(), switch_layer),
        Scene(Pong(), switch_layer),
        Scene(Flappy(), switch_layer),
        Scene(BirdLayer(), switch_layer),
        Scene(WallLayer(), switch_layer),
        Scene(SwitchLayer(red, green, blue), switch_layer),
        Scene(PythonInterpreterLayer(), switch_layer),
        Scene(ColorLayer(150, 0, 0, 255), switch_layer),
        Scene(OptionsMenu(), switch_layer),
        Scene(ColorLayer(0, 150, 0, 255), switch_layer),
        Scene(ActionMenu(actions), switch_layer),
        Scene(EffectMenu(effects), switch_layer),
    ]

    # give the scene list to the switch layer
    switch_layer.scenes = scenes

    # run the first scene
    cocos.director.director.run(scenes[0])
Example #37
0
class FadeTransition(TransitionScene):
    '''Fade out the outgoing scene and then fade in the incoming scene.'''
    def __init__( self, *args, **kwargs ):
        super(FadeTransition, self ).__init__( *args, **kwargs)

        self.fadelayer = ColorLayer(0,0,0,0)

        self.in_scene.visible = False
        self.add( self.fadelayer, z=2 )


    def on_enter( self ):
        super( FadeTransition, self).on_enter()
        self.fadelayer.do( FadeIn( duration=self.duration/2.0) + \
                           CallFunc( self.hide_out_show_in) + \
                           FadeOut( duration=self.duration /2.0 ) + \
                           CallFunc( self.finish) )
    def on_exit( self ):
        super( FadeTransition, self).on_exit()
        self.remove( self.fadelayer )
Example #38
0
    def on_enter(self):
        super(StartPrize, self).on_enter()

        bgcolor = ColorLayer(255, 255, 255, 255, consts_window['width'],
                             consts_window['height'])
        bgcolor.position = (-320, -320)
        # 背景颜色
        self.add(bgcolor)
        # 标题
        self.add(self.top_label)
        self.add(self.top_notice)
        # 转动的背景图
        self.add(self.sprite, z=3)
        self.add(self.alread_prize_sprite, z=3)
        # 人名图
        self.add(self.prizesprite, z=4)
        # 背景图
        self.add(self.bgsprite, z=1)
        self.add(self.pressbgsprite, z=1)

        self.position = 320, 320
Example #39
0
    def __init__(self):
        self.screen = director.get_window_size()
        super(AgarLayer, self).__init__(255, 255, 255, 255, self.screen[0], self.screen[1])
        #self.position = ((self.screen[0]-self.screen[1])/2,0)
        self.imgs = {
            'cell': resource.image("cell.png"),
            'virus': resource.image("virus.png"),
            'agitated': resource.image("agitated.png")
        }
        self.circles = []
        self.sprite_pool = [CellSprite(self.imgs) for _ in xrange(2500)]
        self.sprites = {}
        self.name_pool = [Label("", font_name='DejaVu Mono', font_size=6, bold=True, color=(255, 255, 255, 255), anchor_x='center', anchor_y='center') for _ in xrange(500)]
        self.names = {}
        self.score = 0
        # self.leaders = []
        self.win_size = Vec(self.screen[0], self.screen[1])
        self.screen_center = self.win_size / 2
        self.screen_scale = 1
        self.world_center = Vec(0, 0)
        self.mouse_pos = Vec(0, 0)
        self.movement_delta = Vec()
        # self.names_batch = BatchNode()
        # self.add(self.names_batch)
        self.leaders_batch = BatchNode()
        diff = int(self.screen[1]*.01)
        text.Label("Leaderboard", font_size=24, font_name='DejaVu Mono Bold', x=self.screen[0]-160, y=self.screen[1]-30, bold=True, color=(255, 255, 255, 255),
               anchor_x='center', anchor_y='top', width=150, batch=self.leaders_batch.batch)
        self.leaders = [text.Label("%d. An unnamed cell" % (i+1), font_size=14, font_name='DejaVu Mono', x=self.screen[0]-160, y=self.screen[1]-40-30-i*22, color=(255, 255, 255, 255),
               anchor_x='center', anchor_y='top', width=150, batch=self.leaders_batch.batch) for i in xrange(10)]
        self.add(self.leaders_batch, z=100)

        self.sprite_batch = BatchNode()
        self.add(self.sprite_batch)
        self.scoreSprite = None
        self.proto = None
        leaderBG = ColorLayer(0,0,0,64,280,280)
        leaderBG.position = (self.screen[0]-300,self.screen[1]-300)
        self.add(leaderBG,z=50)
        super( SpriteLayer, self ).__init__()

        sprite1 = Sprite( 'grossini.png' )
        sprite2 = Sprite( 'grossinis_sister1.png')
        sprite3 = Sprite( 'grossinis_sister2.png')

        sprite1.position = (400,240)
        sprite2.position = (300,240)
        sprite3.position = (500,240)

        self.add( sprite1 )
        self.add( sprite2 )
        self.add( sprite3 )

if __name__ == "__main__":
    print 'you shall see an scaled red background and fliping sprites. the background always must be seen (scaled)'
    director.init( resizable=True )
    main_scene = Scene()

    red = ColorLayer(255,0,0,128)

    sprite = SpriteLayer()

    red.scale = 0.75

    main_scene.add( red, z=0 )
    main_scene.add( sprite, z=1 )

    sprite.do( Waves3D(duration=4) + Flip(duration=4) )
    director.run (main_scene)