python端午dragboat消消乐 美轮美奂的界面效果
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                python端午dragboat消消乐 美轮美奂的界面效果
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                python端午,dragboat消消樂 美輪美奐的界面效果
- 1. 效果圖
- 2. 源碼
- 2.1 素材準備源碼(消消樂圖、bg音樂)
- 2.2 消消樂源碼
 
- 參考
 
跟著大佬的步伐,消消樂倆步走~~
- 找素材,做消消樂圖,找bg音樂🎵,成功消除🎵,失敗的🎵;
- 上代碼,調試~~
1. 效果圖
原始圖:
 
 使用數組截取得到消消樂的效果圖如下,粽子圖同理
 消消樂游戲效果圖gif如下~
2. 源碼
2.1 素材準備源碼(消消樂圖、bg音樂)
import cv2
import imutils
import numpy as np
from imutils import pathsimage = cv2.imread('images/xx2.jpg')
width = image.shape[0]
print(image.shape)
image = imutils.resize(image, width=400)
cv2.imshow("origin", image)
image = image[89:, 17:]
print(image.shape)
image = image[:70, :278]
print('--: ', image.shape)
img = imutils.resize(image, width=400)
cv2.imshow("slice", img)print(image.shape[0], image.shape[1])
y = [int(j) for j in np.linspace(0, image.shape[1], 6)]
print(y)for i in range(1, 6):cv2.imshow(str(i), imutils.resize(image[0:image.shape[0], y[i-1]:y[i]], width=200))cv2.imwrite("imgs/pacer"+str(i-1)+".png",imutils.resize(image[0:image.shape[0], y[i-1]:y[i]], width=80))imagePaths = list(paths.list_images("images/"))
print('len: ', len(imagePaths))x = [imagePath for imagePath in imagePaths if (imagePath.endswith(".jpg") and imagePath.__contains__('zz'))]
print(x)
for i, imgpath in enumerate(x):print(i + 5, imgpath)cv2.imshow(str(i + 6), imutils.resize(cv2.imread(imgpath), width=200))cv2.imwrite("imgs/pacer" + str(i + 5) + ".png", imutils.resize(cv2.imread(imgpath), width=80))cv2.waitKey(0)bg音樂及成功失敗的🎵,都選自己喜歡的mp3格式就可以
2.2 消消樂源碼
# USAGE
# python .\xxl.py
'''
Function:消消樂
'''
import os
import sysimport cfg
import pygame
from modules.game import pacerGame'''主程序'''def main():pygame.init()screen = pygame.display.set_mode(cfg.SCREENSIZE)pygame.display.set_caption('dragonboat xxl')# 加載背景音樂pygame.mixer.init()pygame.mixer.music.load(os.path.join(cfg.ROOTDIR, "res/audios/bg.mp3"))pygame.mixer.music.set_volume(0.6)pygame.mixer.music.play(-1)# 加載音效sounds = {}# sounds['mismatch'] = pygame.mixer.Sound(os.path.join(cfg.ROOTDIR, 'res/audios/badswap.wav'))sounds['mismatch'] = pygame.mixer.Sound(os.path.join(cfg.ROOTDIR, 'res/audios/badswap.mp3'))sounds['match'] = []for i in range(6):sounds['match'].append(pygame.mixer.Sound(os.path.join(cfg.ROOTDIR, 'res/audios/match%s.mp3' % i)))# sounds['match'].append(pygame.mixer.Sound(os.path.join(cfg.ROOTDIR, 'res/audios/match%s.wav' % i)))# 字體顯示font = pygame.font.Font(os.path.join(cfg.ROOTDIR, 'res/font/font.TTF'), 25)# 星星pacer_imgs = []for i in range(1, 8):pacer_imgs.append(os.path.join(cfg.ROOTDIR, 'res/imgs/pacer%s.png' % i))# 循環game = pacerGame(screen, sounds, font, pacer_imgs, cfg)while True:score = game.start()flag = False# 給出選擇,玩家選擇重玩或者退出while True:for event in pygame.event.get():if event.type == pygame.QUIT or (event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE):pygame.quit()sys.exit()elif event.type == pygame.KEYUP and event.key == pygame.K_r:flag = Trueif flag:breakscreen.fill((136, 207, 236))text0 = 'Final score: %s' % scoretext1 = 'Press <R> to restart the game.'text2 = 'Press <Esc> to quit the game.'y = 150for idx, text in enumerate([text0, text1, text2]):text_render = font.render(text, 1, (85, 65, 0))rect = text_render.get_rect()if idx == 0:rect.left, rect.top = (223, y)elif idx == 1:rect.left, rect.top = (133.5, y)else:rect.left, rect.top = (126.5, y)y += 99screen.blit(text_render, rect)pygame.display.update()game.reset()'''游戲運行'''
if __name__ == '__main__':main()
參考
- https://blog.csdn.net/weixin_42350212/article/details/117765694
總結
以上是生活随笔為你收集整理的python端午dragboat消消乐 美轮美奂的界面效果的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 使用Python,OpenCV实现图像和
- 下一篇: 永劫无间长跑王成就怎么达成?
