猫史档案馆


【Python作品分享】弹弹乐【求助帖】

用户:黑墨Jf9l黑墨Jf9l查看:0 回复:0 评论:0 创建时间:2023-03-27T14:56:35


【作品展示】

center_image

 

【作品介绍】

大神们,交我一下

 

【作品源代码】

import pygame as pg

import sys

from random import randint

import time


pg.init()


game_window = pg.display.set_mode((600, 500))

pg.display.set_caption("弹弹乐")

score = 0

font = pg.font.Font(None, 60)

window_color = (2, 120, 110) 

ball_color = (255, 0, 120) 

rect_color = (255, 130, 100)  

move_x = 1

move_y = 1

ball_x = randint(20, 580) 

ball_y = randint(20, 480)

points = 1

count = 0


while True:

    game_window.fill(window_color)

    for event in pg.event.get():

        if event.type == pg.QUIT:

            sys.exit()

    mouse_x, mouse_y = pg.mouse.get_pos()

    pg.draw.circle(game_window, ball_color, (ball_x, ball_y), 10)  

    pg.draw.rect(game_window, rect_color, (mouse_x, 490, 100, 10)) 

    ball_x += move_x

    ball_y += move_y

    my_score = font.render(str(score), False, (255, 255, 0))  

    game_window.blit(my_score, (500, 30))

    ball_x += move_x

    ball_y += move_y

    if ball_x <= 20 or ball_x >= 580:  

        move_x = -move_x  

    if ball_y <= 20:  

        move_y = -move_y

    elif ball_x > (mouse_x - 20) and ball_x < (mouse_x + 120) and ball_y >= 470:

        move_y = -move_y  

        score += points

        count += 1  

        if count == 5:

            count = 0

            points += points 

            if move_x > 0:

                move_x += 1

            else:

                move_x -= 1

            move_y -= 1

    elif ball_y > 480 and (ball_x <= mouse_x - 20 or ball_x >= mouse_x + 120):

        ball_y = 490  

        break

    pg.display.update()  

    time.sleep(0.01)  

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页