国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

Pygame實戰:風靡全球的經典泡泡龍小游戲來襲,你會喜歡嘛?(附源碼)

Turbo / 2887人閱讀

摘要:來來來,跟著木木子一起開始玩泡泡龍游戲吧正文一準備中游戲規則游戲玩法是玩家從下方中央的彈珠發射臺射出彩珠,等于個同色珠相連則會消失。直到完全消除界面上的同款泡泡即可勝利,還可以跟小小伙伴兒比拼,看誰用的彩球越少。

導語

Python版的消除類的游戲還是很多的,木木子之前也是推過不少~

?源碼基地?——主頁左側信息免費拿源碼?往期的源碼也在滴?

比如:百變的消消樂,還記得嘛?今天就出一個消除類——泡泡龍小游戲,希望你們喜歡哈~?!

《泡泡樂》是一款適合全年齡玩家的游戲,采用非常經典的“泡泡龍”式的消除泡泡的玩法,游戲沒

有太多創新玩法,容易上手。

當我們一個人獨處而無人聊天時可以用它來打發時間。來來來,跟著木木子一起開始玩泡泡龍游

戲吧~

?

正文

一、準備中

1)游戲規則:

游戲玩法是玩家從下方中央的彈珠發射臺射出彩珠,等于3個同色珠相連則會消失。直到完全消除

界面上的同款泡泡即可勝利,還可以跟小小伙伴兒比拼, 看誰用的彩球越少。

?2)環境安裝

本文用到的環境:Python3、Pycharm、Pygame以及自帶的。

二、開始敲代碼

1)導入模塊

import math, pygame, sys, os, copy, time, randomimport pygame.gfxdrawfrom pygame.locals import *

2)主程序

