当前位置: 首页>>代码示例>>Python>>正文


Python Ball.y方法代码示例

本文整理汇总了Python中ball.Ball.y方法的典型用法代码示例。如果您正苦于以下问题:Python Ball.y方法的具体用法?Python Ball.y怎么用?Python Ball.y使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ball.Ball的用法示例。


在下文中一共展示了Ball.y方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import y [as 别名]
def main():
    """ Main function for the game. """
    pygame.init()

    # Set the width and height of the screen [width,height]
    size = [800, 600]
    screen = pygame.display.set_mode(size)

    pygame.display.set_caption("CMSC 150 is cool")

    # Loop until the user clicks the close button.
    done = False

    # Used to manage how fast the screen updates
    clock = pygame.time.Clock()


    theBall = Ball()
    theBall.x = 100
    theBall.y = 100
    theBall.change_x = 2
    theBall.change_y = 1
    theBall.color = [255,0,0]

    # -------- Main Program Loop -----------
    while not done:
        # ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done = True
        # ALL EVENT PROCESSING SHOULD GO ABOVE THIS COMMENT

        # ALL GAME LOGIC SHOULD GO BELOW THIS COMMENT

        # ALL GAME LOGIC SHOULD GO ABOVE THIS COMMENT

        # ALL CODE TO DRAW SHOULD GO BELOW THIS COMMENT

        # First, clear the screen to white. Don't put other drawing commands
        # above this, or they will be erased with this command.

        # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT

        screen.fill(BLACK)
        theBall.move()
        theBall.draw(screen)

        # Go ahead and update the screen with what we've drawn.
        pygame.display.flip()

        # Limit to 60 frames per second
        clock.tick(60)

    # Close the window and quit.
    # If you forget this line, the program will 'hang'
    # on exit if running from IDLE.
    pygame.quit()
开发者ID:tazz0009,项目名称:pygameTest1,代码行数:59,代码来源:ball_main.py

示例2: main

# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import y [as 别名]
def main():
  pygame.init()

  # Set the height and width of the screen
  size = [constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT]
  screen = pygame.display.set_mode(size)

  pygame.display.set_caption("Block Break Game :D ")

  # Create the player
  player = Player()

  # Create the ball
  ball = Ball()

  # Create all the levels
  level_list = init_levellist(player)

  # Set the current level
  current_level_no = 0
  current_level = level_list[current_level_no]

  active_sprite_list = pygame.sprite.Group()

  player.level = current_level
  player.rect.x = (constants.SCREEN_WIDTH - player.rect.width) /2
  active_sprite_list.add(player)

  # Loop until the user clicks the close button
  done = False
  game_over = False

  # Used to manage how fast the screen updates
  clock = pygame.time.Clock()

  # ============= Main program loop ==============
  while not done:
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        done = True

      if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_LEFT:
          player.move_left()

        if event.key == pygame.K_RIGHT:
          player.move_right()

      if event.type == pygame.KEYUP:
        if event.key == pygame.K_LEFT:
          player.stop()
        if event.key == pygame.K_RIGHT:
          player.stop()

      if event.type == pygame.MOUSEBUTTONDOWN:
        if game_over:
          ball.reset()
          player.rect.x = (constants.SCREEN_WIDTH - player.rect.width) /2
          level_list.clear()
          level_list = init_levellist(player)
          current_level = level_list[current_level_no]
          player_level = current_level
          game_over = False


    # Update the player
    active_sprite_list.update()

    # Update items in the level
    current_level.update()
    ball.update()
   
    if (ball.bottom >= player.rect.top) and (ball.x >= player.rect.x) and (ball.x <= player.rect.x+player.rect.w):
      ball.change_y *= -1
      ball.speed += 0.1
      ball.y = player.rect.top - ball.size + ball.change_y

    for block in current_level.block_list:
      # right side of block
      y = block.rect.y
      x = block.rect.x + block.rect.w
      if (ball.x >= x and ball.x <= x + ball.size and
          ball.y >= y and ball.y <= y + block.rect.h):
        ball.change_x *= -1
        ball.speed += 0.1
        if not hardblock_collision(block, current_level):
          current_level.block_list.remove(block)

      # left side of block
      y = block.rect.y
      x = block.rect.x
      if (ball.x >= x-ball.size and ball.x <= x and
          ball.y >= y and ball.y <= y + block.rect.h):
        ball.change_x *= -1
        ball.speed += 0.1
        if not hardblock_collision(block, current_level):
          current_level.block_list.remove(block)

      # bottom of block
      y = block.rect.y + block.rect.h
#.........这里部分代码省略.........
开发者ID:ddaddabae,项目名称:serin_blockbreaker,代码行数:103,代码来源:breaker.py


注:本文中的ball.Ball.y方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。