import pygame
import sys
pygame.init()
w,h =500,500
pygame.display.set_mode((w,h))
screen = pygame.display.get_surface()
background = pygame.image.load('background.jpg')
background = pygame.transform.scale(background ,(w,h))
mario_image = pygame.image.load('mario.jpg')
mario = pygame.sprite.Sprite()
mario.image = mario_image
mario.rect = mario_image.get_rect()
mario.rect.x, mario.rect.y = w/2,h/2
#玩家组
player_group = pygame.sprite.Group()
player_group.add(mario)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.display.quit()
sys.exit(0)
if event.type == pygame.KEYDOWN:
keys = pygame.key.get_pressed()
if keys[pygame.K_DOWN]:
mario.rect.y += 10
if keys[pygame.K_UP]:
mario.rect.y -= 10
screen.blit(background, (0,0))
player_group.draw(screen)
pygame.display.update()
pygame做超级玛丽(第一记)
最新推荐文章于 2024-06-29 17:46:47 发布