Entity2D.java 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package eu.tankernn.gameEngine.entities;
  2. import org.lwjgl.util.vector.Vector2f;
  3. import eu.tankernn.gameEngine.loader.textures.Texture;
  4. import eu.tankernn.gameEngine.renderEngine.gui.GuiTexture;
  5. public class Entity2D extends GuiTexture {
  6. protected Vector2f velocity = new Vector2f(0, 0);
  7. protected boolean alive = true;
  8. public Entity2D(Texture texture, Vector2f position, Vector2f scale) {
  9. super(texture, position, scale);
  10. }
  11. public void update() {
  12. this.position = Vector2f.add(position, velocity, null);
  13. }
  14. public void setVelocity(Vector2f velocity) {
  15. this.velocity = velocity;
  16. }
  17. public boolean collides(Entity2D b) {
  18. if (Math.abs(position.x - b.getPosition().x) < scale.x + b.getSize().x) {
  19. if (Math.abs(position.y - b.getPosition().y) < scale.y + b.getSize().y) {
  20. return true;
  21. }
  22. }
  23. return false;
  24. }
  25. public Vector2f getPosition() {
  26. return position;
  27. }
  28. public Vector2f getSize() {
  29. return super.getScale();
  30. }
  31. public boolean isAlive() {
  32. return alive;
  33. }
  34. }