Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / entites / gameComponents / Physics.java
  1. package gameEngine.entites.gameComponents;
  2.  
  3. import gameEngine.Time;
  4. import gameEngine.entites.GameObject;
  5.  
  6. public class Physics extends GameComponent{
  7.  
  8. private GameObject parent;
  9. public boolean useGravity = true;
  10. private float gravity = 9.8f; // 地球の重力加速度を使用
  11. private float velocityY = 0; // Y軸方向の速度 Resetしなければ速度が引き継がれる
  12.  
  13. public Physics(GameObject parent){
  14. this.parent = parent;
  15. }
  16.  
  17. @Override
  18. public GameComponent copy() {
  19. return this;
  20. }
  21.  
  22. public void update() {
  23. if (useGravity) {
  24. float deltaTime = Time.deltaTime;
  25.  
  26. velocityY += gravity * deltaTime;
  27.  
  28. float y = parent.transform.position.y;
  29. parent.transform.setPosition(parent.transform.position.x, y + velocityY * deltaTime, parent.transform.position.z);
  30. }
  31. }
  32.  
  33. public void reset() {
  34. velocityY = 0;
  35. }
  36. }