Ejemplo n.º 1
0
def main():
    # window = GWindow(width = 1000, height = 800, title = 'MyFacew')
    # face = GOval(250, 350, x = 350 , y = 200)
    # face.filled = True
    # face.fill_color = 'lightpink'
    # window.add(face)
    # l_eye = GOval(50, 50, x = 400, y = 250)
    # l_eye.filled = True
    # l_eye.fill_color = 'black'
    # window.add(l_eye)
    # r_eye = GOval(50, 50, x = 500, y = 250)
    # r_eye.filled = True
    # r_eye.fill_color = 'black'
    # window.add(r_eye)
    # mouth = GRect(150, 50, x = 400, y = 400)
    # mouth.filled = True
    # mouth.fill_color = 'red'
    # window.add(mouth)
    # window.draw_oval(50, 50, 500, 200)
    #
    # label = GLabel('Hello World!', 100, 200)
    # label.color = 'magenta'
    # window.add(label, 100, 200)
    window = GWindow()
    # triangle = GPolygon()
    # triangle.add_vertex((100, 200))
    # triangle.add_vertex((200, 200))
    # triangle.add_vertex((150, 100))
    # triangle.filled = True
    # triangle.fill_color = 'blue'
    # window.add(triangle)
    arc = GArc(200, 80, 0, 180, window.width / 2, window.height / 2)
    arc.filled = True
    arc.fill_color = 'red'
    window.add(arc)
Ejemplo n.º 2
0
    def __init__(self,
                 window_width=WINDOW_WIDTH,
                 window_height=WINDOW_HEIGHT,
                 zone_width=ZONE_WIDTH,
                 zone_height=ZONE_HEIGHT,
                 ball_radius=BALL_RADIUS):
        # Create window
        self.window = GWindow(window_width, window_height, title='Zone Game')

        # Create zone
        self.zone = GRect(zone_width,
                          zone_height,
                          x=(window_width - zone_width) / 2,
                          y=(window_height - zone_height) / 2)
        self.zone.color = 'blue'
        self.window.add(self.zone)

        # Create ball and initialize velocity/position
        self.ball = GOval(2 * ball_radius, 2 * ball_radius)
        self.ball.filled = True
        self.ball.fill_color = 'salmon'

        self.dx = 0
        self.dy = 0

        self.reset_ball()

        # Initialize mouse listeners
        onmouseclicked(self.handle_click)
Ejemplo n.º 3
0
    def __init__(self, window_width=WINDOW_WIDTH, window_height=WINDOW_HEIGHT,
                 zone_width=ZONE_WIDTH, zone_height=ZONE_HEIGHT, ball_radius=BALL_RADIUS):
        # Create window
        self.w = GWindow(width=window_width, height=window_height, title='Zone_Game')

        # Create zone
        self.zone = GRect(zone_width, zone_height, x=(self.w.width-zone_width)/2, y=(self.w.height-zone_height)/2)
        self.zone.color = 'blue'
        self.w.add(self.zone)

        # Create ball and initialize velocity/position
        self.ball = GOval(ball_radius*2, ball_radius*2)
        self.ball.filled = True

        self.dx = 0
        self.dy = 0
        self.lives = 3
        self.reset_ball()

        # Lives Word
        self.lives_word = GLabel('Lives: ' + str(self.lives), x=WINDOW_WIDTH * 0.02, y=WINDOW_HEIGHT * 0.1)
        self.lives_word.font = 'Courier-25-bold'
        self.w.add(self.lives_word)

        # Initialize mouse listeners
        onmouseclicked(self.handle_click)
Ejemplo n.º 4
0
    def __init__(self, ball_radius=BALL_RADIUS, paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT, paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS, brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH, brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET, brick_spacing=BRICK_SPACING,
                 title='Breakout', __dy=INITIAL_Y_SPEED):
        # Create a graphical window, with some extra space.
        self.window_width = brick_cols * (brick_width + brick_spacing) - brick_spacing
        self.window_height = brick_offset + 3 * (brick_rows * (brick_height + brick_spacing) - brick_spacing)
        self.window = GWindow(width=self.window_width, height=self.window_height, title=title)

        # Create a paddle.
        self.paddle = GRect(width=paddle_width, height=paddle_height, x=(self.window_width-paddle_width)/2, y=(self.window_height-paddle_offset-paddle_height))
        self.paddle.filled = True
        self.paddle.color = '#513743'
        self.paddle.fill_color = '#513743'
        self.window.add(self.paddle)

        self.life_label = GLabel('● ● ●')
        self.life_label.font = '-15'
        self.life_label.color = '#c53d43'

        self.score_label = GLabel('score: 0')
        self.score_label.font = '-15'
        self.score_label.color = '#455765'

        self.brick_rows = BRICK_ROWS
        self.brick_cols = BRICK_COLS

        # Initialize our mouse listeners.
        onmousemoved(self.reset_paddle_location)

        # Draw bricks.
        self.create_bricks()
