There's many ways you could express this, but the way I've done it is to change:
if (MyEvent.keyCode) {x_pos = x_pos - 10;} // left
to become:
if (MyEvent.keyCode == 37 && x_pos > 0) {x_pos = x_pos - 10;} // left
In other words, if the left key is pressed I'll subtract ten from my x position, but
only if it's also true that my
x_pos is greater than zero.
You may recall that && means "and", just like using the "and" operator-block in Scratch. The condition is only true if the first part is true and the second part is true.
I've done the same thing for y_pos, and now you can't drive the cat too far up or to the left.
Try it.
You'd think making a similar change for down and to the right would be equally easy. But you'd be slightly wrong.