Coding the moving platform component class
All we need to do to bring this new object to life is code a UpdateComponent. We already have the specification in the GOSpec package and a regular graphics-related component class has already been coded.
MoveableBlockUpdateComponent
Create a new class called MoveableBlockUpdateComponent, extend UpdateComponent and add the required update method as shown next.
import android.graphics.PointF;
class MovableBlockUpdateComponent implements UpdateComponent {
@Override
public void update(long fps,
Transform t,
Transform playerTransform) {
PointF location = t.getLocation();
if (t.headingUp()) {
location.y -= t.getSpeed() / fps;
} else if (t.headingDown()) {
location.y += t.getSpeed() / fps;
} else {
// Must be first update of the game
// so start with going down
t.headDown();
}
// Check...