diff --git a/GameEngine/src/main/java/gameEngine/entites/gameComponents/Button.java b/GameEngine/src/main/java/gameEngine/entites/gameComponents/Button.java new file mode 100644 index 0000000..44237df --- /dev/null +++ b/GameEngine/src/main/java/gameEngine/entites/gameComponents/Button.java @@ -0,0 +1,38 @@ +package gameEngine.entites.gameComponents; + +import gameEngine.entites.Entity; +import gameEngine.input.Input; +import gameEngine.input.MouseInput; + +public class Button extends GameComponent { + + private Entity entity; + private Mesh mesh; + public Button(Entity entity, Mesh mesh) { + this.entity = entity; + this.mesh = mesh; + } + + @Override + public GameComponent copy() { + return null; + } + + public void init() { + } + + public void update() { + float mouseX = MouseInput.getX(); + float mouseY = MouseInput.getY(); + + float x = entity.transform.position.x; + float y = entity.transform.position.y; + float width = mesh.getDisplayedWidth(); + float height = mesh.getDisplayedHeight(); + + // マウスがボタンの範囲内にあるかどうかをチェック + if (Input.GetMouseButtonUp(0) && mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height) { + System.out.println("Button clicked! Mouse X: " + mouseX + ", Mouse Y: " + mouseY); + } + } +}