FPS          = 120WINDOWWIDTH  = 640WINDOWHEIGHT = 480TEXTHEIGHT   = 20BUBBLERADIUS = 20BUBBLEWIDTH  = BUBBLERADIUS * 2BUBBLELAYERS = 5BUBBLEYADJUST = 5STARTX = WINDOWWIDTH / 2STARTY = WINDOWHEIGHT - 27ARRAYWIDTH = 16ARRAYHEIGHT = 14RIGHT = "right"LEFT  = "left"BLANK = "."## COLORS ###            R    G    BGRAY     = (100, 100, 100)NAVYBLUE = ( 60,  60, 100)WHITE    = (255, 255, 255)RED      = (255,   0,   0)GREEN    = (  0, 255,   0)BLUE     = (  0,   0, 255)YELLOW   = (255, 255,   0)ORANGE   = (255, 128,   0)PURPLE   = (255,   0, 255)CYAN     = (  0, 255, 255)BLACK    = (  0,   0,   0)COMBLUE  = (233, 232, 255)BGCOLOR    = WHITECOLORLIST = [RED, GREEN, BLUE, YELLOW, ORANGE, PURPLE, CYAN]     class Bubble(pygame.sprite.Sprite):    def __init__(self, color, row=0, column=0):        pygame.sprite.Sprite.__init__(self)        self.rect = pygame.Rect(0, 0, 30, 30)        self.rect.centerx = STARTX        self.rect.centery = STARTY        self.speed = 10        self.color = color        self.radius = BUBBLERADIUS        self.angle = 0        self.row = row        self.column = column            def update(self):        if self.angle == 90:            xmove = 0            ymove = self.speed * -1        elif self.angle < 90:            xmove = self.xcalculate(self.angle)            ymove = self.ycalculate(self.angle)        elif self.angle > 90:            xmove = self.xcalculate(180 - self.angle) * -1            ymove = self.ycalculate(180 - self.angle)                self.rect.x += xmove        self.rect.y += ymove    def draw(self):        pygame.gfxdraw.filled_circle(DISPLAYSURF, self.rect.centerx, self.rect.centery, self.radius, self.color)        pygame.gfxdraw.aacircle(DISPLAYSURF, self.rect.centerx, self.rect.centery, self.radius, GRAY)            def xcalculate(self, angle):        radians = math.radians(angle)                xmove = math.cos(radians)*(self.speed)        return xmove    def ycalculate(self, angle):        radians = math.radians(angle)                ymove = math.sin(radians)*(self.speed) * -1        return ymoveclass Arrow(pygame.sprite.Sprite):    def __init__(self):        pygame.sprite.Sprite.__init__(self)        self.angle = 90        arrowImage = pygame.image.load("Arrow.png")        arrowImage.convert_alpha()        arrowRect = arrowImage.get_rect()        self.image = arrowImage        self.transformImage = self.image        self.rect = arrowRect        self.rect.centerx = STARTX         self.rect.centery = STARTY            def update(self, direction):                if direction == LEFT and self.angle < 180:            self.angle += 2        elif direction == RIGHT and self.angle > 0:                    self.angle -= 2        self.transformImage = pygame.transform.rotate(self.image, self.angle)        self.rect = self.transformImage.get_rect()        self.rect.centerx = STARTX         self.rect.centery = STARTY            def draw(self):        DISPLAYSURF.blit(self.transformImage, self.rect)class Score(object):    def __init__(self):        self.total = 0        self.font = pygame.font.SysFont("Helvetica", 15)        self.render = self.font.render("Score: " + str(self.total), True, BLACK, WHITE)        self.rect = self.render.get_rect()        self.rect.left = 5        self.rect.bottom = WINDOWHEIGHT - 5                    def update(self, deleteList):        self.total += ((len(deleteList)) * 10)        self.render = self.font.render("Score: " + str(self.total), True, BLACK, WHITE)    def draw(self):        DISPLAYSURF.blit(self.render, self.rect)def main():    global FPSCLOCK, DISPLAYSURF, DISPLAYRECT, MAINFONT    pygame.init()    FPSCLOCK = pygame.time.Clock()    pygame.display.set_caption("泡泡龍小游戲")    MAINFONT = pygame.font.SysFont("Helvetica", TEXTHEIGHT)    DISPLAYSURF, DISPLAYRECT = makeDisplay()            while True:        score, winorlose = runGame()        endScreen(score, winorlose)def runGame():    musicList =["bgmusic.ogg", "Utopian_Theme.ogg", "Goofy_Theme.ogg"]    pygame.mixer.music.load(musicList[0])    pygame.mixer.music.play()    track = 0    gameColorList = copy.deepcopy(COLORLIST)    direction = None    launchBubble = False    newBubble = None                arrow = Arrow()    bubbleArray = makeBlankBoard()    setBubbles(bubbleArray, gameColorList)        nextBubble = Bubble(gameColorList[0])    nextBubble.rect.right = WINDOWWIDTH - 5    nextBubble.rect.bottom = WINDOWHEIGHT - 5    score = Score()                   while True:        DISPLAYSURF.fill(BGCOLOR)                for event in pygame.event.get():            if event.type == QUIT:                terminate()                            elif event.type == KEYDOWN:                if (event.key == K_LEFT):                    direction = LEFT                elif (event.key == K_RIGHT):                    direction = RIGHT                                elif event.type == KEYUP:                direction = None                if event.key == K_SPACE:                    launchBubble = True                elif event.key == K_ESCAPE:                    terminate()        if launchBubble == True:            if newBubble == None:                newBubble = Bubble(nextBubble.color)                newBubble.angle = arrow.angle                            newBubble.update()            newBubble.draw()                                    if newBubble.rect.right >= WINDOWWIDTH - 5:                newBubble.angle = 180 - newBubble.angle            elif newBubble.rect.left <= 5:                newBubble.angle = 180 - newBubble.angle            launchBubble, newBubble, score = stopBubble(bubbleArray, newBubble, launchBubble, score)            finalBubbleList = []            for row in range(len(bubbleArray)):                for column in range(len(bubbleArray[0])):                    if bubbleArray[row][column] != BLANK:                        finalBubbleList.append(bubbleArray[row][column])                        if bubbleArray[row][column].rect.bottom > (WINDOWHEIGHT - arrow.rect.height - 10):                            return score.total, "lose"                                    if len(finalBubbleList) < 1:                return score.total, "win"                                                                                        gameColorList = updateColorList(bubbleArray)            random.shuffle(gameColorList)                                                                        if launchBubble == False:                                nextBubble = Bubble(gameColorList[0])                nextBubble.rect.right = WINDOWWIDTH - 5                nextBubble.rect.bottom = WINDOWHEIGHT - 5                                                    nextBubble.draw()        if launchBubble == True:            coverNextBubble()                arrow.update(direction)        arrow.draw()                setArrayPos(bubbleArray)        drawBubbleArray(bubbleArray)        score.draw()        if pygame.mixer.music.get_busy() == False:            if track == len(musicList) - 1:                track = 0            else:                track += 1            pygame.mixer.music.load(musicList[track])            pygame.mixer.music.play()                            pygame.display.update()        FPSCLOCK.tick(FPS)def makeBlankBoard():    array = []        for row in range(ARRAYHEIGHT):        column = []        for i in range(ARRAYWIDTH):            column.append(BLANK)        array.append(column)    return arraydef setBubbles(array, gameColorList):    for row in range(BUBBLELAYERS):        for column in range(len(array[row])):            random.shuffle(gameColorList)            newBubble = Bubble(gameColorList[0], row, column)            array[row][column] = newBubble                 setArrayPos(array)def setArrayPos(array):    for row in range(ARRAYHEIGHT):        for column in range(len(array[row])):            if array[row][column] != BLANK:                array[row][column].rect.x = (BUBBLEWIDTH * column) + 5                array[row][column].rect.y = (BUBBLEWIDTH * row) + 5    for row in range(1, ARRAYHEIGHT, 2):        for column in range(len(array[row])):            if array[row][column] != BLANK:                array[row][column].rect.x += BUBBLERADIUS                    for row in range(1, ARRAYHEIGHT):        for column in range(len(array[row])):            if array[row][column] != BLANK:                array[row][column].rect.y -= (BUBBLEYADJUST * row)    deleteExtraBubbles(array)def deleteExtraBubbles(array):    for row in range(ARRAYHEIGHT):        for column in range(len(array[row])):            if array[row][column] != BLANK:                if array[row][column].rect.right > WINDOWWIDTH:                    array[row][column] = BLANKdef updateColorList(bubbleArray):    newColorList = []    for row in range(len(bubbleArray)):        for column in range(len(bubbleArray[0])):            if bubbleArray[row][column] != BLANK:                newColorList.append(bubbleArray[row][column].color)    colorSet = set(newColorList)    if len(colorSet) < 1:        colorList = []        colorList.append(WHITE)        return colorList    else:        return list(colorSet)        def checkForFloaters(bubbleArray):    bubbleList = [column for column in range(len(bubbleArray[0]))                         if bubbleArray[0][column] != BLANK]    newBubbleList = []    for i in range(len(bubbleList)):        if i == 0:            newBubbleList.append(bubbleList[i])        elif bubbleList[i] > bubbleList[i - 1] + 1:            newBubbleList.append(bubbleList[i])    copyOfBoard = copy.deepcopy(bubbleArray)    for row in range(len(bubbleArray)):        for column in range(len(bubbleArray[0])):            bubbleArray[row][column] = BLANK        for column in newBubbleList:        popFloaters(bubbleArray, copyOfBoard, column)def popFloaters(bubbleArray, copyOfBoard, column, row=0):    if (row < 0 or row > (len(bubbleArray)-1)                or column < 0 or column > (len(bubbleArray[0])-1)):        return        elif copyOfBoard[row][column] == BLANK:        return    elif bubbleArray[row][column] == copyOfBoard[row][column]:        return    bubbleArray[row][column] = copyOfBoard[row][column]        if row == 0:        popFloaters(bubbleArray, copyOfBoard, column + 1, row    )        popFloaters(bubbleArray, copyOfBoard, column - 1, row    )        popFloaters(bubbleArray, copyOfBoard, column,     row + 1)        popFloaters(bubbleArray, copyOfBoard, column - 1, row + 1)    elif row % 2 == 0:        popFloaters(bubbleArray, copyOfBoard, column + 1, row    )        popFloaters(bubbleArray, copyOfBoard, column - 1, row    )        popFloaters(bubbleArray, copyOfBoard, column,     row + 1)        popFloaters(bubbleArray, copyOfBoard, column - 1, row + 1)        popFloaters(bubbleArray, copyOfBoard, column,     row - 1)        popFloaters(bubbleArray, copyOfBoard, column - 1, row - 1)    else:        popFloaters(bubbleArray, copyOfBoard, column + 1, row    )        popFloaters(bubbleArray, copyOfBoard, column - 1, row    )        popFloaters(bubbleArray, copyOfBoard, column,     row + 1)        popFloaters(bubbleArray, copyOfBoard, column + 1, row + 1)        popFloaters(bubbleArray, copyOfBoard, column,     row - 1)        popFloaters(bubbleArray, copyOfBoard, column + 1, row - 1)        def stopBubble(bubbleArray, newBubble, launchBubble, score):    deleteList = []    popSound = pygame.mixer.Sound("popcork.ogg")        for row in range(len(bubbleArray)):        for column in range(len(bubbleArray[row])):                        if (bubbleArray[row][column] != BLANK and newBubble != None):                if (pygame.sprite.collide_rect(newBubble, bubbleArray[row][column])) or newBubble.rect.top < 0:                    if newBubble.rect.top < 0:                        newRow, newColumn = addBubbleToTop(bubbleArray, newBubble)                                            elif newBubble.rect.centery >= bubbleArray[row][column].rect.centery:                        if newBubble.rect.centerx >= bubbleArray[row][column].rect.centerx:                            if row == 0 or (row) % 2 == 0:                                newRow = row + 1                                newColumn = column                                if bubbleArray[newRow][newColumn] != BLANK:                                    newRow = newRow - 1                                bubbleArray[newRow][newColumn] = copy.copy(newBubble)                                bubbleArray[newRow][newColumn].row = newRow                                bubbleArray[newRow][newColumn].column = newColumn                                                            else:                                newRow = row + 1                                newColumn = column + 1                                if bubbleArray[newRow][newColumn] != BLANK:                                    newRow = newRow - 1                                bubbleArray[newRow][newColumn] = copy.copy(newBubble)                                bubbleArray[newRow][newColumn].row = newRow                                bubbleArray[newRow][newColumn].column = newColumn                                                                            elif newBubble.rect.centerx < bubbleArray[row][column].rect.centerx:                            if row == 0 or row % 2 == 0:                                newRow = row + 1                                newColumn = column - 1                                if newColumn < 0:                                    newColumn = 0                                if bubbleArray[newRow][newColumn] != BLANK:                                    newRow = newRow - 1                                bubbleArray[newRow][newColumn] = copy.copy(newBubble)                                bubbleArray[newRow][newColumn].row = newRow                                bubbleArray[newRow][newColumn].column = newColumn                            else:                                newRow = row + 1                                newColumn = column                                if bubbleArray[newRow][newColumn] != BLANK:                                    newRow = newRow - 1                                bubbleArray[newRow][newColumn] = copy.copy(newBubble)                                bubbleArray[newRow][newColumn].row = newRow                                bubbleArray[newRow][newColumn].column = newColumn                                                                                elif newBubble.rect.centery < bubbleArray[row][column].rect.centery:                        if newBubble.rect.centerx >= bubbleArray[row][column].rect.centerx:                            if row == 0 or row % 2 == 0:                                newRow = row - 1                                newColumn = column                                if bubbleArray[newRow][newColumn] != BLANK:                                    newRow = newRow + 1                                bubbleArray[newRow][newColumn] = copy.copy(newBubble)                                bubbleArray[newRow][newColumn].row = newRow                                bubbleArray[newRow][newColumn].column = newColumn                            else:                                newRow = row - 1                                newColumn = column + 1                                if bubbleArray[newRow][newColumn] != BLANK:                                    newRow = newRow + 1                                bubbleArray[newRow][newColumn] = copy.copy(newBubble)                                bubbleArray[newRow][newColumn].row = newRow                                bubbleArray[newRow][newColumn].column = newColumn                                                    elif newBubble.rect.centerx <= bubbleArray[row][column].rect.centerx:                            if row == 0 or row % 2 == 0:                                newRow = row - 1                                newColumn = column - 1                                if bubbleArray[newRow][newColumn] != BLANK:                                    newRow = newRow + 1                                bubbleArray[newRow][newColumn] = copy.copy(newBubble)                                bubbleArray[newRow][newColumn].row = newRow                                bubbleArray[newRow][newColumn].column = newColumn                                                            else:                                newRow = row - 1                                newColumn = column                                if bubbleArray[newRow][newColumn] != BLANK:                                    newRow = newRow + 1                                bubbleArray[newRow][newColumn] = copy.copy(newBubble)                                bubbleArray[newRow][newColumn].row = newRow                                bubbleArray[newRow][newColumn].column = newColumn                    popBubbles(bubbleArray, newRow, newColumn, newBubble.color, deleteList)                                                            if len(deleteList) >= 3:                        for pos in deleteList:                            popSound.play()                            row = pos[0]                            column = pos[1]                            bubbleArray[row][column] = BLANK                        checkForFloaters(bubbleArray)                                                score.update(deleteList)                    launchBubble = False                    newBubble = None    return launchBubble, newBubble, score                    def addBubbleToTop(bubbleArray, bubble):    posx = bubble.rect.centerx    leftSidex = posx - BUBBLERADIUS    columnDivision = math.modf(float(leftSidex) / float(BUBBLEWIDTH))    column = int(columnDivision[1])    if columnDivision[0] < 0.5:        bubbleArray[0][column] = copy.copy(bubble)    else:        column += 1        bubbleArray[0][column] = copy.copy(bubble)    row = 0        return row, column        def popBubbles(bubbleArray, row, column, color, deleteList):    if row < 0 or column < 0 or row > (len(bubbleArray)-1) or column > (len(bubbleArray[0])-1):        return    elif bubbleArray[row][column] == BLANK:        return        elif bubbleArray[row][column].color != color:        return    for bubble in deleteList:        if bubbleArray[bubble[0]][bubble[1]] == bubbleArray[row][column]:            return    deleteList.append((row, column))    if row == 0:        popBubbles(bubbleArray, row,     column - 1, color, deleteList)        popBubbles(bubbleArray, row,     column + 1, color, deleteList)        popBubbles(bubbleArray, row + 1, column,     color, deleteList)        popBubbles(bubbleArray, row + 1, column - 1, color, deleteList)    elif row % 2 == 0:                popBubbles(bubbleArray, row + 1, column,         color, deleteList)        popBubbles(bubbleArray, row + 1, column - 1,     color, deleteList)        popBubbles(bubbleArray, row - 1, column,         color, deleteList)        popBubbles(bubbleArray, row - 1, column - 1,     color, deleteList)        popBubbles(bubbleArray, row,     column + 1,     color, deleteList)        popBubbles(bubbleArray, row,     column - 1,     color, deleteList)    else:        popBubbles(bubbleArray, row - 1, column,     color, deleteList)        popBubbles(bubbleArray, row - 1, column + 1, color, deleteList)        popBubbles(bubbleArray, row + 1, column,     color, deleteList)        popBubbles(bubbleArray, row + 1, column + 1, color, deleteList)        popBubbles(bubbleArray, row,     column + 1, color, deleteList)        popBubbles(bubbleArray, row,     column - 1, color, deleteList)            def drawBubbleArray(array):    for row in range(ARRAYHEIGHT):        for column in range(len(array[row])):            if array[row][column] != BLANK:                array[row][column].draw()                    def makeDisplay():    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))    DISPLAYRECT = DISPLAYSURF.get_rect()    DISPLAYSURF.fill(BGCOLOR)    DISPLAYSURF.convert()    pygame.display.update()    return DISPLAYSURF, DISPLAYRECT     def terminate():    pygame.quit()    sys.exit()def coverNextBubble():    whiteRect = pygame.Rect(0, 0, BUBBLEWIDTH, BUBBLEWIDTH)    whiteRect.bottom = WINDOWHEIGHT    whiteRect.right = WINDOWWIDTH    pygame.draw.rect(DISPLAYSURF, BGCOLOR, whiteRect)def endScreen(score, winorlose):    endFont = pygame.font.SysFont("Helvetica", 20)    endMessage1 = endFont.render("You " + winorlose + "! Your Score is " + str(score) + ". Press Enter to Play Again.", True, BLACK, BGCOLOR)    endMessage1Rect = endMessage1.get_rect()    endMessage1Rect.center = DISPLAYRECT.center    DISPLAYSURF.fill(BGCOLOR)    DISPLAYSURF.blit(endMessage1, endMessage1Rect)    pygame.display.update()    while True:        for event in pygame.event.get():            if event.type == QUIT:                terminate()            elif event.type == KEYUP:                if event.key == K_RETURN:                    return                elif event.key == K_ESCAPE:                    terminate()                if __name__ == "__main__":    main()

