赞
踩
上次分享了一版消消乐,内容毕竟简单,没有升级,过关的乐趣,可消除的区域是固定的,娱乐性不是特别的大,今天给大家带来的是一款进阶版的消消乐。
进阶版的消消乐新增了以下内容,界面也很上一版完全不同。
1、新的游戏界面:
2、新增过关属性,玩家可以根据提示完成相关目标的消除数即可进入下一关。
3、背景音乐升级为更加娱乐性的音乐,欢快更贴合游戏。
4、过关提供相应奖励,增加闯关的乐趣和挑战性。
5、增加连续消除的提示信息,包括(good,great,excellent,unbelievable),提供音效。
6、新增步数特性,玩家需要仔细考虑消除的方块是否可以带来更多效果,确保当前可用剩余步数足够完成过关的目标,当剩余步数已经用完,系统会弹出提示,并可以赠送5步,或者选择重新开始。
由于代码量比较多,这里就不全部贴出来了,贴部分比较重要的:
from pygame.sprite import Sprite from pygame.image import load class Tree(Sprite): '''Tree sprite''' # Images tree = 'img/tree.png' fruit = 'img/fruit.png' energy_num = 'img/energy/num.png' money = 'img/money.png' energy_buy = 'img/energy/buy.png' # Positioning 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]) # Fruit positions energy_num_position = (15, 70) # Energy position energy_buy_position = (250, 400) # "Buy energy" position def __init__(self, icon, position): super().__init__() self.image = load(icon).convert_alpha() self.rect = self.image.get_rect() self.rect.bottomleft = position def draw(self, screen): '''Display the tree on the given screen.''' screen.blit(self.image, self.rect) class Board(Sprite): '''Wooden boards''' # Images step_board = 'img/board/step.png' num_format = 'img/text/%d.png' task_board = 'img/task.png' ok = 'img/ok.png' level_format = 'img/level/%d.png' success = 'img/board/success.png' fail = 'img/board/fail.png' step_add = 'img/button/step_add.png' next = 'img/button/next.png' replay = 'img/button/replay.png' stars = 'img/star.png' money = 'img/money.png' energy = 'img/energ.png' # Positioning button_position = [[300, 465], [500, 465]] starts_position = [[330, 340], [413, 340], [495, 340]] def __init__(self, icon, position): super().__init__() self.image = load(icon).convert_alpha() self.speed = [0, 45] self.rect = self.image.get_rect() self.rect.bottomleft = position def move(self): '''Move the board with its speed.''' self.rect = self.rect.move(self.speed) if self.rect.bottom >= 543: self.speed = [0, -45] if self.speed == [0, -45] and self.rect.bottom <= 450: self.speed = [0, 0] def draw(self, screen): '''Display the board on the given screen.''' screen.blit(self.image, self.rect) class Element(Sprite): '''Element type''' # 6 Animals: (0) Fox, (1) bear, (2) chicken, (3) eagle, (4) frog, (5) cow animals = ('img/animal/fox.png', 'img/animal/bear.png', 'img/animal/chick.png', 'img/animal/eagle.png', 'img/animal/frog.png', 'img/animal/cow.png') ice = 'img/ice/normal.png' brick = 'img/brick.png' frame = 'img/frame.png' # Selection frame bling_format = 'img/bling/%d.png' ice_format = 'img/ice/%d.png' # Score images score_level = ('img/text/good.png', 'img/text/great.png', 'img/text/amazing.png', 'img/text/excellent.png', 'img/text/unbelievable.png') none_animal = 'img/none_animal.png' stop = 'img/exit.png' stop_position = (20, 530) def __init__(self, icon, position): super().__init__() self.image = load(icon).convert_alpha() self.rect = self.image.get_rect() self.rect.topleft = position # Topleft positioning self.speed = [0, 0] self.init_position = position def move(self, speed): '''Move with given speed.''' self.speed = speed self.rect = self.rect.move(self.speed) if self.speed[0] != 0: # Moving horizontally if abs(self.rect.left - self.init_position[0]) == self.rect[2]: self.init_position = self.rect.topleft self.speed = [0, 0] else: # Moving vertically 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): '''Display the element on the given screen.''' screen.blit(self.image, self.rect)
from os import environ environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1' import sys import pygame from pygame.locals import KEYDOWN, QUIT, K_q, K_ESCAPE, MOUSEBUTTONDOWN # pylint: disable=no-name-in-module from manager import Manager, TreeManager from sounds import Sounds # Initialize game pygame.init() # pylint: disable=no-member pygame.mixer.init() pygame.display.set_caption('开心消消乐') pygame.mouse.set_visible(False) tree = TreeManager() m = Manager(0, 0) sound_sign = 0 world_bgm = pygame.mixer.Sound(Sounds.WORLD_BGM.value) game_bgm = pygame.mixer.Sound(Sounds.GAME_BGM.value) # This improves the performance of the game get_events, update_window = pygame.event.get, pygame.display.flip while True: if m.level == 0: if sound_sign == 0: game_bgm.stop() world_bgm.play(-1) sound_sign = 1 else: if sound_sign == 1: world_bgm.stop() game_bgm.play(-1) sound_sign = 0 if m.level == 0: tree.draw_tree(m.energy_num, m.money) else: m.set_level_mode(m.level) sprite_group = m.draw() if m.type == 0: m.eliminate_animals() m.death_map() m.swap(sprite_group) m.judge_level() for event in get_events(): if event.type == KEYDOWN: if event.key in (K_q, K_ESCAPE): sys.exit() elif event.type == QUIT: sys.exit() elif event.type == MOUSEBUTTONDOWN: mousex, mousey = event.pos if m.level == 0: tree.mouse_select(m, mousex, mousey, m.level, m.energy_num, m.money) m.mouse_select(mousex, mousey) m.mouse_image() update_window()
需要游戏素材,和完整代码,公众号回复:开心消消乐 即可获取,长期有效。
今天的分享就到这里,希望感兴趣的同学关注我,每天都有新内容,不限题材,不限内容,你有想要分享的内容,也可以私聊我!
扫一扫 关注我的公众号
如果你想要跟大家分享你的文章,欢迎投稿~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。