Hello there,
There is Boolean in the Road class (Boolean ok) and I cant figure out what is going on with it.
It always set to false and after a few hours of trying to solve it ,I can’t figure out why.
I think it might have something to do with my hit detection in its base class.
I tried changing my Hit detection but that didn’t really help.
If someone could take a look to see if there is anything strange it would be much appreciated.
( I will add the base class here as well as the class in question)
( I am working on a frogger project)
( If you need a runnable program please let me know)
public class Rectangle
{
float x;
float y;
float w;
float h;
float left;
float right;
float top;
float bottom;
Rectangle(float x, float y, float w, float h)
{
this.x = x;
this.y = y;
this.w = w;
this.h = h;
left = x;
right = x + w;
top = y;
bottom = y + h;
}
public boolean isHit( Rectangle other)
{
return !(this.left > other.right||
this.right < other.left ||
this.top> other.bottom ||
this.bottom< other.top);
}
//GETTERS
// SETTERS
public void setX(float newX)
{
x += newX;
}
}
public class Road extends Rectangle
{
// this class holds all the objects that 1 road needs
// in here the cars and logs will be stored
Object[] objects;
float speed;
float offset;
boolean isLog;
Road(float x, float y, float w, float h, float speed, float offset, int numOfObjects, boolean isLog)
{
super(x, y, w, h);
this.speed = speed;
this.offset = offset;
this.isLog = isLog;
objects = new Object[numOfObjects];
float tile = 50;
for (int i = 0; i < objects.length; i++)
{
objects[i] = new Object(offset * i, y, w, tile, speed);
}
}
void display(float screenWidth)
{
for (Object object : objects)
{
checkLogs();
object.rebound(screenWidth);
object.move();
object.display();
}
}
void checkLogs()
{
if (frogRowNum > 11)
{
boolean ok = false;
for (Object object : objects)
{
if (player.isHit(object))
{
println("isHit : "+player.isHit(object));
ok = true;
}
}
if (!ok)
{
println("ok : "+ok);
resetPlayer();
}
}
}
}