-다가 marks breaking off one thing to do another, and 들어오다 is coming in. Six lines here are the fixed pair 나갔다가 들어오다 — going out and then coming back in, whether that is stepping out for lunch or a cat going out and returning. The other lines swap in what you were doing first: hanging about a while, playing, and then coming in.