Example #1
0
def opening():
    black_cover = GRect(w.width, w.height, x=0, y=0)
    black_cover.filled = True
    black_cover.fill_color = "black"
    w.add(black_cover)
    far = GLabel("A long time ago in a galaxy far, \nfar away...")
    far.color = "blue"
    far.font = "-20"
    w.add(far, x=w.width / 2 - far.width / 2 + 60, y=w.height / 2)
    pause(1200)
    w.remove(far)
    main_title = GLabel("STAR\nWARS")
    main_title.color = "yellow"
    for i in range(20):
        size = (160 // (int(i) + 1))
        size = -size
        main_title.font = str(size)
        w.add(main_title, x=w.width / 2 - main_title.width / 4, y=w.height / 2)
        pause(FRAME_RATE * 6)
        w.remove(main_title)
    opening_crawl = GLabel("It   is   a   period  of   civil   war\n"
                           "Princess Leia races home abroad\n"
                           "her   spaceship   but   was   later\n"
                           "captured   by   Empires's  agents\n"
                           "Use  your  lightsaber  to destroy\n"
                           "the   force   field   to   save  the\n"
                           "princess")
    opening_crawl.color = "yellow"
    opening_crawl.font = "-15"
    w.add(opening_crawl, x=w.width / 2 - 130, y=w.height + 1)
    for i in range(50):
        opening_crawl.move(0, -10)
        pause(FRAME_RATE * 6)
    w.remove(black_cover)
    w.remove(opening_crawl)
Example #2
0
def main():
    graphics = BreakoutGraphics()

    dx = graphics.get_x_speed()
    dy = graphics.get_y_speed()

    lives = NUM_LIVES

    # Add animation loop here!
    while True:
        pause(FRAME_RATE)

        if graphics.start and lives > 0 and graphics.count > 0:
            graphics.ball.move(dx, dy)

            if graphics.ball.y >= graphics.window.height:
                lives -= 1
                graphics.reset_ball()
            else:
                # ball touches paddle or bricks
                if graphics.get_obj():
                    if graphics.ball.y < graphics.window.height / 2:  # bricks
                        dy = -dy
                    else:  # paddle
                        if dy > 0:  # ensure won’t stick on the paddle
                            dy = -dy
                # ball touches the window
                if graphics.ball.x <= 0 or graphics.ball.x + graphics.ball.width >= graphics.window.width:
                    dx = -dx
                if graphics.ball.y <= 0:
                    dy = -dy

            # update ball velocity
            if graphics.score > 0 and graphics.score % 200 == 0:
                dy += 0.1
                graphics.update_dy(dy)

        elif lives <= 0:
            # game over
            label = GLabel('Game Over', x=0, y=graphics.window.height / 2)
            label.font = '-48-bold'
            label.color = 'red'
            graphics.window.add(label)
            graphics.window.remove(graphics.ball)
            break

        elif graphics.count <= 0:
            # you win
            label = GLabel('You Win!!!', x=0, y=graphics.window.height / 2)
            label.font = '-48-bold'
            label.color = 'forestgreen'
            graphics.window.add(label)
            graphics.window.remove(graphics.ball)
            break

    # label animation
    label_dx = 1
    while label.x <= graphics.window.width / 2 - 120:
        label.move(label_dx, 0)
        pause(10)
Example #3
0
def create_beeper(e):
    # create 4 beepers
    size = 50
    for i in (1, 3, 7, 9):
        beeper = GOval(size, size, x=i * 50 - size / 2, y=400 - size / 2)
        beeper.filled = True
        beeper.fill_color = 'blue'
        window.add(beeper)
    label1 = GLabel('001', x=50 - size / 2 + 9, y=400 - size / 2 + 37)
    label2 = GLabel('101', x=150 - size / 2 + 9, y=400 - size / 2 + 37)
    label3 = GLabel('201', x=350 - size / 2 + 9, y=400 - size / 2 + 37)
    label4 = GLabel('202', x=450 - size / 2 + 9, y=400 - size / 2 + 37)
    label1.font = '-15'
    label2.font = '-15'
    label3.font = '-15'
    label4.font = '-15'
    label1.color = 'white'
    label2.color = 'white'
    label3.color = 'white'
    label4.color = 'white'
    window.add(label1)
    window.add(label2)
    window.add(label3)
    window.add(label4)
    onmouseclicked(build_karel)
Example #4
0
    def __build_txt(self, dx=0, dy=0):
        font = 'Times New Roman'

        # 開始 start_game
        start_game = GLabel('Start',
                            x=200 + self.__boundary_x + dx,
                            y=400 + self.__boundary_y + dy)
        start_game.font = f'{font}-50'
        start_game.color = "dimgray"
        self.window.add(start_game)
        self.obj_txt['start'] = start_game

        # 大標體 tital
        tital = GLabel('Breakout clone',
                       x=200 + self.__boundary_x + dx,
                       y=200 + self.__boundary_y + dy)
        tital.font = f'{font}-100'
        tital.color = "darkgray"
        self.window.add(tital)
        self.obj_txt['tital'] = tital

        # 中標題 subtitle
        subtitle = GLabel('Maker : Tsai NoNo',
                          x=200 + self.__boundary_x + dx,
                          y=300 + self.__boundary_y + dy)
        subtitle.font = f'{font}-50'
        subtitle.color = "gray"
        self.window.add(subtitle)
        self.obj_txt['subtitle'] = subtitle

        return 'self.obj_txt is ok'
Example #5
0
def words_label():
    """
    This function will write the label of Bonjour Paris.
    """
    # paris label
    label2 = GLabel('PARIS', x=90, y=450)
    label2.font = '-80'
    label2.color = 'white'
    window.add(label2)
    # Bonjour label
    label3 = GLabel('BONJOUR', x=40, y=340)
    label3.font = '-70'
    label3.color = 'white'
    window.add(label3)
Example #6
0
def main():
    bg = GRect(950, 600)
    window.add(bg)
    bg.color = 'lightblue'
    bg.fill_color = 'lightblue'
    ryan()
    tube()
    peach()
    title = GLabel('KAKAO FRIENDS')
    title.color = 'cornflowerblue'
    title.font = 'Verdana-50-bold'
    window.add(title, x=255, y=500)
    title2 = GLabel('KAKAO FRIENDS')
    title2.color = 'ivory'
    title2.font = 'Verdana-50-bold'
    window.add(title2, x=251, y=500)
Example #7
0
 def game_over(self):
     game_over = GLabel('Game Over')
     game_over.color = 'tomato'
     game_over.font = 'Courier-30-bold'
     self.window.add(game_over,
                     x=(self.window.width - game_over.width) / 2,
                     y=self.window.height / 2)
Example #8
0
 def congrats(self):
     label_win = GLabel('Congratulations!')
     label_win.color = 'navy'
     label_win.font = 'Courier-30-bold'
     self.window.add(label_win,
                     x=(self.window.width - label_win.width) / 2,
                     y=self.window.height / 2)
Example #9
0
def main():
    graphics = BreakoutGraphics()

    dx = graphics.get_x_speed()
    dy = graphics.get_y_speed()

    lives = NUM_LIVES

    # Add animation loop here!
    while True:
        pause(FRAME_RATE)
        if graphics.start and lives > 0 and graphics.count > 0:
            graphics.ball.move(dx, dy)

            if graphics.ball.y + graphics.ball.height >= graphics.window.height:
                lives -= 1
                graphics.reset_ball()
            else:
                if graphics.get_obj():
                    dy = -dy
                if graphics.ball.x <= 0 or graphics.ball.x + graphics.ball.width >= graphics.window.width:
                    dx = -dx
                if graphics.ball.y <= 0:
                    dy = -dy

        elif lives <= 0:
            # game over
            label = GLabel('Game Over', x=0, y=graphics.window.height / 2)
            label.font = '-48-bold'
            label.color = 'red'
            graphics.window.add(label)
            graphics.window.remove(graphics.ball)
            break
        elif graphics.count <= 0:
            # you win
            label = GLabel('You Win!!!', x=0, y=graphics.window.height / 2)
            label.font = '-48-bold'
            label.color = 'forestgreen'
            graphics.window.add(label)
            graphics.window.remove(graphics.ball)
            break

    # move the label
    dx = 1
    while label.x <= graphics.window.width / 2 - 120:
        label.move(dx, 0)
        pause(10)
 def gameover(self):
     over = GLabel('Game Over!')
     over.font = '-50'
     over.color = 'red'
     self.window.add(over,
                     x=(self.window.width - over.width) / 2,
                     y=self.window.height / 2)
     self.window.remove(self.ball)
Example #11
0
 def game_over(self):
     """
     When lives are used over, the game is over!
     """
     game_over = GLabel('Game over :(')
     game_over.font = '-40-bold'
     game_over.color = 'gray'
     self.window.add(game_over, (self.window.width/2)-(game_over.width/2), self.window.height/2)
Example #12
0
def main():
    # background
    background_color = ['ivory', 'lightblue', 'skyblue']

    for i in range(0, 3):
        background = GRect(window.width,
                           window.height / 3,
                           x=0,
                           y=window.height / 3 * i)
        background.filled = True
        background.fill_color = '' + background_color[i]
        background.color = '' + background_color[i]
        window.add(background)

    # pyramid
    pyramid_color = [
        'saddlebrown', 'darkgoldenrod', 'goldenrod', 'orange', 'gold',
        'palegoldenrod', 'lemonchiffon'
    ]

    for i in range(0, 7):
        # pyramid Grect
        pyramid = GRect(FIRST_X - REDUCE * i,
                        FIRST_Y,
                        x=5 + REDUCE / 2 * i,
                        y=window.height - FIRST_Y * (1 + i))
        pyramid.filled = True
        pyramid.fill_color = '' + pyramid_color[i]
        window.add(pyramid)

        # pyramid GLabel
        # pyramid_label = GLabel('STAGE '+str(i+1), x=260, y=window.height - FIRST_Y * i -10)
        # pyramid_label.font = '-24'
        # pyramid_label.color = 'darkgrey'
        # window.add(pyramid_label)

    # flag
    flagstaff = GRect(5, 100, x=280, y=50)
    flagstaff.filled = True
    flagstaff.fill_color = 'brown'
    window.add(flagstaff)

    flag = GRect(100, 40, x=285, y=50)
    flag.filled = True
    flag.fill_color = 'silver'
    window.add(flag)

    flag_label = GLabel('GOAL!!!', x=290, y=85)
    flag_label.font = '-26'
    flag_label.color = 'red'
    window.add(flag_label)

    # sun
    sun()

    # robot
    robot_face()
    robot_body()
Example #13
0
def build_start_sign():
    """
    This function creates a start sign with GLabel
    :return: object, sign
    """
    sign = GLabel('Click Anywhere !!!', x=START_X + 40, y=START_Y + 10)
    sign.color = 'dimgrey'
    sign.font = 'Times New Roman-15-italic-bold'
    return sign
Example #14
0
def label_gameover():
    """
    show "Game over!" as game ends
    :return: gobject, show player the game is over
    """
    label = GLabel('Game over!')
    label.font = '-50'
    label.color = 'skyblue'
    return label
Example #15
0
def label_win_the_game():
    """
    Show "You Win!" as user wins the game
    :return: gobject
    """
    label = GLabel('You Win!')
    label.font = '-50'
    label.color = 'skyblue'
    return label
Example #16
0
def build_special_stop_sign():
    """
    This function creates a special stop sign with GLabel
    :return: object, sign
    """
    random_x = random.randint(0, 600)
    random_y = random.randint(30, 500)
    sign = GLabel(random_word(), x=random_x, y=random_y)
    sign.color = random_color()
    sign.font = 'Times New Roman-20-bold'
    return sign
Example #17
0
def build_stop_sign():
    """
    This function creates a stop sign with GLabel
    :return: object, sign
    """
    random_x = random.randint(0, 640)
    random_y = random.randint(30, 500)
    sign = GLabel('Stop Clicking !!! ', x=random_x, y=random_y)
    sign.color = 'firebrick'
    sign.font = 'Times New Roman-15-bold'
    return sign
Example #18
0
    def start_page(self):
        """
        This method draw the start page and restart page.
        """
        if self._page == 0:
            check = self._window.get_object_at(self._window.width // 2,
                                               self._window.height // 2)
            if check is None:
                progress_rate_board = GLabel(f'Loading...0%')
                progress_rate_board.font = 'Chalkduster-15'
                self._window.add(
                    progress_rate_board,
                    (self._window.width - progress_rate_board.width) // 2,
                    (self._window.height + PROGRESS_BAR_SIZE) // 2 +
                    progress_rate_board.height + LABEL_SPACING)
                pause_time = 300
                for i in range(10):
                    color = COLOR_LIST[i % len(COLOR_LIST)]
                    progress_bar = GRect(PROGRESS_BAR_SIZE * (i + 1),
                                         PROGRESS_BAR_SIZE)
                    progress_bar.filled = True
                    progress_bar.fill_color = color
                    progress_bar.color = color
                    self._window.add(
                        progress_bar,
                        self._window.width // 2 - PROGRESS_BAR_SIZE * 5,
                        self._window.height // 2 - PROGRESS_BAR_SIZE // 2)
                    progress_rate_board.text = f'Loading...{10*(i+1)}'
                    pause(pause_time)
                    pause_time += 100

            self._window.clear()
            self.draw_bricks()
            self._start_label.text = f'Click to start'
            self._window.add(
                self._start_label,
                (self._window.width - self._start_label.width) // 2,
                (self._window.height + self._start_label.height) // 2)
        elif self._page == 2:
            self._window.clear()
            # self.draw_bricks()
            self._start_label.text = f'Click to restart'
            self._window.add(
                self._start_label,
                (self._window.width - self._start_label.width) // 2,
                (self._window.height + self._start_label.height) // 2)
            highscore_board = GLabel(f'High score: {self._highscore}')
            highscore_board.font = 'Chalkduster-60'
            highscore_board.color = 'navy'
            self._window.add(
                highscore_board,
                (self._window.width - highscore_board.width) // 2,
                self._start_label.y - self._start_label.height -
                LABEL_SPACING * 3)
Example #19
0
 def fail_game2(self):
     fail_frame = GRect(450, 80)
     fail_frame.filled = True
     fail_frame.fill_color = 'white'
     fail_frame.color = 'white'
     self.window.add(fail_frame, (self.window.width - fail_frame.width) / 2,
                     (self.window.height - fail_frame.height) / 2)
     failed = GLabel('Game Over')
     failed.font = '-60-bold'
     failed.color = 'black'
     self.window.add(failed, fail_frame.x + 70, fail_frame.y + 75)
Example #20
0
def add_words(window):
    """This function add words to the window"""

    # plot the word1
    word1 = GLabel('LOVE', x=WINDOW_WIDTH * 0.3, y=WINDOW_HEIGHT * 0.45)
    word1.color = 'black'
    word1.font = 'Courier-100-bold'
    window.add(word1)

    # plot the word2
    word2 = GLabel('IS', x=WINDOW_WIDTH * 0.45, y=WINDOW_HEIGHT * 0.5)
    word2.color = 'black'
    word2.font = 'Courier-50-bold'
    window.add(word2)

    # plot the word3
    word3 = GLabel('LOVE', x=WINDOW_WIDTH * 0.3, y=WINDOW_HEIGHT * 0.65)
    word3.color = 'black'
    word3.font = 'Courier-100-bold'
    window.add(word3)
 def win(self):
     self.window.clear()
     win_background = GRect(self.window.width, self.window.height)
     win_background.filled = True
     win_background.color = '#e5abbe'
     win_background.fill_color = '#e5abbe'
     win_label = GLabel('WIN')
     win_label.font = '-50'
     win_label.color = '#fdeff2'
     self.window.add(win_background)
     self.window.add(win_label, self.window.width/2-win_label.width/2, self.window.height/2.5)
     self.window.add(self.score_label, (self.window_width-self.score_label.width)/2, win_label.y+50)
 def lose(self):
     self.window.clear()
     lose_background = GRect(self.window.width, self.window.height)
     lose_background.filled = True
     lose_background.color = '#a6a5c4'
     lose_background.fill_color = '#a6a5c4'
     lose_label = GLabel('GAME OVER')
     lose_label.font = '-50'
     lose_label.color = '#e7e7eb'
     self.window.add(lose_background)
     self.window.add(lose_label, self.window.width/2-lose_label.width/2, self.window.height/2.5)
     self.window.add(self.score_label, (self.window_width-self.score_label.width)/2, lose_label.y+50)
Example #23
0
 def show_damage_number(self, damage):
     """
     This method can show damage number on the graphic
     :param damage: int, damage number
     """
     damage_label = GLabel(f'-{damage}')
     damage_label.color = 'red'
     damage_label.font = f'-{damage}'
     self.window.add(damage_label, x=self.hero.body.x + self.hero.body.width,
                     y=self.hero.body.y + self.hero.body.height)
     pause(80)
     self.window.remove(damage_label)
Example #24
0
 def finish_game(self):
     finish_frame = GRect(450, 80)
     finish_frame.filled = True
     finish_frame.fill_color = 'white'
     finish_frame.color = 'white'
     self.window.add(finish_frame,
                     (self.window.width - finish_frame.width) / 2,
                     (self.window.height - finish_frame.height) / 2)
     finish = GLabel('Congratulation!!! You win!')
     finish.font = '-35-bold'
     finish.color = 'red'
     self.window.add(finish, finish_frame.x + 10, finish_frame.y + 65)
Example #25
0
 def end_game(self):
     """
     One of the conditions for game over. When all bricks were remove.
     :return: Bool
     """
     if self.__count == 0:
         self.window.remove(self.ball)
         congrats = GLabel('Congratulation!')
         congrats.font = '-70-bold'
         congrats.color = 'red'
         self.window.add(congrats, (self.window.width - congrats.width) / 2,
                         500)
         return True
Example #26
0
def word(window):
    """
    :param window:window
    """
    square = GRect(150, 30)
    square.filled = True
    square.fill_color = "Crimson"
    square.color = 'Crimson'
    window.add(square, x=window.width / 2 - square.width / 2, y=375)
    code = GLabel("stanCode")
    code.color = 'snow'
    code.font = "-20"
    window.add(code, x=window.width / 2 - code.width / 2, y=380 + code.height)
    def build_win(self):
        """
        This method builds the 'Winning' scene
        """
        win_sign_1 = GLabel('S A V A G E')
        win_sign_1.font = 'Mamelon-40'
        win_sign_1.color = 'mediumturquoise'
        win_sign_2 = GLabel('S A V A G E')
        win_sign_2.font = 'Mamelon-40'
        win_sign_2.color = 'mediumturquoise'
        win_sign_3 = GLabel('S A V A G E')
        win_sign_3.font = 'Mamelon-40'
        win_sign_3.color = 'mediumturquoise'

        # To create the flashing animation
        for i in range(12):
            if i % 2 != 0:
                self.window.add(win_sign_1,
                                x=(self.window.width - win_sign_1.width) / 2,
                                y=(self.window.height - win_sign_1.height) / 2)
                self.window.add(
                    win_sign_2,
                    x=(self.window.width - win_sign_2.width) / 2,
                    y=(self.window.height - win_sign_2.height) / 2 + 50)
                self.window.add(
                    win_sign_3,
                    x=(self.window.width - win_sign_3.width) / 2,
                    y=(self.window.height - win_sign_3.height) / 2 + 100)
            else:
                self.window.remove(win_sign_1)
                self.window.remove(win_sign_2)
                self.window.remove(win_sign_3)

            pause(100)

        self.fire_work()
Example #28
0
 def the_end(self):
     num = 0
     vx = 1
     vy = 0
     if self.score <= 4:
         gameover = GLabel('Game Over')
         gameover.color = 'goldenrod'
         gameover.font = 'Courier-35-bold'
         self.window.add(gameover, x=80, y=400)
         while True:
             pause(1000 / 120)
             if num == 10:
                 break
             else:
                 gameover.move(vx, vy)
                 if gameover.x + gameover.width >= self.window.width or gameover.x == 0:
                     vx = -vx
                     num += 1
     elif self.score >= 5:
         goodgame = GLabel('Congratulation!')
         goodgame.color = 'red'
         goodgame.font = 'Courier-30-bold'
         self.window.add(goodgame, x=30, y=400)
         while True:
             pause(1000 / 120)
             if num == 100:
                 break
             else:
                 goodgame.move(vx, vy)
                 if 0 <= goodgame.x <= 20:
                     goodgame.color = 'red'
                 elif 20 <= goodgame.x <= 40:
                     goodgame.color = 'orange'
                 elif 40 <= goodgame.x <= 60:
                     goodgame.color = 'yellow'
                 elif 60 <= goodgame.x <= 80:
                     goodgame.color = 'green'
                 elif 80 <= goodgame.x <= 100:
                     goodgame.color = 'blue'
                 elif 100 <= goodgame.x <= 109:
                     goodgame.color = 'purple'
                 if goodgame.x + goodgame.width >= self.window.width or goodgame.x == 0:
                     vx = -vx
                     num += 1
                     print(goodgame.x)
Example #29
0
def main():
    """
    This program can show a picture I draw, after few second,
    it will show the origin version of this picture
    """
    make_rect(49, 40, 1, 39, 'navy')  # l_body
    make_rect(22, 28, 16, 16, 'white')  # l_beard
    make_rect(16, 20, 20, 20, 'peachpuff')  # l_head
    make_polygon(3, [(25, 1), (3, 17), (46, 17)], 'red')  # l_hat
    make_rect(40, 25, 53, 52, 'grey')  # r_body
    make_polygon(3, [(72, 28), (82, 28), (96, 57)], 'black')  # l_hair
    make_rect(20, 27, 52, 28, 'peachpuff')  # r_head
    make_rect(32, 15, 52, 13, 'darkgrey')  # r_hat
    label = GLabel('我全都要', x=window.width * 0.25, y=window.height * 0.9)
    label.color = 'magenta'
    label.font = '-{}'.format(10 * SIZE)
    window.add(label)

    pause(3000)
    show_origin_picture()
Example #30
0
    def add_fb_button(self, fb_button_width=FB_BUTTON_WIDTH, fb_button_height=FB_BUTTON_HEIGHT):
        self.fb_button.color = 'blue'
        self.fb_button.filled = True
        self.fb_button.fill_color = 'blue'
        self.window.add(self.fb_button, (self.window.width - self.fb_button.width) / 2, self.window.height * 0.5)

        self.fb_label.font = '-15'
        self.fb_label.color = 'white'
        self.window.add(self.fb_label, self.fb_button.x + self.fb_button.width * 0.3,
                        self.fb_button.y + self.fb_button.height - (self.fb_button.height - self.fb_label.height) / 2)

        fb_logo = GRect(self.fb_button.height * 0.7, self.fb_button.height * 0.7)
        fb_logo.color = 'white'
        fb_logo.filled = True
        fb_logo.fill_color = 'white'
        self.window.add(fb_logo, self.fb_button.x + self.fb_button.width * 0.1,
                        self.fb_button.y + (self.fb_button.height - fb_logo.height) / 2)

        fb_logo_label = GLabel('f')
        fb_logo_label.color = 'navy'
        fb_logo_label.font = '-25'
        self.window.add(fb_logo_label, fb_logo.x + fb_logo.width * 0.5,
                        fb_logo.y + fb_logo.height + 7)