package gameEngine.entites; import gameEngine.entites.gameComponents.GameComponent; import gameEngine.entites.gameComponents.Mesh; import gameEngine.entites.gameComponents.TextMesh; import gameEngine.scenes.GameScene; import gameEngine.views.Window; import java.util.ArrayList; import java.util.List; public class GameObject extends Entity { public final List<GameComponent> gameComponents = new ArrayList<>(); public GameObject(String id) { super(id); } public void addComponent(GameComponent component) { for (GameComponent existingComponent : gameComponents) { if (existingComponent.getClass().equals(component.getClass())) { System.out.println("Component already exists: " + component.getClass().getSimpleName()); return; } } this.gameComponents.add(component); System.out.println("Component added: " + component.getClass().getSimpleName()); } public void removeComponent(GameComponent component) { boolean removed = this.gameComponents.remove(component); if (removed) { System.out.println("Component removed: " + component.getClass().getSimpleName()); } else { System.out.println("Component not found: " + component.getClass().getSimpleName()); } } public void initComponents() { for (GameComponent component : gameComponents) { component.init(); } } public void updateComponents() { for (GameComponent component : gameComponents) { component.update(); } } public <T extends GameComponent> T getComponent(Class<T> componentClass){ for (GameComponent gameComponent :gameComponents) { if (componentClass.isInstance(gameComponent)) { return componentClass.cast(gameComponent); } } return null; } }