This is ridiculously long function now could you maybe factor out peace into function that takes `position`, `state` & `rect` and returns, `x, y, width, height` ?