0
私はパイゲームには新しく、重力に応じてボールをバウンスさせるプログラムを作ったが、これは完璧に機能するが、今は1つ作成することで無限にできるようにしたいどこをクリックしてもクリックの座標を取得する方法はわかっていますが、複数の円を作成する方法はわかりません。私は何とか関数やクラスを使用しますか?ここで私のコードは、ごめんなさい、少し面倒です。バウンスボールパイゲームの複数のインスタンスを作成する
import pygame,random,time
pygame.init()
infoObject = pygame.display.Info()
side = pygame.display.Info().current_h
side = side - ((1.0/12)*(pygame.display.Info().current_h))
side = int(side)
screen = pygame.display.set_mode([side, side])
pygame.display.set_caption("")
clock = pygame.time.Clock()
done = False
BLACK = (0,0,0)
WHITE = (255,255,255)
RED = (250,30,25)
GREEN = (25, 240, 25)
YELLOW = (250,240,25)
FPS = 60
x=100
y=100
t=0
r=10
direction=0
count = 0
def faller(x,y,color,size):
pygame.draw.circle(screen,color,(x,y),size,0)
def reverse():
global t,direction
if direction == 0:
direction = 1
t=t*4/5
elif direction == 1:
direction = 0
t=1
while not done:
clock.tick(FPS)
events = pygame.event.get()
screen.fill(BLACK)
for event in events:
if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
done = True
if direction==0:
t+=1
y+=int((9.8/FPS)*t)
elif direction==1:
t-=1
y-=int((9.8/FPS)*t)
if t==0:
reverse()
if y+r>side:
y=side-r
faller(x,y,RED,r)
reverse()
else:
faller(x,y,RED,r)
if y==side-r:
count+=1
else:
count=0
if count>=3:
done = True
pygame.display.flip()
pygame.quit()
まあ、たくさんのことを学ぶ準備をしてください! : – rtmh
[ここ](http://www.tutorialsp.com/jp/python/python_functions.htm)と[ここ](http://www.learnpython.org/en/Functions)と[ここ](https: /docs.python.org/3/tutorial/controlflow.html#defining-functions)は、機能に関するリソースです – rtmh
[ここ](https://docs.python.org/2/tutorial/classes.html)と[here] (http://www.tutorialspoint.com/python/python_classes_objects.htm)と[ここ](https://www.codecademy.com/courses/python-intermediate-en-WL8e4/0/1?curriculum_id=4f89dab3d788890003000096)クラスに関するサイトです。私はグーグルで数分間でこれらを手に入れました。それは優れたスキルであり、あなたがプログラムを習得する際に最重要に活用すべきものです。ほとんどの情報は既にそこにあります。スキルは学ぶ方法を学んでいます。運が良かった。 – rtmh