国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

隕石掉落,從零開(kāi)始用Python制作飛機(jī)大戰(zhàn)【教程第4集】

2023-07-28 15:07 作者:Scratch_V同學(xué)  | 我要投稿

turtle庫(kù)的飛機(jī)大戰(zhàn):簡(jiǎn)單好理解,

完全自制,可打包




from turtle import Screen, Turtle

import time,random

import winsound

import os


screen = Screen()


screen.register_shape(os.path.join('rock.gif'))

screen.register_shape(os.path.join('player__p.gif'))

screen.register_shape(os.path.join('bullet.gif'))

screen.register_shape(os.path.join('background.gif'))


screen.bgpic(os.path.join('background.gif'))

screen.setup(600, 800)

screen.bgcolor('white')

screen.tracer(0)


player = Turtle()

player.penup()

player.goto(0,-360)

player.shape(os.path.join('player__p.gif'))


zd = Turtle()

zd.color('red')

zd.pu()

zd.seth(90)

zd.hideturtle()

zd.shape(os.path.join('bullet.gif'))


class Scoreboard(Turtle):

? ? def __init__(self):

? ? ? ? super().__init__()

? ? ? ? self.score = 0

? ? ? ? self.penup()

? ? ? ? self.goto(0,250)

? ? ? ? self.pencolor('black')

? ? ? ? self.score_write()

? ? ? ? self.hideturtle()

? ? def score_write(self):

? ? ? ? ? ? ? ? self.clear()

? ? ? ? ? ? ? ? self.write(f'Your scord: {self.score}',align='center',font=('Arial',25,'normal'))

? ? def score_(self):

? ? ? ? self.score += 1

? ? ? ? self.score_write()


scoreboard = Scoreboard()


def dis(a,b,c):

? ? if a.distance(b) < c:

? ? ? ? return True

? ? else:

? ? ? ? return False

def left():

? ? player.goto(player.xcor()-8,player.ycor())

def right():

? ? player.goto(player.xcor()+8,player.ycor())

def fs(): ? ? ?

? ? zd.goto(player.xcor(),-360)

? ? winsound.PlaySound(os.path.join("fire.wav"), winsound.SND_ASYNC)

? ? zd.showturtle()


a = []


screen.listen()

screen.onkey(left,'Left')

screen.onkey(right,'Right')

screen.onkey(fs,'space')


run = True

while run:

? ? screen.update()

? ? if random.randint(1,300) == 1:

? ? ? ? new = Turtle()

? ? ? ? new.shape(os.path.join('rock.gif'))

? ? ? ? new.shapesize(1,1)

? ? ? ? new.pu()

? ? ? ? new.seth(270)

? ? ? ? new.goto(random.randint(-290,290),390)

? ? ? ? a.append(new)

? ? for a_i in a:

? ? ? ? a_i.goto(a_i.xcor(),a_i.ycor() - 0.5)

? ? ? ? if dis(a_i,zd,20):

? ? ? ? ? ? a_i.hideturtle()

? ? ? ? ? ? zd.hideturtle()

? ? ? ? ? ? zd.goto(-30000,280)

? ? ? ? ? ? winsound.PlaySound(os.path.join("hit.wav"), winsound.SND_ASYNC)

? ? ? ? ? ? a_i.goto(-3000,290)

? ? ? ? ? ? scoreboard.score_()

? ? ? ? if dis(a_i,player,50):

? ? ? ? ? ? winsound.PlaySound(os.path.join("end.wav"), winsound.SND_ASYNC)

? ? ? ? ? ? time.sleep(2)

? ? ? ? ? ? run = False

? ? ? ? a_i.left(random.randint(10,30) / 100)

? ? zd.fd(1)

? ? if zd.xcor() > 390:

? ? ? ? zd.hideturtle()

隕石掉落,從零開(kāi)始用Python制作飛機(jī)大戰(zhàn)【教程第4集】的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
扎囊县| 沾益县| 仁寿县| 长丰县| 买车| 华池县| 霍林郭勒市| 井陉县| 望奎县| 博野县| 赤壁市| 正安县| 遂川县| 巴彦县| 福海县| 金堂县| 凤阳县| 巴里| 宁河县| 临洮县| 壶关县| 特克斯县| 礼泉县| 南丰县| 顺平县| 繁峙县| 贞丰县| 北宁市| 报价| 屏山县| 崇礼县| 西藏| 龙南县| 墨玉县| 常熟市| 马龙县| 昭觉县| 红桥区| 金湖县| 沂源县| 攀枝花市|