Block.java 698 B

123456789101112131415161718192021222324252627282930
  1. package eu.tankernn.breakout;
  2. import org.lwjgl.util.vector.Vector2f;
  3. import eu.tankernn.gameEngine.entities.Entity2D;
  4. import eu.tankernn.gameEngine.loader.textures.Texture;
  5. public class Block extends Entity2D {
  6. public static final int ROWS = 8, COLUMNS = 14;
  7. int health = 1;
  8. public Block(Texture texture, int gridX, int gridY) {
  9. super(texture, new Vector2f(0, 0), new Vector2f(1.0f / (COLUMNS), 0.5f / (ROWS)));
  10. this.position.x = this.scale.x * 2f * (gridX) + this.scale.x - 1;
  11. this.position.y = this.scale.y * 2f * (gridY) + this.scale.y;
  12. }
  13. public Block setHealth(int health) {
  14. this.health = health;
  15. return this;
  16. }
  17. public void hit() {
  18. this.alive = --health > 0;
  19. }
  20. }