import pygame
import random
from pygame.locals import *
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)
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):
"""画tree"""
Tree(Tree.tree, (0, 600)).draw(self.screen) # 画树
Tree(Tree.energy_num, Tree.energy_num_position).draw(self.screen) # 画精力
# print("energy", energy_num)
if energy_num > 30:
self.load_text(str(30) + '/30', (22, 55), 21)
else:
self.load_text(str(energy_num)+'/30', (22, 55), 21)
# print("money", money_num)
Tree(Tree.money, (15, 135)).draw(self.screen) # 画银币
self.load_text(str(money_num), (32, 124), 21)
for i in range(0, 10): # 画果子
Tree(Tree.fruit, Tree.position[i]).draw(self.screen)
self.load_text(str(i+1), (Tree.position[i][0]+15, Tree.position[i][1]-47))
if self.type == 1:
Tree(Tree.energy_buy, Tree.energy_buy_position).draw(self.screen)
if self.energy_full:
self.load_text("energy is full!", (430, 310), 30, (255, 0, 0))
pygame.display.flip()
pygame.time.delay(500)
self.energy_full = False
if self.money_empty:
self.load_text("money is not enough!", (410, 310), 30, (255, 0, 0))
pygame.display.flip()
pygame.time.delay(500)
self.money_empty = False
def mouse_select(self, button, level, energy_num, money_num):
"""鼠标点击"""
if button.type == MOUSEBUTTONDOWN:
mouse_down_x, mouse_down_y = button.pos
print(button.pos)
if level == 0:
if self.type == 0: # 树界面
for i in range(0, 10):
if Tree.position[i][0] < mouse_down_x < Tree.position[i][0] + self.fruit_width \
and Tree.position[i][1] - self.fruit_height < mouse_down_y < Tree.position[i][1]:
if energy_num <= 0:
self.type = 1
else:
level = i + 1
if Tree.energy_num_position[0] < mouse_down_x < Tree.energy_num_position[0]+60 \
and Tree.energy_num_position[1]-60 < mouse_down_y < Tree.energy_num_position[1]: # 精力60*60
SoundPlay(SoundPlay.click)
self.type = 1
else: # 加精力弹窗界面
if 408 < mouse_down_x < 600 and 263 < mouse_down_y < 313: # 点加精力按钮
SoundPlay(SoundPlay.click_button)
if money_num < 50:
self.money_empty = True
if energy_num >= 30:
self.energy_full = True
elif energy_num < 30 and money_num >= 50:
energy_num += 5
money_num -= 50
elif 619 < mouse_down_x < 638 and 158 < mouse_down_y < 177: # 点叉号
self.type = 0
if button.type == MOUSEBUTTONUP:
pass
return level, energy_num, money_num
class Element(pygame.sprite.Sprite):
""" 元素类 """
# 图标元组,包括6个小动物,
animal = ('pic2/fox.png', 'pic2/bear.png', 'pic2/chick.png', 'pic2/eagle.png', 'pic2/frog.png', 'pic2/cow.png')
ice = 'pic2/ice.png' # 冰层
brick = 'pic2/brick.png' # 砖
frame = 'pic2/frame.png' # 选中框
bling = ("pic2/bling1.png", "pic2/bling2.png", "pic2/bling3.png", "pic2/bling4.png", "pic2/bling5.png",\
"pic2/bling6.png", "pic2/bling7.png", "pic2/bling8.png", "pic2/bling9.png") # 消除动画
ice_eli = ('pic2/ice0.png', 'pic2/ice1.png', 'pic2/ice2.png', 'pic2/ice3.png', 'pic2/ice4.png', 'pic2/ice5.png',\
'pic2/ice6.png', 'pic2/ice7.png', 'pic2/ice8.png') # 消除冰块动画
# 得分图片
score_level = ('pic2/good.png', 'pic2/great.png', 'pic2/amazing.png', 'pic2/excellent.png', 'pic2/unbelievable.png')
none_animal = 'pic2/noneanimal.png' # 无可消除小动物
stop = 'pic2/exit.png' # 暂停键
stop_position = (20, 530)
def __init__(self, icon, position):
super().__init__()
self.image = pygame.image.load(icon).convert_alpha()
self.rect = self.image.get_rect()
self.rect.topleft = position # 左上角坐标
self.speed = [0, 0]
self.init_position = position
def move(self, speed):
self.speed = speed
self.rect = self.rect.move(self.speed)
if self.speed[0] != 0: # 如果左右移动
if abs(self.rect.left-self.init_position[0]) == self.rect[2]:
self.init_position = self.rect.topleft
self.speed = [0, 0]
else:
if abs(self.rect.top-self.init_position[1]) == self.rect[3]:
self.init_position = self.rect.topleft
self.speed = [0, 0]
def draw(self, screen):
screen.blit(self.image, self.rect)
class Board(pygame.sprite.Sprite):
step_board = 'pic2/step.png' # 剩余步数板子
step = ('pic2/0.png', 'pic2/1.png', 'pic2/2.png', 'pic2/3.png', 'pic2/4.png', 'pic2/5.png',\
'pic2/6.png', 'pic2/7.png', 'pic2/8.png', 'pic2/9.png', )
task_board = 'pic2/task.png'
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
python-pygame-消消乐 (143个子文件)
pyIceHappy-master.iml 543B
GameSceneBGM.mp3 682KB
WorldSceneBGM.mp3 536KB
money.mp3 25KB
unbelievable.mp3 22KB
ice_break.mp3 18KB
amazing.mp3 17KB
excellent.mp3 16KB
board.mp3 14KB
Eliminate8.mp3 14KB
Eliminate4.mp3 13KB
Eliminate7.mp3 13KB
Eliminate1.mp3 13KB
Eliminate5.mp3 13KB
Eliminate2.mp3 13KB
Eliminate6.mp3 13KB
Eliminate3.mp3 13KB
great.mp3 11KB
good.mp3 11KB
click.bubble.mp3 3KB
click.common.button.mp3 3KB
GameSceneBGM.ogg 570KB
WorldSceneBGM.ogg 544KB
money.ogg 26KB
unbelievable.ogg 19KB
amazing.ogg 15KB
board.ogg 15KB
eliminate8.ogg 15KB
eliminate4.ogg 14KB
excellent.ogg 14KB
eliminate6.ogg 14KB
ice_break.ogg 13KB
eliminate2.ogg 13KB
eliminate1.ogg 13KB
eliminate3.ogg 13KB
eliminate7.ogg 12KB
eliminate5.ogg 12KB
good.ogg 11KB
great.ogg 11KB
click.bubble.ogg 9KB
click_common_button.ogg 7KB
tree.png 465KB
bg.png 313KB
failBoard.png 217KB
successtest1.png 183KB
successtest.png 182KB
success.png 176KB
success1.png 174KB
energy_buy.png 52KB
step.png 47KB
noneanimal.png 43KB
unbelievable.png 39KB
amazing.png 27KB
excellent.png 24KB
good.png 20KB
great.png 18KB
level8.png 16KB
level9.png 15KB
level10.png 15KB
level6.png 15KB
level2.png 15KB
level7.png 15KB
level5.png 15KB
level3.png 15KB
level4.png 15KB
level0.png 15KB
level1.png 15KB
replay.png 12KB
next.png 11KB
step_add.png 10KB
startest.png 9KB
task.png 8KB
money.png 7KB
replay-.png 6KB
next-.png 6KB
play_num.png 6KB
energy_num.png 6KB
ice4.png 6KB
ice7.png 6KB
ice6.png 5KB
stop.png 5KB
ice3.png 5KB
step_add-.png 5KB
ice8.png 5KB
ice5.png 5KB
bling9.png 5KB
eagle.png 5KB
bling7.png 5KB
ice2.png 5KB
bling8.png 5KB
bling6.png 5KB
bling5.png 5KB
test.png 5KB
bling4.png 5KB
star.png 5KB
bling3.png 5KB
frog.png 5KB
ice1.png 5KB
bear.png 5KB
cow.png 4KB
共 143 条
- 1
- 2
资源评论
_pray
- 粉丝: 113
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- BLOCK_TYPE_HEARTBEAT_D70A3465D4EE4E9_046141_dump_1st.dmp
- 项目方法测试调用接口工具
- studyupdate
- 基于西瓜数据集的决策树实现.zip
- 60套HTML网站源码-响应式-涵盖(简历&作品展示&商业&科技&培训&商城&课设等)-适配移动设备-解压即用.zip
- 贪心算法要点和难点实例代码解析
- 65套HTML网站源码-响应式-涵盖(简历&作品展示&商业&科技&培训&商城&课设等)-适配移动设备-解压即用.zip
- 多因素决策树的Python实现.zip
- 使用Python在莺尾花数据集上实现了决策树算法,文件里有数据集.zip
- python实现决策树.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功