flyingObject.py 774 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #-*- coding: UTF-8 -*-
  2. import tkinter
  3. import pygame
  4. import os
  5. import sys
  6. import time
  7. import abc
  8. class FlyingObject(object):
  9. def __init__(self,screen,x,y,image):
  10. self.screen = screen
  11. self.x = x
  12. self.y = y
  13. self.width = image.get_rect()[2]
  14. self.height = image.get_rect()[3]
  15. self.image = image
  16. @abc.abstractmethod
  17. def outOfBounds(self):
  18. pass
  19. @abc.abstractmethod
  20. def step(self):
  21. pass
  22. def shootBy(self,bullet):
  23. x1 = self.x
  24. x2 = self.x + self.width
  25. y1 = self.y
  26. y2 = self.y + self.height
  27. x = bullet.x
  28. y = bullet.y
  29. return x>x1 and x<x2 and y>y1 and y<y2
  30. def blitme(self):
  31. self.screen.blit(self.image,(self.x,self.y))