1 Star 0 Fork 1

torres/2dGameDemo

forked from Cerber2ol8/2dGameDemo 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Src_loader.py 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
Cerber2ol8 提交于 2022-01-12 23:47 . Add files via upload
# -*- coding: utf-8 -*-
import pygame
from pygame.locals import *
if not pygame.font: print('Warning, fonts disabled')
if not pygame.mixer: print('Warning, sound disabled')
import os, sys
def load_img(img):
img = pygame.image.load(img)
img = img.convert_alpha()
return img
def load_image(name, colorkey=None):
fullname = os.path.join('src', name)
try:
image = pygame.image.load(fullname)
except pygame.error as e:
print('Cannot load image:', name, e)
raise SystemExit
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, RLEACCEL)
return image, image.get_rect()
def load_sound(name):
class NoneSound:
def play(self): pass
if not pygame.mixer:
return NoneSound()
fullname = os.path.join('src', name)
try:
sound = pygame.mixer.Sound(fullname)
except pygame.error:
print('Cannot load sound:', wav)
raise SystemExit
return sound
def cropimg(img, rect):
subImg = img.subsurface(rect)
return subImg
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/torres_c/py2dGameDemo.git
git@gitee.com:torres_c/py2dGameDemo.git
torres_c
py2dGameDemo
2dGameDemo
master

搜索帮助