diff --git a/GameEngine/src/main/java/gameEngine/entites/GameObject.java b/GameEngine/src/main/java/gameEngine/entites/GameObject.java index da2e510..a8f3a7b 100644 --- a/GameEngine/src/main/java/gameEngine/entites/GameObject.java +++ b/GameEngine/src/main/java/gameEngine/entites/GameObject.java @@ -56,4 +56,13 @@ } } + public T getComponent(Class componentClass){ + for (GameComponent gameComponent :gameComponents) { + if (componentClass.isInstance(gameComponent)) { + return componentClass.cast(gameComponent); + } + } + return null; + } + } \ No newline at end of file diff --git a/GameEngine/src/main/java/gameEngine/entites/gameComponents/MoveImage.java b/GameEngine/src/main/java/gameEngine/entites/gameComponents/MoveImage.java index ba50d62..a1930e4 100644 --- a/GameEngine/src/main/java/gameEngine/entites/gameComponents/MoveImage.java +++ b/GameEngine/src/main/java/gameEngine/entites/gameComponents/MoveImage.java @@ -21,6 +21,23 @@ } public void update() { + + if(Input.GetKey(GLFW_KEY_O)){ + GameObject gameObject = (GameObject) entity; + TextMesh textmesh = gameObject.getComponent(TextMesh.class); + textmesh.setTextSize(textmesh.textSize+1); + } + if(Input.GetKey(GLFW_KEY_P)){ + GameObject gameObject = (GameObject) entity; + TextMesh textmesh = gameObject.getComponent(TextMesh.class); + textmesh.setTextSize(textmesh.textSize-1); + } + if(Input.GetKeyDown(GLFW_KEY_I)){ + GameObject gameObject = (GameObject) entity; + TextMesh textmesh = gameObject.getComponent(TextMesh.class); + textmesh.setText("popopo"); + } + if (Input.GetKey(GLFW_KEY_W)) { float y = entity.transform.position.y; entity.transform.setPosition(entity.transform.position.x, y - 1, entity.transform.position.z); diff --git a/GameEngine/src/main/java/gameEngine/entites/gameComponents/TextMesh.java b/GameEngine/src/main/java/gameEngine/entites/gameComponents/TextMesh.java index 69784e5..457ca67 100644 --- a/GameEngine/src/main/java/gameEngine/entites/gameComponents/TextMesh.java +++ b/GameEngine/src/main/java/gameEngine/entites/gameComponents/TextMesh.java @@ -24,6 +24,7 @@ public TextMesh(Entity parent, String text, int textSize) { this.parent = parent; this.text = text; + this.textSize = textSize; Font font = new Font(new java.awt.Font(SANS_SERIF, PLAIN, textSize),true); fontTexture = font.getTexture(); fontGlyphs = font.getGlyphs(); @@ -31,12 +32,12 @@ } public TextMesh(TextMesh original, Entity newParent) { - this.fontTexture = original.fontTexture; - this.fontGlyphs = original.fontGlyphs; - this.fontHeight = original.fontHeight; + this.parent = newParent; this.text = original.text; this.textSize = original.textSize; - this.parent = newParent; // 新しい親オブジェクトに設定 + this.fontGlyphs = original.fontGlyphs; + this.fontTexture = original.fontTexture; + this.fontHeight = original.fontHeight; } @@ -59,6 +60,23 @@ renderText(); // テキストの描画 } + public void setText(String newText){ + this.text = newText; + renderText(); + } + + public void setTextSize(int newTextSize) { + if(newTextSize < 3 || newTextSize > 127) return; + + this.textSize = newTextSize; + Font font = new Font(new java.awt.Font(SANS_SERIF, PLAIN, textSize), true); + this.fontTexture = font.getTexture(); + this.fontGlyphs = font.getGlyphs(); + this.fontHeight = font.getFontHeight(); + + renderText(); + } + public void renderText() { // Switch to 2D rendering mode glMatrixMode(GL_PROJECTION); diff --git a/GameEngine/src/main/java/gameEngine/scenes/Scene.java b/GameEngine/src/main/java/gameEngine/scenes/Scene.java index a6f1915..8901587 100644 --- a/GameEngine/src/main/java/gameEngine/scenes/Scene.java +++ b/GameEngine/src/main/java/gameEngine/scenes/Scene.java @@ -62,12 +62,24 @@ }); } - // コンポーネントの追加メソッド + /** + * Adds a component to the specified GameObject. + * This method enqueues a task to add the given GameComponent to the GameObject's component list. + * + * @param gameObject The GameObject to which the component will be added. + * @param component The GameComponent to be added to the GameObject. + */ public void addComponentToGameObject(GameObject gameObject, GameComponent component) { enqueueTask(() -> gameObject.addComponent(component)); } - // コンポーネントの削除メソッド + /** + * Removes a component from the specified GameObject. + * This method enqueues a task to remove the given GameComponent from the GameObject's component list. + * + * @param gameObject The GameObject from which the component will be removed. + * @param component The GameComponent to be removed from the GameObject. + */ public void removeComponentFromGameObject(GameObject gameObject, GameComponent component) { enqueueTask(() -> gameObject.removeComponent(component)); } @@ -94,26 +106,26 @@ newGameObject.setName(original.getName() + "_copy"); newGameObject.transform = new Transform(original.transform); - for (GameComponent gameComponent : original.gameComponents) { - if (gameComponent instanceof Mesh) { - newGameObject.addComponent(new Mesh((Mesh)gameComponent.copy(), newGameObject)); - } - if (gameComponent instanceof TextMesh) { - newGameObject.addComponent(new TextMesh((TextMesh)gameComponent.copy(), newGameObject)); - } - if (gameComponent instanceof ColorController) { - newGameObject.addComponent(new ColorController()); - } - if (gameComponent instanceof CopyEntity) { - newGameObject.addComponent(new CopyEntity(newGameObject)); - } - if (gameComponent instanceof MoveImage) { - newGameObject.addComponent(new MoveImage(newGameObject)); - } - if (gameComponent instanceof Physics) { - newGameObject.addComponent(new Physics(newGameObject)); - } + + if (original.getComponent(Mesh.class) != null) { + newGameObject.addComponent(new Mesh((Mesh)original.getComponent(Mesh.class).copy(), newGameObject)); } + if (original.getComponent(TextMesh.class) != null) { + newGameObject.addComponent(new TextMesh((TextMesh)original.getComponent(TextMesh.class).copy(), newGameObject)); + } + if (original.getComponent(ColorController.class) != null) { + newGameObject.addComponent(new ColorController()); + } + if (original.getComponent(CopyEntity.class) != null) { + newGameObject.addComponent(new CopyEntity(newGameObject)); + } + if (original.getComponent(MoveImage.class) != null) { + newGameObject.addComponent(new MoveImage(newGameObject)); + } + if (original.getComponent(Physics.class) != null) { + newGameObject.addComponent(new Physics(newGameObject)); + } + addEntity(newId, newGameObject); });