国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python實(shí)現(xiàn)超級(jí)馬里奧

瀏覽:3日期:2022-08-02 09:11:01

本文實(shí)例為大家分享了Python寫超級(jí)馬里奧的具體代碼,供大家參考,具體內(nèi)容如下

完整代碼和素材戳我

主代碼

import pygame as pgfrom source.main import mainif __name__==’__main__’: main() pg.quit()

main

__author__ = ’marble_xu’import pygame as pgfrom . import setup, toolsfrom . import constants as cfrom .states import main_menu, load_screen, leveldef main(): game = tools.Control() state_dict = {c.MAIN_MENU: main_menu.Menu(), c.LOAD_SCREEN: load_screen.LoadScreen(), c.LEVEL: level.Level(), c.GAME_OVER: load_screen.GameOver(), c.TIME_OUT: load_screen.TimeOut()} game.setup_states(state_dict, c.MAIN_MENU) game.main()

setup

__author__ = ’marble_xu’import osimport pygame as pgfrom . import constants as cfrom . import toolspg.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()GFX = tools.load_all_gfx(os.path.join('resources','graphics'))

tools

__author__ = ’marble_xu’import osimport pygame as pgfrom abc import ABC, abstractmethodkeybinding = { ’action’:pg.K_s, ’jump’:pg.K_a, ’left’:pg.K_LEFT, ’right’:pg.K_RIGHT, ’down’:pg.K_DOWN}class State(): def __init__(self): self.start_time = 0.0 self.current_time = 0.0 self.done = False self.next = None self.persist = {} @abstractmethod def startup(self, current_time, persist): ’’’abstract method’’’ def cleanup(self): self.done = False return self.persist @abstractmethod def update(sefl, surface, keys, current_time): ’’’abstract method’’’class Control(): def __init__(self): self.screen = pg.display.get_surface() self.done = False self.clock = pg.time.Clock() self.fps = 60 self.current_time = 0.0 self.keys = pg.key.get_pressed() self.state_dict = {} self.state_name = None self.state = None def setup_states(self, state_dict, start_state): self.state_dict = state_dict self.state_name = start_state self.state = self.state_dict[self.state_name] def update(self): self.current_time = pg.time.get_ticks() if self.state.done: self.flip_state() self.state.update(self.screen, self.keys, self.current_time) def flip_state(self): previous, self.state_name = self.state_name, self.state.next persist = self.state.cleanup() self.state = self.state_dict[self.state_name] self.state.startup(self.current_time, persist) def event_loop(self): for event in pg.event.get(): if event.type == pg.QUIT:self.done = True elif event.type == pg.KEYDOWN:self.keys = pg.key.get_pressed() elif event.type == pg.KEYUP:self.keys = pg.key.get_pressed() def main(self): while not self.done: self.event_loop() self.update() pg.display.update() self.clock.tick(self.fps)def get_image(sheet, x, y, width, height, colorkey, scale): image = pg.Surface([width, height]) rect = image.get_rect() image.blit(sheet, (0, 0), (x, y, width, height)) image.set_colorkey(colorkey) image = pg.transform.scale(image, (int(rect.width*scale), int(rect.height*scale))) return imagedef load_all_gfx(directory, colorkey=(255,0,255), accept=(’.png’, ’.jpg’, ’.bmp’, ’.gif’)): graphics = {} for pic in os.listdir(directory): name, ext = os.path.splitext(pic) if ext.lower() in accept: img = pg.image.load(os.path.join(directory, pic)) if img.get_alpha():img = img.convert_alpha() else:img = img.convert()img.set_colorkey(colorkey) graphics[name] = img return graphics

運(yùn)行成果

python實(shí)現(xiàn)超級(jí)馬里奧

python實(shí)現(xiàn)超級(jí)馬里奧

python實(shí)現(xiàn)超級(jí)馬里奧

好了,被忘了在GitHub里面點(diǎn)star喔。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 图木舒克市| 新密市| 绥滨县| 广汉市| 阳原县| 苏尼特左旗| 拉孜县| 即墨市| 武清区| 嘉义县| 泸西县| 宁海县| 汨罗市| 高雄县| 哈尔滨市| 乡宁县| 台南县| 固原市| 多伦县| 新沂市| 界首市| 大安市| 吕梁市| 时尚| 腾冲县| 东宁县| 湄潭县| 河池市| 玉屏| 咸宁市| 靖州| 朝阳县| 称多县| 靖江市| 蒙阴县| 双牌县| 莎车县| 卢龙县| 望城县| 洛宁县| 福建省|