python pygame 憤怒的小鳥(niǎo)游戲示例代碼
小鳥(niǎo)(image)

游戲展示

代碼展示
import pygame,syspygame.init()#初始化操作#保存窗口大小width,height=600,400screen=pygame.display.set_mode([width,height])#創(chuàng)建游戲窗口#設(shè)置窗口標(biāo)題pygame.display.set_caption('憤怒的小鳥(niǎo)')#加載小鳥(niǎo)素材player=pygame.image.load('xiaoniao.png')#獲取圖像矩形位置rect=player.get_rect()#聲明XY運(yùn)動(dòng)速度的列表speed = [3,2]left_head = pygame.transform.flip(player,True,False)right_head = player#無(wú)限循環(huán)while True: for event in pygame.event.get(): if event.type ==pygame.QUIT: exit() if event.type ==pygame.KEYDOWN: if event.key == pygame.K_LEFT: player = left_head #小鳥(niǎo)的頭向左 speed=[-2,1] if event.key == pygame.K_RIGHT: player = right_head #小鳥(niǎo)的頭向左 speed=[2,1] if event.key == pygame.K_UP: player = left_head #小鳥(niǎo)的頭向左 speed=[2,-1] if event.key == pygame.K_DOWN: player = right_head #小鳥(niǎo)的頭向左 speed=[2,1] rect =rect.move(speed) if rect.right>width or rect.left<0: #將圖片水平翻轉(zhuǎn) 反轉(zhuǎn)對(duì)象 是否水平反轉(zhuǎn) 是否垂直翻轉(zhuǎn) player = pygame.transform.flip(player,True,False) speed[0]=-speed[0] if rect.bottom>height or rect.top<0: speed[1]=-speed[1] screen.fill((255,255,255)) screen.blit(player,rect) pygame.display.update() pygame.time.delay(10)
這就是用python制作的完整原創(chuàng)憤怒小鳥(niǎo),如果有懶得小伙伴可以在我的資源里下載呢,5個(gè)積分即可下載哦!我直接附上資源鏈接好了:python原創(chuàng)游戲
到此這篇關(guān)于python pygame 憤怒的小鳥(niǎo)游戲示例代碼的文章就介紹到這了,更多相關(guān)python憤怒的小鳥(niǎo)內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. PHP驗(yàn)證碼工具-Securimage2. Vue 實(shí)現(xiàn)對(duì)quill-editor組件中的工具欄添加title3. JavaScript實(shí)現(xiàn)簡(jiǎn)單的彈窗效果4. 我所理解的JavaScript中的this指向5. javascript實(shí)現(xiàn)貪吃蛇小練習(xí)6. PHP利用curl發(fā)送HTTP請(qǐng)求的實(shí)例代碼7. Java commons-httpclient如果實(shí)現(xiàn)get及post請(qǐng)求8. PHP單件模式和命令鏈模式的基礎(chǔ)知識(shí)9. 一文帶你徹底理解Java序列化和反序列化10. js實(shí)現(xiàn)碰撞檢測(cè)

網(wǎng)公網(wǎng)安備