|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import pygame
import random
import os
class Game:
def __init__(self):
self.screen = pygame.display.get_surface()
self.clock = pygame.time.Clock()
def run(self):
GRAPHICS = load_graphics('resources/graphics')
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.quit()
elif event.type == pygame.KEYDOWN:
self.keys = pygame.key.get_pressed()
elif event.type == pygame.KEYUP:
self.keys = pygame.key.get_pressed()
self.screen.fill((random.randint(0, 255), random.randint(0, 255),random.randint(0, 255)))
image = get_image(GRAPHICS['mario_bros'], 145, 32, 16, 16, (0, 0 ,0), 5)
self.screen.blit(image, (300, 300))
pygame.display.update()
self.clock.tick(60)
def load_graphics(path, accept=('jpg', 'png', 'bmp', 'gif')):
graphics = {}
for pic in os.listdir(path):
name, ext = os.path.splitext(pic)
if ext.lower() in accept:
img = pygame.image.load(os.path.join(path, pic))
if img.get_alpha():
img = img.convert_alpha()
else:
img = img.convert()
graphics[name] = img
return graphics
def get_image(sheet, x, y, width, height, colorkey, scale):
image = pygame.Surface((width, height))
image.blit(sheet, (0, 0), (x, y, width, height))
image.set_colorkey(colorkey)
image = pygame.transform.scale(image, (int(width*height), int(width*height)))
return image
|
-
这是文件路径和所需要的项目
|