In the last lesson you added code to move your ship around the game screen. After testing your code, you noticed that even though your ship initializes inside your shooter game screen it can still move outside of the game screen. Today, you will add code the keep your ship inside your game screen.
1. Your code changes will be done with your Ship class. Make the following code changes for your 4 ship movement methods. Don’t forget to test each code change after you added the new code to each method.
moveUp
self y: self y + 5.
(self top < owner top)
ifTrue: [self top: owner top + self borderWidth].
owner changed
moveDown
self y: self y - 5.
(self bottom > owner bottom)
ifTrue: [self bottom: owner bottom - self borderWidth].
owner changed
moveLeft
self x: self x - 5.
(self left < owner left)
ifTrue: [self left: owner left + self borderWidth].
owner changed
moveRight
self x: self x + 5.
(self right > owner right)
ifTrue: [self right: owner right - self borderWidth].
owner changed
2. What do you notice about the ship and your shooter game? What else needs to be done?
3. Save and Quit your Smalltalk image.