-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloading.html
More file actions
254 lines (224 loc) · 6.81 KB
/
Copy pathloading.html
File metadata and controls
254 lines (224 loc) · 6.81 KB
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<style>
* { margin:0; padding:0; box-sizing:border-box; }
body { background:#000011; overflow:hidden; width:512px; height:448px; }
canvas { display:block; image-rendering:pixelated; }
</style>
</head>
<body>
<canvas id="c" width="512" height="448"></canvas>
<script>
const c = document.getElementById('c');
const ctx = c.getContext('2d');
const W = 512, H = 448;
let frame = 0;
const MARIO = [
[0,0,0,1,1,1,1,1,0,0,0,0],
[0,0,1,1,1,1,1,1,1,1,1,0],
[0,0,3,3,3,2,2,3,2,0,0,0],
[0,3,2,3,2,2,2,3,2,2,2,0],
[0,3,2,3,3,2,2,2,3,2,2,3],
[0,3,3,2,2,2,2,3,3,3,3,0],
[0,0,0,2,2,2,2,2,2,2,0,0],
[0,0,1,1,4,1,1,1,0,0,0,0],
[0,1,1,1,4,1,1,4,1,1,1,0],
[1,1,1,1,4,4,4,4,1,1,1,1],
[2,2,1,4,4,4,4,4,4,1,2,2],
[2,2,2,4,4,0,0,4,4,2,2,2],
[0,0,3,3,0,0,0,0,3,3,0,0],
[0,3,3,3,0,0,0,0,3,3,3,0],
];
const MARIO_COLORS = ['rgba(0,0,0,0)','#e8000d','#ffaa77','#6b3a2a','#2244cc','#111111'];
const MARIO_RUN1 = [...MARIO,
[3,3,3,0,0,0,0,0,0,3,3,3],
[3,3,0,0,0,0,0,0,0,0,3,3],
];
const MARIO_RUN2 = [...MARIO,
[0,3,3,3,0,0,0,0,3,3,3,0],
[0,0,3,3,3,0,0,3,3,3,0,0],
];
function drawMario(x, y, scale, frame) {
const sprite = (Math.floor(frame/8) % 2 === 0) ? MARIO_RUN1 : MARIO_RUN2;
sprite.forEach((row, ri) => {
row.forEach((col, ci) => {
if(col === 0) return;
ctx.fillStyle = MARIO_COLORS[col];
ctx.fillRect(x + ci*scale, y + ri*scale, scale, scale);
});
});
}
function drawCoin(x, y, t) {
const phase = Math.abs(Math.sin(t * 0.12));
const w = Math.max(3, 14 * phase);
ctx.fillStyle = '#ffcc00';
ctx.fillRect(x - w/2, y - 10, w, 20);
if(w > 7) {
ctx.fillStyle = '#ffaa00';
ctx.fillRect(x - w/2 + 2, y - 7, w - 4, 14);
}
}
function drawMushroom(x, y, t) {
const bob = Math.sin(t * 0.08 + x) * 3;
ctx.fillStyle = '#e8000d';
ctx.fillRect(x-10, y+bob-10, 20, 12);
ctx.fillRect(x-14, y+bob-6, 28, 8);
ctx.fillStyle = '#ffffff';
ctx.fillRect(x-8, y+bob-9, 5, 5);
ctx.fillRect(x+4, y+bob-9, 5, 5);
ctx.fillRect(x-2, y+bob-12, 5, 4);
ctx.fillStyle = '#ffddaa';
ctx.fillRect(x-8, y+bob+2, 16, 10);
ctx.fillStyle = '#000';
ctx.fillRect(x-5, y+bob+4, 3, 3);
ctx.fillRect(x+2, y+bob+4, 3, 3);
}
function drawStar(x, y, t) {
const bob = Math.sin(t * 0.1 + x) * 2;
ctx.fillStyle = '#ffcc00';
const s = 4;
ctx.fillRect(x, y+bob-3*s, s, s);
ctx.fillRect(x-s, y+bob-2*s, 3*s, s);
ctx.fillRect(x-2*s, y+bob-s, 5*s, 3*s);
ctx.fillRect(x-s, y+bob+2*s, 3*s, s);
ctx.fillRect(x, y+bob+3*s, s, s);
ctx.fillStyle = '#fff7aa';
ctx.fillRect(x, y+bob-s, s, 3*s);
}
function drawBlock(x, y) {
ctx.fillStyle = '#cc8800';
ctx.fillRect(x, y, 32, 32);
ctx.fillStyle = '#ffaa00';
ctx.fillRect(x+2, y+2, 28, 14);
ctx.fillStyle = '#aa6600';
ctx.fillRect(x+2, y+16, 28, 14);
ctx.fillStyle = '#ffcc44';
ctx.fillRect(x+4, y+4, 6, 6);
ctx.fillRect(x+22, y+4, 6, 6);
ctx.fillStyle = '#884400';
ctx.fillRect(x, y+15, 32, 2);
ctx.fillRect(x+15, y, 2, 32);
}
function drawGround(scrollX) {
ctx.fillStyle = '#5c3d11';
ctx.fillRect(0, H-40, W, 40);
ctx.fillStyle = '#4a8f00';
ctx.fillRect(0, H-44, W, 8);
for(let x=(scrollX)%64; x<W+64; x+=64) {
ctx.fillStyle = '#3a7a00';
ctx.fillRect(x-32, H-48, 32, 6);
}
for(let x=(scrollX%32); x<W+32; x+=32) {
ctx.strokeStyle = '#7a5020';
ctx.lineWidth = 1;
ctx.strokeRect(x-32, H-40, 32, 40);
}
}
function drawPipe(x) {
ctx.fillStyle = '#00aa00';
ctx.fillRect(x, H-40-80, 40, 80);
ctx.fillStyle = '#00cc00';
ctx.fillRect(x+4, H-40-80, 32, 80);
ctx.fillStyle = '#008800';
ctx.fillRect(x+28, H-40-80, 12, 80);
ctx.fillStyle = '#00aa00';
ctx.fillRect(x-6, H-40-80, 52, 16);
ctx.fillStyle = '#00cc00';
ctx.fillRect(x-2, H-40-80, 44, 12);
}
function drawCloud(x, y) {
ctx.fillStyle = '#ffffff';
ctx.fillRect(x+10, y+10, 40, 20);
ctx.fillRect(x, y+20, 60, 20);
ctx.fillRect(x+5, y+5, 20, 20);
ctx.fillRect(x+35, y+8, 18, 18);
}
function drawProgressBar(pct) {
const bx = 40, by = H-72, bw = W-80, bh = 18;
ctx.fillStyle = '#ffcc00';
ctx.fillRect(bx-3, by-3, bw+6, bh+6);
ctx.fillStyle = '#000011';
ctx.fillRect(bx, by, bw, bh);
const fillW = (bw * pct)|0;
const grad = ['#e8000d','#ff6600','#ffcc00','#00cc44'];
const seg = fillW / grad.length;
for(let i=0; i<grad.length; i++) {
const sx = bx + i*seg;
const sw = Math.min(seg, fillW - i*seg);
if(sw > 0) ctx.fillRect(sx|0, by, sw|0, bh);
ctx.fillStyle = grad[i];
}
for(let i=0; i<Math.floor(fillW/8); i++) {
if(i%2===0) {
ctx.fillStyle = 'rgba(255,255,255,0.12)';
ctx.fillRect(bx + i*8, by, 8, 6);
}
}
}
let marioX = 40;
let scrollX = 0;
let barPct = 0;
function draw() {
frame++;
const t = frame;
ctx.fillStyle = '#5c94fc';
ctx.fillRect(0, 0, W, H);
const cx = scrollX * 0.3;
drawCloud(((120 - cx) % (W+80) + W+80) % (W+80) - 80, 40);
drawCloud(((300 - cx) % (W+80) + W+80) % (W+80) - 80, 20);
drawCloud(((500 - cx) % (W+80) + W+80) % (W+80) - 80, 55);
const blockX = ((200 - scrollX) % (W+100) + W+100) % (W+100) - 100;
drawBlock(blockX, H-40-80);
drawBlock(blockX+36, H-40-80);
drawBlock(blockX+72, H-40-80);
drawBlock(((380-scrollX) % (W+100) + W+100) % (W+100) - 100, H-40-140);
drawPipe(((420 - scrollX) % (W+80) + W+80) % (W+80) - 80);
drawGround(scrollX);
scrollX += 2;
marioX += 2;
if(marioX > W + 50) marioX = -50;
drawMario(marioX, H-40-112, 4, t);
drawCoin(130, H-40-110, t);
drawCoin(340, H-40-110, t+20);
drawCoin(490, H-40-110, t+40);
drawMushroom(220, H-40-120, t);
drawStar(420, H-40-130, t);
ctx.fillStyle = 'rgba(0,0,17,0.75)';
ctx.fillRect(0, 0, W, 120);
ctx.font = 'bold 28px monospace';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = '#440000';
ctx.fillText('NOW LOADING', W/2+2, 42);
ctx.fillStyle = '#e8000d';
ctx.fillText('NOW LOADING', W/2, 40);
const dots = [' ','. ','.. ','...'][(Math.floor(t/15)) % 4];
ctx.font = 'bold 22px monospace';
ctx.fillStyle = '#ffcc00';
ctx.fillText(dots, W/2+60, 40);
ctx.font = '14px monospace';
ctx.fillStyle = '#aaccff';
ctx.fillText('PLEASE WAIT WHILE YOUR GAME BOOTS UP', W/2, 70);
if(Math.floor(t/25) % 2 === 0) {
ctx.font = 'bold 13px monospace';
ctx.fillStyle = '#00ff44';
ctx.fillText('— INSERT COIN —', W/2, 95);
}
// Bar slowly fills over ~30 seconds (600 frames at 20fps)
barPct = Math.min(0.95, barPct + 0.0016);
drawProgressBar(barPct);
ctx.font = 'bold 13px monospace';
ctx.textAlign = 'center';
ctx.fillStyle = '#ffffff';
ctx.fillText(Math.floor(barPct * 100) + '%', W/2, H-46);
ctx.fillStyle = 'rgba(0,0,0,0.07)';
for(let y=0;y<H;y+=3) ctx.fillRect(0,y,W,1);
}
// ── KEY FIX: use setInterval instead of requestAnimationFrame ──
// requestAnimationFrame pauses in background tabs — setInterval does not
setInterval(draw, 50); // 20fps
</script>
</body>
</html>