飞机大战
1.全部代码:
import random
import time
import pygame
pygame.init()
screen = pygame.display.set_mode((480, 550))
pygame.display.set_caption("飞机大战")
icon = pygame.image.load("img/icon.png")
pygame.display.set_icon(icon)
bg_img = pygame.image.load("img/background.png")
hero_img1 = pygame.image.load("img/me1.png")
hero_img2 = pygame.image.load("img/me2.png")
hero_bomb_imgs = ["img/me_destroy_1.png",
"img/me_destroy_2.png",
"img/me_destroy_3.png",
"img/me_destroy_4.png"]
hero_rect = pygame.Rect(190, 526, 66, 80)
# 英雄精灵的x,y轴坐标
heroPlaneX = hero_rect.x
heroPlaneY = hero_rect.y
enemy_img = pygame.image.load('img/enemy2.png')
enemy_img2 = pygame.image.load('img/enemy2_hit.png')
#
enemy_bomb_imgs = ["img/enemy2_down1.png",
"img/enemy2_down2.png",
"img/enemy2_down3.png",
"img/enemy2_down4.png"]
# 定义敌机的rect
enemy_rect = pygame.Rect(206, 0, 69, 89) # x=480
# 敌机精灵的x,y轴坐标
enemyPlaneX = enemy_rect.x
enemyPlaneY = enemy_rect.y
#绘制敌机精灵
screen.blit(enemy_img,(enemyPlaneX,enemyPlaneY))
pygame.key.set_repeat(20, 30)
# 创建游戏时钟,
clock = pygame.time.Clock()
# 作为切换图片索引
heroIndexShift = 0
# 定义敌机初始移动方向
direct =