Ejemplo n.º 5
0
    def __init__(self, ball_radius=BALL_RADIUS, paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT, paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS, brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH, brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET, brick_spacing=BRICK_SPACING,
                 title='Breakout'):
        # Create a graphical window, with some extra space.
        window_width = brick_cols * (brick_width + brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows * (brick_height + brick_spacing) - brick_spacing)
        self.window = GWindow(width=window_width, height=window_height, title=title)

        # Create a paddle.
        self.paddle = GRect(paddle_width, paddle_height)
        self.window.add(self.paddle, (self.window.width - paddle_width) / 2,
                        self.window.height - paddle_offset - paddle_height)
        self.paddle.filled = True
        self.paddle.fill_color = 'blue'
        self.paddle.color = 'blue'

        # Center a filled ball in the graphical window.
        self.ball = GOval(ball_radius * 2, ball_radius * 2)
        self.ball.filled = True
        self.reset_ball()

        # Default initial velocity for the ball.
        self.__dx = 0
        self.__dy = 0
        self.switch = False

        # Initialize our mouse listeners.
        onmouseclicked(self.game_start)
        onmousemoved(self.move_paddle)

        # Draw bricks.
        by = 0
        for i in range(brick_rows):
            bx = 0
            for j in range(brick_cols):
                self.brick = GRect(brick_width, brick_height)
                self.brick.filled = True
                if i < brick_cols / 5:
                    self.brick.fill_color = 'red'
                elif brick_cols / 5 <= i < brick_cols / 5 * 2:
                    self.brick.fill_color = 'orange'
                elif brick_cols / 5 * 2 <= i < brick_cols / 5 * 3:
                    self.brick.fill_color = 'yellow'
                elif brick_cols / 5 * 3 <= i < brick_cols / 5 * 4:
                    self.brick.fill_color = 'green'
                else:
                    self.brick.fill_color = 'blue'
                self.window.add(self.brick, bx, brick_offset+by)
                bx += brick_width + brick_spacing
            by += brick_height + brick_spacing

        # scoreboard
        self.earned_score = 0
        self.total_score = brick_cols * brick_rows
        self.scoreboard = GLabel(f'score: {self.earned_score}/{self.total_score}', x=10, y=30)
        self.scoreboard.font = 'courier-20'
        self.window.add(self.scoreboard)
Ejemplo n.º 6
0
 def __init__(self,
              window_width=WINDOW_WIDTH,
              window_height=WINDOW_HEIGHT,
              zone_width=ZONE_WIDTH,
              zone_height=ZONE_HEIGHT,
              ball_radius=BALL_RADIUS):
     # Create window
     self.window = GWindow(WINDOW_WIDTH, WINDOW_HEIGHT, title='ZONE_GAME')
     # Create zone
     self.zone = GRect(zone_width,
                       zone_height,
                       x=(self.window.width - zone_width) / 2,
                       y=(self.window.height - zone_height) / 2)
     self.zone.color = 'blue'
     self.zone.filled = True
     self.zone.fill_color = "blue"
     self.window.add(self.zone)
     # Create ball and initialize velocity/position
     self.ball = GOval(BALL_RADIUS * 2, BALL_RADIUS * 2)
     self.ball.filled = True
     self.set_ball_position()
     self.ball.fill_color = 'black'
     self.window.add(self.ball)
     #speed
     self.dx_right = True
     self.dy_down = True
Ejemplo n.º 7
0
    def __init__(self,
                 ball_radius=BALL_RADIUS,
                 paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT,
                 paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS,
                 brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH,
                 brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET,
                 brick_spacing=BRICK_SPACING,
                 title='Breakout'):

        # Create a graphical window, with some extra space.
        window_width = brick_cols * (brick_width +
                                     brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows *
                                            (brick_height + brick_spacing) -
                                            brick_spacing)
        self.window = GWindow(width=window_width,
                              height=window_height,
                              title='breakout')

        # make a ball that is black
        self.ball = GOval(ball_radius, ball_radius)
        self.ball.filled = True
        self.ball.fill_color = 'black'
        self.reset_ball()

        self.brick_height = BRICK_HEIGHT
        self.brick_rows = BRICK_ROWS
        self.brick_spacing = BRICK_SPACING
        self.brick_cols = BRICK_COLS
Ejemplo n.º 8
0
    def __init__(self,
                 ball_radius=BALL_RADIUS,
                 paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT,
                 paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS,
                 brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH,
                 brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET,
                 brick_spacing=BRICK_SPACING,
                 title='Breakout'):

        # Create a graphical window, with some extra space.
        self.window_width = brick_cols * (brick_width +
                                          brick_spacing) - brick_spacing
        self.window_height = brick_offset + 3 * (
            brick_rows * (brick_height + brick_spacing) - brick_spacing)
        self.window = GWindow(width=self.window_width,
                              height=self.window_height,
                              title=title)

        # Create a paddle.
        self.pw = paddle_width
        self.ph = paddle_height
        self.paddle = GRect(self.pw,
                            self.ph,
                            x=(self.window_width - self.pw) / 2,
                            y=self.window_height - paddle_offset)
        self.paddle.filled = True
        self.window.add(self.paddle)

        # Center a filled ball in the graphical window.
        self.bra = ball_radius * 2
        self.ball = GOval(self.bra, self.bra)
        self.ball.filled = True
        self.window.add(self.ball, (self.window_width - self.bra) / 2,
                        (self.window_height - self.bra) / 2)

        # Default initial velocity for the ball.
        self.__dx = 0
        self.__dy = 0

        # Initialize our mouse listeners.
        onmousemoved(self.paddle_move)
        onmouseclicked(self.ball_move)

        # Draw bricks.
        self.build_bricks()

        self.score = 0
        self.score_text = GLabel('Score: ' + str(self.score))
        self.score_text.font = '-15-bold'
        self.window.add(self.score_text, 0, self.window_height)

        self.lives_text = GLabel('Lives: ' + str(3))
        self.lives_text.font = '-15-bold'
        self.window.add(self.lives_text, self.window_width - 80,
                        self.window_height)
