猫史档案馆


【Python作品分享】弹球游戏(成稿)【求助帖】

用户:刘慈欣十级学者刘慈欣十级学者查看:0 回复:4 评论:0 创建时间:2021-06-09T22:19:25


【作品展示】

center_image

 

【作品介绍】

代码有一点问题,还正在调试,并且遇到了一些问题,希望朋友们能提供一些帮助

 

【作品源代码】

import pgzrun


WIDTH = 400
HEIGHI = 600
score=0
ball_x,ball_y=220,300
x_speed,y_speed=6,-6
pannel=Rect(200,500,80,10)

def draw():
    screen.fill('lightblue')
    screen.draw.filled_circle((ball_x,ball_y),6,'orange')
    screen.draw.filled_rect(pannel,'brown')
    screen.draw.text('score:'+str(score),(300,10),
                    color='orange',fontsize=30)

def update():
    global ball_x,ball_y,x_speed,y_speed,score
    ball_x += x_speed>384:
        x_speed=-x_speed
    ball_y += y_speed>584:
        y_speed=-y_speed
    if keyboard.a:
        pannel.x-=5
    elif keyboaed.d:
        pannel.x+=5
    if ball_x-pannel.x>=0 and ball_x-pannel.x<=80\
        and pannel.y-ball_ball_y<=16 and pannel.yy-ball_y>=0:
        y_speed=-y_speed


pgzrun.go()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
xiao998xiao998

大神,别人打了©的图片还敢用~

大神,Python好玩吗?

大神~

点赞1


评论


xiao998xiao998

emotion_嘻嘻

点赞0


评论


lsk666666lsk666666

你这程序有亿点点错误,等我改一会的

点赞0


评论


lsk666666lsk666666

import pgzrun
import random

WIDTH = 400
HEIGHT = 600
score=0
last_ball_y = 0
ball_x,ball_y=220,300
x_speed,y_speed=6,-6
pannel=Rect(200,500,80,10)

def draw():
    screen.fill('lightblue')
    screen.draw.filled_circle((ball_x,ball_y),6,'orange')
    screen.draw.filled_rect(pannel,'brown')
    screen.draw.text('score:'+str(score),(300,10),
                    color='orange',fontsize=30)

def update():
    global ball_x,ball_y,x_speed,y_speed,score,last_ball_y
    ball_x += x_speed
    if ball_x > 384 or ball_x < 0:
        x_speed *= -1
    ball_y += y_speed
    if ball_y > 584 or ball_y < 0:
        y_speed *= -1
    if keyboard.a:
        pannel.x-=5
    elif keyboard.d:
        pannel.x+=5
    if ball_x-pannel.x>=0 and ball_x-pannel.x<=80\
        and pannel.y-ball_y<=16 and pannel.y-ball_y>=0:
        y_speed *= -1
        if not last_ball_y > 500:
            score += 1
    if ball_y == 588:
        # Do something to handle game over...
        pass
    if (ball_y - last_ball_y) > 20:
       last_ball_y = ball_y


pgzrun.go()

点赞0


评论