python使用pygame编写游戏--飞机大战全部代码和图片

飞机大战

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//2-69//2
# 敌机精灵的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 =
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值