package com.ezardlabs.dethsquare;

import java.util.ArrayList;

/**
 * {@link Component} that contains the position of a {@link GameObject}
 */
public final class Transform extends Component {
	public Vector2 position = new Vector2();

	private Transform parent;
	private ArrayList<Transform> children = new ArrayList<>();

	Transform() {
		position.setVector2ChangeListener((xDiff, yDiff) -> {
			for (int i = 0; i < children.size(); i++) {
				children.get(i).position.x += xDiff;
				children.get(i).position.y += yDiff;
			}
		});
	}

	public void setParent(Transform parent) {
		setParent(parent, true);
	}

	private void setParent(Transform parent, boolean addChild) {
		this.parent = parent;
		if (addChild) parent.addChild(this, false);
	}

	public Transform getParent() {
		return parent;
	}

	public void addChild(Transform child) {
		addChild(this, true);
	}

	private void addChild(Transform child, boolean setParent) {
		children.add(child);
		if (setParent) child.setParent(this, false);
	}

	public Transform getChild(int index) {
		return children.get(index);
	}

	/**
	 * Move the {@link GameObject} that this {@link Transform} is attached to. If the {@link GameObject} has a {@link Collider} attached, then the physics
	 *
	 * @param x
	 * @param y
	 */
	public void translate(float x, float y) {
		if (gameObject.isStatic) throw new Error("Static objects cannot be moved");
		if (x == 0 && y == 0) return;
		if (gameObject.collider != null) {
			gameObject.collider.move(x, y);
		} else {
			position.x += x;
			position.y += y;
		}
		for (int i = 0; i < children.size(); i++) {
			children.get(i).translate(x, y);
		}
	}
}

@@ -28,16 +28,80 @@
 quare;%0A%0A
+import com.ezardlabs.dethsquare.Vector2.Vector2ChangeListener;%0A%0A
 import j
@@ -436,28 +436,112 @@
 ner(
-(xDiff,
+new Vector2ChangeListener() %7B%0A%09%09%09@Override%0A%09%09%09public void onVector2Changed(float xDiff, float
  yDiff)
- -%3E
  %7B%0A
+%09
 %09%09%09f
@@ -583,24 +583,25 @@
  i++) %7B%0A%09%09%09%09
+%09
 children.get
@@ -625,16 +625,17 @@
  xDiff;%0A
+%09
 %09%09%09%09chil
@@ -667,16 +667,22 @@
  yDiff;%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D

Replace lambda with anonymous function