コード例 #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)
コード例 #2
0
 def pilot(self):
     # Instructions
     line_1 = GLabel('Welcome to my Breakout Game!')
     line_1.font = 'Courier-12-bold'
     line_2 = GLabel('Your mission is to get the highest score.')
     line_2.font = 'Courier-12-bold'
     line_3 = GLabel('No matter how you get it >.^')
     line_3.font = 'Courier-12-bold'
     self.window.add(line_1,
                     x=(self.window.width - line_1.width) / 2,
                     y=self.window.height - 40)
     self.window.add(line_2,
                     x=(self.window.width - line_2.width) / 2,
                     y=self.window.height - 20)
     self.window.add(line_3,
                     x=(self.window.width - line_3.width) / 2,
                     y=self.window.height)
     # Animation
     while True:
         # Update
         line_1.move(0, -5)
         line_2.move(0, -5)
         line_3.move(0, -5)
         # Check
         if line_1.y <= self.window.height / 2:
             break
         # Pause
         pause(100)
     pause(1000)
     self.window.remove(line_1)
     self.window.remove(line_2)
     self.window.remove(line_3)
     pause(1000)
コード例 #3
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)
コード例 #4
0
ファイル: my_drawing.py プロジェクト: shihjames/sc-projects
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)
コード例 #5
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'
コード例 #6
0
ファイル: breakoutgraphics.py プロジェクト: egsui/sc-projects
 def game_over(self):
     g_over = GLabel('GAME OVER!')
     g_over.font = 'Courier-25'
     g_over = GLabel('GAME OVER!',
                     self.__window.width / 2 - g_over.width / 2,
                     self.__window.height / 2)
     g_over.font = 'Courier-25'
     self.__window.add(g_over)
コード例 #7
0
ファイル: breakout.py プロジェクト: 105071076/pw-projects
def main():

    global graphics, life_cnt
    graphics.window.add(graphics.score, 250, graphics.score.height + 3)
    graphics.window.add(graphics.life, 0, graphics.life.height + 3)
    graphics.window.add(graphics.life1, graphics.life.width + 3, 3)
    graphics.window.add(graphics.life2, graphics.life.width + 6 + graphics.life1.width, 3)
    graphics.window.add(graphics.life3, graphics.life.width + 9 + graphics.life1.width * 2, 3)

    # Add animation loop here!

    while True:

        pause(FRAME_RATE)
        dx = graphics.get_dx()
        dy = graphics.get_dy()

        graphics.ball.move(dx, dy)
        # Check wall
        graphics.check_wall()

        # Check four points
        graphics.check_pts()

        # Life cnt
        if graphics.ball.y > graphics.window.height:
            life_cnt -= 1
            graphics.life.text = 'LIVES:'
            graphics.lives = life_cnt
            if life_cnt == 2:
                graphics.window.remove(graphics.life1)
            elif life_cnt == 1:
                graphics.window.remove(graphics.life2)
            elif life_cnt == 0:
                graphics.window.remove(graphics.life3)
            graphics.window.remove(graphics.ball)
            graphics.window.add(graphics.ball, x=(graphics.window.width - graphics.ball.width) / 2,
                                y=(graphics.window.height - graphics.ball.height) / 2)
            dx = 0
            dy = 0
            graphics.set2_dx(dx)
            graphics.set2_dy(dy)

        if life_cnt == 0:
            graphics.window.remove(graphics.ball)
            oh_no = GLabel("NO MORE LIVES! :'( ")
            oh_no.font = 'Helvetica-25-italic'
            graphics.window.add(oh_no, x=(graphics.window.width - oh_no.width) / 2,
                                y=(graphics.window.height - oh_no.height) / 2)
            break

        elif graphics.score_cnt == graphics.brick_rows * graphics.brick_cols:
            graphics.window.remove(graphics.ball)
            oh_no = GLabel("YOU WIN! :D ")
            oh_no.font = 'Helvetica-25-italic'
            graphics.window.add(oh_no, x=(graphics.window.width - oh_no.width) / 2,
                                y=(graphics.window.height - oh_no.height) / 2)
            break
コード例 #8
0
ファイル: breakoutgraphics.py プロジェクト: egsui/sc-projects
 def win_game(self):
     if self.__left_bricks <= 0:
         you_win = GLabel('YOU WIN!')
         you_win.font = 'Courier-25'
         you_win = GLabel('YOU WIN!',
                          self.__window.width / 2 - you_win.width / 2,
                          self.__window.height / 2)
         you_win.font = 'Courier-25'
         self.__window.add(you_win)
         return True
コード例 #9
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)
コード例 #10
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)
コード例 #11
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)
コード例 #12
0
def main_game(e):
    # run this when user click
    global COUNT, life_ui, score_ui, vx, vy, score_count, life_left, ball
    # create life count ui
    if is_at_original_point():
        # check if the game started
        if life_left > 0 and score_count < WIN_SCORE:
            while ball.y < w.height:
                # game loop: keep the game going if ball doesn't fall out of the border
                if score_count < WIN_SCORE/2:
                    ball.move(vx, vy)
                    pause(FRAME_RATE)
                    check_if_ball_hit_sth()
                else:
                    boss_fight()
                    break
                w.remove(score_ui)
                score_ui = update_score()
            life_left -= 1
            w.remove(ball)
            if score_count >= WIN_SCORE:
                over = GLabel("YOU WON")
                over.font = "-60"
                w.add(over, w.width / 2 - over.width / 2, w.height / 2)
            elif life_left <= 0:
                game_over()
            else:
                ball = graphics.ball()
                w.remove(life_ui)
                life_ui = update_life()
    else:
        pass
