Line 19 creates a new MyWorld object which is not the world that this Brick object is in. To access the world this brick is in, use:
MyWorld world = (MyWorld)getWorld();
MyWorld world = (MyWorld)getWorld();
accB = world.addSpeed(accB,"B");
//In Brick in similar in the Mobil and Mobil2
public static int speed = 4;
public void act()
{
setLocation(getX(), getY()+speed);
if (getY() > getWorld().getHeight()-2) removeObject(this);
}//in world subclass
private int time = 0;
public void act()
{
time++;
if (time == 100)
{
time = 0;
Brick.speed += 4;
Mobil.speed += 2;
Mobil2.speed += 6;
}
}/** in MyWorld class */
// instance field
private int time;
// in constructor
SmoothMover.accLevel = 1;
// in act method or a method it calls
time = (time+1)%100; // cycles value from 0 to 99 repeatedly
if (time == 0) SmoothMover.accLevel++;
/** ******************** */
/** in SmoothMover class */
// class field
public static int accLevel;
// instance fields
public int acc;
// instance method
public void speed()
{
setLocation(getX(), getY()+acc*accLevel);
}
/** ****************** */
/** in Brick (and mobil classes) */
// constructor (Brick example)
public Brick()
{
acc = 4;
}
// act method
public void act()
{
speed();
checkout("t");
}