后端开发 \ Python \ python微信飞机大战(CSDN获奖)

python微信飞机大战(CSDN获奖)

总点击94
简介:本程序的java版本  http://blog.csdn.net/zwyjg/article/details/18144915 本程序在CSDN获奖 http://blog.csdn.net/blogdevteam/article/details/72626843

python微信飞机大战(CSDN获奖)


本程序的java版本 

http://blog.csdn.net/zwyjg/article/details/18144915


本程序在CSDN获奖

http://blog.csdn.net/blogdevteam/article/details/72626843


python微信飞机大战(CSDN获奖)


Main

import pygame

from pygame.locals import *

from sys import exit

import time

from Enemy import *

from Player import *

class Main(object):

screen=""

enemies=[]

if __name__ == '__main__':

screen = pygame.display.set_mode((400,600),32)

background = pygame.image.load("background.png")

def __init__(self):

print()

player=Player(screen)

mouse_x,mouse_y = 0,0

keyDown=True

info=0

while True:

for event in pygame.event.get():

if event.type == QUIT:

exit()

if event.type == KEYUP:

if event.key == K_SPACE:

if keyDown:

keyDown=False

if event.type == MOUSEMOTION:

pos = pygame.mouse.get_pos()

mouse_x = pos[0]

mouse_y = pos[1]

player.keyhandle("mousedown",mouse_x,mouse_y,'')

if info%10==0:

player.keyhandle("fire",enemies)

info+=1

screen.blit(background,(0,0))

numX=random.randint(1,370)

if numX %55==0:

enemies.append(Enemy(numX,screen))

for temp in enemies:

temp.draw()

temp.move()

player.draw()

pygame.display.update()

time.sleep(0.01)


player类


import pygame

from PlayerBullet import *

class Player(object):

enemies=[]

def __init__(self,screen):

self.image=pygame.image.load("hero1.png")

self.x=200

self.y=500

self.speed=5

self.planeName='player'

self.frame=screen

self.playerBullet=[]

def draw(self):

self.frame.blit(self.image,(self.x-51,self.y-55))

for temp in self.playerBullet:

temp.draw(self.enemies,self.frame)

def keyhandle(self,keyValue,x,y,enemies):

self.enemies=enemies

if keyValue=="mousedown":

self.x=x

self.y=y

elif keyValue=="fire":

self.playerBullet.append(PlayerBullet(self.x,self.y-55,self.frame,self.playerBullet))


Bullet类


import pygame

class Bullet(object):

def __init__(self,screen,bullet):

self.img=pygame.image.load("bullet1.png")

self.x=x

self.y=y

self.frame=screen

self.speed=4

self.bullet=bullet


Enemy类

import pygame

import random

from EnemyBullet import *

class Enemy(object):

enemyBullet=[]

def __init__(self,screen):

self.img=pygame.image.load("enemy1.png")

self.x=x

self.y=y

self.frame=screen

self.enemyBullet=[]

enemyBullet=self.enemyBullet

self.speed=2

def draw(self):

self.frame.blit(self.img,(self.x,self.y))

def move(self):

self.y+=self.speed

num=random.randint(1,100)

if num in [1,70]:

self.enemyBullet.append(EnemyBullet(self.x+28,self.y+43,self.enemyBullet))

for temp in self.enemyBullet:

temp.draw()


EnemyBullet


import pygame

from Bullet import *

class EnemyBullet(Bullet):

def draw(self):

self.y+=self.speed

if self.y>600:

self.bullet.remove(self)

self.frame.blit(self.img,self.y))


PlayerBullet

import pygame

from Bullet import *

class PlayerBullet(Bullet):

enemies=[]

info=0

def draw(self,enemies,screen):

self.enemies=enemies

self.frame=screen

self.y-=self.speed

if self.y<0:

self.bullet.remove(self)

self.frame.blit(self.img,self.y))

for ene in self.enemies:

if self.x>ene.x and self.x<ene.x+57 and self.y>ene.y and self.y<ene.y+43:

self.enemies.remove(ene)

self.bullet.remove(self)


意见反馈 常见问题 官方微信 返回顶部