-
Notifications
You must be signed in to change notification settings - Fork 1
/
Reward.java
46 lines (38 loc) · 1.21 KB
/
Reward.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
43
44
45
46
package ast;
import static constants.Constant.GAME_UNIT;
import static constants.Constant.REWARD_DISTANCE;
/**
* Base reward for our game which specifies how much to reward per a specified distance the user travels
*/
public class Reward extends Node {
private final Integer value;
private final Integer distance;
private final Integer factor;
private int counter;
public Reward(Integer value, Integer distance) {
this.value = value;
this.distance = distance * GAME_UNIT;
// we want to update reward every 5 pixels travelled. So need to scale distance and value accordingly
// e.g. if value=100 and distance=50pixels, this is equivalent to rewarding 10 every 5 units
factor = this.distance / REWARD_DISTANCE;
}
public Integer getValue() {
return value;
}
public Integer getValueNormalized() {
return value / factor;
}
public Integer getDistance() {
return distance;
}
public int getCounter() { return counter; }
/**
* Always update reward every 5 PIXELS travelled
*/
public void update(){
if(counter == REWARD_DISTANCE){
counter = 0;
}
counter++;
}
}