-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYarnBall.pde
143 lines (131 loc) · 3.35 KB
/
YarnBall.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
public class YarnBall
{
private float yarnX;
private float yarnY;
private float yarnWidth;
private float dropSpeedY;
//default constructor method setting default values of fields using validation in setter methods
public YarnBall()
{
setYarnX(yarnX);
setYarnY(yarnY);
setYarnWidth(yarnWidth);
resetYarnBall();
dropSpeedY = random(0.5, 1.5);
}
/*
overloaded constructor method taking in 3 parameters, not called in main program
*/
public YarnBall(float yarnX, float yarnY, float yarnWidth)
{
this.yarnX = yarnX;
this.yarnY = yarnY;
this.yarnWidth = yarnWidth;
dropSpeedY = random(0.5, 1.5);
}
//getter methods
public float getYarnX()
{
return yarnX;
}
public float getYarnY()
{
return yarnY;
}
public float getYarnWidth()
{
return yarnWidth;
}
public float getDropSpeedY()
{
return dropSpeedY;
}
//setter methods
//method with validation so that yarn ball does not move outside the x-axis/width of output window
public void setYarnX(float yarnX)
{
if (yarnX <50)
{
yarnX = 50;
}
if (yarnX >width-50)
{
yarnX = width-50;
}
}
public void setYarnY(float yarnY)
{
this.yarnY = yarnY;
}
//validation used to set diameter reasonably
public void setYarnWidth(float yarnWidth)
{
if ((yarnWidth >=40) && (yarnWidth <=80))
{
this.yarnWidth = yarnWidth;
} else
{
this.yarnWidth = 60;
}
}
public void setDropSpeedY(float dropSpeedY)
{
this.dropSpeedY = dropSpeedY;
}
/*
public method with no return drawing the Yarn Balls with angry faces
*/
public void drawAngryYarn()
{
stroke(0);
strokeWeight(1);
fill(181, 92, 180);
circle(yarnX, yarnY, yarnWidth);
line(yarnX-30, yarnY+5, yarnX+21, yarnY+21);
line(yarnX-28, yarnY-5, yarnX +26, yarnY +11);
line(yarnX-26, yarnY-15, yarnX+30, yarnY+1);
line(yarnX, yarnY-30, yarnX-5, yarnY-14);
line(yarnX+10, yarnY-28, yarnX+4, yarnY-8);
line(yarnX+20, yarnY-23, yarnX+13, yarnY-2);
line(yarnX-17, yarnY+24, yarnX-12, yarnY+10);
line(yarnX-7, yarnY+29, yarnX-2, yarnY+14);
line(yarnX+3, yarnY+30, yarnX+8, yarnY+18);
fill(255, 0, 0);
circle(yarnX - 12, yarnY - 5, 10);
circle(yarnX + 12, yarnY - 5, 10);
strokeWeight(4);
line(yarnX -18, yarnY -18, yarnX -7, yarnY -12);
line(yarnX +18, yarnY -18, yarnX +7, yarnY -12);
line(yarnX -10, yarnY +12, yarnX +10, yarnY +12);
}
/*
public method with no return moving the
yarn balls down the screen by increasing the y coordinate
*/
public void update()
{
yarnY = yarnY + dropSpeedY;
}
/*
public method with boolean return used to show when a life is lost in the game - i.e. when a Yarn Ball reaches the
end of the screen a life is lost.
*/
public boolean reachedBottom()
{
boolean lifeLost = false;
if (yarnY >= height)
{
lifeLost = true;
}
return lifeLost;
}
/*
public method with no return resetting yarn ball to certain values. Used in main program.
Also called in default constructor to set starting values of yarn ball.
*/
public void resetYarnBall()
{
yarnX = random(30, width-30);
yarnY = 0;
}
}