コード例 #13
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)
コード例 #14
0
def make_title():
    """
    this code can make a title on the window
    """
    title = GLabel('Similarity.py')
    title.font = '-70'
    window.add(title, 50, 150)
コード例 #15
0
ファイル: my_drawing.py プロジェクト: hsiaohan416/stancode
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)
コード例 #16
0
ファイル: breakout.py プロジェクト: juneyochen/sc-projects
def main():
    """
    set up the score label and how many life dose the user have.
    """
    graphics = BreakoutGraphics()
    life = NUM_LIVES
    score_label = GLabel('Score: ' + str(graphics.score) + ' and live: ' + str(life))
    score_label.font = '-20'
    graphics.window.add(score_label, 0, graphics.window.height)
    switch = 1  # a switch that prevents user to click while the ball is moving

    # Add animation loop here!
    while switch == 1 and life >= 0:
        # renew the score and life every time
        score_label.text = 'Score: ' + str(graphics.score) + ' and life: ' + str(life)
        # let the ball moves
        graphics.ball.move(graphics.get_vx(), graphics.get_vy())
        # check whether ball touches objects or not
        graphics.object_check()
        # when touching the bricks, the bricks should be eliminated
        graphics.eliminate_brick()
        # when touching the edge of the window, the ball should reflect
        graphics.edge_check()
        # when the ball touches to the bottom of the window, switch = -1 and the life should minus one
        switch = graphics.check_dead()
        if switch == -1:
            life -= 1
            switch = 1
            graphics.ball.x = (graphics.window.width - graphics.ball.width) / 2
            graphics.ball.y = (graphics.window.height - graphics.ball.height) / 2
            graphics.ball_restart()
        # if all the bricks are eliminated, the game should be ended
        if graphics.score == graphics.max_score:
            break
        pause(FRAME_RATE)  # prevent the ball move too fast
コード例 #17
0
ファイル: breakout.py プロジェクト: tzuling/sc101-project
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)
コード例 #18
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)
コード例 #19
0
 def game_over(self):
     """
     One of the conditions for game over. When all chances were used out.
     """
     self.reset_ball()
     lose = GLabel('You lose!')
     lose.font = '-70-bold'
     self.window.add(lose, (self.window.width - lose.width) / 2, 500)
コード例 #20
0
 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)
コード例 #21
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()
コード例 #22
0
ファイル: breakoutgraphics.py プロジェクト: fredi5566/SC101
 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)
コード例 #23
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
コード例 #24
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
コード例 #25
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
コード例 #26
0
 def set_end_massage(self, massage):
     """
     This method can show massage on center of graphic at the end of game.
     :param massage: str, massage want to show.
     """
     massage_label = GLabel(massage)
     massage_label.font = '-40'
     self.window.add(massage_label, x=(self.window.width - massage_label.width) / 2,
                     y=(self.window.height - massage_label.height) / 2)
コード例 #27
0
def textbox(dx=0, dy=0):
    """
    Function: draw text
    Principle: use label
    :param dx: x-axis displacement
    :param dy: y-axis displacement
    """
    txt = GLabel('保夾500元', x=dx + 130, y=dy + 160)
    txt.font = 'Arial-55'
    window.add(txt)
コード例 #28
0
 def remove_all(self, score):
     self.window.remove(self.ball)
     self.window.remove(self.paddle)
     self.window.remove(self.sscore)
     self.window.remove(self.live)
     self.window.remove(self.disturb)
     if score == 300:
         win = GLabel('YOU WIN!!  . .    YA!!!!!!!!!\n                  U',
                      x=50,
                      y=350)
         win.font = '-20'
         self.window.add(win)
     else:
         sscore = GLabel('YOUR SCORE IS:' + str(score) +
                         '\n HA HA HA YOU LOSE!!!',
                         x=50,
                         y=350)
         sscore.font = '-20'
         self.window.add(sscore)
コード例 #29
0
 def win(self):
     """
     This method shows an image and label if the user wins the game by clearing
     all the bricks
     """
     if self.score == 100:
         win = GLabel('WIN!!')
         win.font = 'Times-50'
         self.window.add(win, 50, 235)
         self.window.add(self.img, 10, 25)
         self.window.remove(self.ball)
コード例 #30
0
ファイル: my_drawing.py プロジェクト: shihjames/sc-projects
def speech_bub():
    # Show what Karel says.
    bub1 = GOval(10, 10, x=300, y=340)
    bub2 = GOval(15, 15, x=320, y=330)
    bub3 = GOval(150, 40, x=345, y=303)
    bub1.filled = True
    bub2.filled = True
    bub3.filled = True
    bub1.fill_color = 'white'
    bub2.fill_color = 'white'
    bub3.fill_color = 'white'
    word1 = GLabel('I love stanCode!', x=365, y=325)
    word2 = GLabel('I love Jerry !', x=375, y=338)
    word1.font = 'Courier-8-bold'
    word2.font = 'Courier-8-bold'
    window.add(bub1)
    window.add(bub2)
    window.add(bub3)
    window.add(word1)
    window.add(word2)