Tino Intro To Java

Last modified: April 08, 2026

Lode Runner HW 9 Digging Holes

In this lab you will add digging to the game. Here is a demo of what this will look like using the simple hole implementation given below. The full game shows a more complex version that looks nicer, but that is not required.

Digging Holes

In the original game, the player can dig holes to the left or right. This is a critical feature to have if you want your game to be truly playable as this is a core game mechanic that allows the player to avoid the enemies and reach treats buried in walls or in otherwise unreachable locations. In this assignment you will add a simple version of digging to your game.

  • 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.

Simple Hole Implementation

For now we will implement a simple hole digging strategy. It won't look as nice as the original, but it will be functional. If you are up for a challenge, you can later try to implement the feature exactly as in the original game.

  1. When the player presses the dig left or dig right button (z and x)
    1. The player should snap to grid (set their location to the center of the grid square that contains their current location).
    2. the wall in the grid position diagonally down and to the left or down and to the right of the player's grid position is removed
    3. a Hole object is added at the position of the wall that was removed.
    4. Hole objects have a blank image created using the GreenfootImage constructor that takes width and height, so they are transparent.
  2. In the act() method of the Hole class, a hole counts how long it has been in the world. When a hole has been in the world for 600 frames, it places a wall in its position and removes itself.
  3. In the Enemy class: Add an instance variable to keep track of how long an enemy has been in a hole. If an enemy is touching a Hole but not at the center of the hole, the enemy is placed at the center of the hole. If an enemy is at the center of a hole, they should not fall and should update the escape counter.
  4. When an enemy has been in the hole for 150 frames (the escape counter reaches some value), the enemy is teleported out of the hole to an open grid position up and to the left or up and to the right and the escape counter is reset as needed.
  5. When a hole closes while the player is in the hole, it kills the player (for now just teleport them back to where they started the level).
  6. When a hole closes while an enemy is in the hole, it kills the enemy, so the enemy respawns somewhere at the top of the level or to where they started the level. Here are some ideas of how to implement that:
    • Make an invisible spawn point actor (image is fully transparent). When an enemy dies, teleport them to the spawn point.
    • Store the spawn point as instance variables and teleport the enemy back to that point every time they die. If you override addedToWorld(World w) you can initialize the variables to the location where the enemy first was added to the world.
  7. Players and enemies can both walk on enemies (An enemy below is another reason not to fall). This is true regardless of whether they are in a hole.

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