-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduster.html
236 lines (206 loc) · 8.71 KB
/
duster.html
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Duster</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
<link rel="stylesheet" href="buttons.css">
<style>
body {
background-color: black;
cursor: url('sprites/room/cursor1.png'), auto;
}
button:hover {
cursor: url('sprites/room/cursor2.png'), auto;
}
</style>
</head>
<body>
<button id="uh" style="display: none;">Uh, maybe another time...</button>
<button id="niceStart" style="display: none;">Can you handle some dust bunnies?</button>
<button id="meanStart" style="display: none;">CLEAN FOR ME!</button>
<button id="sorry" style="display: none;">Sorry, what I meant to say was...</button>
<button id="meanAgain" style="display: none;">GET TO WORK!</button>
<button id="niceAgain" style="display: none;">I have a dime. Would that work?</button>
<button id="meanEnd" style="display: none;">Nothing?</button>
<button id="return" style="display: none;">Return to Room</button>
<script>
var dusterCheck = localStorage.getItem('dusterCheck');
let canvasX;
let canvasY;
let backdrop;
let duster;
let convo = 0;
function preload() {
backdrop = loadImage('sprites/characters/dusterBackground.png');
duster = loadImage('sprites/characters/duster.png');
}
function setup() {
scale = Math.min(windowWidth / backdrop.width, windowHeight / backdrop.height);
canvasX = (windowWidth / 2) - (backdrop.width / 2) * scale;
canvasY = (windowHeight / 2) - (backdrop.height / 2) * scale;
width = backdrop.width * scale;
height = backdrop.height * scale;
canvas = createCanvas(width, height).attribute('id', 'mainCanvas').attribute('willReadFrequently', true);
canvas.position(canvasX, canvasY);
positionButtons();
if (dusterCheck === '-1') {
showButtons(['uh']);
}
else {
showButtons(['niceStart', 'meanStart']);
}
}
function windowResized() {
scale = Math.min(windowWidth / backdrop.width, windowHeight / backdrop.height);
canvasX = (windowWidth / 2) - (backdrop.width / 2) * scale;
canvasY = (windowHeight / 2) - (backdrop.height / 2) * scale;
width = backdrop.width * scale;
height = backdrop.height * scale;
resizeCanvas(width, height);
canvas.position(canvasX, canvasY);
positionButtons();
}
function styledText(string, x, y) {
stroke(0, 0, 0);
strokeWeight(4);
sizeOfText = 18 * scale;
textSize(sizeOfText);
textStyle(BOLD);
textAlign(CENTER);
textFont('Papyrus');
fill(255);
text(string, x, y);
}
function draw() {
clear();
background(backdrop);
image(duster, width / 2 - duster.width / 8 * scale, height - duster.height / 2.7 * scale, duster.width / 4 * scale, duster.height / 4 * scale);
switch (convo) {
case 0:
styledText("Can I help you?", width / 2, height / 1.35);
break;
case 1:
styledText("Excuse me?", width / 2, height / 1.35);
break;
case 2:
styledText("Of course, but what's in it for me?", width / 2, height / 1.35);
break;
case 3:
styledText("No thanks", width / 2, height / 1.35);
break;
case 4:
styledText("Sure, why not?", width / 2, height / 1.35);
break;
case 5:
styledText("Yeaaa, no.", width / 2, height / 1.35);
break;
case 6:
styledText("Uh huh?", width / 2, height / 1.35);
break;
case 7:
styledText("Whatever...", width / 2, height / 1.35);
break;
default:
}
}
function positionButtons() {
const canvas = document.getElementById('mainCanvas');
if (canvas) {
const canvasRect = canvas.getBoundingClientRect();
const buttons = [
{ id: 'uh', top: canvasY + height / 1.22 },
{ id: 'niceStart', top: canvasY + height / 1.28 },
{ id: 'meanStart', top: canvasY + height / 1.16 },
{ id: 'sorry', top: canvasY + height / 1.16 },
{ id: 'meanAgain', top: canvasY + height / 1.28 },
{ id: 'niceAgain', top: canvasY + height / 1.16 },
{ id: 'meanEnd', top: canvasY + height / 1.28 },
{ id: 'return', top: canvasY + height / 1.22 },
];
buttons.forEach(button => {
const element = document.getElementById(button.id);
element.style.top = `${button.top}px`;
element.style.left = `${canvasRect.left + canvasRect.width / 2}px`;
element.style.transform = 'translate(-50%)';
element.style.width = `${width}px`;
});
}
}
document.addEventListener("DOMContentLoaded", function () {
var uhButton = document.getElementById('uh');
uhButton.addEventListener('click', function () {
convo = 7;
hideButtons(['uh']);
showButtons(['return']);
});
});
document.addEventListener("DOMContentLoaded", function () {
var niceStartButton = document.getElementById('niceStart');
niceStartButton.addEventListener('click', function () {
convo = 2;
hideButtons(['niceStart', 'meanStart']);
showButtons(['niceAgain', 'meanEnd']);
});
});
document.addEventListener("DOMContentLoaded", function () {
var meanStartButton = document.getElementById('meanStart');
meanStartButton.addEventListener('click', function () {
convo = 1;
hideButtons(['niceStart', 'meanStart']);
showButtons(['sorry', 'meanAgain']);
});
});
document.addEventListener("DOMContentLoaded", function () {
var sorryButton = document.getElementById('sorry');
sorryButton.addEventListener('click', function () {
convo = 6;
hideButtons(['sorry', 'meanAgain']);
showButtons(['niceStart', 'meanStart']);
});
});
document.addEventListener("DOMContentLoaded", function () {
var meanAgainButton = document.getElementById('meanAgain');
meanAgainButton.addEventListener('click', function () {
convo = 3;
hideButtons(['sorry', 'meanAgain']);
showButtons(['return']);
});
});
document.addEventListener("DOMContentLoaded", function () {
var niceAgainButton = document.getElementById('niceAgain');
niceAgainButton.addEventListener('click', function () {
convo = 4;
localStorage.setItem('dusterCheck', '1');
hideButtons(['niceAgain', 'meanEnd']);
showButtons(['return']);
});
});
document.addEventListener("DOMContentLoaded", function () {
var meanEndButton = document.getElementById('meanEnd');
meanEndButton.addEventListener('click', function () {
convo = 5;
hideButtons(['niceAgain', 'meanEnd']);
showButtons(['return']);
});
});
document.addEventListener("DOMContentLoaded", function () {
var returnButton = document.getElementById('return');
returnButton.addEventListener('click', function () {
window.location.href = 'room.html';
});
});
function hideButtons(buttonIds) {
buttonIds.forEach(id => {
document.getElementById(id).style.display = 'none';
});
}
function showButtons(buttonIds) {
buttonIds.forEach(id => {
document.getElementById(id).style.display = 'block';
});
}
</script>
</body>
</html>