Question: Modify your moveShip() function so that the ship moves to a new dimension only if it leaves the canvas by flying through the passage. The
Modify your moveShip() function so that the ship moves to a new dimension only if it leaves the canvas by flying through the passage. The ship must have flown off the correct edge of the canvas, and with an x or y coordinate that shows that the ship is inside the passage, and not on either side of it. Test your modifications before continuing with the rest of Q4. Write a void checkCollision() function which will check to see if any of the three points of the ship (the nose or either of the two fins) is inside either of the two rectangles that form the passage. If so, it should set a boolean variable and terminate the game, displaying a Game Over message (see below). This will require doing six separate checks to see whether or not a point is inside a rectangle (3 points 2 rectangles). To enable you to do this more easily, a function ptInRect(x, y, left, top, wide, high) has been provided which will determine whether or not the point (x,y) is defined as usual by the other four parameters. It returns a boolean result. Now arent you glad you pre-calculated and stored all the coordinates of the points of the ship and the rectangles? A void showGameOverMessage() function has also been provided which will draw a suitable message in the centre of the canvas when the game is over. This uses material on text and Strings which will be covered in Week 6. You may modify the size or colour of the text if you wish. Both of the provided functions are contained in the file A2SuppliedCode.pde. Cut and paste this code into your own file, at the bottom. Use a boolean gameOver variable to control the end of the game. When this variable is set to true, then nothing should happen. Dont move the ship, draw anything, or change anything. The game should be frozen
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
