def update(self, image, basePos, width, height): xb, yb = basePos if self.ship.armor != self.hp1: if abs(self.ship.armor - self.hp1) > 5: # new damage self.hp2 = self.hp1 self.hp1 = self.ship.armor self.t = 0 else: self.hp1 = self.ship.armor if self.t < self.maxT1: if self.t + self.dt >= self.maxT1: self.dhp = (self.hp1 - self.hp2) / (self.maxT2 - self.maxT1) elif self.t < self.maxT2: self.hp2 += self.dhp * self.dt else: self.hp2 = self.hp1 self.t += self.dt hp1, hp2 = self.hp1, self.hp2 rect = Rect((0, 0), (width, hp1/config.MaxArmor * height)) rect.bottomleft = (xb, yb) pygame.draw.rect(image, self.HPColor, rect) if hp1 < hp2: rect.size = (width, (hp2 - hp1)/config.MaxArmor * height) rect.bottomleft = (xb,1 + yb - hp1/config.MaxArmor * height) pygame.draw.rect(image, self.HPColorDamage, rect)
def __init__(self, screen: pygame.surface.Surface, rect: pygame.Rect, manager: pygame_gui.UIManager) -> None: self.screen = screen self.manager = manager self.rect = rect # self.rect.height -= MIDI_HEIGHT # self.rect.topleft = self.rect.x, self.rect.y + MIDI_HEIGHT self.max_lines = 9 dropdown_rect = (0, 0, 200, MIDI_HEIGHT) rect = pygame.Rect(*dropdown_rect) rect.bottomleft = (0, self.screen.get_height()) keys = ['auto', 'скрипичный', 'басовый'] self.clef = pygame_gui.elements.UIDropDownMenu( keys, keys[0], rect, self.manager, ) self.clef.expand_direction = 'up' for state in self.clef.menu_states.values(): state.expand_direction = 'up' self.selected_clef = keys[0] self._bottomline_note: int self._note: ty.Optional[int] = None
def test_bottomleft(self): """Changing the bottomleft attribute moves the rect and does not change the rect's size """ r = Rect(1, 2, 3, 4) new_bottomleft = (r.left + 20, r.bottom + 30) expected_topleft = (r.left + 20, r.top + 30) old_size = r.size r.bottomleft = new_bottomleft self.assertEqual(new_bottomleft, r.bottomleft) self.assertEqual(expected_topleft, r.topleft) self.assertEqual(old_size, r.size)
def test_bottomleft( self ): """Changing the bottomleft attribute moves the rect and does not change the rect's size """ r = Rect( 1, 2, 3, 4 ) new_bottomleft = (r.left+20,r.bottom+30) expected_topleft = (r.left+20,r.top+30) old_size = r.size r.bottomleft = new_bottomleft self.assertEqual( new_bottomleft, r.bottomleft ) self.assertEqual( expected_topleft, r.topleft ) self.assertEqual( old_size, r.size )