赞
踩
完整代码和素材戳我
主代码
import pygame as pg
from source.main import main
if \_\_name\_\_=='\_\_main\_\_':
main()
pg.quit()
main
\_\_author\_\_ = 'marble\_xu' import pygame as pg from . import setup, tools from . import constants as c from .states import main\_menu, load\_screen, level def 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 os
import pygame as pg
from . import constants as c
from . import tools
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()
GFX = tools.load\_all\_gfx(os.path.join("resources","graphics"))
tools
\_\_author\_\_ = 'marble\_xu' import os import pygame as pg from abc import ABC, abstractmethod keybinding = { '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 image def 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
运行成果
好了,被忘了在GitHub里面点star喔。
学好 Python 不论是就业还是做副业赚钱都不错,但要学会 Python 还是要有一个学习规划。最后给大家分享一份全套的 Python 学习资料,希望提供给想学习 Python 的小伙伴们一点帮助!
保存图片微信扫描下方CSDN官方认证二维码免费领取【保证100%免费
】
Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。
② 路线对应学习视频
还有很多适合0基础入门的学习视频,有了这些视频,轻轻松松上手Python~在这里插入图片描述
③练习题
每节视频课后,都有对应的练习题哦,可以检验学习成果哈哈!
因篇幅有限,仅展示部分资料
当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。
学习Python常用的开发软件都在这里了!每个都有详细的安装教程,保证你可以安装成功哦!
光学理论是没用的,要学会跟着一起敲代码,动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。100+实战案例源码等你来拿!
如果觉得上面的实战案例有点枯燥,可以试试自己用Python编写小游戏,让你的学习过程中增添一点趣味!
我们学习Python必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。
而且学会Python以后,还可以在各大兼职平台接单赚钱,各种兼职渠道+兼职注意事项+如何和客户沟通,我都整理成文档了。
这份完整版的Python全套学习资料已经上传CSDN,朋友们如果需要可以保存图片微信扫描下方CSDN官方认证二维码免费领取【保证100%免费
】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。