How do you compute what wall you are looking at and how
far away from the player it is?
Ah. I see the problem. Bresenham would most likely be too slow and BSP would be too memory intensive. I was going to try to explain the math here, but it would just take too much time for me to write. After all, it’s an algo with a lot of gotchas. I highly recommend finding a used copy of “Tricks of the Game Programming Gurus”. It’s the best source I know of for Ray Casting. Here’s a high level description:
You need to remember that your walls need to actually be square “blocks” that take up a square number of world coordinates (i.e. 64x64). You test only every block and not for every coordinate. This speeds things up tremendously.
Use the slope of each ray to calculate the next intersection. Depending on the angle of the ray, it may intersect both vertical and horizontal walls. You’ll need to check each wall for both vertical and horizontal for each block the ray passes through until the ray goes past the clipping range or intersects with a wall. The formulas are something like this:
Let w = next wall from player or previous intersection
Let p = player location
Since the player is “inside” an empty block, you need to test for the first intersection. Here’s the formulas:
yIntersection = raySlope * (xw - xp) + yp
xIntersection = (raySlope exp -1) *(yi - yp) +xp
Every intersection after that uses the formulas:
nextYIntersection = previousYIntersection + raySlope * blockHeight
nextXIntersection = previousXIntersection + (raySlope exp -1) * blockWidth
Once you find a wall, you should have coordinates for both the player and the intersection. Use these coordinates as values to calculate the hypotenuse of a right triange (Pythagorean theorem). There are ways of optimizing this that I’m not going to get into right now. The hypotenuese is the distance of the player from the “sliver”. You can use this to calculate how tall the sliver should be. A simple inverse (1/distance) calc should work fine on a square pixel screen. If you have a non-square screen (i.e. 320x200) try using a different value than 1 to adjust for distortion (i.e. 1.5/distance).
Last problem. This method mixes polar (circular) coordinates with cartesian (rectangular) coordinates. this causes spherical distortion. (Like looking through a fish bowl). Getting rid of it is a bit more math. You multiply the scale of the sliver against the (cos exp -1) of the current ray. Just to be clear, this is the cosine of your field of view (i.e. -30 to +30 degrees) and not the actual direction (i.e. 300 to 360 degrees) the player is looking.
I don’t know how helpful this is as Raycasting is a very involved topic. Never the less, there you are. My only suggestion is that you first try making this work using a normal Java application, then later port the code to MIDP. That way you can work out the bugs in what you’re doing.