穿过云朵升一级是要花6个金币的,有的时候金币真的很重要
前言
嗨喽,大家好呀!这里是魔王~
一天晚上,天空中掉下一颗神奇的豌豆种子,正好落在了梦之森林的村长屋附近。
种子落地后吸收了池塘的水分,迅速成长,一夜之间变成参天大藤蔓……
第二天早上,村民们醒来后看到巨大的藤蔓都惊呆了,聚在一起议论纷纷。
有人说他似乎看到村长的房子在高耸入云的藤蔓上,房子似乎还在上升,有人号召说应该爬上去救村长,玩家需要破解难题,成功写出代码,通关游戏,救出村长~🤭
今天本博主就带着大家自制一款开心消消乐,还原度超高哦~还在等什么动动手就能拥有属于自
己的”消消乐“小游戏呢,赶快学起来吧~
一、准备
1.1 图片素材 🖼
1.2 音频素材 🎶
二、代码
2.1 导入模块
import pygame
import random
from pygame.locals import *
2.2 游戏音乐设置
class SoundPlay:
game_bgm = "sound/GameSceneBGM.ogg"
world_bgm = 'sound/WorldSceneBGM.ogg'
eliminate = ('sound/eliminate1.ogg', 'sound/eliminate2.ogg', 'sound/eliminate3.ogg', 'sound/eliminate4.ogg',\
'sound/eliminate5.ogg') # 消除声音
score_level = ('sound/good.ogg', 'sound/great.ogg', 'sound/amazing.ogg', 'sound/excellent.ogg',\
'sound/unbelievable.ogg') # 得分声音
click = "sound/click.bubble.ogg" # 点击选中声音
board_sound = 'sound/board.ogg' # 落板子声音
click_button = 'sound/click_common_button.ogg' # 点击按钮声音
money_sound = 'sound/money.ogg' # 点击银币声音
ice_break = 'sound/ice_break.ogg' # 冰消除声音
def __init__(self, filename, loops=0):
self.sound = pygame.mixer.Sound(filename)
self.sound.play(loops)
2.3 制作树类
class Tree(pygame.sprite.Sprite):
"""树类"""
tree = 'pic2/tree.png' # 树
fruit = 'pic2/fruit.png' # 果子
energy_num = 'pic2/energy_num.png' # 精力
money = 'pic2/money.png' # 银币
energy_buy = 'pic2/energy_buy.png' # 购买精力
x, y = 340, 510
h = 90
position = ([x, y], [x+50, y-25], [x+105, y-45], [x-5, y-h-5], [x+55, y-25-h+10], [x+105, y-45-h], \
[x, y-h*2], [x+50+10, y-25-h*2-5], [x+105+25, y-45-h*2-14], [x+30, y-h*3-30]) # 果子坐标组
energy_num_position = (15, 70) # 精力坐标
energy_buy_position = (250, 400)
def __init__(self, icon, position):
super().__init__()
self.image = pygame.image.load(icon).convert_alpha()
self.rect = self.image.get_rect()
self.rect.bottomleft = position # 左下角为坐标
def draw(self, screen):
screen.blit(self.image, self.rect)
class ManagerTree:
"""管理树类"""
__screen_size = (900, 600)
screen = pygame.display.set_mode(__screen_size, DOUBLEBUF, 32)
fruit_list = []
fruit_image = pygame.image.load(Tree.fruit).convert_alpha()
fruit_width = fruit_image.get_width()
fruit_height = fruit_image.get_height()
type = 0 # 0树界面,1加精力界面
energy_full = False # 精力已满标志 初始未满
money_empty = False # 银币不足
def load_text(self, text, position, txt_size=25, txt_color=(255, 255, 255)):
my_font = pygame.font.SysFont(None, txt_size)
text_screen = my_font.render(text, True, txt_color)
self.screen.blit(text_screen, position)
def draw_tree(self, energy_num, money_num