PythonPygame實(shí)戰(zhàn)之憤怒的小鳥游戲?qū)崿F(xiàn)_第1頁
PythonPygame實(shí)戰(zhàn)之憤怒的小鳥游戲?qū)崿F(xiàn)_第2頁
PythonPygame實(shí)戰(zhàn)之憤怒的小鳥游戲?qū)崿F(xiàn)_第3頁
PythonPygame實(shí)戰(zhàn)之憤怒的小鳥游戲?qū)崿F(xiàn)_第4頁
PythonPygame實(shí)戰(zhàn)之憤怒的小鳥游戲?qū)崿F(xiàn)_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論