Ejemplo n.º 9
0
    def __init__(self, ball_radius=BALL_RADIUS, paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT, paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS, brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH, brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET, brick_spacing=BRICK_SPACING,
                 title='Breakout'):

        # Create a graphical window, with some extra space
        window_width = brick_cols * (brick_width + brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows * (brick_height + brick_spacing) - brick_spacing)
        self.window = GWindow(width=window_width, height=window_height, title=title)
        self.paddle_offset = PADDLE_OFFSET
        self.ball_r = BALL_RADIUS
        # Create a paddle
        self.paddle = GRect(paddle_width, paddle_height, x=(window_width-paddle_width)/2, y=window_height-paddle_offset-paddle_height)
        self.paddle.filled = True
        self.paddle.fill_color = 'blue'
        self.window.add(self.paddle)
        # Center a filled ball in the graphical window
        self.first_ball = GOval(ball_radius*2, ball_radius*2, x=(window_width-ball_radius)/2, y=(window_height-ball_radius)/2)
        self.first_ball.filled = True
        self.first_ball.fill_color = 'black'
        self.window.add(self.first_ball)
        self.initial_x = (window_width-ball_radius)/2
        self.initial_y = (window_height-ball_radius)/2
        # Default initial velocity for the ball

        self.__dx = random.randint(1, MAX_X_SPEED)
        self.__dy = INITIAL_Y_SPEED
        if random.random() > 0.5:
            self.__dx = -self.__dx

        # Initialize our mouse listeners
        self.activate = False
        self.crash_is_paddle = False
        self.crash_is_brick = False
        self.point_count = 0
        onmousemoved(self.paddle_move)
        onmouseclicked(self.ball_start)

        # Draw bricks

        for y_pos in range(0, (BRICK_HEIGHT+BRICK_SPACING)*BRICK_ROWS-BRICK_SPACING, BRICK_HEIGHT+BRICK_SPACING):
            for x_pos in range(0, (BRICK_WIDTH+BRICK_SPACING)*BRICK_COLS-BRICK_SPACING, BRICK_WIDTH+BRICK_SPACING):
                self.brick = GRect(BRICK_WIDTH, BRICK_HEIGHT)
                self.brick.filled = True
                if y_pos < BRICK_HEIGHT+BRICK_SPACING * 2 + 1:
                    self.brick.fill_color = 'red'
                elif y_pos < (BRICK_HEIGHT+BRICK_SPACING) * 4:
                    self.brick.fill_color = 'orange'
                elif y_pos < (BRICK_HEIGHT+BRICK_SPACING) * 6:
                    self.brick.fill_color = 'yellow'
                elif y_pos < (BRICK_HEIGHT+BRICK_SPACING) * 8:
                    self.brick.fill_color = 'green'
                elif y_pos < (BRICK_HEIGHT+BRICK_SPACING) * 10:
                    self.brick.fill_color = 'blue'
                else:
                    self.brick.fill_color = 'black'
                self.window.add(self.brick, x=x_pos, y=y_pos)
    def __init__(self,
                 ball_radius=BALL_RADIUS,
                 paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT,
                 paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS,
                 brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH,
                 brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET,
                 brick_spacing=BRICK_SPACING,
                 title='Breakout'):

        # Create a graphical window, with some extra space
        window_width = brick_cols * (brick_width +
                                     brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows *
                                            (brick_height + brick_spacing) -
                                            brick_spacing)
        self.window = GWindow(width=window_width,
                              height=window_height,
                              title='Breakout')

        # Element score label
        self.score = 0
        self.score_label = GLabel('Score: ' + str(self.score))

        # Element for game winning
        self.win_show = GLabel('Create by Mike Lin', x=100, y=100)
        self.win_show2 = GLabel('March 20 stanCode SC101', x=135, y=115)

        # Create a paddle
        self.paddle = GRect(paddle_width,
                            paddle_height,
                            x=(window_width - paddle_width) / 2,
                            y=window_height - paddle_offset)
        self.window.add(self.paddle)
        self.paddle.filled = True

        # Center a filled ball in the graphical window
        self.ball = GOval(2 * ball_radius,
                          2 * ball_radius,
                          x=window_width / 2 - ball_radius,
                          y=window_height / 2 - ball_radius)
        self.ball_x = window_width / 2 - ball_radius
        self.ball_y = window_height / 2 - ball_radius

        # Default initial velocity for the ball
        self.__dx = 0
        self.__dy = 0

        # Other variables
        self.total_bricks = 0

        # Initialize our mouse listeners
        onmousemoved(
            self.paddle_move)  # using own method must add 'self.' in the front
        onmouseclicked(self.clicked)
        self.draw_bricks_and_ball()
