猫史档案馆


【Python作品分享】疯狂弹球(未完工)【作业帖】

用户:活力的蓝雀rrzg活力的蓝雀rrzg查看:0 回复:0 评论:0 创建时间:2023-02-24T12:01:56


【作品展示】

center_image

 

【作品介绍】

就是个作业,而且还没做完。

 

【作品源代码】

import random
import pygame
import time


ball = pygame.image.load("小球.png")
flip = pygame.image.load("挡板.png")
width = 400
height = 500
screen = pygame.display.set_mode((width,height))
pygame.display.set_caption("弹球游戏")
screen.fill((51,213,201))
ball_x = random.randint(30, 370)
ball_y = random.randint(30, 400)
flip_x = random.randint(20, 380)
flip_y = 480
ball_speed_x = 5
ball_speed_y = 5
clock = pygame.time.Clock()
while True:
    clock.tick(50)
    ball_x += ball_speed_x
    ball_y += ball_speed_y
    screen.fill((51,213,201))
    screen.blit(ball,(ball_x,ball_y))
    time.sleep(0.01)
    for event in pygame.event.get():
        if (event.type == pygame.QUIT):
            pygame.quit()
    if ball_x <= 0 or ball_x >= width - 30:
        ball_speed_x = -ball_speed_x
    if ball_y <= 0 or ball_y >= height - 30:
        ball_speed_y = -ball_speed_y
    screen.blit(ball, (ball_x, ball_y))
    screen.blit(flip, (flip_x, flip_y))
    pygame.display.update()
pygame.display.update()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页