-
Notifications
You must be signed in to change notification settings - Fork 0
/
Burger.java
42 lines (35 loc) · 1.14 KB
/
Burger.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package org.cis1200.snake;
import java.util.LinkedList;
public class Burger extends Fruit {
private long startTime;
private boolean eaten;
public Burger(int courtWidth, int courtHeight, int x, int y) {
super(courtWidth, courtHeight, "files/burger.png", x, y, "burger");
}
// if eaten makes the snake slower for 30 seconds
@Override
public void eaten(LinkedList<Snake> snake) {
int originalVx = snake.getFirst().getVx();
int originalVy = snake.getFirst().getVy();
// record start time
if (startTime == 0) {
startTime = System.currentTimeMillis();
}
// check if 10 sec passed
if (System.currentTimeMillis() - startTime < 10000 && !eaten) {
for (Snake s : snake) {
s.setVx(s.getVx() / 2);
s.setVy(s.getVy() / 2);
}
eaten = true;
} else {
// resets values after 10 seconds
startTime = 0;
for (Snake s : snake) {
s.setVx(originalVx);
s.setVy(originalVy);
}
eaten = false;
}
}
}