|
17 | 17 |
|
18 | 18 | <script>
|
19 | 19 |
|
20 |
| - |
| 20 | +var level = 1 |
| 21 | +var maxlevels = 2; |
21 | 22 | var gameover = 0;
|
22 | 23 | // max hits for castles
|
23 | 24 | var maxhits = 6;
|
|
39 | 40 | var maxEnemyArrows = 50;
|
40 | 41 | var test=0;
|
41 | 42 | var speedscale = 600
|
| 43 | +var pause_game = 0 |
42 | 44 |
|
43 | 45 | var background = {
|
44 | 46 | file : "background.gif",
|
|
98 | 100 |
|
99 | 101 |
|
100 | 102 | var myScoreSetup = {
|
101 |
| - font: "30px Consolas", |
| 103 | + font: "25px Consolas", |
102 | 104 | color : "green",
|
103 |
| - x : 280, |
104 |
| - y : 40, |
| 105 | + x : 230, |
| 106 | + y : 80, |
105 | 107 | text : ""
|
106 | 108 | }
|
107 | 109 |
|
|
110 | 112 | font: "100px Consolas",
|
111 | 113 | color : "red",
|
112 | 114 | x : background.x/4,
|
113 |
| - y : background.y/4, |
| 115 | + y : background.y/2, |
| 116 | + text : "" |
| 117 | +} |
| 118 | + |
| 119 | +// text for game over etc |
| 120 | +var myGameSetup2 = { |
| 121 | + font: "50px Consolas", |
| 122 | + color : "red", |
| 123 | + x : background.x/4, |
| 124 | + y : background.y/2+background.y/20, |
114 | 125 | text : ""
|
115 | 126 | }
|
116 | 127 |
|
117 | 128 | // life indicator
|
118 | 129 | var myLifeSetup = {
|
119 |
| - font: "30px Consolas", |
| 130 | + font: "25px Consolas", |
120 | 131 | color : "black",
|
121 |
| - x : 280, |
122 |
| - y : 80, |
123 |
| - text : "❤️".repeat(maxlives) |
| 132 | + x : 230, |
| 133 | + y : 120, |
| 134 | + text : "❤️".repeat(maxlives) + " " + (level).toString() |
124 | 135 | }
|
125 | 136 |
|
126 | 137 | // story text
|
|
155 | 166 | yourGamePiece = new component(yourAvatar);
|
156 | 167 | // game over msgs
|
157 | 168 | myGame = new text_component(myGameSetup);
|
| 169 | + myGame2 = new text_component(myGameSetup2); |
158 | 170 | // score
|
159 | 171 | myScore = new text_component(myScoreSetup);
|
160 | 172 | // Lives
|
|
225 | 237 | ctx = myGameArea.context
|
226 | 238 | ctx.font = this.font;
|
227 | 239 | ctx.fillStyle = this.color;
|
228 |
| - ctx.fillText(this.text, this.x, this.y); |
| 240 | + if ( this.text ) ctx.fillText(this.text, this.x, this.y); |
229 | 241 | }
|
230 | 242 | }
|
231 | 243 |
|
|
339 | 351 | }
|
340 | 352 | // what happens when you win
|
341 | 353 | this.win = function() {
|
342 |
| - gameover=1 |
343 | 354 | myScore.text="SCORE: " + myGameArea.score;
|
344 | 355 | myScore.update();
|
345 |
| - myGame.text="YOU WIN" |
| 356 | + if ( level == maxlevels ) { |
| 357 | + myGame.text="YOU WIN" |
| 358 | + myGame2.text="" |
| 359 | + this.iwon=1; |
| 360 | + gameover=1 |
| 361 | + } else { |
| 362 | + myGame.text="NEXT LEVEL" |
| 363 | + myGame2.text="PAUSED" |
| 364 | + pause_game=1 |
| 365 | + level += 1 |
| 366 | + reset() |
| 367 | + } |
346 | 368 | myGame.update();
|
347 |
| - this.iwon=1; |
348 | 369 | for (i = 0; i < this.myBullets.length; i += 1) {
|
349 | 370 | this.myBullets[i].active = 0
|
350 | 371 | }
|
351 | 372 | }
|
| 373 | + this.cheat = function(isPiece) { |
| 374 | + var rockbottom = myGameArea.canvas.width - this.width - buffer; |
| 375 | + this.x = rockbottom; |
| 376 | + this.win() |
| 377 | + } |
352 | 378 | this.hitLeft = function(isPiece) {
|
353 | 379 | var rockbottom = myGameArea.canvas.width - this.width - buffer;
|
354 | 380 | if (this.x > rockbottom) {
|
|
446 | 472 | that.removeBullet(that.myBullets[j])
|
447 | 473 | myGameArea.score += 10
|
448 | 474 | myGame.text="GREAT SHOT"
|
| 475 | + myGame2.text="" |
449 | 476 | myGame.update();
|
450 | 477 | }
|
451 | 478 | }
|
|
457 | 484 | this.remove(this.myBullets[i],that.myCastles[j])
|
458 | 485 | myGameArea.score += 1
|
459 | 486 | myGame.text="DAMAGE"
|
| 487 | + myGame2.text="" |
460 | 488 | myGame.update();
|
461 | 489 | }
|
462 | 490 | }
|
|
489 | 517 | if (myPiece.crashWith(yourPiece.myBullets[i],0)) {
|
490 | 518 | myPiece.lives = myPiece.lives - 1;
|
491 | 519 | myGame.text="YOU'RE HIT"
|
492 |
| - myLife.text="❤️".repeat(myPiece.lives) |
| 520 | + myGame2.text="" |
| 521 | + myLife.text="❤️".repeat(myPiece.lives) + " " + (level).toString() |
493 | 522 | myLife.update();
|
494 | 523 | yourPiece.myBullets[i].active = 0
|
495 | 524 | if ( myPiece.lives < 1 ) {
|
496 | 525 | // what happens if you lose
|
497 |
| - gameover = 1; |
498 |
| - myPiece.iwon=0; |
499 |
| - yourPiece.iwon=1; |
500 | 526 | for (i = 0; i < myPiece.myBullets.length; i += 1) {
|
501 | 527 | myPiece.myBullets[i].active = 0
|
502 | 528 | }
|
503 |
| - myGame.text="GAME OVER" |
| 529 | + // in case you want to do different |
| 530 | + if ( level == maxlevels ) { |
| 531 | + myGame.text="DOWN A LEVEL" |
| 532 | + level -= 1 |
| 533 | + if ( level < 1 ) level = 1 |
| 534 | + myGame2.text="PAUSED" |
| 535 | + pause_game=1 |
| 536 | + reset() |
| 537 | + } else { |
| 538 | + myGame.text="GAME OVER" |
| 539 | + myGame2.text="" |
| 540 | + gameover = 1; |
| 541 | + myPiece.iwon=0; |
| 542 | + yourPiece.iwon=1; |
| 543 | + } |
504 | 544 | myGame.update();
|
505 | 545 | return true
|
506 | 546 | }
|
|
529 | 569 | myPiece.stop()
|
530 | 570 | myPiece.left(1)
|
531 | 571 | myGame.text="YOU'RE HIT"
|
| 572 | + myGame2.text="" |
532 | 573 | myPiece.lives = myPiece.lives - 1;
|
533 |
| - myLife.text="❤️".repeat(myPiece.lives) |
| 574 | + myLife.text="❤️".repeat(myPiece.lives) + " " + (level).toString() |
534 | 575 | myLife.update();
|
535 | 576 | myPiece.removeCastle(yourPiece.myCastles[j])
|
536 | 577 | if ( myPiece.lives < 1 ) {
|
537 | 578 | // what happens if you lose
|
538 |
| - gameover = 1; |
539 |
| - myPiece.iwon=0; |
540 |
| - yourPiece.iwon=1; |
| 579 | + if ( level == maxlevels ) { |
| 580 | + myGame.text="DOWN A LEVEL" |
| 581 | + level -= 1 |
| 582 | + if ( level < 1 ) level = 1 |
| 583 | + myGame2.text="PAUSED" |
| 584 | + pause_game=1 |
| 585 | + reset() |
| 586 | + } else { |
| 587 | + myGame.text="GAME OVER" |
| 588 | + myGame2.text="" |
| 589 | + gameover = 1; |
| 590 | + myPiece.iwon=0; |
| 591 | + yourPiece.iwon=1; |
| 592 | + } |
541 | 593 | for (i = 0; i < myPiece.myBullets.length; i += 1) {
|
542 | 594 | myPiece.myBullets[i].active = 0
|
543 | 595 | }
|
544 |
| - myGame.text="GAME OVER" |
545 | 596 | myGame.update();
|
546 | 597 | return true
|
547 | 598 | }
|
|
551 | 602 | return false;
|
552 | 603 | }
|
553 | 604 |
|
| 605 | +function pause() { |
| 606 | + pause_game = 1 - pause_game |
| 607 | +} |
| 608 | + |
554 | 609 | function updateGameArea() {
|
555 | 610 | var x, height, gap, minHeight, maxHeight, minGap, maxGap;
|
556 | 611 |
|
| 612 | + if ( pause_game == 1) { |
| 613 | + myGame.text="" |
| 614 | + myGame2.text="" |
| 615 | + myGame.update(); |
| 616 | + myGame.text="PAUSED" |
| 617 | + myGame2.text="" |
| 618 | + myGame.update(); |
| 619 | + return; |
| 620 | + } |
| 621 | + |
557 | 622 | if ( gameover == 1 ) return;
|
558 | 623 |
|
559 | 624 | // check if your arrows collide with myGamePiece
|
|
571 | 636 | // fire my arrows from alien
|
572 | 637 | if (myGameArea.frameNo == 1 || everyinterval(Math.floor(Math.random()*600))) {
|
573 | 638 | myGame.text=""
|
| 639 | + myGame2.text="" |
574 | 640 | yourGamePiece.clearArrows()
|
575 | 641 | if ( yourGamePiece.myBullets.length <= maxEnemyArrows ) {
|
576 | 642 | // fire from your leader
|
|
587 | 653 | for (i = 0; i < yourGamePiece.myCastles.length; i += 1) {
|
588 | 654 | if (everyinterval(Math.floor(Math.random()*5000))) {
|
589 | 655 | myGame.text=""
|
| 656 | + myGame2.text="" |
590 | 657 | yourGamePiece.clearArrows()
|
591 | 658 | x = yourGamePiece.myCastles[i].x
|
592 | 659 | y = yourGamePiece.myCastles[i].y
|
|
622 | 689 | myGamePiece.removeBullet(myGamePiece.myBullets[i])
|
623 | 690 | myGameArea.score += 100
|
624 | 691 | myGame.text="BONUS 100"
|
| 692 | + myGame2.text="" |
625 | 693 | myGame.update();
|
626 |
| - //myGame.text="" |
627 | 694 | }
|
628 | 695 | }
|
629 | 696 |
|
630 | 697 | // advance the score and update
|
631 | 698 | myScore.text="SCORE: " + myGameArea.score;
|
632 | 699 | myScore.update();
|
633 | 700 |
|
634 |
| - myLife.text="❤️".repeat(myGamePiece.lives) |
| 701 | + myLife.text="❤️".repeat(myGamePiece.lives) + " " + (level).toString() |
635 | 702 | myLife.update();
|
636 | 703 |
|
637 | 704 | // move on the piece and update
|
|
654 | 721 | // test for lose
|
655 | 722 | for (i = 0; i < yourGamePiece.myCastles.length; i += 1) {
|
656 | 723 | if ( yourGamePiece.myCastles[i].x < -10 ) {
|
657 |
| - gameover = 1; |
658 |
| - myGamePiece.iwon=0; |
659 |
| - yourGamePiece.iwon=1; |
| 724 | + if ( level == maxlevels ) { |
| 725 | + myGame.text="DOWN A LEVEL" |
| 726 | + level -= 1 |
| 727 | + if ( level < 1 ) level = 1 |
| 728 | + myGame2.text="PAUSED" |
| 729 | + pause() |
| 730 | + reset() |
| 731 | + } else { |
| 732 | + myGame.text="GAME OVER" |
| 733 | + gameover = 1; |
| 734 | + myPiece.iwon=0; |
| 735 | + yourPiece.iwon=1; |
| 736 | + } |
660 | 737 | for (i = 0; i < myGamePiece.myBullets.length; i += 1) {
|
661 | 738 | myGamePiece.myBullets[i].active = 0
|
662 | 739 | }
|
663 |
| - myGame.text="GAME OVER" |
664 | 740 | myGame.update();
|
665 | 741 | return true
|
666 | 742 | }
|
|
701 | 777 | }
|
702 | 778 |
|
703 | 779 |
|
704 |
| -function reset(){ |
| 780 | +function reset_level1(){ |
705 | 781 | myGamePiece.reset()
|
706 | 782 | //myGameArea.frameNo = 1;
|
707 | 783 | gameover=0;
|
|
727 | 803 | startGame()
|
728 | 804 | }
|
729 | 805 |
|
| 806 | +function reset_level2(){ |
| 807 | + myGamePiece.reset() |
| 808 | + //myGameArea.frameNo = 1; |
| 809 | + gameover=0; |
| 810 | + //myGameArea.score = 0; |
| 811 | + |
| 812 | + // game pieces |
| 813 | + delete myField; |
| 814 | + // my character |
| 815 | + delete myGamePiece; |
| 816 | + // your character |
| 817 | + delete yourGamePiece; |
| 818 | + // game over msgs |
| 819 | + delete myGame; |
| 820 | + // score |
| 821 | + delete myScore; |
| 822 | + // Lives |
| 823 | + delete myLife; |
| 824 | + |
| 825 | + //myGameArea.start(); |
| 826 | + |
| 827 | + clearInterval(myGameArea.interval) |
| 828 | + delete myGameArea |
| 829 | + startGame() |
| 830 | +} |
| 831 | + |
| 832 | +function reset_poor(){ |
| 833 | + // try again, but lose your score |
| 834 | + myGameArea.score = myGameArea.score/2 |
| 835 | + if ( level == 1 ) reset_level1(); |
| 836 | + if ( level == 2 ) reset_level2(); |
| 837 | +} |
| 838 | + |
| 839 | +function reset(){ |
| 840 | + if ( level == 1 ) reset_level1(); |
| 841 | + if ( level == 2 ) reset_level2(); |
| 842 | +} |
730 | 843 |
|
731 | 844 | </script>
|
732 | 845 | <br>
|
|
737 | 850 | <br>
|
738 | 851 | <button onmousedown="myGamePiece.down(1)" onmouseover="myGamePiece.down(1)" onmouseup="myGamePiece.stopy()" ontouchstart="myGamePiece.down(1)">DOWN</button>
|
739 | 852 | <br>
|
740 |
| -<button onmouseover="myGamePiece.stop()">STOP</button> |
741 |
| -<button onmousedown="reset()">reset</button> |
742 | 853 | <button onmouseover="myGamePiece.fire()" onmousedown="myGamePiece.fire()" onmouseup="myGamePiece.fire()" ontouchstart="myGamePiece.fire()">FIRE</button>
|
743 |
| -<p>Meet the Tudors: Make it to the right of the screen</p> |
| 854 | +<br> |
| 855 | +<br> |
| 856 | +<button onmouseover="myGamePiece.stop()">STOP</button> |
| 857 | +<button onmousedown="reset_poor()">Try Again</button> |
| 858 | +<p>Meet the Tudors: Make it to the right of the screen to win</p> |
| 859 | +<br> |
| 860 | +<button onmousedown="pause()" onmouseover="pause()">pause</button> |
744 | 861 |
|
| 862 | +<button onmousedown="myGamePiece.cheat()">cheat</button> |
| 863 | +<br> |
745 | 864 | <audio id="myAudio" controls>
|
746 | 865 | <source src="greensleeves-flute-and-guitar.mp3" type="audio/mpeg">
|
747 | 866 | Your browser does not support the audio element.
|
|
0 commit comments