Each time you move the player's sprite, check to see if its position is above the hole's position. If it is, they fall!

Note: if you're building the level background from a grid of tiles, you probably have some 2-D array of tiles (e.g. tileType[12][5] == 2, where 2 means 'ladder', 3 means 'hole', etc.). Now just create an extra array isSolid[], where isSolid[2] == true and isSolid[3] == false, etc. Now you can just check whether the player's sprite's position is above a tile for which isSolid

[y] == true. (Typically they'll be above 2 or 3 tiles, so you may have to check each of these). If none of the tiles below them is solid, they fall!

Your tiles don't need to be sprites. Instead, your tiled background needs to have its own class. Have a look at how the MIDP 2.0 game API works, and write similar classes yourself.

The tile image PNG file could have all the different tile type images in e.g. a horizontal row. Then you build the real background image by drawing the 'frames' of that resource file image repeatedly onto a big blank image according to your tile grid (array 'tiles' below).

Since you've got the tile grid, you can also use it to find out which type of tile is at a certain grid position. If you have an array ('isSolid' below) telling which types of tile are solid, you can use that in an 'isSolid' method.

Warning: the code below is an adaptation from memory of part of a (working) demo game I wrote, but I just typed it in now and I haven't even tried to compile it - no guarantees! I'm afraid YABB does wierd things with its indentation .

I assume that you start the character sprite in a place that doesn't overlap any solid tiles. Now each time the player wants to move left, check that the one-pixel-wide column of pixels to his left doesn't overlap any solid tiles:

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org