Last modified: April 15, 2023
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!
In the original game, the player can dig holes to the left or right.
getLoader().setFalseWallClass(FalseWall.class);
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:
// 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");
// 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.
Zip your entire project folder and submit it below.
PX_LastName_FirstName_LodeRunner
.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
You must Sign In to submit to this assignment