欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于Python編寫(xiě)一個(gè)中秋節(jié)嫦娥投食小游戲

 更新時(shí)間:2022年09月06日 08:46:09   作者:輕松學(xué)Python  
今天給大家?guī)?lái)的是給玉兔投喂月餅的小游戲。八月十五中秋夜晚,讓我們對(duì)著月亮許愿:希望我們?cè)谝夂驮谝馕覀兊娜?,諸邪避退、百事無(wú)忌、平安喜樂(lè)、萬(wàn)事勝意。提前祝大家中秋節(jié)快樂(lè)

山河遠(yuǎn)闊,煙火人間,又一年,千里嬋娟~

今天給大家?guī)?lái)的是給玉兔投喂月餅的小游戲。八月十五中秋夜晚,讓我們對(duì)著月亮許愿:希望我們?cè)谝夂驮谝馕覀兊娜?,諸邪避退、百事無(wú)忌、平安喜樂(lè)、萬(wàn)事勝意。提前祝大家中秋節(jié)快樂(lè)。

中秋節(jié)的起源

中秋節(jié)起源于上古時(shí)代,普及于漢代,定型于唐朝初年,盛行于宋朝以后。中秋節(jié)是秋季時(shí)令習(xí)俗的綜合,其所包含的節(jié)俗因素,大都有古老的淵源。中秋節(jié)以月之圓兆人之團(tuán)圓,為寄托思念故鄉(xiāng),思念親人之情,祈盼豐收、幸福,成為豐富多彩、彌足珍貴的文化遺產(chǎn)。

游戲設(shè)計(jì)

1、游戲背景

故事的開(kāi)始,中秋佳節(jié)至,玉兔因?yàn)樨澩姹悔s下人間,抬頭望向天際,總是不自覺(jué)的會(huì)想起蘇軾的詞:“但愿人久,千里共嬋娟”。這是一年中,最溫柔又最有詩(shī)意的節(jié)日,可惜玉兔與嫦娥今年不能相聚,但嫦娥為了不讓玉兔餓肚子,在八月十五中秋節(jié)的晚上,嫦娥在月球?yàn)橛裢猛妒吃嘛?hellip;…為了讓玉兔吃到更多,嫦娥開(kāi)啟全民投食,只要給博主三連,就能給玉兔投食月餅啦!難道你忍心看到可愛(ài)的玉兔餓肚子嗎?

2、功能設(shè)計(jì)

人物:玉兔使用鼠標(biāo)來(lái)控制左右運(yùn)動(dòng)

月餅:隨機(jī)從上界降落至下界,當(dāng)碰到玉兔時(shí),加10分,落到下界減5分。

月亮:隨機(jī)從上界降落至下界,當(dāng)碰到玉兔時(shí),減5分,且血條減一格。

血條:HP

值為3格時(shí),生命為滿(mǎn)值,當(dāng)碰到月亮?xí)r減1格。減為0格時(shí),游戲結(jié)束。

開(kāi)始:開(kāi)始按鈕,鼠標(biāo)點(diǎn)擊即開(kāi)始游戲

重來(lái):重來(lái)按鈕,鼠標(biāo)點(diǎn)擊即重新開(kāi)始

效果展示

兔兔是不是很可愛(ài)嘞!

代碼素材

環(huán)境如下

python 3.8.0

pygame 2.1.0

代碼

看看素材地址是否一致,不一致要改成素材本地的地址。

import pygame
import random
 
pygame.init()
sc = pygame.display.set_mode((600, 695))
pygame.display.set_caption("玉兔吃月餅——猿童學(xué)祝大家中秋節(jié)快樂(lè)!")
basket = pygame.image.load("pic/basket.png")
bj = pygame.image.load("pic/bj.jpg")
bomb = pygame.image.load("pic/bomb.png")
coin = pygame.image.load("pic/coin.png")
start = pygame.image.load("pic/start.jpg")
over = pygame.image.load("pic/over.jpg")
ihp = pygame.image.load("pic/hp.png")
btn_up = pygame.image.load("pic/btn_up.png")
btn_down = pygame.image.load("pic/btn_down.png")
bbtn_up = pygame.image.load("pic/bbtn_up.png")
bbtn_down = pygame.image.load("pic/bbtn_down.png")
word = "HP"
font = pygame.font.SysFont("", 32)
text = font.render(word, True, (75, 217, 65))
score = 0
text1 = font.render(str(score), True, (255, 255, 255))
bx = 0
lx, ly = [], []
fx, fy = [], []
speedy = 1
hp = 4
# 月餅生成的序列,通過(guò)序列可以源源不斷生成月餅
for i in range(0, 4):
    tx = random.randint(0, 586)
    ty = (i - 1) * 150
    lx.append(tx)
    ly.append(ty)
 
# 月亮生成的序列
for i in range(0, 2):
    x = random.randint(0, 586)
    y = (i - 1) * 300
    fx.append(x)
    fy.append(y)
 
 
