import pygame
import time
import random
from pygame.locals import *
size = width, height = 480, 800
i = 0
# 提取父类
class Plane(object):
def __init__(self, screen_temp, x, y, image_path):
# 位置
self.x = x # 200 0
self.y = y # 650 0
# 屏幕对象
self.screen = screen_temp
# 飞机图片对象
self.image_plane = pygame.image.load(image_path)
# 准备一个存放子弹的列表
self.bullet_list = []
def display(self):
self.screen.blit(self.image_plane, (self.x, self.y))
# 空列表 要删除的子弹
remove_bullet_list = []
# 遍历子弹
for bullet in self.bullet_list:
bullet.display()
bullet.move()
# 判断子弹是否越界
if bullet.check():
# self.bullet_list.remove(bullet)
remove_bullet_list.append(bullet)
# 移除
for remove_bullet in remove_bullet_list:
self.bullet_list.remove(remove_bullet)
# 定义一个我方飞机类
class MyPlane(Plane):
def __init__(self, screen_temp):
super().__init__(screen_temp, 200, 650, "./feiji/plane.png")
# 飞机移动
def move_left(self):
self.x -= 5
def move_right(self):
self.x += 5
def move_up(self):
self.y -= 5
def move_down(self):
self.y += 5
# 重写display
def display(self, enemy):
self.enemy = enemy
super().display()
for bullet in self.bullet_list:
flag
Python版飞机大战
最新推荐文章于 2024-08-08 11:32:32 发布
本文介绍了使用Python编程语言开发的一款飞机大战游戏,详细讲解了游戏的实现过程,包括飞行器控制、碰撞检测、得分系统等核心功能。通过阅读,读者可以了解到Python在游戏开发中的应用和基本的编程技巧。
摘要由CSDN通过智能技术生成