基于python的飞机大战论文_基于python的飞机大战

今天在这里和大家分享一下简易的python飞机大战

如果没有安装树pygame的库,请执行这个代码

[Python] 纯文本查看 复制代码pip install pygame

如果是使用的树莓派,系统里面可能会包含这个库文件,所以如果这一步没有执行成功,也可以尝试直接运行这个里面的代码。

整个代码:

[Python] 纯文本查看 复制代码#Import pygame

import pygame, sys, time

import random

#Pygame init

pygame.init()

size=width,height=400,500

win=pygame.display.set_mode(size)

pygame.display.set_caption('Pygame 游戏之旅')

clock=pygame.time.Clock()

class hostplayer:

def __init__(self,x,y,width,height):

self.xPos=x

self.yPos=y

self.widthValue=width

self.heightValue=height

self.bulletHoder=[]

class bullet:

def __init__(self,x,y,width,height):

self.xPos=x

self.yPos=y

self.widthValue=width

self.heightValue=height

class enemyplayer:

def __init__(self,x,y,width,height):

self.xPos=x

self.yPos=y

self.widthValue=width

self.heightValue=height

def drawGame(playerArray,enemyArray):

pygame.draw.rect(win,(255,255,255),(0,0,width,height))

for i in playerArray:

pygame.draw.rect(win,(255,0,0),(i.xPos,i.yPos,i.widthValue,i.heightValue))

for q in i.bulletHoder:

pygame.draw.rect(win,(0,255,0),(q.xPos,q.yPos,q.widthValue,q.heightValue))

for k in enemyArray:

pygame.draw.rect(win,(0,0,255),(k.xPos,k.yPos,k.widthValue,k.heightValue))

pygame.display.update()

def bulletjunction(playerArray,enemyArray):

for player in playerArray:

m=0

for bulletTemp in player.bulletHoder:

for e_player in enemyArray:

n=0

if bulletTemp.xPos>

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值