# 按鈕類(lèi)和按鈕點(diǎn)擊事件
class Button(object):
    def __init__(self, btn_up, btn_down, position):
        self.btn_up = btn_up
        self.btn_down = btn_down
        self.position = position
 
    def isOver(self):
        point_x, point_y = pygame.mouse.get_pos()
        x, y = self.position
        w, h = self.btn_down.get_size()
 
        in_x = x - w / 2 < point_x < x + w / 2
        in_y = y - h / 2 < point_y < y + h / 2
        return in_x and in_y
 
    def isPressed(self):
        if event.type == pygame.MOUSEBUTTONDOWN:
            point_x, point_y = pygame.mouse.get_pos()
            x, y = self.position
            w, h = self.btn_down.get_size()
            in_x = x - w / 2 < point_x < x + w / 2
            in_y = y - h / 2 < point_y < y + h / 2
            return True
 
    def render(self):
        w, h = self.btn_up.get_size()
        x, y = self.position
 
        if self.isOver():
            sc.blit(self.btn_down, (x - w / 2, y - h / 2))
        else:
            sc.blit(self.btn_up, (x - w / 2, y - h / 2))
 
 
button = Button(btn_up, btn_down, (288, 460))
 
bbutton = Button(bbtn_up, bbtn_down, (288, 460))
 
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    # 游戲開(kāi)始界面
    sc.blit(start, (0, 0))
    bbutton.render()
    if bbutton.isPressed():
        hp = 3
        score = 0
        text1 = font.render(str(score), True, (255, 255, 255))
    # 進(jìn)入游戲
    if hp > 0 and hp < 4 and score >= 0:
        sc.blit(bj, (0, 0))
        sc.blit(text, (10, 583))
        sc.blit(text1, (570, 570))
        sc.blit(basket, (bx, 540))
        # 難度變化
        if score <= 50:
            speedy = 0.4
        if score > 100:
            speedy = 0.8
        if score > 150:
            speedy = 1.2
        if score > 200:
            speedy = 1.6
        for i in range(len(lx)):
            sc.blit(coin, (lx[i], ly[i] - 600))
            ly[i] += speedy
            if ly[i] > 610 + 600:
                ly[i] = 600
                lx[i] = random.randint(0, 540)
                score -= 5
                text1 = font.render(str(score), True, (255, 255, 255))
            # 玉兔的寬62 高 48
            # 碰撞判斷
            if lx[i] + 24 > bx and \
                    lx[i] + 24 < bx + 62 and \
                    ly[i] >= 1120 and \
                    ly[i] <= 1140:
                ly[i] = 600
                lx[i] = random.randint(0, 586)
                score += 10
                text1 = font.render(str(score), True, (255, 255, 255))
        for i in range(len(fx)):
            sc.blit(bomb, (fx[i], fy[i] - 600))
            fy[i] += speedy
            if fy[i] > 610 + 600:
                fy[i] = 600
                fx[i] = random.randint(0, 545)
 
            if fx[i] + 24 > bx and \
                    fx[i] + 24 < bx + 62 and \
                    fy[i] >= 1120 and \
                    fy[i] <= 1140:
                hp -= 1
                fy[i] = 600
                fx[i] = random.randint(0, 586)
 
        # 籃子跟隨鼠標(biāo)運(yùn)動(dòng)
        if event.type == pygame.MOUSEMOTION:
            mx, my = pygame.mouse.get_pos()
            bx = mx - 24
        if bx < 0:
            bx = 0
        if bx > 610 - 62:
            bx = 548
        # 通過(guò)鍵盤(pán)控制籃子
        keys = pygame.key.get_pressed()
        if keys[pygame.K_a] or \
                keys[pygame.K_RIGHT]:
            bx += 5
        if keys[pygame.K_d] or \
                keys[pygame.K_LEFT]:
            bx += -5
        for i in range(0, hp):
            sc.blit(ihp, (22 * i + 40, 585))
 
    # 重新開(kāi)始游戲
    if hp == 0 or score < 0:
        # 重新初始化游戲
        bx = 0
        speedy = 1
        # 月餅生成的序列
        for i in range(len(lx)):
            lx[i] = random.randint(0, 586)
            ly[i] = (i - 1) * 150
 
        # 月亮生成的序列
        for i in range(len(fx)):
            fx[i] = random.randint(0, 586)
            fy[i] = (i - 1) * 300
        sc.blit(over, (0, 0))
        button.render()
        # 點(diǎn)擊按鈕后重新開(kāi)始游戲
        if button.isPressed():
            hp = 3
            score = 0
            text1 = font.render(str(score), True, (255, 255, 255))
    pygame.display.update()

素材

框框里的是圖片的名字,可以在網(wǎng)上找自己喜歡的素材替換,名字一致即可,下面有一些也提供了多個(gè)選擇。

素材放在pic文件夾中,有如下材料:

basket.png

bj.jpg

bomb.png

coin.png

start.jpg

over.jpg

這里不想找了,所以就一樣了,大家可以更換成自己喜歡的背景。

hp.png

btn_up.png

btn_down.png

bbtn_up.png

bbtn_down.png

到此這篇關(guān)于基于Python編寫(xiě)一個(gè)中秋節(jié)嫦娥投食小游戲的文章就介紹到這了,更多相關(guān)Python嫦娥投食游戲內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論