def draw(screen, image, position, direction, viewPosition, viewDirection): PI = 3.14159265 viewDirection += PI / 2 image = Image(image) image = image.rotate(viewDirection - direction) screen.draw(image = image, position = (position - viewPosition ).rotate(-viewDirection) - image.getSize() / 2 + screen.getSize() / 2)
class Bar(Runnable): def __init__(self, unit, maxHp, position = Coordinate(0, 0)): Runnable.__init__(self) self.image = Image('graphics/lifeBar.bmp', permeate = False) self.imageSize = self.image.getSize() self.position = Coordinate(position) self.unit = unit self.maxHp = maxHp def step(self): pass def draw(self, screen): if not self.unit.checkAlive(): return ration = self.unit.getHp() / self.maxHp # print(ration, self.position) if ration < 0: ration = 0 if ration > 1: ration = 1 screen.draw(self.image.getSubImage((0, 0), (self.imageSize.getX() * ration, self.imageSize.getY())), self.position - self.imageSize / 2)