bullet.py 722 B

123456789101112131415161718192021222324252627282930
  1. #-*- coding: UTF-8 -*-
  2. import pygame
  3. from pygame.locals import *
  4. import time
  5. import random
  6. from baseImage import BaseImage
  7. class Bullet(BaseImage):
  8. """基础子弹类,可视为工厂"""
  9. def __init__(self,x,y,bgScreen,type):
  10. #生成子弹位置
  11. self.x = x
  12. self.y = y
  13. #根据类别选择子弹图片
  14. if type == "Hero":
  15. self.imageName = "./images/bullet-3.gif"
  16. elif type == "Enemy":
  17. self.imageName = "./images/bullet-1.gif"
  18. super(Bullet,self).__init__(bgScreen)
  19. def move(self,direction,speed=1):
  20. if direction == "up":
  21. self.y -= speed
  22. elif direction == "down":
  23. self.y += speed