Ninja World has a scoring system: Now it’s time to add some levels. For
this example, you’ll make the game have a different background image when
the player progresses to the next level. The player will reach level two
when his or her score is greater than 500.
Where do you define the BACKGROUND image? Keep the original
background for the first level, but define a new variable,
BACKGROUND2, that will be used for level 2.
Now that you have another background image, it needs to be drawn into the
game- but only when a certain condition is met.
What must be true for the player to progress to
level 2 in the game?
Which function handles the way the game looks?
What is the only thing different in level 2 of Ninja World?
The only thing that changes at level 2 is the way the game looks:
specifically, the background image. Because the background only changes when
a certain condition is met, you’ll need to change the draw-world
function so that it uses cond. Leave the current code alone for now
and start right under (define (draw-world w)).
What is the first thing to write, to let the computer
know that this will be a function with different
conditions?
What is the first condition to check? (Hint: is
the sore large enough to progress to level 2?)
If this test evaluates to true, the result will look similar to the
code you already have for draw-world, starting with put-image.
What is the one thing that needs to change?
Instead of putting all your images on top of BACKGROUND, you’ll put
them over BACKGROUND2, your new background image:
Don’t forget to add an else clause before your original code,
right underneath what you just wrote. If the score is not
greater than 500, the world will be drawn with the images on the
original background.
Now Ninja World has a level 2! You can use the same process to add more levels
when the score gets even higher. Maybe instead of the background changing, you
can have the player transform, or make the game more difficult by making the
danger move faster.
You can use the provided background image for level 2 of Ninja World,
or walk students through finding and adding their own image to the game.
These modifications can be seen in action in the
Completed Ninja World file,
or NWComplete.rkt from source-files.zip.
Some more options for students who finish early:
Change the update-world function so that the danger and
target move faster if the score is greater than 500.
Use the text function to display a game over message
on the screen when the score drops below 0.
Change the images of all the game characters when the
player progresses to the next level.