Tino Intro To Java

Last modified: April 15, 2023

Lode Runner HW 10 Final Version

(optional) Gold Challenges

While you now have a playable version of Lode Runner, there are many features you could still add to make the game better. Here is the version made by Mr. McLeod. In the following sections, you will see some ideas for adding these features. You can also come up with your own features. Be creative!

  1. You can get the original lode runner images and sounds if you want your version to look more like the web version you played earlier.
  2. To make your current game as enjoyable as the original Lode Runner arcade game:
    1. Add more levels
    2. Add the dig feature
    3. Add undiggable walls
    4. Add win ladders (player must climb to the top of a level to pass the level)
    5. Add false walls
    6. Improve enemy AI
  3. To make your current game even more enjoyable than the original Lode Runner arcade game:
    1. Levers / switches / pressure plates that change things (raise/lower ladder), move or extend platforms...etc
    2. Portals (teleports you to another place in the level)
    3. Lava (instant death)
    4. Walls that appear and disappear regularly
    5. Spikes that shoot up or down and then go back into the wall on regular intervals.

(optional) Digging Holes

In the original game, the player can dig holes to the left or right.

  • If a player falls in a hole, it behaves the same as if there had never been a wall there.
  • If an enemy falls in a hole, the enemy gets stuck in the hole for a limited time.
    • When an enemy is in a hole, the player can walk over the enemy as if the enemy was a wall.
    • After some time, the enemy can climb out of the hole.
  • After some amount of time, the hole closes back up.
    • If the player is in a hole when it closes, the player dies (same as if an enemy had touched the player)
    • If an enemy is in the hole when it closes, the enemy dies and respawns somewhere at the top of the level (or possibly in the same place they started out).
  • There are solid walls that cannot be dug through.

Tips for Holes

  1. When the player presses the dig left or dig right button, the wall in the grid position diagonally down and to the left or down and to the right is removed and a Hole object is added there.
    1. Hole objects have a blank image created using the GreenfootImage constructor that takes width and height, so they are transparent.
  2. In the Hole act() method, holes count how long they have been in the world. When they have been in the world long enough (you decide), they replace themselves with a wall.
  3. If an enemy is touching a Hole but is not yet at the center, the enemy is placed at the center of the hole and a counter starts
  4. When an enemy has been in the hole for some amount of time chosen by you, it is teleported out of the hole to an open adjacent grid position up and to the left or up and to the right.
  5. When a hole closes, it also kills any player it is touching and makes enemies respawn at the top of the level.
  6. Players and enemies can both walk on enemies that are in holes.

(optional) Adding False Wall or Win Ladder

  1. Create a class to represent a false wall and choose the brick image.
  2. Create a level in the level creator that contains false walls.
  3. In the MyLevelWorld class, set the class for false wall to the class you made. Example:
    1. getLoader().setFalseWallClass(FalseWall.class);
  4. Done! Your FalseWall objects will look like walls, but when your player code calls a method like isTouching(Wall.class), it will return false because a FalseWall object is not a Wall, and thus your player will fall through the false wall.

(optional) Adding More Custom Classes

You can add additional types by doing the following. First in the Level Editor, you should add the type as an option to draw in levels:

  1. Make the class (let’s say it is called Banana) and assign it an image.
  2. If needed, scale the image to fit inside a grid position using an image editor or by adding code in the default constructor the class.
  3. In the LodeRunnerEditorWorld, you will see a section of code shown below. That code is called a static initializer and it runs at the beginning of the program, even before any instances of the LodeRunnerEditorWorld have been created. You will need to add some code so the user will know how to draw bananas in a level.
// this code runs when the class is loaded (at the beginning of the program before any instance is created)
static {
    // Initialize the Grid Offsets for Gold and Bar
    EditorWorld.gridWidth = gridSize;
    EditorWorld.gridHeight = gridSize;

    // If you add a tile that needs to be placed anywhere other than the center of a grid square
    // then define the offset here
    EditorWorld.gridOffsets.put(Gold.class, new Point(0, gridSize / 2 - new Gold().getImage().getHeight() / 2));
    EditorWorld.gridOffsets.put(Bar.class, new Point(0, -gridSize / 2 + new Bar().getImage().getHeight() / 2 + 3));

    // If you added extra tile types, then you should add directions indicating what key will
    // make that be the type of tile that is drawn
    EditorWorld.addCustomInstruction("W = Wall    G = Gold    L = Ladder    B = Bar    P = Player");
    EditorWorld.addCustomInstruction("C = Win Ladder    E = Enemy    F = False Wall    U = Undiggable Wall");
}

If the new class is supposed to be placed anywhere other than the center of the grid square (like with a bar), then add a line of code that defines the offset. For example:

 // put bananas centered halfway along the diagonal from the upper left corner to the center of the grid square
EditorWorld.gridOffsets.put(Banana.class, new Point(-gridSize / 4, -gridSize / 4));

Add instructions so it will say which key to press to draw bananas in the editor, either in a new line or squeezed in to an existing line:

Adding instruction on new line

// adds a new line of instructions at the bottom of the level
EditorWorld.addCustomInstruction("N = Banana");

Squeezing it in to an existing line (can't make it too long if you do this):

// add instructions for drawing bananas to the first line of instructions
EditorWorld.addCustomInstruction("W = Wall  G = Gold  L = Ladder  B = Bar  P = Player  N = Banana");
  1. Finally, you will need to add the type by adding a line to the defineTypes() method as shown below:
// If you add a new type of tile, simply add the type here
@Override
public void defineTypes() {
    addType("W", "W", Wall.class);
    addType("G", "G", Gold.class);
    addType("L", "L", Ladder.class);
    addType("B", "B", Bar.class);
    addType("P", "P", Player.class);
    addType("E", "E", Enemy.class);
    addType("F", "F", FalseWall.class);
    addType("C", "C", WinLadder.class);
    addType("U", "U", UndiggableWall.class);
    addType("BAN", "N", Banana.class); // add the Banana type as the type to switch to when pressing the N key
}

Note that we used "BAN" for the symbol to write to the file and "N" is the key to press to draw bananas. Symbols can be any length, but they should not include white space. If we followed the convention I used in the other classes, I would have made the symbol "N", but I wanted to make sure you understood it can be different from the key.

Next, you will want to be able to load a level containing a banana in your Load Runner game. Open your Lode Runner project and create the Banana class. You don't need to actually code all the behaviors in the Banana class yet - you just need the class to exist. Open the MyLevelWorld class and edit the defineClassTypes() method to define the Banana type.

@Override
public void defineClassTypes() {
    // define which classes represent walls, ladders, bars, players, and enemies
    // TODO: REPLACE WITH YOUR CLASSES
    getLoader().setWallClass(Wall.class);
    getLoader().setPlayerClass(Player.class);
    getLoader().setLadderClass(Ladder.class); // you can remove this if you have no ladders in your game
    getLoader().setBarClass(Bar.class); // you can remove this if you have no bars in your game
    getLoader().setEnemyClass(Enemy.class); // you can remove this if you have no enemies in your game
    getLoader().setGoldClass(Gold.class); // you can remove this if you have no gold in your game
    getLoader().setGoldClass(Gold.class); // you can remove this if you have no gold in your game
    getLoader().defineType("BAN", Banana.class); // define the Banana class.
}

In the example above, we defined "BAN" to represent the Banana class. It is important that the string you pass matches the string you used for the smbol in the editor.

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