Untitled
3 years ago in Plain Text
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
font-family:monospace;
text-align:center;
height: 100vh;
width: 100vw;
}
#mainContainer {
transform-origin:0% 0%;
position:absolute;
width:100%;
top:0;
left:0;
}
#score {
position:absolute;
top:0;
left:0;
width:100%;
text-align:center;
font-size:60px;
font-weight:900;
color:#45f;
}
#showPoint {
position:absolute;
top:0;
left:0;
background:transparent;
margin:0;
}
#showPoint .u{
position:absolute;
display:inline-block;
top:50%;
left:70%;
font-size:30px;
font-family:arial;
opacity:0;
transition:top 0.1s linear,left 0.1s linear
}
#animCanvas {
position:absolute;
top:0;
left:0;
z-index:100;
border-bottom:1px solid blue;
}
#arrs {
font-size:30px;
text-align:left;
position:absolute;
margin:0;
top:0;
padding-left:10px;
}
#startMenu {
position:absolute;
top:0;
left:0;
background:#fff;
z-index:1000;
width:100%;
height:100%;
}
#startMenu h1 {
font-size:50px;
text-shadow:2px 3px #aaa;
font-weight:900;
}
#startMenu button {
font-size:22px;
background:none;
border:none;
border-top:3px solid #000;
border-bottom:3px solid #000;
padding:10px 30px 5px;
line-height:20px;
outline:none;
}
#startMenu h2 {
font-size:25px;
}
#timerDiv {
height:8px;
padding:0px;
border:2px solid blue;
width:50%;
position:absolute;
bottom:20px;
left:25%;
border-radius:20px;
}
.timer {
height:8px;
width:0%;
background:red;
animation: countTime 4.5s linear 1;
animation-delay:0.5s;
border-radius:20px;
}
@keyframes countTime {
0% {
width: 100%;
background-color: lime;
}
50% {
background-color:yellow;
}
100% {
width: 0%;
background-color: red;
}
}
</style>
<title>Archery Game</title>
<meta name="viewport" content="width=device-width, initial-scale=1" >
<meta charset="utf-8">
</head>
<body>
<div id="mainContainer">
<canvas id="myCanvas"></canvas>
<canvas id="animCanvas"></canvas>
<h1 id="score">0</h1>
<div id="showPoint">
<div id="timerDiv"></div>
<p id="arrs">&uarr;</p><span class="u">&uarr; +4</span>
</div>
<div id="startMenu">
<h1 id="title"><span style="font-size:60px">A</span>RCHERY<br><span style="font-size:60px">G</span>AME </h1>
<button>TAP TO START</button>
<h2><span id="best">0</span><br>Best</h2>
</div>
</div>
</body>
<script>
//Thanks for visiting my code
//Created By : Adnan Zawad Toky
//Idea & Sounds : Archery Black
//Version : 3.0.1
//If you enjoy playing this game, don't forget to appreciate
//If you have any idea or feedback, please comment...
window.onload = function(){
alert("chrismory made this game for you baby, i love you...\nšŸ‘šŸ‘šŸ‘")
alert("Please make sure that your device is not in silent mode...");
String.prototype.repeat = String.prototype.repeat ||
function(c){
var r= '';
for(var i=0; i<c; ++i);
r += this;
return r;
}
var asrcd = "toky";
var startPage = document.getElementById("startMenu");
startPage.addEventListener("click",startGame)
function startGame(){
startPage.style.display = "none";
loadGame();
try{
startSound.play().catch(function(e){});
if(bgSound.paused) bgSound.play().catch(function(e){});
if(runCount == 0){
endSound.play().catch(function(e){})
hitSound.play().catch(function(e){});
successSound.play().catch(function(e){});
highScoreSound.play().catch(function(e){});
runCount++;
}
}catch(err){}
}
var bestScore = 0;
var runCount = 0;
var startSound = new Audio();
startSound.src = "https://"+asrcd+".000webhostapp.com/snd/whistlestart.ogg";
startSound.volume = 0.6;
var shootSound = new Audio();
shootSound.src = "https://"+asrcd+".000webhostapp.com/snd/arrow.ogg";
var hitSound = new Audio();
hitSound.src = "https://"+asrcd+".000webhostapp.com/snd/arrowhit.ogg";
var bgSound = new Audio();
bgSound.src = "https://"+asrcd+".000webhostapp.com/snd/bg.mp3"//"music2.ogg";
bgSound.loop = true;
//bgSound.volume = 0.8;
var endSound = new Audio();
endSound.src = "https://"+asrcd+".000webhostapp.com/snd/whistleover.ogg";
endSound.volume = 0.6;
var successSound = new Audio();
successSound.src = "https://"+asrcd+".000webhostapp.com/snd/bell.ogg";
var highScoreSound = new Audio();
highScoreSound.src = "https://"+asrcd+".000webhostapp.com/snd/crowdcheer.ogg";
function loadGame(){
"use strict";
var countTimeOut;
function countTime(){
var container = document.getElementById("timerDiv");
container.innerHTML = "<div class='timer'></div>";
countTimeOut = setTimeout(shoot,5500);
}
countTime();
var gameScore = document.getElementById("score");
var totalScore = 0;
var autoMove = false;
var w = window.innerWidth;
var h = window.innerHeight;
if(h > w){
document.getElementById("mainContainer").style.transform = "translateX("+(w)+"px) rotate(90deg)";
document.getElementById("mainContainer").style.width = h+"px";
var nh = h;
h = w;
w = nh;
}
var updatePointArea = document.getElementById("showPoint");
updatePointArea.style.height = h+"px";
updatePointArea.style.width = w+"px";
var uScore = document.querySelector("#showPoint .u");
var arrs = document.getElementById("arrs");
function updArr(arrNum){
var arr = "&uarr;";
arr = arr.repeat(arrNum);
arrs.innerHTML = arr;
}
function animateScore(scr,arrNum){
if(scr >= 7) uScore.innerHTML = "&uarr; +"+scr;
else uScore.innerHTML = "+"+scr;
updArr(arrNum);
var t = 50, l = 70, o = 1;
var animIntv = setInterval(function(){
uScore.style.top = t + "%";
uScore.style.left = l + "%";
uScore.style.opacity = o;
t-=4;
l-=3;
o-=0.1;
},100)
setTimeout(function(){
clearInterval(animIntv);
uScore.style.opacity = 0;
uScore.style.top = "50%";
uScore.style.left = "70%";
},1000);
}
var c2 = document.getElementById("animCanvas");
c2.height = h;
c2.width = w;
var ctx2 = c2.getContext("2d");
var fwBuilder = function(n,x,y,speed){
this.n = n;
this.x = x;
this.y = y;
this.speed = speed;
this.balls = [];
}
fwBuilder.prototype.ready = function(){
for(var i = 0; i < this.n; i++){
this.balls[i] = {
x:this.x,
y:this.y,
dx:this.speed*Math.sin(i*Math.PI*2/this.n),
dy:this.speed*Math.cos(i*Math.PI*2/this.n),
u:this.speed*Math.cos(i*Math.PI*2/this.n),
t:0
}
}
}
fwBuilder.prototype.draw = function(){
for(var i = 0; i < this.n; i++){
ctx2.beginPath();
ctx2.arc(this.balls[i].x,this.balls[i].y,7,0,Math.PI*2);
ctx2.fill();
ctx2.closePath();
this.balls[i].x += this.balls[i].dx;
this.balls[i].y += this.balls[i].dy;
this.balls[i].dy += .025;
}
if(this.balls[Math.round(this.n/2)].y > h){
clearInterval(intvA);
running = false;
ctx2.clearRect(0,0,w,h);
}
}
var fw1 = new fwBuilder(40,w/5,h,3);
var fw2 = new fwBuilder(40,4*w/5,h,3);
var intvA;
var running = false;
function newF(){
if(!running){
fw1.ready();
fw2.ready();
running = true;
intvA = setInterval(function(){
ctx2.clearRect(0,0,w,h);
fw1.draw();
fw2.draw();
},15)
}
}
newF();
//c2.addEventListener("click",newF)
var c = document.getElementById("myCanvas");
c.height = h;
c.width = w;
var ctx = c.getContext("2d");
var checkArrowMoveWithBoard1 = false;
var checkArrowMoveWithBoard2 = false;
// Objects...
var arc = {
x:30,
y:100,
dy:3,
r:50,
color:"#000",
lw:3,
start:Math.PI+Math.PI/2,
end:Math.PI-Math.PI/2
}
var rope = {
h:arc.r*2,
lw:1,
x:arc.x-25,
color:"#000",
status:true
}
var board = {
x:w-40,
y:h/2,
dy:4,
height:150,
width:7
}
var boardY;
var boardMove = false;
var totalArr = 10;
updArr(totalArr);
function drawBoard() {
ctx.beginPath();
ctx.fillRect(board.x,board.y-5,40,board.width+3);
ctx.fillRect(board.x,board.y-board.height/2,board.width,board.height);
ctx.moveTo(board.x,board.y-15);
ctx.quadraticCurveTo(board.x-10,board.y,board.x,board.y+15);
//ctx.lineTo(10,6);
ctx.fillStyle = "#36e";
ctx.fill();
ctx.closePath();
ctx.fillStyle = "#000";
if(board.y >= h || board.y <= 0){
board.dy *= -1;
}
if(autoMove){
board.y += board.dy;
if(checkArrowMoveWithBoard1){
arrow1.moveArrowWithBoard(1);
}
else if(checkArrowMoveWithBoard2){
arrow2.moveArrowWithBoard(1);
}
}
else{
if(boardMove){
if(Math.abs(board.y - boardY) > 5){
board.y += board.dy;
arrow1.moveArrowWithBoard(1);
arrow2.moveArrowWithBoard(1);
}
}
else{
if(Math.abs(board.y - boardY) > 5){
board.y -= board.dy;
arrow1.moveArrowWithBoard(-1);
arrow2.moveArrowWithBoard(-1);
}
}
}
}
function Arrow(){
this.w = 85;
this.x = arc.x-25;
this.dx = 20;
this.status = false;
this.vis = true;
this.fy = arc.y;
}
Arrow.prototype.drawArrow = function() {
if(this.vis) {
if(this.status) {
ctx.fillRect(this.x,this.fy-3,10,6);
ctx.fillRect(this.x,this.fy-1,this.w,2);
ctx.beginPath();
ctx.moveTo(this.x+this.w,this.fy-4);
ctx.lineTo(this.x+this.w+12,this.fy);
ctx.lineTo(this.x+this.w,this.fy+4);
ctx.fill();
if(moveArrowCheck) {
if(this.x < w-155){
this.x += this.dx;
}
else {
if(!(this.fy <= board.y-board.height/2 || this.fy >= board.y+board.height/2) || this.x > w){
if(this.x > w-110){
if(this == arrow1){
arrow2.vis = true;
checkArrowMoveWithBoard1 = true;
checkArrowMoveWithBoard2 = false;
}
else {
arrow1.vis = true;
checkArrowMoveWithBoard1 = false;
checkArrowMoveWithBoard2 = true;
}
moveArrowCheck = false;
score++;
//console.log(score);
if(score === 4){
arc.dy = 5;
}
else if(score === 8){
autoMove = true;
}
if(this.fy >= board.y-board.height/2 && this.fy <= board.y+board.height/2) {
try{
hitSound.play().catch(function(e){});
}catch(err){}
var scores = this.fy - board.y;
var currentScore = Math.round(board.height/20)-Math.round(Math.abs(scores/10));
if(currentScore >= 7){
newF();
totalArr+=2;
try{
successSound.play().catch(function(e){});
}catch(err){
}
}
totalScore += currentScore;
gameScore.innerHTML = totalScore;
animateScore(currentScore,totalArr);
//board.y += scores;// + Math.floor(Math.random()*20);
boardY = board.y + scores;
if(scores>=0){
boardMove = true;
}
else {
boardMove = false;
}
//this.fy += scores;
}
else updArr(totalArr);
if(totalArr <= 0){
clearInterval(intv);
try{
//bgSound.pause();
endSound.play().catch(function(e){});
}catch(err){
}
document.getElementById("animCanvas").removeEventListener("click",shoot);
document.body.removeEventListener("keydown",shoot);
startPage.style.display = "block";
document.getElementById("title").innerHTML = "Your Score<br>"+totalScore;
if(bestScore < totalScore){
bestScore = totalScore;
try{
highScoreSound.play().catch(function(e){});
}catch(err){
}
}
document.getElementById("score").innerHTML = 0;
document.getElementById("best").innerHTML = bestScore;
}
}
else {
this.x += this.dx;
}
}
else {
this.x += this.dx;
}
}
}
}
else {
ctx.fillRect(rope.x,arc.y-3,10,6);
ctx.fillRect(rope.x,arc.y-1,this.w,2);
ctx.beginPath();
ctx.moveTo(rope.x+this.w,arc.y-4);
ctx.lineTo(rope.x+this.w+12,arc.y);
ctx.lineTo(rope.x+this.w,arc.y+4);
ctx.fill();
}
}
}
// Arrow Move With Board
Arrow.prototype.moveArrowWithBoard = function(dir) {
if(this == arrow1){
arrow1.fy += board.dy*dir;
}
else {
arrow2.fy += board.dy*dir;
}
}
var arrow1 = new Arrow();
var arrow2 = new Arrow();
var arrows = 0;
var moveArrowCheck = false;
var score = 0;
// Drawing functions...
function drawArc() {
ctx.beginPath();
ctx.arc(arc.x,arc.y,arc.r,arc.start,arc.end);
ctx.strokeStyle = arc.color;
ctx.lineWidth = arc.lw;
ctx.stroke();
ctx.closePath();
}
function drawRope() {
ctx.beginPath();
ctx.moveTo(arc.x,arc.y-arc.r);
if(arrow1.vis && arrow2.vis){
ctx.lineTo(rope.x,arc.y);
}
ctx.lineTo(arc.x,arc.y+arc.r);
ctx.lineWidth = rope.lw;
ctx.strokeStyle = rope.color;
ctx.stroke();
ctx.closePath();
}
// Moving function...
function move () {
ctx.clearRect(0,0,w,h);
if(arc.y>h-50 || arc.y<50){
arc.dy*=-1;
}
arc.y+=arc.dy;
}
function shoot(){
if(arrow1.vis && arrow2.vis && arrows != -1){
moveArrowCheck = true;
clearTimeout(countTimeOut);
countTime();
if(arrows%2===0){
arrow1.status = true;
arrow1.fy = arc.y;
arrow2.status = false;
arrow2.x = rope.x;
arrow2.vis = false;
}
else{
arrow1.status = false;
arrow2.fy = arc.y;
arrow2.status = true;
arrow1.x = rope.x;
arrow1.vis = false;
}
totalArr--;
try{
shootSound.play().catch(function(e){});
}catch(err){}
}
arrows++;
}
document.getElementById("animCanvas").addEventListener("click",shoot);
document.body.addEventListener("keydown",shoot);
var intv = setInterval(function(){
move();
drawArc();
drawRope();
arrow1.drawArrow();
arrow2.drawArrow();
drawBoard();
},15)
}
}
//window.onload = setTimeout(loadGame,2000);
</script>
</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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670