diff --git a/src/main/dev/lh/Food.java b/src/main/dev/lh/Food.java index 560ed93..d47fa77 100644 --- a/src/main/dev/lh/Food.java +++ b/src/main/dev/lh/Food.java @@ -5,6 +5,8 @@ import java.awt.Graphics2D; import java.awt.Rectangle; /** + * Represents a food item. + *
* Project: Snake
* File: Food.java
* Created: 01.07.2020
@@ -18,23 +20,35 @@ public final class Food implements Updateable {
private final int lengthBonus;
private final Rectangle bounds;
+ /**
+ * Constructs a food item.
+ *
+ * @param color the color of the food item
+ * @param lengthBonus the length added to the snake when the food item is eaten
+ * @param bounds the bounds of the food item
+ * @since Snake 1.1
+ */
public Food(Color color, int lengthBonus, Rectangle bounds) {
this.color = color;
this.lengthBonus = lengthBonus;
this.bounds = bounds;
}
- public void checkCollision(Snake snake) {
- if (bounds.intersects(snake.getHead())) {}
- }
-
@Override
public void render(Graphics2D g) {
g.setColor(color);
g.fill(bounds);
}
+ /**
+ * @return the length added to the snake when the food item is eaten
+ * @since Snake 1.1
+ */
public int getLengthBonus() { return lengthBonus; }
+ /**
+ * @return the bounds of the food item
+ * @since Snake 1.1
+ */
public Rectangle getBounds() { return bounds; }
}
diff --git a/src/main/dev/lh/FoodFactory.java b/src/main/dev/lh/FoodFactory.java
index 7de2c2c..e8aaa18 100755
--- a/src/main/dev/lh/FoodFactory.java
+++ b/src/main/dev/lh/FoodFactory.java
@@ -55,8 +55,8 @@ public final class FoodFactory {
FOOD_LENGTH_BONUSES[seed],
new Rectangle(random.nextInt(width - 100) + 50,
random.nextInt(height - 100) + 50,
- seed * 10,
- seed * 10
+ 10 + seed * 5,
+ 10 + seed * 5
)
);
}
diff --git a/src/main/dev/lh/Handler.java b/src/main/dev/lh/Handler.java
index c1fe515..562ae0b 100644
--- a/src/main/dev/lh/Handler.java
+++ b/src/main/dev/lh/Handler.java
@@ -19,6 +19,13 @@ public final class Handler implements Updateable {
private volatile Food food;
+ /**
+ * Constructs a handler.
+ *
+ * @param snake the snake
+ * @param foodFactory the food factory
+ * @since Snake 1.1
+ */
public Handler(Snake snake, FoodFactory foodFactory) {
this.snake = snake;
this.foodFactory = foodFactory;
@@ -29,6 +36,7 @@ public final class Handler implements Updateable {
public void tick() {
snake.tick();
food.tick();
+
// Check for food collision
if (snake.getHead().intersects(food.getBounds())) {
snake.addLength(food.getLengthBonus());
diff --git a/src/main/dev/lh/Viewport.java b/src/main/dev/lh/Viewport.java
index 9c5b6f2..943f3a7 100644
--- a/src/main/dev/lh/Viewport.java
+++ b/src/main/dev/lh/Viewport.java
@@ -60,7 +60,7 @@ public class Viewport extends Canvas {
long time = System.currentTimeMillis();
double dt = (time - lastTime) * 1E-3;
lastTime = time;
-
+ // TODO: Delta time adjustment
gameRoot.tick();
render();
}