Obstacle.py 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import math as Math
  2. class Obstacle():
  3. def __init__(self, canvas, x,y, width, height, color = "LightGray"):
  4. self.canvas = canvas
  5. self.x = x
  6. self.y = y
  7. self.width = width
  8. self.height = height
  9. self.radius = Math.sqrt(Math.pow(self.width+2,2)+Math.pow(self.height+2,2))
  10. halfwidth = width/2
  11. halfheight = height/2
  12. self.coords =[(self.x-halfwidth, self.y-halfheight), (self.x+halfwidth, self.y-halfheight),
  13. (self.x+halfwidth, self.y+halfheight), (self.x-halfwidth, self.y+halfheight)]
  14. self.image = self.canvas.create_polygon(self.coords,outline="SlateGray4",width=0, stipple="gray50", tags="obstacle", fill=color)
  15. def getRadius(self):
  16. return self.radius
  17. def getX(self):
  18. return self.x
  19. def getY(self):
  20. return self.y
  21. def getWidth(self):
  22. return self.width
  23. def getCoords(self):
  24. return self.coords
  25. def getImage(self):
  26. return self.image