Tino Intro To Java

Last modified: March 28, 2023

Lode Runner HW 2 Create Ladders

In this lab, you will add ladders to your Lode Runner world and allow your player to move up and down ladders.

You can download a demo of this lab here.

Please thoroughly explore the demo; it is super helpful for you to understand this lab's requirements.

Create ladders

Start with the level you had from HW 1.

Create a Ladder class; give it the appropriate image.

Then, in MyWorld, add some code that draws columns of ladders leading up to the platforms. You can even have some ladders go nowhere and some ladders horizontally adjacent to each other.

Note that the picture above looks very different than your HW 1 layout, but it is fine if you just add ladders to your existing HW 1 layout. Make sure each ladder is centered in a grid square with side lengths equal to the width of a wall so ladders are in the same grid as walls.

Player movement on ladders

Add code in your player class that makes your player go up or down a ladder when pressing the up or down arrow key.

When entering ladder, your player should initially be positioned in the horizontal middle of the ladder.

Advanced option: Your game will look better if the player moves one pixel toward the center of the ladder each time the player moves up or down rather than being snapped instantly to the middle.

While climbing, your player should:

  1. animate itself as climbing by repeated mirroring its image left and right
  2. never move into a wall
  3. be able to move left and right according to arrow keyboard
    1. if the player goes too far left or right, it should fall off the ladder

The player should also be able to get up onto platforms from a ladder.

Hints and tips

Rather than writing super-long if-else statements to check if the Player is on a ladder, about to fall off, etc., you can make helper methods that return the answers as suggested in HW 1. You just need to add some helper methods that answer questions like:

  • Is the player touching a ladder?
  • Is there a ladder below?
  • Can the player climb up?
  • Can the player climb down?

Then, you can simply say if (someMethod()) instead of writing all the details out.

You should review the collision methods from HW 1 to help you implement these methods.

Read about isTouching in the Actor API.

Read about getOneIntersectingObject in the Actor API.

Read about getOneObjectAtOffset in the Actor API.

Once you have these methods defined, you can write simple expressions like:

if (onPlatform() && !touchingLadder()) {
    // do something
}

Submission

Zip your entire project folder and submit it below.

  • Name your project folder PX_LastName_FirstName_LodeRunner.
  • Right click on your project folder and Send To -> Compressed (zipped) folder. On a mac compressing is similar, using a right click, but has a slightly different option.
    • You should end up with a zip file named PX_LastName_FirstName_LodeRunner.zip. For example if you were in 3rd period and named Michael Wang, then you would name the file P3_Wang_Michael_LodeRunner.zip
  • Make sure your Google Doc has Editing permissions for "anyone with the link". This is for your teacher and TAs.
  • Paste the link to your Google Doc in the Submission Comments section on this submission form (which becomes visible after you enter a file to submit)

You must Sign In to submit to this assignment

Dark Mode

Outline