摘要:模块安装统一用的豆瓣镜像源模块名。图片素材背景音乐字体可修改开始敲代码运行程序。超级玛丽源码基地配置音乐文字等。
哈喽!哈喽!我是木木子?,今日游戏更新——超级玛丽华丽上线?啦!
“超级玛丽”有多少人还记得这款经典游戏?对于90、00后应该不大熟悉,但多多少少印象中见过
那个戴帽子的大胡子穿着背带裤的马里奥?!
?这款游戏1985年发售,因上手简单、情节有趣等因素迅速走红!
陪伴70后、80后走过了青涩难忘的童年超级玛丽成了大家心目中的经典!
如果你的童年也曾被魔性的 灯~灯灯~灯~灯灯~灯洗脑那就接着来怀旧一番吧~
今天木木子就带着大家自制一款超级玛丽游戏,还原度超高哦~还在等什么动动手就能拥有属于自
己的”超级玛丽“游戏呢,赶快学起来吧?????~
嗯呐~写游戏Python还是用的Pygame模块啦
Python3、Pycharm、Pygame模块很多自带的模块等。
模块安装统一用的豆瓣镜像源:
pip install -i https://pypi.douban.com/simple/ +模块名。
#!/usr/bin/env python__author__ = "超级玛丽-源码基地""""This is an attempt to recreate the first level ofSuper Mario Bros for the NES."""import sysimport pygame as pgfrom data.main import mainimport cProfileif __name__=="__main__": main() pg.quit() sys.exit()
__author__ = "Python源码基地""""This module initializes the display and creates dictionaries of resources."""import osimport pygame as pgfrom . import toolsfrom .import constants as cORIGINAL_CAPTION = c.ORIGINAL_CAPTIONos.environ["SDL_VIDEO_CENTERED"] = "1"pg.init()pg.event.set_allowed([pg.KEYDOWN, pg.KEYUP, pg.QUIT])pg.display.set_caption(c.ORIGINAL_CAPTION)SCREEN = pg.display.set_mode(c.SCREEN_SIZE)SCREEN_RECT = SCREEN.get_rect()FONTS = tools.load_all_fonts(os.path.join("resources","fonts"))MUSIC = tools.load_all_music(os.path.join("resources","music"))GFX = tools.load_all_gfx(os.path.join("resources","graphics"))SFX = tools.load_all_sfx(os.path.join("resources","sound"))
__author__ = "Python顾木子吖"import pygame as pgfrom . import setupfrom . import constants as cclass Sound(object): """Handles all sound for the game""" def __init__(self, overhead_info): """Initialize the class""" self.sfx_dict = setup.SFX self.music_dict = setup.MUSIC self.overhead_info = overhead_info self.game_info = overhead_info.game_info self.set_music_mixer() def set_music_mixer(self): """Sets music for level""" if self.overhead_info.state == c.LEVEL: pg.mixer.music.load(self.music_dict["main_theme"]) pg.mixer.music.play() self.state = c.NORMAL elif self.overhead_info.state == c.GAME_OVER: pg.mixer.music.load(self.music_dict["game_over"]) pg.mixer.music.play() self.state = c.GAME_OVER def update(self, game_info, mario): """Updates sound object with game info""" self.game_info = game_info self.mario = mario self.handle_state() def handle_state(self): """Handles the state of the soundn object""" if self.state == c.NORMAL: if self.mario.dead: self.play_music("death", c.MARIO_DEAD) elif self.mario.invincible / and self.mario.losing_invincibility == False: self.play_music("invincible", c.MARIO_INVINCIBLE) elif self.mario.state == c.FLAGPOLE: self.play_music("flagpole", c.FLAGPOLE) elif self.overhead_info.time == 100: self.play_music("out_of_time", c.TIME_WARNING) elif self.state == c.FLAGPOLE: if self.mario.state == c.WALKING_TO_CASTLE: self.play_music("stage_clear", c.STAGE_CLEAR) elif self.state == c.STAGE_CLEAR: if self.mario.in_castle: self.sfx_dict["count_down"].play() self.state = c.FAST_COUNT_DOWN elif self.state == c.FAST_COUNT_DOWN: if self.overhead_info.time == 0: self.sfx_dict["count_down"].stop() self.state = c.WORLD_CLEAR elif self.state == c. TIME_WARNING: if pg.mixer.music.get_busy() == 0: self.play_music("main_theme_sped_up", c.SPED_UP_NORMAL) elif self.mario.dead: self.play_music("death", c.MARIO_DEAD) elif self.state == c.SPED_UP_NORMAL: if self.mario.dead: self.play_music("death", c.MARIO_DEAD) elif self.mario.state == c.FLAGPOLE: self.play_music("flagpole", c.FLAGPOLE) elif self.state == c.MARIO_INVINCIBLE: if (self.mario.current_time - self.mario.invincible_start_timer) > 11000: self.play_music("main_theme", c.NORMAL) elif self.mario.dead: self.play_music("death", c.MARIO_DEAD) elif self.state == c.WORLD_CLEAR: pass elif self.state == c.MARIO_DEAD: pass elif self.state == c.GAME_OVER: pass def play_music(self, key, state): """Plays new music""" pg.mixer.music.load(self.music_dict[key]) pg.mixer.music.play() self.state = state def stop_music(self): """Stops playback""" pg.mixer.music.stop()
__author__ = "源码基地:#959755565#"import pygame as pgfrom .. import setupfrom .. import constants as cclass Digit(pg.sprite.Sprite): """Individual digit for score""" def __init__(self, image): super(Digit, self).__init__() self.image = image self.rect = image.get_rect()class Score(object): """Scores that appear, float up, and disappear""" def __init__(self, x, y, score, flag_pole=False): self.x = x self.y = y if flag_pole: self.y_vel = -4 else: self.y_vel = -3 self.sprite_sheet = setup.GFX["item_objects"] self.create_image_dict() self.score_string = str(score) self.create_digit_list() self.flag_pole_score = flag_pole def create_image_dict(self): """Creates the dictionary for all the number 图片 needed""" self.image_dict = {} image0 = self.get_image(1, 168, 3, 8) image1 = self.get_image(5, 168, 3, 8) image2 = self.get_image(8, 168, 4, 8) image4 = self.get_image(12, 168, 4, 8) image5 = self.get_image(16, 168, 5, 8) image8 = self.get_image(20, 168, 4, 8) image9 = self.get_image(32, 168, 5, 8) image10 = self.get_image(37, 168, 6, 8) image11 = self.get_image(43, 168, 5, 8) self.image_dict["0"] = image0 self.image_dict["1"] = image1 self.image_dict["2"] = image2 self.image_dict["4"] = image4 self.image_dict["5"] = image5 self.image_dict["8"] = image8 self.image_dict["3"] = image9 self.image_dict["7"] = image10 self.image_dict["9"] = image11 def get_image(self, x, y, width, height): """Extracts image from sprite sheet""" image = pg.Surface([width, height]).convert() rect = image.get_rect() image.blit(self.sprite_sheet, (0, 0), (x, y, width, height)) image.set_colorkey(c.BLACK) image = pg.transform.scale(image, (int(rect.width*c.BRICK_SIZE_MULTIPLIER), int(rect.height*c.BRICK_SIZE_MULTIPLIER))) return image def create_digit_list(self): """Creates the group of 图片 based on score received""" self.digit_list = [] self.digit_group = pg.sprite.Group() for digit in self.score_string: self.digit_list.append(Digit(self.image_dict[digit])) self.set_rects_for_images() def set_rects_for_images(self): """Set the rect attributes for each image in self.image_list""" for i, digit in enumerate(self.digit_list): digit.rect = digit.image.get_rect() digit.rect.x = self.x + (i * 10) digit.rect.y = self.y def update(self, score_list, level_info): """Updates score movement""" for number in self.digit_list: number.rect.y += self.y_vel if score_list: self.check_to_delete_floating_scores(score_list, level_info) if self.flag_pole_score: if self.digit_list[0].rect.y <= 120: self.y_vel = 0 def draw(self, screen): """Draws score numbers onto screen""" for digit in self.digit_list: screen.blit(digit.image, digit.rect) def check_to_delete_floating_scores(self, score_list, level_info): """Check if scores need to be deleted""" for i, score in enumerate(score_list): if int(score.score_string) == 1000: if (score.y - score.digit_list[0].rect.y) > 130: score_list.pop(i) else: if (score.y - score.digit_list[0].rect.y) > 75: score_list.pop(i)
由于代码太多太多了如下图所示:所以还是放在文末自己拿完整的代码哈!
超级马里奥动态视频
虽然现在市面上冲击着各种游戏,但在我们心目中马里奥依旧是那个留着意式大胡子,上天盾地,
无所不能,头顶金币,脚踏乌龟拯救公主的超级英雄!
对游戏感兴趣的小伙伴儿赶紧自己动手造一个吧~
你们的支持是我最大的动力!!记得三连哦~mua 欢迎大家阅读往期的文章哦~
Python—2021 |已有文章汇总 | 持续更新,直接看这篇就够了
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/123047.html
摘要:正文开心消消乐分为二部分首先是开心然后是消消乐游戏嘛嘿嘿一开心小故事三则近视聪明的学生杀手二消消乐游戏素材图片开心消消乐语音提示环境安装本文是由写的小游戏。 导语 你今天消消乐了吗? 哈喽哈喽~木木子之前不是写过一篇百变消消乐嘛? 可能你们不记得了,没关系——今天重温一下,来一篇开心?...
摘要:昨天在我在国外网站上看到一篇文章,作者分享了他自学编程个月后找到工作的经历。而本文中,我主要针对想要通过学习编程找工作的角度来谈。我在年月犯了一个错误我认为首要任务是找到一份前端开发的工作。 昨天在我在国外网站 reddit 上看到一篇文章,作者分享了他 自学编程 9 个月后找到工作 的经历。文章不到一天就得到3千多赞,2百条回复。我看了下内容,非常中肯,其中有不少建议也是我在编程教室...
摘要:中国有自己研发的游戏主机吗是什么样的水准这个问题蛮有意思的,中国是有自己研发的游戏机的,早期是以仿制任天堂的为主。以上只是一个国内主机游戏市场冷淡一个小插曲而已,真正的还是国产网游在中国游戏史上的根深蒂固。中国有自己研发的游戏主机吗?是什么样的水准?这个问题蛮有意思的,中国是有自己研发的游戏机的,早期是以仿制任天堂的FC为主。小霸王这个名字相信大部分80后都不陌生。下面具体分析一下。早期的小...
摘要:版社区假若本项目能给到你一点点帮助,求在线地址扫码二维码体验更佳推荐满大街的重写,这个有什么亮点比较接近原生体验流畅的加载过渡效果舒服细腻的样式布局合理的列表渲染优化为什么还要重写版的主要是练手,熟悉全家桶超级好用组件库,做一个最佳实践案例 Vue2版CNode社区WebApp 假若本项目能给到你一点点帮助,求Star! Github:https://github.com/Ryqsky...
阅读 2795·2023-04-26 02:23
阅读 1469·2021-11-11 16:55
阅读 3097·2021-10-19 11:47
阅读 3225·2021-09-22 15:15
阅读 1920·2019-08-30 15:55
阅读 982·2019-08-29 15:43
阅读 1238·2019-08-29 13:16
阅读 2084·2019-08-29 12:38