我仍在编写我的 Flappy Bird 游戏,我现在正在开始“调试”部分为此,我修复了一些问题,例如没有出现的乐谱文本,我什至自定义了图标以及名称窗口(很少注意细节)。除了我必须纠正一个相当不幸的细节之外,小鸟下落的速度太慢了。因此,玩家无法实现位移,尤其是当小鸟从一对非常高的管道移动到一对非常低的管道时。然而,鸟的跳跃是完美的,我当然不想改变它们!
对我来说,在鸟下落时增加下落速度是合乎逻辑的,但无事可做,我使用了各种方法来编程这个增加的速度,但它们还没有完成。例如,我试图分解鸟的运动,但它没有改变任何东西。我知道我的经验很少,但我认为可以而且我在网上找不到类似的主题
为了让你帮助我,我把我的程序降到了最低限度,只有游戏对象的移动,我知道这周我要求你太多帮助,很抱歉,但我答应了,调整后你再也见不到我了!
from tkinter import *
import random
from random import randint
def sauter(event):
canvas.move(image_oiseau, 0, -10*DY)
def deplacement():
global mouvement
global tuyx,tuyx2,h,H,oisx,oisy,solx,sol2x,score,pause
x0, y0, x1, y1 = canvas.bbox(image_oiseau)
canvas.move(image_oiseau, 0, DY)
canvas.coords(image_sol,solx,512)
if solx >= -144:
solx=solx-5
else:
solx=144
canvas.coords(image_sol2,sol2x,512)
if sol2x >= 144:
sol2x=sol2x-5
else:
sol2x=432
canvas.coords(image_tuyau_haut,tuyx,h)
canvas.coords(image_tuyau_bas,tuyx,h-379.8)
if tuyx>=-28:
tuyx=tuyx-5
else:
tuyx=316
h=randint(272,523)
canvas.coords(image_tuyau_haut2,tuyx2,H)
canvas.coords(image_tuyau_bas2,tuyx2,H-379.8)
if tuyx2>=-28:
tuyx2=tuyx2-5
else:
tuyx2=316
H=randint(272,523)
canvas.after(40,deplacement)
LARGEUR = 286
HAUTEUR = 510
DY = 5
tuyx=316
tuyx2=488
h=randint(272,523)
H=randint(272,523)
oisx=67
oisy=244
solx=144
sol2x=432
fenetre = Tk()
canvas = Canvas(fenetre, width=LARGEUR, height=HAUTEUR)
fond = PhotoImage(file="background-day.png")
fond2 = PhotoImage(file="background-night.png")
fond=[fond,fond2]
F= random.choice(fond)
canvas.create_image(144,256, anchor=CENTER,image=F)
tuyau_haut = PhotoImage(file="tuyau_vers_le_haut.png")
image_tuyau_haut = canvas.create_image(tuyx,h,anchor=CENTER,image=tuyau_haut)
image_tuyau_haut2 = canvas.create_image(tuyx2,H,anchor=CENTER,image=tuyau_haut)
tuyau_bas = PhotoImage(file="tuyau_vers_le_bas.png")
image_tuyau_bas = canvas.create_image(tuyx,h,anchor=CENTER,image=tuyau_bas)
image_tuyau_bas2 = canvas.create_image(tuyx2,H,anchor=CENTER,image=tuyau_bas)
sol = PhotoImage(file="sol-day.png")
image_sol = canvas.create_image(144,512, anchor=S,image=sol)
image_sol2 = canvas.create_image(432,512, anchor=S,image=sol)
oiseau = PhotoImage(file="yellowbird-midflap.png")
oiseau2 = PhotoImage(file="bluebird-midflap.png")
oiseau3 = PhotoImage(file="redbird-midflap.png")
oiseau=[oiseau,oiseau2,oiseau3]
O=random.choice(oiseau)
image_oiseau=canvas.create_image(oisx,oisy, anchor=W,image=O)
canvas.pack()
canvas.focus_set()
deplacement()
canvas.bind("<space>",sauter)
fenetre.mainloop()