这版和网上流传的大部分差不多,没有声音,不能计分。有时间会写个的
首先你得安装了Python3 和pygame ,最好用pycharm编写。
- 第一步我们先做一些准备工作:
测试pygame是否能运行
import pygame
pygame.init()
#创建游戏窗口
screen = pygame.display.set_mode((480,700))
bg = pygame.image.load("./images/background.png")
screen.blit(bg,(0,0))
pygame.display.update()
while True:
pass
pygame.quit()
上面代码我没写定时关闭,运行时注意
- 写英雄图像
import pygame
pygame.init()
#创建游戏窗口
screen = pygame.display.set_mode((480,700))
bg = pygame.image.load("./images/ul0961-7549.jpg")
screen.blit(bg,(0,0))
pygame.display.update()
#英雄图像
hero = pygame.image.load("./images/me1.png")
screen.blit(hero,(200,500))
pygame.display.update()
clock = pygame.time.Clock()
hero_rect = pygame.Rect(200, 500, 102, 126)
while True:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("游戏退出...")
pygame.quit()
exit()
hero_rect.y -= 2
if hero_rect.y <=0:
hero_rect.y = 700
screen.blit(bg,(0,0))
screen.blit(hero, hero_rect)
pygame.display.update()
pygame.quit()
“”
3 写敌机
import pygame
from piane_sprites import*
pygame.ini