Im working on a Car Game where the Car should get slowed down when its not on the race track anymore. My Car and the race track are both actors, thats why I tried out the following code (car class):
This solution isn't working. My assumption was that transparent pixels count as an actor too. My Race Track Image is as big as my World image, but only the pixels of the track are not transparent, the rest is.
Can someone tell me why this isn't working? Any help is appreciated ;)
public class Car extends SmoothMover { double speed = 0; double maxSpeed = -4; double acceleration = -0.02; double breaking = 0.008; public void act() { driving(); checkOnTrack(); } public void driving() { move(speed); if(Greenfoot.isKeyDown("a")) { turn(-2); } if(Greenfoot.isKeyDown("d")) { turn(2); } if(Greenfoot.isKeyDown("w") && speed > maxSpeed) { speed = speed + acceleration; } if(!Greenfoot.isKeyDown("w") && speed < 0) { speed = speed + breaking; } } public void checkOnTrack() { Actor Car = getOneIntersectingObject(RaceTrack.class); if(Car !=null) { double speed = 0; double maxSpeed = -4; double acceleration = -0.02; double breaking = 0.008; } else { double maxSpeed = -2; double acceleration = -0.02; double breaking = 0.08; } } }