Пример #1
0
    def __init__(self, limits, game_time, player_num):
        super().__init__("Scoreboard Manager", player=player_num)
        self._game_time = game_time

        text_style = {"fillcolour": None, "outlinecolour": None,
                      "align_horiz": "L", "width": 200, "height": 35}

        tb_score = cdkk.Sprite_TextBox("Score", style=text_style)
        tb_score.set_text_format("Score: {0}", 0)
        tb_score.rect.topleft = (limits.left+10, limits.top+5)
        self.add(tb_score)
        self.score = 0

        self._timer = cdkk.Timer(
            self._game_time, cdkk.EVENT_GAME_TIMER_1, auto_start=self.game_is_active)
        tb_time_left = cdkk.Sprite_TextBox("Time Left", style=text_style)
        tb_time_left.set_text_format("Time Left: {0:0.1f}", 0)
        tb_time_left.rect.midtop = (
            limits.left + limits.width*0.5, limits.top+5)
        self.add(tb_time_left)

        tb_balls_left = cdkk.Sprite_TextBox("Balls Left", style=text_style)
        tb_balls_left.set_text_format("Balls Left: {0}", 0)
        tb_balls_left.rect.topright = (limits.right-10, limits.top+5)
        self.add(tb_balls_left)
        self.balls_left = 0

        self._game_over = cdkk.Sprite_GameOver(limits)
        self._game_over.rect.center = (
            limits.left + limits.width*0.5, limits.top + limits.height*0.5)
Пример #2
0
    def __init__(self, limits, game_time):
        super().__init__("Scoreboard Manager")
        self._game_time = game_time

        text_style = {
            "fillcolour": None,
            "outlinecolour": None,
            "align_horiz": "L",
            "width": 200,
            "height": 35
        }

        tb_score = cdkk.Sprite_TextBox("Score", style=text_style)
        tb_score.set_text_format("Score: {0}", 0)
        tb_score.rect.midleft = (limits.width * 0.1, limits.height * 0.05)
        self.add(tb_score)
        self.score = 0

        self._timer = cdkk.Timer(self._game_time, cdkk.EVENT_GAME_TIMER_1)
        tb_time_left = cdkk.Sprite_TextBox("Time Left", style=text_style)
        tb_time_left.set_text_format("Time Left: {0:0.1f}", 0)
        tb_time_left.rect.center = (limits.width * 0.45, limits.height * 0.05)
        self.add(tb_time_left)

        tb_balls_left = cdkk.Sprite_TextBox("Balls Left", style=text_style)
        tb_balls_left.set_text_format("Balls Left: {0}", 0)
        tb_balls_left.rect.midright = (limits.width * 0.85,
                                       limits.height * 0.05)
        self.add(tb_balls_left)
        self.balls_left = 0

        self._game_over = cdkk.Sprite_GameOver(limits)
        self._game_over.rect.center = (limits.width * 0.5, limits.height * 0.5)
Пример #3
0
    def __init__(self, limits, name="Test PyGame App Manager"):
        super().__init__(name)

        image_sprite = cdkk.Sprite()
        image_sprite.load_image_from_file("beachball.png")
        image_sprite.rect.topleft = (10, 10)
        self.add(image_sprite)

        anim_sprite = cdkk.Sprite_Animation()
        anim_sprite.load_spritesheet("Explode",
                                     "ExplosionCount.png",
                                     4,
                                     4,
                                     set_anim=True)
        anim_sprite.rect.topleft = (200, 10)
        self.add(anim_sprite)

        rect_sprite = cdkk.Sprite_Shape("Shape:Rectangle",
                                        cdkk.cdkkRect(300, 10, 60, 30),
                                        {"fillcolour": "blue"})
        self.add(rect_sprite)

        ellipse_sprite = cdkk.Sprite_Shape("Shape:Ellipse",
                                           cdkk.cdkkRect(400, 10, 60, 50), {
                                               "fillcolour": "green3",
                                               "outlinecolour": "red4",
                                               "shape": "Ellipse"
                                           })
        self.add(ellipse_sprite)

        polygon_sprite = cdkk.Sprite_Shape("Shape:Polygon",
                                           cdkk.cdkkRect(500, 10, 101, 101), {
                                               "fillcolour": None,
                                               "shape": "Polygon"
                                           })
        polygon_sprite.setup_polygon([(0, 50), (50, 0), (100, 50), (50, 100)])
        self.add(polygon_sprite)

        image_from_ss = cdkk.Sprite()
        image_from_ss._image.set_spritesheet("ExplosionCount.png", 4, 4)
        image_from_ss._image.spritesheet_image(6)
        image_from_ss._image_size_to_rect()
        image_from_ss.rect.topleft = (650, 10)
        self.add(image_from_ss)

        tb_default = cdkk.Sprite_TextBox("TextBox: Default",
                                         cdkk.cdkkRect(10, 150, 300, 60))
        self.add(tb_default)

        tb_style = {
            "textcolour": "blue",
            "fillcolour": None,
            "outlinecolour": "blue"
        }
        tb_style1 = cdkk.Sprite_TextBox("Blue/None/Blue",
                                        cdkk.cdkkRect(320, 150, 300, 60),
                                        style=tb_style)
        self.add(tb_style1)

        tb_style["fillcolour"] = "yellow1"
        tb_style["textsize"] = 20
        tb_style["shape"] = "Ellipse"
        tb_style2 = cdkk.Sprite_TextBox("Blue/Yellow/Blue, O, 20",
                                        cdkk.cdkkRect(640, 150, 300, 60),
                                        style=tb_style)
        self.add(tb_style2)

        tb_topleft = cdkk.Sprite_TextBox("TextBox: Top Left",
                                         cdkk.cdkkRect(10, 220, 300, 60),
                                         style={
                                             "align_horiz": "L",
                                             "align_vert": "T"
                                         })
        self.add(tb_topleft)

        tb_bottomright = cdkk.Sprite_TextBox("TextBox: Bottom Right",
                                             cdkk.cdkkRect(320, 220, 300, 60),
                                             style={
                                                 "align_horiz": "R",
                                                 "align_vert": "B"
                                             })
        self.add(tb_bottomright)

        tb_click_me = cdkk.Sprite_TextBox("Click Me",
                                          cdkk.cdkkRect(640, 220, 300, 60))
        ev_Clicked = cdkk.EventManager.gc_event("Clicked")
        ev_Unclicked = cdkk.EventManager.gc_event("Unclicked")
        tb_click_me.setup_mouse_events(ev_Clicked, ev_Unclicked)
        self.add(tb_click_me)

        self.game_over = cdkk.Sprite_GameOver(cdkk.cdkkRect(320, 300, 300, 60))
        ev_Clicked = cdkk.EventManager.gc_event("ToggleGameOver")
        self._click_game_over = cdkk.Sprite_Button(
            "End Game", cdkk.cdkkRect(10, 300, 300, 60), ev_Clicked)
        self.add(self._click_game_over)
        self.start_game()

        self._fps = cdkk.Sprite_DynamicText("FPS",
                                            cdkk.cdkkRect(640, 300, 120, 40),
                                            style={
                                                "fillcolour": None,
                                                "align_horiz": "L",
                                                "textformat": "FPS: {0:4.1f}"
                                            })
        self.add(self._fps)
        self._fps_units = cdkk.Sprite_Label("frames/sec",
                                            cdkk.cdkkRect(770, 300, 150, 40))
        self._fps_units.rect.centery = 320
        self.add(self._fps_units)

        tb_auto_size = cdkk.Sprite_TextBox("AutoSize",
                                           cdkk.cdkkRect(10, 400, 0, 0),
                                           auto_size=True)
        ev_Auto_Clicked = cdkk.EventManager.gc_event("AutoSize")
        tb_auto_size.setup_mouse_events(ev_Auto_Clicked, None)
        self.add(tb_auto_size)