-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroundItem.pde
64 lines (58 loc) · 1.33 KB
/
GroundItem.pde
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class GroundItem {
String myType;
int alpha = 100;
float myX, myY;
boolean pickedUp, alphaIncreasing;
PImage icon;
GroundItem (String type, float x, float y) {
myType = type;
myX = x;
myY = y;
// String item types, matching the inventory HashMaps name, for easier item spawning
switch (myType) {
case "Boomerang":
icon = boomerang.copy();
break;
case "Vegemite":
icon = vegemite.copy();
break;
case "Grenade":
icon = grenade.copy();
break;
case "Landmine":
icon = landmine.copy();
break;
case "Gas":
icon = grenade.copy();
break;
default:
icon = boomerang.copy();
break;
}
}
// if the truck is on the item, adds the item type to the inventory
void pickup () {
if (truck.getX() < myX + 150 && truck.getX() > myX - 150 && truck.getY() < myY + 150 && truck.getY() > myY - 150) {
inventory.put(myType, inventory.get(myType) + 1);
pickedUp = true;
}
}
boolean toRemove() {
return pickedUp;
}
void update() {
// item alpha creates flashing effect
if (alphaIncreasing) {
alpha+=3;
} else {
alpha-=3;
}
if (alpha < 100 || alpha > 200) {
alphaIncreasing = !alphaIncreasing;
}
tint(alpha);
image(icon, myX, myY);
noTint();
pickup();
}
}