-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.pde
71 lines (61 loc) · 1.78 KB
/
Player.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
69
70
71
class Player{
AudioPlayer wallHit;
int numPoints;
int initRadius;
float radius;
float baseAngle;
float angVel;
float rVel;
//PImage sprite;
Player(int _numPoints, AudioPlayer _wallHit){
wallHit = _wallHit;
numPoints = _numPoints;
initRadius = 20;
radius = initRadius;
baseAngle = 0;
angVel = 0;
rVel = 0;
//sprite = _sprite;
}
void draw(){
stroke(255);
noFill();
baseAngle += angVel;
baseAngle = baseAngle % (TWO_PI / ((float)numPoints));
if(baseAngle < 0){
baseAngle += (TWO_PI / ((float)numPoints));
}
radius += rVel;
if(p.handleWallCollision(l)){
wallHit.rewind();
wallHit.setVolume(0.25);
wallHit.play();
}
for(int i = 0; i < numPoints; ++i){
ellipse(radius*cos(baseAngle + i*(TWO_PI / ((float)numPoints) ) ), radius*sin(baseAngle + i*(TWO_PI / ((float)numPoints) ) ), 5, 5);
//image(sprite, radius*cos(baseAngle + i*(TWO_PI / ((float)numPoints) ) ), radius*sin(baseAngle + i*(TWO_PI / ((float)numPoints) ) ));
}
}
boolean _handleWallCollision(Circle c){
if( abs(baseAngle - c.rotAngle) % (TWO_PI / ((float) c.numHoles)) < asin(c.holeWidth / c.diameter)
|| abs(baseAngle - c.rotAngle) % (TWO_PI / ((float) c.numHoles)) > TWO_PI / ((float) c.numHoles) - asin(c.holeWidth / c.diameter)
){ return false;}
else if(radius < c.diameter / 2 + 5 && radius > c.diameter / 2 - 5){
if(radius < c.baseDiameter / 2 + 5){
radius = initRadius;
}
else{
radius -= 3 * c.baseDiameter / 4;
}
return true;
}
return false;
}
boolean handleWallCollision(Level l){
boolean buff = false;
for(int i = 0; i < l.numCircles; ++i){
buff = buff || _handleWallCollision(l.walls[i]);
}
return buff;
}
};