Question: Define a function void newDimension() which will create a new random dimension, storing all of the relevant data in a set of state variables (about
Define a function void newDimension() which will create a new random dimension, storing all of the relevant data in a set of state variables (about 10 of them). The dimension should have a random dark background colour. You can store a colour in a single int variable, using the built-in function color(r,g,b) to convert the three separate values for red, green, and blue (all 0 to 255) into a single int value. You can endure that the colour is dark by generating random values that never get too large. The passage to the next dimension should be a simple pair of white rectangles, close together, drawn on an edge of the canvas, as shown in the figure. Use suitable constants to define the shape of the rectangles, and how far apart they are. The spaceship should be able to fly between them, without touching them, but it shouldnt be too easy to do. In the first dimension, when the program starts, the passage should be on either the top or bottom edge of the canvas (at random). In the next dimension, it should be on either the left or right edge (at random). The next time, it should again be on the top or bottom, and this alternation should repeat. You must use two boolean variables to control which edge the passage is on. One should control whether it is on the top/bottom or left/right, and this one should change every time newDimension() is called. The other one should control whether its on the top or left, or on the bottom or right. This one should be random. Choose a random position for the passage, but not too close to any corner. The distance from the passage to any corner should never be smaller than the length of the passage (the long side of the rectangles). This is so that the spaceship will never fly through a passage straight into a wall in the next dimension. That wouldnt be a very fair game. Calculate and store all the information that you need to draw the rectangles once, when the dimension is created, not every frame when you draw them. Use an appropriate set of state variables. Split the work into smaller functions to prevent newDimension() from getting too big. Add additional code to draw your dimensions and test the way that they are generated. Write a void drawPassage() function which will draw the two rectangles forming the passage between dimensions. It should be very short because youve done all the calculations in advance... right? Modify moveShip() so that it switches to a new dimension every time the ship flies off any edge of the screen. Make sure the passages are drawn correctly, and are generated correctly. Just while youre testing Q3, you could make the ship fly faster, so that you see the new dimensions more quickly. But makes it slower again for Q4. Make appropriate modifications to setup() and draw().
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
