import pygame as p
import time
p.init()
screen = p.display.set_mode((682, 500))
# 设置标题 captiion 船长 首都 ----标题
p.display.set_caption("无限接球")
# 具体指应用函数的时候写括号
ballx = 100
bally = 150
ban_x, ban_y, ban_k, ban_g = 300, 460, 120, 40
# 让电脑没过多少毫秒监控一次
p.key.set_repeat(100, 1)
# 1.设置字体 font 字体
ziti = p.font.Font(None, 30)
score = 0
while 1 > 0:
for sj in p.event.get():
# print(sj)
if sj.type == p.QUIT:
p.quit()
# 判断事件类型是不是按键 键 key
elif sj.type == p.KEYDOWN:
# 判断按了哪一个键
if sj.key == p.K_RIGHT:
ban_x = ban_x + 10
elif sj.key == p.K_LEFT:
ban_x = ban_x - 10
# 判断事件类型是不是鼠标动作 motion动作
elif sj.type == p.MOUSEMOTION:
ban_x, _ = sj.pos
screen.fill((120, 255, 30))
bally = bally + 1
if bally > 500:
bally = 0
ballx = ballx + 100
if ballx > 682:
ballx = 0
# 左边空气墙
if ban_x < -50:
ban_x = 5
elif 682 < ban_x:
ban_x = 580
# 画一个小球
p.draw.circle(screen, (172, 85, 255), (ballx, bally), 10, 0)
# 画一个长方形 rect 屏幕 颜色
p.draw.rect(screen, (172, 85, 255), (ban_x, ban_y, ban_k, ban_g), 0)
score = score+1
# 设置文字
text = ziti.render("score:%d"%score, True, (0, 0, 0))
screen.blit(text,(132,436))
p.display.update()
# time.sleep(0.00001)
ziheng -无限接球3.0
最新推荐文章于 2020-03-11 09:52:17 发布