版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
第PythonPygame實(shí)戰(zhàn)之憤怒的小鳥游戲?qū)崿F(xiàn)elifevent.type==pygame.KEYDOWNandevent.key==pygame.K_s:
space.gravity=(0.0,-10.0)
level.bool_space=True
elifevent.type==pygame.KEYDOWNandevent.key==pygame.K_n:
space.gravity=(0.0,-700.0)
level.bool_space=False
if(pygame.mouse.get_pressed()[0]andx_mouse100and
x_mouse250andy_mouse370andy_mouse550):
mouse_pressed=True
if(event.type==pygame.MOUSEBUTTONUPand
event.button==1andmouse_pressed):
#Releasenewbird
mouse_pressed=False
iflevel.number_of_birds0:
level.number_of_birds-=1
t1=time.time()*1000
xo=154
yo=156
ifmouse_distancerope_lenght:
mouse_distance=rope_lenght
ifx_mousesling_x+5:
bird=Bird(mouse_distance,angle,xo,yo,space)
birds.append(bird)
else:
bird=Bird(-mouse_distance,angle,xo,yo,space)
birds.append(bird)
iflevel.number_of_birds==0:
t2=time.time()
ifevent.type==pygame.MOUSEBUTTONUPandevent.button==1:
if(x_mouse60andy_mouse155andy_mouse90):
game_state=1
ifgame_state==1:
ifx_mouse500andy_mouse200andy_mouse300:
#Resumeinthepausedscreen
game_state=0
ifx_mouse500andy_mouse300:
#Restartinthepausedscreen
restart()
level.load_level()
game_state=0
bird_path=[]
ifgame_state==3:
#Restartinthefailedlevelscreen
ifx_mouse500andx_mouse620andy_mouse450:
restart()
level.load_level()
game_state=0
bird_path=[]
score=0
ifgame_state==4:
#Buildnextlevel
ifx_mouse610andy_mouse450:
restart()
level.number+=1
game_state=0
level.load_level()
score=0
bird_path=[]
bonus_score_once=True
ifx_mouse610andx_mouse500andy_mouse450:
#Restartinthelevelclearedscreen
restart()
level.load_level()
game_state=0
bird_path=[]
score=0
x_mouse,y_mouse=pygame.mouse.get_pos()
#Drawbackground
screen.fill((130,200,100))
screen.blit(background2,(0,-50))
#Drawfirstpartofthesling
rect=pygame.Rect(50,0,70,220)
screen.blit(sling_image,(138,420),rect)
#Drawthetrailleftbehind
forpointinbird_path:
pygame.draw.circle(screen,WHITE,point,5,0)
#Drawthebirdsinthewaitline
iflevel.number_of_birds0:
foriinrange(level.number_of_birds-1):
x=100-(i*35)
screen.blit(redbird,(x,508))
#Drawslingbehavior
ifmouse_pressedandlevel.number_of_birds0:
sling_action()
else:
iftime.time()*1000-t1300andlevel.number_of_birds0:
screen.blit(redbird,(130,426))
else:
pygame.draw.line(screen,(0,0,0),(sling_x,sling_y-8),
(sling2_x,sling2_y-7),5)
birds_to_remove=[]
pigs_to_remove=[]
counter+=1
#Drawbirds
forbirdinbirds:
ifbird.shape.body.position.y0:
birds_to_remove.append(bird)
p=to_pygame(bird.shape.body.position)
x,y=p
x-=22
y-=20
screen.blit(redbird,(x,y))
pygame.draw.circle(screen,BLUE,
p,int(bird.shape.radius),2)
ifcounter=3andtime.time()-t15:
bird_path.append(p)
restart_counter=True
ifrestart_counter:
counter=0
restart_counter=False
#Removebirdsandpigs
forbirdinbirds_to_remove:
space.remove(bird.shape,bird.shape.body)
birds.remove(bird)
forpiginpigs_to_remove:
space.remove(pig.shape,pig.shape.body)
pigs.remove(pig)
#Drawstaticlines
forlineinstatic_lines:
body=line.body
pv1=body.position+line.a.rotated(body.angle)
pv2=body.position+line.b.rotated(body.angle)
p1=to_pygame(pv1)
p2=to_pygame(pv2)
pygame.draw.lines(screen,(150,150,150),False,[p1,p2])
i=0
#Drawpigs
forpiginpigs:
i+=1
#print(i,pig.life)
pig=pig.shape
ifpig.body.position.y0:
pigs_to_remove.append(pig)
p=to_pygame(pig.body.position)
x,y=p
angle_degrees=math.degrees(pig.body.angle)
img=pygame.transform.rotate(pig_image,angle_degrees)
w,h=img.get_size()
x-=w*0.5
y-=h*0.5
screen.blit(img,(x,y))
pygame.draw.circle(screen,BLUE,p,int(pig.radius),2)
#DrawcolumnsandBeams
forcolumnincolumns:
column.draw_poly('columns',screen)
forbeaminbeams:
beam.draw_poly('beams',screen)
#Updatephysics
dt=1.0/50.0/2.
forxinrange(2):
space.step(dt)#maketwoupdatesperframeforbetterstability
#Drawingsecondpartofthesling
rect=pygame.Rect(0,0,60,200)
screen.blit(sling_image,(120,420),rect)
#Drawscore
score_font=bold_font.render("SCORE",1,WHITE)
number_font=bold_font.render(str(score),1,WHITE)
screen.blit(score_font,(1060,90))
ifscore==0:
screen.blit(number_font,(1100,130))
else:
screen.blit(number_font,(1060,130))
screen.blit(pause_button,(10,90))
#Pauseoption
ifgame_state==1:
screen.blit(play_button,(500,200))
screen.blit(replay_button,(500,300))
draw_level_cleared()
draw_level_failed()
pygame.display.flip()
clock.tick(50
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026年環(huán)境評估(土壤環(huán)境質(zhì)量評估)試題及答案
- 2025年中職(醫(yī)學(xué)檢驗(yàn))血常規(guī)檢測實(shí)務(wù)綜合測試題及答案
- 2025年大學(xué)(測繪科學(xué)與技術(shù)專業(yè))地理信息系統(tǒng)基礎(chǔ)試題及答案
- 2025年大學(xué)第四學(xué)年(工程項(xiàng)目融資)融資方案設(shè)計(jì)階段測試題及答案
- 2025年大學(xué)美術(shù)學(xué)(美術(shù)學(xué)概論)試題及答案
- 2025年大學(xué)安全教育(交通安全知識)試題及答案
- 2025年中職(市場開發(fā)實(shí)務(wù))客戶開發(fā)流程階段測試試題及答案
- 2025年中職船舶工程技術(shù)(船舶建造工藝)試題及答案
- 2025年中職道路橋梁工程技術(shù)(路橋施工技術(shù))試題及答案
- 2025年大學(xué)臨床醫(yī)學(xué)(臨床診療技術(shù))試題及答案
- LY/T 3408-2024林下經(jīng)濟(jì)術(shù)語
- 2025年湖南邵陽市新邵縣經(jīng)濟(jì)開發(fā)區(qū)建設(shè)有限公司招聘筆試參考題庫附帶答案詳解
- ICH《M10:生物分析方法驗(yàn)證及樣品分析》
- 國家開放大學(xué)電大24210丨學(xué)前兒童科學(xué)教育活動(dòng)指導(dǎo)(統(tǒng)設(shè)課)期末終考題庫
- 【讀后續(xù)寫】2021年11月稽陽聯(lián)考讀后續(xù)寫講評:Saving the Daisies 名師課件-陳星可
- 教育培訓(xùn)班項(xiàng)目可行性研究報(bào)告
- 人參健康食品營銷策劃
- 2024年人參項(xiàng)目營銷策劃方案
- 工會(huì)職工大會(huì)制度實(shí)施細(xì)則范本
- ups拆除施工方案
- GB/T 21196.4-2007紡織品馬丁代爾法織物耐磨性的測定第4部分:外觀變化的評定
評論
0/150
提交評論