Hey I`m currently working on a "3D" game created with Greenfoot. It is based on the techniques Wolfenstein 3D used to create a 3D effect.
That means that I basically use a top-down perspective. In every acting-cycle I look how far the wall in front of me is away from me. Then I calculate the height of the Wall and draw a rectangle with this height on my screen.
This is the code I use for that (and it works)
Drawer.class is basically a canvas.
The method is started in the act method.
However I obviously also want to draw the walls that aren`t directly in front of me. I tried to use this code for doing that.
However now he always thinks he already is in a wall and the while-loop is never entered and therefore direction stays 0 and the rectangle get drawn at full height.
I do not understand why the player thinks he is in a wall.
Thanks for the help
Tritos
public void drawSightF()
{
GreenfootImage drawerImg = getWorld().getObjects(Drawer.class).get(0).getImage();
drawerImg.clear();
int distance = 0;
int xSave = getX();
int ySave = getY();
while(!isTouching(Wall.class))
{
distance = distance + 15;
move(10);
}
int h1 = (int)(900.0*((1400.0-distance)/(1400.0)));
drawerImg.fillRect(690, 450 - (h1/2), 10, h1);
setLocation(xSave, ySave);
}public void drawSight()
{
GreenfootImage drawerImg = getWorld().getObjects(Drawer.class).get(0).getImage();
drawerImg.clear();
int distance = 0;
int xSave = getX();
int ySave = getY();
for(int n = 0; n <= 90; n = n + 10)
{
turn((int)(n));
while(!isTouching(Wall.class))
{
distance = distance + 15;
move(10);
}
int h1 = (int)(900.0*((1400.0-distance)/(1400.0)));
drawerImg.fillRect(690 + n, 450 - (h1/2), 1, h1);
distance = 0;
setRotation(getRotation()-(n*2));
while(!isTouching(Wall.class))
{
distance = distance + 15;
move(10);
}
h1 = (int)(900.0*((1400.0-distance)/(1400.0)));
drawerImg.fillRect(690 - n, 450 - (h1/2), 1, h1);
distance = 0;
setRotation(getRotation()+n);
}
setLocation(xSave, ySave);
}

