def update(self): last = Rect(*(self.pos + self.size)) dx = 0 if keys.get(Keyboard.keycodes['left']): dx -= 2 * params.scale if keys.get(Keyboard.keycodes['right']): dx += 2 * params.scale if keys.get(Keyboard.keycodes['spacebar']) and self.resting: self.dy = 9 * params.scale self.resting = False self.dy = max(-8 * params.scale, self.dy - .5 * params.scale) self.x += dx self.y += self.dy new = Rect(*(self.pos + self.size)) for cell in self.map.layers['objects'].collide(new, 'blocker'): blocker = cell['blocker'] if 'l' in blocker and last.right <= cell.left and new.right > cell.left: new.right = cell.left if 'r' in blocker and last.left >= cell.right and new.left < cell.right: new.left = cell.right if 't' in blocker and last.bottom >= cell.top and new.bottom < cell.top: self.resting = True new.bottom = cell.top self.dy = 0 if 'b' in blocker and last.top <= cell.bottom and new.top > cell.bottom: new.top = cell.bottom self.dy = 0 self.pos = new.bottomleft
def close_rect(self): border = self.border_width() rc = Rect(border, border, self.width(), self.caption_height()) margin = self.system_control_margin() side = rc.height() - 2 * margin rc.set_top(rc.top() + margin) rc.set_bottom(rc.bottom() - margin) rc.set_left(rc.right() - side) rc.translate(-margin, 0) return rc