Python版飞机大战

本文介绍了使用Python编程语言开发的一款飞机大战游戏,详细讲解了游戏的实现过程,包括飞行器控制、碰撞检测、得分系统等核心功能。通过阅读,读者可以了解到Python在游戏开发中的应用和基本的编程技巧。
摘要由CSDN通过智能技术生成
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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值