Hello everyone, I`ve got a problem with my racing game. The problem is I can't get the lap counter work properly and I really don`t know what to do as I`m a beginner.
Actor Subaru = getOneIntersectingObject(LapLine.class);
if(isTouching(LapLine.class))
{
World myWorld = getWorld();
Level1 level1 = (Level1) myWorld;
S1Lap s1Lap = level1.getS1Lap();
s1Lap.adds1Lap();
}
This is from my LapCounter class :
public class S1Lap extends Subaru
{
int S1Lap = 0;
public void act()
{
setImage(new GreenfootImage("S1Lap: " + S1Lap,24,Color.GREEN, Color.BLACK));
}
public void adds1Lap()
{
S1Lap++;
}
}
public class LapLine extends Actor
{
int S1Lap = 0;
int S2Lap = 0;
public void act()
{
if(isTouching(Subaru.class))
{
S1Lap++;
setImage(new GreenfootImage("S1Lap: " + S1Lap,24,Color.GREEN, Color.BLACK));
}
if(isTouching(Subaru2.class))
{
S2Lap++;
setImage(new GreenfootImage("S2Lap: " + S2Lap,24,Color.GREEN, Color.BLACK));
}
}
public boolean isTouching(Class clss)
{
Actor actor = getOneObjectAtOffset(5, 5, clss);
return actor != null;
}
}
The code below is from my car class:
