-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskFolding.pde
209 lines (183 loc) · 6.52 KB
/
taskFolding.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
class TaskFolding extends Task {
TaskFolding(String sceneName, String backgroundImageFile, MoveToSceneObject sceneStarter, GameObject replaceWith, String desc, PVector minimapLocation, PImage minimapIcon, int sa) {
super(sceneName, backgroundImageFile, sceneStarter, replaceWith, desc, minimapLocation, minimapIcon, sa);
}
PImage[] pileOfClothes;
PImage noClothesOnPile;
PImage[] foldedClothes;
PImage[] cloths;
Quad[] parts;
boolean[] lock = new boolean[] {false, false, false};
boolean[] pointInQuad = new boolean[] {false, false, false};
boolean[] released = new boolean[] {true, true, true};
boolean[] isMouseOverPile = new boolean[] {false, false}; // 0 is to finish the cloth, 1 is to get a cloth
boolean hasSomethingInHand = false;
boolean hasClothToFold = false;
boolean addedACloth = true;
int folded = -1;
int clothesLeft = 0;
//int tshirt = 0;
void setup()
{
setCursor(ARROW);
pileOfClothes = new PImage[] { loadImage("tasks/folding/unfoldedClothes1.png"), loadImage("tasks/folding/unfoldedClothes2.png"), loadImage("tasks/folding/unfoldedClothes3.png"), loadImage("tasks/folding/unfoldedClothes4.png")};
noClothesOnPile = loadImage("tasks/folding/foldedClothes0.png");
foldedClothes = new PImage[] {loadImage("tasks/folding/foldedClothes1.png"), loadImage("tasks/folding/foldedClothes2.png"), loadImage("tasks/folding/foldedClothes3.png"), loadImage("tasks/folding/foldedClothes4.png")};
cloths = new PImage[] {loadImage("tasks/folding/tshirt1.png"), loadImage("tasks/folding/tshirt2.png"), loadImage("tasks/folding/tshirt3.png"), loadImage("tasks/folding/tshirt4.png")};
parts = new Quad[3];
parts[0] = new Quad(new PVector(825.6, 449.4), new PVector(825.6, 499.4), new PVector(750.6, 529.4), new PVector(750.6, 479.4));
parts[1] = new Quad(new PVector(754 + cloths[folded + 1].width, 300), new PVector(754 + cloths[folded + 1].width, 350), new PVector(800 + cloths[folded + 1].width, 370), new PVector(800 + cloths[folded + 1].width, 320));
parts[2] = new Quad(new PVector(754, 300 + cloths[folded + 1].height), new PVector(754 + cloths[folded + 1].width, 300 + cloths[folded + 1].height), new PVector(754 + cloths[folded + 1].width, 650), new PVector(754, 650));
mouse = new PVector(0, 0);
}
void draw()
{
if (folded == 3)
{
done();
}
canvas.image(backgroundImage, 0, 0);
if (clothesLeft < 4)
canvas.image(pileOfClothes[clothesLeft], 1297, 488);
if (folded >= 0)
canvas.image(foldedClothes[folded], 250, 455);
if (folded < 0)
canvas.image(noClothesOnPile, 250, 455);
if (hasClothToFold)
{
canvas.image(cloths[folded + 1], 825.6, 446.4);
if (folded + 1 == 0)
{
canvas.strokeWeight(3);
canvas.stroke(#76001d);
canvas.fill(#b9153e);
} else if (folded + 1 == 1)
{
canvas.strokeWeight(3);
canvas.stroke(#417da9);
canvas.fill(#82b7dd);
} else if (folded + 1 == 2)
{
canvas.strokeWeight(3);
canvas.stroke(#7ed7a6);
canvas.fill(#beffdb);
} else {
canvas.strokeWeight(3);
canvas.stroke(#9c5d00);
canvas.fill(#ff9800);
}
for (int i = 0; i < 3; i++)
{
canvas.quad(parts[i].a.x, parts[i].a.y, parts[i].b.x, parts[i].b.y, parts[i].c.x, parts[i].c.y, parts[i].d.x, parts[i].d.y);
}
}
/*
stroke(1);
noFill();
circle((parts[0].c.x + parts[0].d.x)/2, (parts[0].c.y + parts[0].d.y)/2, (parts[0].c.y - parts[0].d.y));
*/
}
void mouseClicked()
{
if (debugMode) println(isMouseOverPile[1]);
if (random(1.0) < 0.5)
sfxFolding1.play();
else
sfxFolding2.play();
for (int i = 0; i < 3; i++)
{
if (!lock[i])
{
if (pointInQuad[i] && !hasSomethingInHand)
{
hasSomethingInHand = true;
released[i] = false;
}
if ((parts[i].c.x > 825.6 && parts[i].c.x < 825.6 + cloths[folded + 1].width && parts[i].c.y > 446.4 && parts[i].c.y < 446.4 + cloths[folded + 1].height)
&& (parts[i].d.x > 825.6 && parts[i].d.x < 825.6 + cloths[folded + 1].width && parts[i].d.y > 446.4 && parts[i].d.y < 446.4 + cloths[folded + 1].height))
{
lock[i] = true;
released[i] = true;
hasSomethingInHand = false;
}
}
}
if (isMouseOverPile[1] && !hasClothToFold)
{
hasClothToFold = true;
addedACloth = false;
parts[0] = new Quad(new PVector(825.6, 449.4), new PVector(825.6, 499.4), new PVector(750.6, 526.4), new PVector(750.6, 479.4));
parts[1] = new Quad(new PVector(825.6 + cloths[folded + 1].width, 449.4), new PVector(825.6 + cloths[folded + 1].width, 499.4), new PVector(900.6 + cloths[folded + 1].width, 529.4), new PVector(900.6 + cloths[folded + 1].width, 479.4));
parts[2] = new Quad(new PVector(828.6, 446.4 + cloths[folded + 1].height), new PVector(823.6 + cloths[folded + 1].width, 446.4 + cloths[folded + 1].height),
new PVector(823.6 + cloths[folded + 1].width, 750), new PVector(828.6, 750));
hasSomethingInHand = false;
for (int i = 0; i < 3; i++)
{
lock[i] = false;
released[i] = true;
}
clothesLeft++;
}
if (isMouseOverPile[0] && !addedACloth && theClothIsFolded())
{
hasClothToFold = false;
addedACloth = true;
folded ++;
}
}
void mouseMoved()
{
if (clothesLeft < 4)
if (mouse.x > 1297 && mouse.x < 1297 + pileOfClothes[clothesLeft].width && mouse.y > 488 && mouse.y < 488 + pileOfClothes[clothesLeft].height)
{
isMouseOverPile[1] = true;
} else
{
isMouseOverPile[1] = false;
}
if (mouse.x > 0 && mouse.x < 550)
{
isMouseOverPile[0] = true;
} else
{
isMouseOverPile[0] = false;
}
for (int i = 0; i < 3; i++)
{
if (parts[i].pointCheck(mouse))
{
pointInQuad[i] = true;
} else
{
pointInQuad[i] = false;
}
if (!released[i])
{
if (i!=2)
{
parts[i].c.x = mouse.x;
parts[i].d.x = mouse.x;
parts[i].c.y = mouse.y + 25;
parts[i].d.y = mouse.y - 25;
} else {
parts[i].c.y = mouse.y;
parts[i].d.y = mouse.y;
parts[i].c.x = mouse.x + 83;
parts[i].d.x = mouse.x - 83;
}
}
}
}
boolean theClothIsFolded()
{
int a = 1;
for (int i = 0; i < 3; i++)
{
if (!lock[i])
a = 0;
}
if (a == 1)
return true;
else return false;
}
}