Ejemplo n.º 11
0
    def __init__(self,
                 ball_radius=BALL_RADIUS,
                 paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT,
                 paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS,
                 brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH,
                 brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET,
                 brick_spacing=BRICK_SPACING,
                 title='Breakout'):

        # Create a graphical window, with some extra space.
        window_width = brick_cols * (brick_width +
                                     brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows *
                                            (brick_height + brick_spacing) -
                                            brick_spacing)
        self.window = GWindow(width=window_width,
                              height=window_height,
                              title=title)

        # Create a paddle.
        self.pof = paddle_offset
        self.paddle = GRect(paddle_width, paddle_height)
        self.paddle.filled = True
        self.window.add(self.paddle, (window_width - self.paddle.width) / 2,
                        window_height - self.pof)

        # Center a filled ball in the graphical window.
        self.ball = GOval(2 * ball_radius, 2 * ball_radius)
        self.ball.filled = True
        self.window.add(self.ball, self.window.width / 2 - self.ball.width / 2,
                        self.window.height / 2)
        self.initial_x = self.window.width / 2 - self.ball.width / 2
        self.initial_y = self.window.height / 2
        # Default initial velocity for the ball.
        self.__dx = 0
        self.__dy = 0
        self.set_speed()
        self.get_dx()
        self.get_dy()

        # Initialize our mouse listeners.
        self.click = False
        onmousemoved(self.paddle_follow)
        onmouseclicked(self.start)

        # Draw bricks.
        self.br = brick_rows
        self.bc = brick_cols
        self.sp = brick_spacing
        self.of = brick_offset
        self.set_brick()
        # self.check()
        # self.rest_ball()
        self.total = self.br * self.bc
Ejemplo n.º 12
0
    def __init__(self,
                 ball_radius=BALL_RADIUS,
                 paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT,
                 paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS,
                 brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH,
                 brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET,
                 brick_spacing=BRICK_SPACING,
                 title='Breakout'):
        num_bricks = 100
        # Create a graphical window, with some extra space.
        window_width = brick_cols * (brick_width +
                                     brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows *
                                            (brick_height + brick_spacing) -
                                            brick_spacing)
        self.window = GWindow(width=window_width,
                              height=window_height,
                              title=title)
        self.paddle = GRect(paddle_width, paddle_height, x=(window_width - paddle_width)/2, y = window_height - \
                            paddle_offset)

        # initializing the paddle
        self.paddle.filled = True
        self.paddle.fill_color = 'black'
        self.window.add(self.paddle)

        # initializing the ball
        self.ball = GOval(width=ball_radius * 2,
                          height=ball_radius * 2,
                          x=window_width / 2 - BALL_RADIUS,
                          y=window_height / 2 - BALL_RADIUS)
        self.ball.filled = True
        self.ball.fill_color = 'black'
        self.window.add(self.ball)

        # initial velocity
        self.vx = 0
        self.vy = INITIAL_Y_SPEED

        # draw bricks
        self.draw_bricks()

        # number of lives left
        self.num_lives = 3

        # running? big question mark
        self.running = False

        # brick count
        self.brick_count = 100

        # mouse listeners
        onmouseclicked(self.start)
        onmousemoved(self.move_paddle)
Ejemplo n.º 13
0
    def __init__(self, ball_radius=BALL_RADIUS, paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT, paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS, brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH, brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET, brick_spacing=BRICK_SPACING,
                 title='Breakout'):

        # Create a graphical window, with some extra space
        window_width = brick_cols * (brick_width + brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows * (brick_height + brick_spacing) - brick_spacing)
        self.window = GWindow(width=window_width, height=window_height, title='Breakout')

        # Create a paddle
        self.paddle = GRect(paddle_width, paddle_height, x=(window_width-paddle_width)/2,
                            y=window_height-paddle_offset)
        self.window.add(self.paddle)
        self.paddle.filled = True
        # Center a filled ball in the graphical window
        self.ball = GOval(2*ball_radius, 2*ball_radius, x=window_width/2 - ball_radius,
                          y=window_height/2 - ball_radius)
        self.window.add(self.ball)
        self.ball.filled = True

        self.ball_x = window_width/2 - ball_radius
        self.ball_y = window_height/2 - ball_radius

        # Default initial velocity for the ball
        self.__dx = 0
        self.__dy = 0
        # Other variables
        self.total_bricks = 0
        self.__start = False
        # Initialize our mouse listeners
        onmousemoved(self.paddle_move)  # using own method must add 'self.' in the front
        onmouseclicked(self.clicked)

        # Draw bricks
        color_num = BRICK_COLS/5

        for i in range(BRICK_ROWS):
            for j in range(BRICK_COLS):
                if j // color_num == 0:
                    color = 'red'
                elif j // color_num == 1:
                    color = 'orange'
                elif j // color_num == 2:
                    color = 'yellow'
                elif j // color_num == 3:
                    color = 'green'
                else:
                    color = 'blue'
                bricks = GRect(BRICK_WIDTH, BRICK_HEIGHT)
                self.window.add(bricks, x=0+i*(BRICK_WIDTH+BRICK_SPACING),
                                y=BRICK_OFFSET+j*(BRICK_HEIGHT+BRICK_SPACING))
                bricks.filled = True
                bricks.fill_color = color
                self.total_bricks += 1
    def __init__(self,
                 ball_radius=BALL_RADIUS,
                 paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT,
                 paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS,
                 brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH,
                 brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET,
                 brick_spacing=BRICK_SPACING,
                 title='Breakout'):

        # Create a graphical window, with some extra space.
        window_width = brick_cols * (brick_width +
                                     brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows *
                                            (brick_height + brick_spacing) -
                                            brick_spacing)
        self.window = GWindow(width=window_width,
                              height=window_height,
                              title=title)

        # Create a paddle.
        self.paddle = GRect(paddle_width,
                            paddle_height,
                            x=(window_width - paddle_width) / 2,
                            y=window_height - paddle_offset)
        self.paddle.filled = True
        self.window.add(self.paddle)
        # Center a filled ball in the graphical window.
        self.ball = GOval(ball_radius * 2,
                          ball_radius * 2,
                          x=window_width / 2 - ball_radius,
                          y=window_height / 2 - ball_radius)
        self.window.add(self.ball)
        self.ball.filled = True
        # Default initial velocity for the ball.
        random_x = random.randint(1, MAX_X_SPEED)
        self.__vx = random_x
        if random.random() > 0.5:
            self.__vx = -self.__vx
        self.__vy = INITIAL_Y_SPEED
        # Initialize our mouse listeners.
        self.moved = onmousemoved(self.move_paddle)
        self.__is_gaming = False
        # Draw bricks.
        for i in range(brick_rows):
            for j in range(brick_cols):
                self.bricks = GRect(brick_width,
                                    brick_height,
                                    x=+j * (brick_width + brick_spacing),
                                    y=brick_offset + i *
                                    (brick_height + brick_spacing))
                self.bricks.filled = True
                self.set_brick_color(self.bricks, i, j)
                self.window.add(self.bricks)
