-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPowerupItem.pde
68 lines (57 loc) · 1.62 KB
/
PowerupItem.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
65
66
67
68
//Represents powerups that the player can pick up.
//Uses the powerup enum.
class PowerupItem implements ICharacter{
Powerup type;
int sizeValue;
PShape avatar;
PVector position;
PVector orientation;
//Constructs a powerup of a certain type.
PowerupItem(Powerup p){
type = p;
position = new PVector(random(0,width),random(0,height));
while(PVector.dist(player1.position,position) < radius()+player1.sizeValue){
position.x = random(0,width);
position.y = random(0,height);
}
orientation = PVector.random2D();
sizeValue = 3; //For ease of adjustment
avatar = createShape();
avatar.beginShape();
avatar.noFill();
avatar.vertex(-1*sizeValue,0);
avatar.vertex(-2*sizeValue,1.5*sizeValue);
avatar.vertex(2*sizeValue,0);
avatar.vertex(-2*sizeValue,-1.5*sizeValue);
avatar.vertex(-1*sizeValue,0);
avatar.endShape();
color c = color(255,0,255);
if(type == Powerup.NONE){
c = color(0,255,0);
} else if(type == Powerup.DOUBLE_POINTS){
c = color(255,255,0);
} else if(type == Powerup.SPEEDY){
c = color(0,0,255);
}
avatar.setStroke(c);
}
//Method required by interface.
void update(){
}
//Draws the powerup.
void draw(){
pushMatrix();
translate(position.x,position.y);
rotate(orientation.heading());
shape(avatar);
popMatrix();
}
//Gives the powerup's position.
PVector position(){
return position;
}
//Gives the radius of the powerup's bounding circle. I added a 1 pixel buffer for more accurate collisions.
int radius(){
return sizeValue+1;
}
}