用户:
天边云霞aaa查看:0 回复:1 评论:0 创建时间:2023-03-24T18:07:43
【作品展示】

【作品介绍】
adws移动球球大作战
吃小球变大
【作品源代码】
import pygame as pg
import random as rd
import math
pg.init()
sc = pg.display.set_mode((700, 700))
sc.fill((0, 0, 0))
class Ball():
def __init__(self):
self.coler = (255, 0, 0)
self.x = 350
self.y = 350
self.size = 15
me = Ball()
class Food():
def __init__(self):
self.coler = (rd.randint(200, 255), rd.randint(
200, 255), rd.randint(200, 255))
self.x = rd.randint(0, 700)
self.y = rd.randint(0, 700)
foods = []
for i in range(100):
foods.append(Food())
def draw():
sc.fill((0, 0, 0))
pg.draw.circle(sc, me.coler, (me.x, me.y), me.size, 0)
for i in foods:
pg.draw.circle(sc, i.coler, (i.x, i.y), rd.randint(1, 3), 0)
pg.display.update()
def control():
keys = pg.key.get_pressed()
speed = rd.randint(1, 5)
if keys[pg.K_w] == 1:
me.y -= speed
if keys[pg.K_s] == 1:
me.y += speed
if keys[pg.K_a] == 1:
me.x -= speed
if keys[pg.K_d] == 1:
me.x += speed
def distancrTo(x1, x2, y1, y2):
return math.sqrt((x1-x2)**2+(y1-y2)**2)
def isTouching(x1, x2, y1, y2, dis):
if distancrTo(x1, x2, y1, y2) <= dis:
return True
def eat():
for i in range(len(foods)):
if isTouching(me.x, foods[i].x, me.y, foods[i].y, me.size):
me.size += 1
foods.pop(i)
break
def more():
if pg.time.get_ticks() % 10000 < 10:
for i in range(50):
foods.append(Food())
clock = pg.time.Clock()
while True:
clock.tick(60)
event = pg.event.poll()
if event.type == pg.QUIT:
pg.quit()
exit()
draw()
control()
eat()
more()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn