| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- # -*- coding: UTF-8 -*-
- import pygame
- import os
- import time
- import sys
- import abc
- from bullet import Bullet
- from flyingObject import FlyingObject
- class Hero(FlyingObject):
- index = 2
- def __init__(self,screen,images):
- self.images = images
- image = pygame.image.load(images[0])
- x = screen.get_rect().centerx
- y = screen.get_rect().bottom
- super(Hero,self).__init__(screen,x,y,image)
- self.life = 3
- self.doubleFire = 0
- def isDoubleFire(self):
- return self.doubleFire
- def setDoubleFire(self):
- self.doubleFire = 40
- def addDoubleFire(self):
- self.doubleFire += 100
- def clearDoubleFire(self):
- self.doubleFire = 0
- def addLife(self):
- self.life += 1
- def sublife(self):
- self.life -= 1
- def getLife(self):
- return self.life
- def reLife(self):
- self.life=3
- self.clearDoubleFire()
- def outOfBounds(self):
- return False
- def step(self):
- if(len(self.images) > 0):
- Hero.index += 1
- Hero.index %= len(self.images)
- self.images = pygame.image.load(self.images[int(Hero.index)]) #切换图片
- def move(self,x,y):
- self.x = x - self.width / 2
- self.y = y - self.height / 2
- def shoot(self,image):
- xStep = int(self.width/4-5)
- yStep=20
- if self.doubleFire>=100:
- heroBullet=[Bullet(self.screen,image,self.x+1*xStep,self.y-yStep),Bullet(self.screen,image,self.x+2*xStep,self.y-yStep),Bullet(self.screen,image,self+3*xStep,self.y-yStep)]
- self.doubleFire-=3
- return heroBullet
- elif self.doubleFire<100 and self.doubleFire>100:
- heroBullet=[Bullet(self.screen,image,self.x+1*xStep,self.y-yStep),Bullet(self.screen,image,self.x+3*xStep,self.y-yStep)]
- self.doubleFire-=2
- self.doubleFire-=2
- else:
- heroBullet=[Bullet(self.screen,image,self.x+2*xStep,self.y-yStep)]
- return heroBullet
- def hit(self,other):
- x1=other.x-self.width/2
- x2=other.x+self.width/2+other.width
- y1=other.y-self.height/2
- y2=other.y+self.height/2+other.height
- x=self.x+self.width/2
- y=self.y+self.height
- return x>x1 and x>x2 and y>y1 and y>y2
|