成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

程序員自制游戲:超級(jí)瑪麗100%真實(shí)版,能把你玩哭了~【附源碼】

Salamander / 1593人閱讀

摘要:模塊安裝統(tǒng)一用的豆瓣鏡像源模塊名。圖片素材背景音樂(lè)字體可修改開(kāi)始敲代碼運(yùn)行程序。超級(jí)瑪麗源碼基地配置音樂(lè)文字等。

導(dǎo)語(yǔ)?

哈嘍!哈嘍!我是木木子?,今日游戲更新——超級(jí)瑪麗華麗上線?啦!

“超級(jí)瑪麗”有多少人還記得這款經(jīng)典游戲?對(duì)于90、00后應(yīng)該不大熟悉,但多多少少印象中見(jiàn)過(guò)

那個(gè)戴帽子的大胡子穿著背帶褲的馬里奧?!

?

?這款游戲1985年發(fā)售,因上手簡(jiǎn)單、情節(jié)有趣等因素迅速走紅!

陪伴70后、80后走過(guò)了青澀難忘的童年超級(jí)瑪麗成了大家心目中的經(jīng)典!

如果你的童年也曾被魔性的?燈~燈燈~燈~燈燈~燈洗腦那就接著來(lái)懷舊一番吧~

今天木木子就帶著大家自制一款超級(jí)瑪麗游戲,還原度超高哦~還在等什么動(dòng)動(dòng)手就能擁有屬于自

己的”超級(jí)瑪麗“游戲呢,趕快學(xué)起來(lái)吧???????~

正文?

嗯吶~寫游戲Python還是用的Pygame模塊啦

1)準(zhǔn)備中?

1.1環(huán)境安裝?

Python3、Pycharm、Pygame模塊很多自帶的模塊等。

模塊安裝統(tǒng)一用的豆瓣鏡像源:?

pip install -i https://pypi.douban.com/simple/ +模塊名。

1.2圖片素材+背景音樂(lè)+字體(可修改)?

2)開(kāi)始敲代碼?

2.1 運(yùn)行程序:mario_level_1.py。?

#!/usr/bin/env python__author__ = "超級(jí)瑪麗-源碼基地""""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()

2.2 配置音樂(lè)文字等setup.py。?

__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"))

2.3游戲音樂(lè)設(shè)置game_sound.py。?

__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()

2.4取得的分?jǐn)?shù)?

__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)

?3)完整的游戲?

由于代碼太多太多了如下圖所示:所以還是放在文末自己拿完整的代碼哈!

?4)效果展示(僅部分)?

4.0 展示動(dòng)態(tài)視頻一波,完美。?

超級(jí)馬里奧動(dòng)態(tài)視頻

4.1 Part 1 游戲運(yùn)行界面——?

?4.2 Part 2 三條命——?

4.3 Part 3 吃了蘑菇的馬里奧——?

總結(jié)?

雖然現(xiàn)在市面上沖擊著各種游戲,但在我們心目中馬里奧依舊是那個(gè)留著意式大胡子,上天盾地,

無(wú)所不能,頭頂金幣,腳踏烏龜拯救公主的超級(jí)英雄!

對(duì)游戲感興趣的小伙伴兒趕緊自己動(dòng)手造一個(gè)吧~

?

你們的支持是我最大的動(dòng)力!!記得三連哦~mua?歡迎大家閱讀往期的文章哦~

關(guān)注小編獲取更多精彩內(nèi)容!

文章匯總——

Python—2021 |已有文章匯總 | 持續(xù)更新,直接看這篇就夠了

?

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/123047.html

相關(guān)文章

  • 【Pygame實(shí)戰(zhàn)】開(kāi)心——消消樂(lè),你樂(lè),我樂(lè),大家樂(lè)~

    摘要:正文開(kāi)心消消樂(lè)分為二部分首先是開(kāi)心然后是消消樂(lè)游戲嘛嘿嘿一開(kāi)心小故事三則近視聰明的學(xué)生殺手二消消樂(lè)游戲素材圖片開(kāi)心消消樂(lè)語(yǔ)音提示環(huán)境安裝本文是由寫的小游戲。 導(dǎo)語(yǔ) 你今天消消樂(lè)了嗎? ? 哈嘍哈嘍~木木子之前不是寫過(guò)一篇百變消消樂(lè)嘛? 可能你們不記得了,沒(méi)關(guān)系——今天重溫一下,來(lái)一篇開(kāi)心?...

    changfeng1050 評(píng)論0 收藏0
  • 我是如何在自學(xué)編程9個(gè)月后找到工作的

    摘要:昨天在我在國(guó)外網(wǎng)站上看到一篇文章,作者分享了他自學(xué)編程個(gè)月后找到工作的經(jīng)歷。而本文中,我主要針對(duì)想要通過(guò)學(xué)習(xí)編程找工作的角度來(lái)談。我在年月犯了一個(gè)錯(cuò)誤我認(rèn)為首要任務(wù)是找到一份前端開(kāi)發(fā)的工作。 昨天在我在國(guó)外網(wǎng)站 reddit 上看到一篇文章,作者分享了他 自學(xué)編程 9 個(gè)月后找到工作 的經(jīng)歷。文章不到一天就得到3千多贊,2百條回復(fù)。我看了下內(nèi)容,非常中肯,其中有不少建議也是我在編程教室...

    gaosboy 評(píng)論0 收藏0
  • 國(guó)內(nèi)主機(jī)是什么-國(guó)內(nèi)主機(jī)游戲市場(chǎng)冷淡的原因是什么?

    摘要:中國(guó)有自己研發(fā)的游戲主機(jī)嗎是什么樣的水準(zhǔn)這個(gè)問(wèn)題蠻有意思的,中國(guó)是有自己研發(fā)的游戲機(jī)的,早期是以仿制任天堂的為主。以上只是一個(gè)國(guó)內(nèi)主機(jī)游戲市場(chǎng)冷淡一個(gè)小插曲而已,真正的還是國(guó)產(chǎn)網(wǎng)游在中國(guó)游戲史上的根深蒂固。中國(guó)有自己研發(fā)的游戲主機(jī)嗎?是什么樣的水準(zhǔn)?這個(gè)問(wèn)題蠻有意思的,中國(guó)是有自己研發(fā)的游戲機(jī)的,早期是以仿制任天堂的FC為主。小霸王這個(gè)名字相信大部分80后都不陌生。下面具體分析一下。早期的小...

    wenyiweb 評(píng)論0 收藏0
  • 較流暢的Vue2CNode社區(qū)WebApp(源碼)——?dú)g迎交流反饋

    摘要:版社區(qū)假若本項(xiàng)目能給到你一點(diǎn)點(diǎn)幫助,求在線地址掃碼二維碼體驗(yàn)更佳推薦滿大街的重寫,這個(gè)有什么亮點(diǎn)比較接近原生體驗(yàn)流暢的加載過(guò)渡效果舒服細(xì)膩的樣式布局合理的列表渲染優(yōu)化為什么還要重寫版的主要是練手,熟悉全家桶超級(jí)好用組件庫(kù),做一個(gè)最佳實(shí)踐案例 Vue2版CNode社區(qū)WebApp 假若本項(xiàng)目能給到你一點(diǎn)點(diǎn)幫助,求Star! Github:https://github.com/Ryqsky...

    yunhao 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<