赞
踩
在你的童年记忆里,是否有一个蹦跳、顶蘑菇的小人已经被遗忘?
如果你回忆起了它,你定然会觉得现在它幼稚、无聊,画面不漂亮,游戏不精彩……但请你记住:这才是真正的游戏,它给了你无限的欢乐!许多人只玩过红白机或者网上玩家自己制作的几个破Flash小游戏就还以为任天堂所骄傲的“马里奥”系列就这样子的,你们真的以为超级马里奥就是1985年的“踩蘑菇/采蘑菇”么?
小伙伴们可以关注小编的Python源码、问题解答&学习交流群:733089476
有很多的资源可以白嫖的哈,需要源码的小伙伴可以在+君羊领取
控制马里奥大叔消灭敌人,收集金币,突破障碍在有限的时间内快速到达目的地
Python版本:3.7.8
相关模块:
pygame模块;
tools模块;
setup模块;
constants模块;
以及一些python自带的模块。
安装Python并添加到环境变量,pip安装需要的相关模块即可。
main_menu
#python编程小知识教学,入门到精通视频+源码+课件+学习解答加群:733089476 __author__ = 'marble_xu' import pygame as pg from .. import tools from .. import setup from .. import constants as c from .. components import info class Menu(tools.State): def __init__(self): tools.State.__init__(self) persist = { c.COIN_TOTAL: 0, c.SCORE: 0, c.LIVES: 3, c.TOP_SCORE: 0, c.CURRENT_TIME: 0.0, c.LEVEL_NUM: 1, c.PLAYER_NAME: c.PLAYER_MARIO} self.startup(0.0, persist) def startup(self, current_time, persist): self.next = c.LOAD_SCREEN self.persist = persist self.game_info = persist self.overhead_info = info.Info(self.game_info, c.MAIN_MENU) self.setup_background() self.setup_player() self.setup_cursor() def setup_background(self): self.background = setup.GFX['level_1'] self.background_rect = self.background.get_rect() self.background = pg.transform.scale(self.background, (int(self.background_rect.width*c.BACKGROUND_MULTIPLER), int(self.background_rect.height*c.BACKGROUND_MULTIPLER))) self.viewport = setup.SCREEN.get_rect(bottom=setup.SCREEN_RECT.bottom) self.image_dict = { } image = tools.get_image(setup.GFX['title_screen'], 1, 60, 176, 88, (255, 0, 220), c.SIZE_MULTIPLIER) rect = image.get_rect() rect.x, rect.y = (170, 100) self.image_dict['GAME_NAME_BOX'] = (image, rect) def setup_player(self): self.player_list = [] player_rect_info = [(178, 32, 12, 16), (178, 128, 12, 16)] for rect in player_rect_info: image = tools.get_image(setup.GFX['mario_bros'], *rect, c.BLACK, 2.9) rect = image.get_rect() rect.x, rect.bottom = 110, c.GROUND_HEIGHT self.player_list.append((image, rect)) self.player_index = 0 def setup_cursor(self): self.cursor = pg.sprite.Sprite() self.cursor.image = tools.get_image(setup.GFX[c.ITEM_SHEET], 24, 160, 8, 8, c.BLACK, 3) rect = self.cursor.image.get_rect() rect.x, rect.y = (220, 358) self.cursor.rect = rect self.cursor.state = c.PLAYER1 def update(self, surface, keys, current_time): self.current_time = current_time self.game_info[c.CURRENT_TIME] = self.current_time self.player_image = self.player_list[self.player_index][0] self.player_rect = self.player_list[self.player_index][1] self.update_cursor(keys) self.overhead_info.update(self.game_info) surface.blit(self.background, self.viewport, self.viewport) surface.blit(self.image_dict['GAME_NAME_BOX'][0], self.image_dict['GAME_NAME_BOX'][1]) surface.blit(self.player_image, self.player_rect) surface.blit(self.cursor.image, self.cursor.rect) self.overhead_info.draw(surface) def update_cursor(self, keys): if self.cursor.state == c.PLAYER1: self.cursor.rect.y = 358 if keys[pg.K_DOWN]: self.cursor.state = c.PLAYER2 self.player_index = 1 self.game_info[c.PLAYER_NAME] = c.PLAYER_LUIGI elif self.cursor.state == c.PLAYER2: self.cursor.rect.y = 403 if keys[pg.K_UP]: self.cursor.state = c.PLAYER1 self.player_index = 0 self.game_info[c.PLAYER_NAME] = c.PLAYER_MARIO if keys[pg.K_RETURN]: self.reset_game_info() self.done = True def reset_game_info(self): self.game_info[c.COIN_TOTAL] = 0 self.game_info[c.SCORE] = 0 self.game_info[c.LIVES] = 3 self.game_info[c.CURRENT_TIME] = 0.0 self.game_info[c.LEVEL_NUM] = 1 self.persist = self.game_info
load_screen
#python编程小知识教学,入门到精通视频+源码+课件+学习解答加群:733089476 __author__ = 'marble_xu' from .. import setup, tools from .. import constants as c from ..components import info class LoadScreen(tools.State): def __init__(self): tools.State.__init__(self) self.time_list = [2400, 2600, 2635] def startup(self, current_time, persist): self.start_time = current_time self.persist = persist self.game_info = self.persist self.next = self.set_next_state() info_state = self.set_info_state() self.overhead_info = info.Info(self.game_info, info_state) def set_next_state(self): return c.LEVEL def set_info_state(self): return c.LOAD_SCREEN def update(self, surface, keys, current_time): if (current_time - self.start_time) < self.time_list[0]: surface.fill(c.BLACK) self.overhead_info.update(self.game_info) self.overhead_info.draw(surface) elif (current_time - self.start_time) < self.time_list[1]: surface.fill(c.BLACK) elif (current_time - self.start_time) < self.time_list[2]: surface.fill((106, 150, 252)) else: self.done = True class GameOver(LoadScreen): def __init__(self): LoadScreen.__init__(self) self.time_list = [3000, 3200, 3235] def set_next_state(self): return c.MAIN_MENU def set_info_state(self): return c
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。