Ejemplo n.º 15
0
class NoGraphics:
    def __init__(self,
                 window_width=WINDOW_WIDTH,
                 window_height=WINDOW_HEIGHT,
                 boundary_x=BOUNDARY_X,
                 boundary_y=BOUNDARY_Y):
        # 介面碼定義
        self.__menu_code = 0  # 介面碼 0:wait 1:main 2:game 9:none
        # 狀態碼定義
        self.__status_code = 0  # 狀態碼 0:wait 1:start 9:reade

        # 邊界定義
        self.__boundary_x = boundary_x
        self.__boundary_y = boundary_y

        # 建視窗
        self.window = GWindow(width=window_width,
                              height=window_height,
                              title='NONO',
                              color="green")

        self.__obj = None

    def grid_line(self, size=50, dx=0, dy=0):
        """
        功能:輔助功能,方格線
        size = 單位方格大小
        dx = x軸位移量
        dy = y軸位移量
        """
        line_color = 'lightgray'

        # 水平輔助線
        for r in range(self.window.width // size + 1):
            p1_x = r * size + dx
            p1_y = 0
            p2_x = r * size + dx
            p2_y = self.window.height

            line_row = GLine(p1_x, p1_y, p2_x, p2_y)
            line_row.color = line_color

            self.window.add(line_row)

        # 垂直輔助線
        for c in range(self.window.height // size + 1):
            p1_x = 0
            p1_y = c * size + dy
            p2_x = self.window.width
            p2_y = c * size + dy

            line_column = GLine(p1_x, p1_y, p2_x, p2_y)
            line_column.color = line_color

            self.window.add(line_column)
Ejemplo n.º 16
0
def main():
    print(f'__name__== {__name__}')
    window = GWindow(600, 400)

    r1 = SuperRobot(200, 100, super_c='salmon', counter=5)
    r1_ball = r1.give_me_a_ball(100)
    window.add(r1_ball, 200, 200)
    r1.self_intro()
    r1.bmi()
    SuperRobot.say_tater()
    r1.self_count()
Ejemplo n.º 17
0
    def __init__(self, ball_radius = BALL_RADIUS, paddle_width = PADDLE_WIDTH,
                 paddle_height = PADDLE_HEIGHT, paddle_offset = PADDLE_OFFSET,
                 brick_rows = BRICK_ROWS, brick_cols = BRICK_COLS,
                 brick_width = BRICK_WIDTH, brick_height = BRICK_HEIGHT,
                 brick_offset = BRICK_OFFSET, brick_spacing = BRICK_SPACING,
                 title='Breakout'):

        # Create a graphical window, with some extra space
        window_width = brick_cols * (brick_width + brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows * (brick_height + brick_spacing) - brick_spacing)
        self.window = GWindow(width=window_width, height=window_height, title=title)

        # Create a paddle
        self.paddle_touch = 0  # (0:untouch paddle; 1: touch paddle)

        # self.paddle = GRect(paddle_width, paddle_height)
        self.paddle = GRect(paddle_width, paddle_height)  # Test width "430"
        self.paddle.filled = True
        self.window.add(self.paddle, x=(window_width-paddle_width)/2, y=window_height-paddle_offset)

        # Center a filled ball in the graphical window
        self.ball_radius = ball_radius
        self.remove_succ = 0  # (0: untouch bricks; 1: touch bricks)
        self.ball = GOval(ball_radius*2, ball_radius*2)
        self.ball.filled = True
        self.window.add(self.ball, x=(window_width-ball_radius)/2, y=(window_height-ball_radius)/2)

        # Default initial velocity for the ball
        self.__dy = INITIAL_Y_SPEED
        self.__dx = random.randint(1, MAX_X_SPEED+1)
        if random.random() > 0.5:
            self.__dx = -self.__dx

        # Initialize our mouse listeners
        self.switch = 0  # This variable controls if the game start or not. (1:start, 0: unstart)
        onmouseclicked(self.click_m)
        onmousemoved(self.move_m)

        # Draw bricks
        self.sum_bricks = brick_rows * brick_cols
        self.bricks_remove = 0  # record how many bricks were removed
        brick_spacing = (window_width - (brick_width*brick_rows))/(brick_rows-1)
        position_height = brick_offset
        for i in range(brick_cols):
            position_width = 0
            for j in range(brick_rows):
                bricks = GRect(brick_width, brick_height)
                bricks.filled = True
                self.window.add(bricks, x=position_width, y=position_height)
                position_width += (brick_spacing + brick_width)
            position_height += (brick_spacing + brick_height)

        # The following variables are used to control user's life or die
        self.dead = 0  # (0: still life; 1: die)
Ejemplo n.º 18
0
    def __init__(self, ball_radius = BALL_RADIUS, paddle_width = PADDLE_WIDTH,
                 paddle_height = PADDLE_HEIGHT, paddle_offset = PADDLE_OFFSET,
                 brick_rows = BRICK_ROWS, brick_cols = BRICK_COLS,
                 brick_width = BRICK_WIDTH, brick_height = BRICK_HEIGHT,
                 brick_offset = BRICK_OFFSET, brick_spacing = BRICK_SPACING,
                 title='Breakout'):

        self.b_r = brick_rows
        self.b_c = brick_cols
        self.b_w = brick_width
        self.b_h = brick_height
        self.b_o = brick_offset
        self.b_s = brick_spacing
        self.b_amount = brick_rows * brick_cols
        self.ball_r = ball_radius
        self.paddle_o = paddle_offset

        # Create a graphical window, with some extra space.
        self.brick = GRect(brick_width, brick_height)
        window_width = brick_cols * (brick_width + brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows * (brick_height + brick_spacing) - brick_spacing)
        self.window = GWindow(width=window_width, height=window_height, title=title)

        # create an image
        self.img = GImage('luv.png')
        self.reset_img()

        # Create a paddle.
        self.paddle = GRect(paddle_width, paddle_height)
        self.paddle.filled = True
        self.paddle.fill_color = 'coral'
        self.paddle.color = 'coral'
        self.window.add(self.paddle, (self.window.width-self.paddle.width)/2, \
                        (self.window.height-paddle_offset))

        # Draw bricks.
        self.add_bricks()

        # Center a filled ball in the graphical window.
        self.ball = GOval(ball_radius * 2, ball_radius * 2)
        self.ball.filled = True
        self.ball.fill_color = 'royalblue'
        self.ball.color = 'royalblue'
        self.window.add(self.ball, (self.window.width - self.ball.width) / 2,
                        (self.window.height - self.ball.height) / 2)

        # Default initial velocity for the ball.
        self.__dy = 0
        self.__dx = 0
        self.ball_velocity()

        # Initialize our mouse listeners.h
        onmousemoved(self.paddle_move)
Ejemplo n.º 19
0
    def __init__(self, ball_radius=BALL_RADIUS, paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT, paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS, brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH, brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET, brick_spacing=BRICK_SPACING,
                 title='Breakout'):

        self.__dx = 0
        self.__dy = 0
        self.paddle_height = paddle_height
        self.paddle_width = paddle_width
        self.paddle_offset = paddle_offset
        self.count = 0

        # Create a graphical window, with some extra space.
        self.window_width = brick_cols * (brick_width + brick_spacing) - brick_spacing
        self.window_height = brick_offset + 3 * (brick_rows * (brick_height + brick_spacing) - brick_spacing)
        self.window = GWindow(width=self.window_width, height=self.window_height, title=title)

        # Create a paddle.
        self.paddle = GRect(paddle_width, paddle_height)
        self.window.add(self.paddle, 0.5 * self.window_width - 0.5 * paddle_width, \
                        self.window_height - paddle_offset - paddle_height)
        self.paddle.filled = True

        # Center a filled ball in the graphical window.
        self.ball = GOval(2 * ball_radius, 2 * ball_radius)
        self.window.add(self.ball, 0.5 * self.window_width - ball_radius, 0.5 * self.window_height - ball_radius)
        self.ball.filled = True

        # Default initial velocity for the ball.

        # Initialize our mouse listeners.
        onmousemoved(self.move)
        onmouseclicked(self.start)

        # Draw bricks.
        n = brick_offset
        m = 0
        color = ['red', 'orange', 'yellow', 'green', 'blue']
        for i in range(brick_rows):
            n += brick_height + brick_spacing
            for j in range(brick_cols):
                m = j * (brick_width + brick_spacing)
                brick = GRect(brick_width, brick_height)
                brick.filled = True
                brick.fill_color = color[i // 2]
                #  why cannot use else at the end?
                self.window.add(brick, m, n)

        self.original_x = 0.5 * self.window_width - ball_radius
        self.original_y = 0.5 * self.window_height - ball_radius
Ejemplo n.º 20
0
def main():
    """
    Center a magenta rect on the canvas
    where the width and height are SIZE
    """
    rect = GRect(SIZE, SIZE)
    rect.filled = True
    rect.color = 'magenta'
    rect.fill_color = 'magenta'
    window = GWindow()
    rect_x = (window.width - rect.width) / 2
    rect_y = (window.height - rect.height) / 2
    window.add(rect, rect_x, rect_y)
Ejemplo n.º 21
0
    def __init__(self, bar_width=BAR_WIDTH, bar_height=BAR_HEIGHT, win_width=WIN_WIDTH, win_height=WIN_HEIGHT,
                 play_button_width=PLAY_BUTTON_WIDTH, play_button_height=PLAY_BUTTON_HEIGHT,
                 fb_button_width=WIN_WIDTH * 0.6,
                 fb_button_height=FB_BUTTON_HEIGHT):

        self.window = GWindow(win_width, win_height, title='Welcome')
        self.load_bar = GRect(bar_width, bar_height)
        self.load_label = GLabel('0%')
        self.solid_bar = GRect(0, bar_height)
        self.play_button = GRect(play_button_width, play_button_height)
        self.play_label = GLabel('Start New Game')
        self.fb_button = GRect(fb_button_width, fb_button_height)
        self.fb_label = GLabel('continue with facebook')
Ejemplo n.º 22
0
 def __init__(self, ball_radius=BALL_RADIUS, paddle_width=PADDLE_WIDTH,
              paddle_height=PADDLE_HEIGHT, paddle_offset=PADDLE_OFFSET,
              brick_rows=BRICK_ROWS, brick_cols=BRICK_COLS,
              brick_width=BRICK_WIDTH, brick_height=BRICK_HEIGHT,
              brick_offset=BRICK_OFFSET, brick_spacing=BRICK_SPACING,
              title='Breakout'):
     # Instance Variable
     self.__game_status = False
     self.life_icon_list = []
     self.__monster_list = []
     self.__monster_dict = {}
     # Create a graphical window, with some extra space.
     window_width = brick_cols * (brick_width + brick_spacing) - brick_spacing
     window_height = brick_offset + 2.5 * (brick_rows * (brick_height + brick_spacing) - brick_spacing)
     self.window = GWindow(width=window_width, height=window_height, title=title)
     # Draw bricks as a monster.
     color = ['0xFFABAB', '0xFFE5B5', '0xFFFF45', '0xB5FFB5	', '0xC2C2FF']
     for row in range(brick_rows):
         for col in range(brick_cols):
             monster = Monster(brick_width, brick_height, x=col * (brick_width + brick_spacing),
                               y=row * (brick_height + brick_spacing), hp=MONSTER_HP*(BRICK_ROWS-row))
             monster.body.fill_color = color[row]
             self.__monster_list.append(monster.body)
             self.__monster_dict[monster.body] = monster
             self.window.add(monster.body)
             self.window.add(monster.l_eye)
             self.window.add(monster.r_eye)
             self.window.add(monster.hp_label)
     # Create a paddle.
     self.paddle = GRect(paddle_width, paddle_height)
     self.paddle.filled = True
     self.paddle.fill_color = 'black'
     self.window.add(self.paddle, x=(self.window.width-self.paddle.width)/2,
                     y=self.window.height-paddle_offset)
     # Create score board
     self.score = 0
     self.score_label = GLabel(f'Score: {self.score}')
     self.score_label.font = '-20'
     self.window.add(self.score_label, x=0, y=self.window.height)
     # Center a filled ball in the graphical window as a hero.
     self.ball_radius = ball_radius
     self.hero = Hero(ball_radius * 2, ball_radius * 2)
     self.hero.body.filled = True
     self.hero.body.fill_color = 'black'
     self.set_hero_position()
     # Default initial velocity for the ball.
     self.__dx = 0
     self.__dy = 0
     # Initialize our mouse listeners.
     onmousemoved(self.set_paddle)
     onmouseclicked(self.game_start)
Ejemplo n.º 23
0
    def __init__(self, ball_radius=BALL_RADIUS, paddle_width=PADDLE_WIDTH,
                 paddle_height=PADDLE_HEIGHT, paddle_offset=PADDLE_OFFSET,
                 brick_rows=BRICK_ROWS, brick_cols=BRICK_COLS,
                 brick_width=BRICK_WIDTH, brick_height=BRICK_HEIGHT,
                 brick_offset=BRICK_OFFSET, brick_spacing=BRICK_SPACING,
                 title='Breakout'):

        # Create a graphical window, with some extra space
        window_width = brick_cols * (brick_width + brick_spacing) - brick_spacing
        window_height = brick_offset + 3 * (brick_rows * (brick_height + brick_spacing) - brick_spacing)
        self.window = GWindow(width=window_width, height=window_height, title=title)

        # Create a paddle
        self.paddle = GRect(paddle_width, paddle_height)
        self.paddle.filled = True
        self.window.add(self.paddle, (self.window.width - self.paddle.width) / 2,
                        (self.window.height - self.paddle.height - paddle_offset))

        # Center a filled ball in the graphical window
        self.ball = GOval(ball_radius * 2, ball_radius * 2)
        self.ball.filled = True
        self.window.add(self.ball, (self.window.width - self.ball.width) / 2,
                        (self.window.height - self.ball.height) / 2)

        self.move = False  # Set move so the ball won't be influenced by clicks

        # Default initial velocity for the ball
        self.__dx = random.randint(1, MAX_X_SPEED)
        if random.random() > 0.5:
            self.__dx = -self.__dx
        self.__dy = INITIAL_Y_SPEED
        # Initialize our mouse listeners
        onmouseclicked(self.start)
        onmousemoved(self.paddle_move)
        self.paddle_offset = PADDLE_OFFSET  # Set paddle_offset as an attribute so it can be used in methods
        self.row = brick_rows  # Count the number of rows
        self.col = brick_cols  # Count the number of columns

        # Draw bricks
        y = brick_offset
        for i in range(brick_rows):
            x = 0  # Put position x in for loop to reset the x value at every row
            for j in range(brick_cols):
                self.rect = GRect(brick_width, brick_height)
                self.rect.filled = True
                color = ['red', 'red', 'orange', 'orange', 'yellow', 'yellow', 'green', 'green', 'blue', 'blue']
                self.rect.fill_color = color[i]
                self.window.add(self.rect, x, y)
                x += (brick_width + brick_spacing)
            y += (brick_height + brick_spacing)
Ejemplo n.º 24
0
class ZoneGraphics:
    def __init__(self,
                 window_width=WINDOW_WIDTH,
                 window_height=WINDOW_HEIGHT,
                 zone_width=ZONE_WIDTH,
                 zone_height=ZONE_HEIGHT,
                 ball_radius=BALL_RADIUS):
        # Create window
        self.window = GWindow(WINDOW_WIDTH, WINDOW_HEIGHT, title='ZONE_GAME')
        # Create zone
        self.zone = GRect(zone_width,
                          zone_height,
                          x=(self.window.width - zone_width) / 2,
                          y=(self.window.height - zone_height) / 2)
        self.zone.color = 'blue'
        self.zone.filled = True
        self.zone.fill_color = "blue"
        self.window.add(self.zone)
        # Create ball and initialize velocity/position
        self.ball = GOval(BALL_RADIUS * 2, BALL_RADIUS * 2)
        self.ball.filled = True
        self.set_ball_position()
        self.ball.fill_color = 'black'
        self.window.add(self.ball)
        #speed
        self.dx_right = True
        self.dy_down = True
        #bounce

        # Initialize mouse listeners

    def set_ball_position(self):
        while True:
            rand_x = random.randint(0, self.window.width - self.ball.width)
            rand_y = random.randint(0, self.window.height - self.ball.height)
            if not (self.zone.x < rand_x < self.zone.x + ZONE_WIDTH
                    and self.zone.y < rand_y < self.zone.y + ZONE_HEIGHT):
                break
        self.ball.x = rand_x
        self.ball.y = rand_y

    def set_ball_velocity(self):
        self.dx = random.randint(MIN_SPEED, MAX_SPEED)
        if random.random() > 0.5:
            self.dx *= -1
        self.dy = random.randint(MIN_SPEED, MAX_SPEED)
        if random.random() > 0.5:
            self.dy *= -1
Ejemplo n.º 25
0
def main():

    window = GWindow()
    rect = GRect(SIZE,
                 SIZE,
                 x=(window.width - SIZE) / 2,
                 y=(window.height - SIZE) / 2)
    rect.filled = True
    rect.fill_color = 'hotpink'
    window.add(rect)
    vx = 5
    while True:
        rect.move(vx, 0)
        if rect.x <= 0 or (rect.x + SIZE) >= window.width:
            vx = -vx
        pause(DELAY)
Ejemplo n.º 26
0
def main():
    """This program plots a heart and a rainbow to express 'Love is love' """
    find_maxmin()
    window = GWindow(WINDOW_WIDTH, WINDOW_HEIGHT, title='LoveisLove.py')
    add_rainbow(window)
    add_heart(window)
    add_words(window)
Ejemplo n.º 27
0
def main():
    window = GWindow()
    rect = set_up_r()
    window.add(rect, (window.width - rect.width) // 2,
               (window.height - rect.height) // 2)
    vx = 5
    while True:
        rect.move(vx, 0)
        if rect.x <= 0 or rect.x + rect.width >= window.width:
            vx = -vx
            if vx > 0:
                rect.color = 'purple'
                rect.filled = True
                rect.fill_color = rect.color
            else:
                rect.color = 'green'
                rect.filled = True
                rect.fill_color = rect.color
        pause(DELAY)
Ejemplo n.º 28
0
def main():
    """
    This program show micky to you
    """
    window = GWindow(width=800, height=500, title="林冠伶")
    back(window)
    up(window)
    eye(window)
    body(window)
    word(window)
Ejemplo n.º 29
0
    def __init__(self,
                 window_width=WINDOW_WIDTH,
                 window_height=WINDOW_HEIGHT,
                 boundary_x=BOUNDARY_X,
                 boundary_y=BOUNDARY_Y):
        # 介面碼定義
        self.__menu_code = 0  # 介面碼 0:wait 1:main 2:game 9:none
        # 狀態碼定義
        self.__status_code = 0  # 狀態碼 0:wait 1:start 9:reade

        # 邊界定義
        self.__boundary_x = boundary_x
        self.__boundary_y = boundary_y

        # 建視窗
        self.window = GWindow(width=window_width,
                              height=window_height,
                              title='NONO',
                              color="green")

        self.__obj = None
Ejemplo n.º 30
0
def main():
    window = GWindow(500, 500)
    r1 = Robot(188, 80, color='black')
    r1.give_me_a_ball(SIZE)
    print(__name__)
    # r1.speak()
    # r1.self_intro()
    # print(r1.bmi())
    # window.add(r1.ball, window.width/2 - SIZE/2, window.height/2 - SIZE/2)
    # print(r1.ball.width)
    # r1.say_hi1()
    # Robot.say_hi2()
    #
    #
    # right_r1_arm = r1.RobotArm("right", 100)
    # print(right_r1_arm.property, "arm length = ", right_r1_arm.length)

    r2 = Robot2(200, 300, color2="brown", count2=5)
    r2.start_count()
    r2.say_hi1()
    r2.say_hi2()
    r2.self_intro()

    r3 = Robot3(300, 400, "pink", color3="black", count3=100)
    r3.bmi()
    rect = r3.give_me_a_rect(20)
    r3.give_me_a_ball(SIZE)
    window.add(r1.ball, window.width / 2 - SIZE / 2,
               window.height / 2 - SIZE / 2)
    window.add(rect, window.width / 2 - SIZE / 2, window.height / 2 - SIZE / 2)