三、效果展示

空格鍵是發球、方向鍵左右是遙控箭頭的。

1)運行界面

?2)同色三個可消除

?3)結束頁面

一顆球是10個成績點,界面的球被我消了總的591個才結束這個游戲!2333,有點難

總結

嘿!小游戲寫到這結束了,自己動手玩一玩吖~哈哈哈?。源碼都是免費拿滴~滴滴我!

于?茫茫人海相遇——感謝你的閱讀!相遇即是緣分,如有幫助到你,記得三連哦~

我是木木子,一個不止能編程的女碼農,還能教你玩游戲、制作節日驚喜、甚至撩小姐姐、小哥哥的表白小程序哦......

寫在最后——往期也有很多精彩內容,歡迎閱讀!關注我,每日更新??

?源碼基地:

私信小編06或點擊這行藍色字體即可免費拿!往期的也在哦

?文章匯總——

1.1Python—2021 |已有文章匯總 | 持續更新,直接看這篇就夠了~

?

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/123377.html

相關文章

  • Pygame實戰】嗷大喵歷險記之程序員吸貓指南:真太上頭了~

    摘要:嗷大喵和他的小伙伴們快樂的生活在一起,他們總是能給大家帶來歡樂。大家都說嗷大喵真棒。大家要做的就是解救嗷大喵遠離惡龍。 導語 哈嘍~大家好,我是木子,首先今天木子先給大家講個小故事: 在喵界有這樣一只網紅——混跡于二次元、表情包界,賤萌活潑,調皮機靈,白色的大圓臉,脖子 上系了個鈴鐺,年齡不...

    dreamans 評論0 收藏0
  • Pygame實戰】開心——消消樂,你樂,我樂,大家樂~

    摘要:正文開心消消樂分為二部分首先是開心然后是消消樂游戲嘛嘿嘿一開心小故事三則近視聰明的學生殺手二消消樂游戲素材圖片開心消消樂語音提示環境安裝本文是由寫的小游戲。 導語 你今天消消樂了嗎? ? 哈嘍哈嘍~木木子之前不是寫過一篇百變消消樂嘛? 可能你們不記得了,沒關系——今天重溫一下,來一篇開心?...

    changfeng1050 評論0 收藏0
  • Pygame實戰:慎點|虐單身狗最高境界是…【源碼

    摘要:導語各位戲精大家好我是木木子,這個中秋已經結束了,你們都帶著對象回家了碼中秋那幾天朋友圈簡直是大型秀恩愛現場。 導語 各位戲精大家好!我是木木子,這個中秋已經結束了,你們都帶著對象回家了碼? 中秋那幾天朋友圈簡直是大型秀恩愛現場。 又是一年中秋夜,依舊憑實力單身!呼吁大家記得保護下單身狗啊喂...

    DDreach 評論0 收藏0
  • Pygame實戰:記憶差怎么辦?別急,增強記憶力游戲送給你~【越玩越上癮】

    摘要:導語哈嘍大家好,我是木木子。首先準備好相應的圖片這里準備的。 導語 哈嘍!大家好,我是木木子。 今日游戲更新系列來啦,是不是很想知道今天的游戲是什么類型的?立馬安排上—— 隨著年紀的不斷上升,我們開始丟三落四,忘東忘西,記憶力越來越差了! 這不止大人隨著年紀增大記憶力退卻,其實很多小孩子也...

    nanfeiyan 評論0 收藏0

發表評論

0條評論

最新活動
閱讀需要支付1元查看
<