Skip to content

Commit 1bd2e55

Browse files
committed
update
1 parent c067875 commit 1bd2e55

File tree

3 files changed

+152
-33
lines changed

3 files changed

+152
-33
lines changed

back_arrow.gif

6.26 KB
Loading

background.gif

-140 KB
Loading

beau.html

Lines changed: 152 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
<script>
1919

20-
20+
var level = 1
21+
var maxlevels = 2;
2122
var gameover = 0;
2223
// max hits for castles
2324
var maxhits = 6;
@@ -39,6 +40,7 @@
3940
var maxEnemyArrows = 50;
4041
var test=0;
4142
var speedscale = 600
43+
var pause_game = 0
4244

4345
var background = {
4446
file : "background.gif",
@@ -98,10 +100,10 @@
98100

99101

100102
var myScoreSetup = {
101-
font: "30px Consolas",
103+
font: "25px Consolas",
102104
color : "green",
103-
x : 280,
104-
y : 40,
105+
x : 230,
106+
y : 80,
105107
text : ""
106108
}
107109

@@ -110,17 +112,26 @@
110112
font: "100px Consolas",
111113
color : "red",
112114
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,
114125
text : ""
115126
}
116127

117128
// life indicator
118129
var myLifeSetup = {
119-
font: "30px Consolas",
130+
font: "25px Consolas",
120131
color : "black",
121-
x : 280,
122-
y : 80,
123-
text : "❤️".repeat(maxlives)
132+
x : 230,
133+
y : 120,
134+
text : "❤️".repeat(maxlives) + " " + (level).toString()
124135
}
125136

126137
// story text
@@ -155,6 +166,7 @@
155166
yourGamePiece = new component(yourAvatar);
156167
// game over msgs
157168
myGame = new text_component(myGameSetup);
169+
myGame2 = new text_component(myGameSetup2);
158170
// score
159171
myScore = new text_component(myScoreSetup);
160172
// Lives
@@ -225,7 +237,7 @@
225237
ctx = myGameArea.context
226238
ctx.font = this.font;
227239
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);
229241
}
230242
}
231243

@@ -339,16 +351,30 @@
339351
}
340352
// what happens when you win
341353
this.win = function() {
342-
gameover=1
343354
myScore.text="SCORE: " + myGameArea.score;
344355
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+
}
346368
myGame.update();
347-
this.iwon=1;
348369
for (i = 0; i < this.myBullets.length; i += 1) {
349370
this.myBullets[i].active = 0
350371
}
351372
}
373+
this.cheat = function(isPiece) {
374+
var rockbottom = myGameArea.canvas.width - this.width - buffer;
375+
this.x = rockbottom;
376+
this.win()
377+
}
352378
this.hitLeft = function(isPiece) {
353379
var rockbottom = myGameArea.canvas.width - this.width - buffer;
354380
if (this.x > rockbottom) {
@@ -446,6 +472,7 @@
446472
that.removeBullet(that.myBullets[j])
447473
myGameArea.score += 10
448474
myGame.text="GREAT SHOT"
475+
myGame2.text=""
449476
myGame.update();
450477
}
451478
}
@@ -457,6 +484,7 @@
457484
this.remove(this.myBullets[i],that.myCastles[j])
458485
myGameArea.score += 1
459486
myGame.text="DAMAGE"
487+
myGame2.text=""
460488
myGame.update();
461489
}
462490
}
@@ -489,18 +517,30 @@
489517
if (myPiece.crashWith(yourPiece.myBullets[i],0)) {
490518
myPiece.lives = myPiece.lives - 1;
491519
myGame.text="YOU'RE HIT"
492-
myLife.text="❤️".repeat(myPiece.lives)
520+
myGame2.text=""
521+
myLife.text="❤️".repeat(myPiece.lives) + " " + (level).toString()
493522
myLife.update();
494523
yourPiece.myBullets[i].active = 0
495524
if ( myPiece.lives < 1 ) {
496525
// what happens if you lose
497-
gameover = 1;
498-
myPiece.iwon=0;
499-
yourPiece.iwon=1;
500526
for (i = 0; i < myPiece.myBullets.length; i += 1) {
501527
myPiece.myBullets[i].active = 0
502528
}
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+
}
504544
myGame.update();
505545
return true
506546
}
@@ -529,19 +569,30 @@
529569
myPiece.stop()
530570
myPiece.left(1)
531571
myGame.text="YOU'RE HIT"
572+
myGame2.text=""
532573
myPiece.lives = myPiece.lives - 1;
533-
myLife.text="❤️".repeat(myPiece.lives)
574+
myLife.text="❤️".repeat(myPiece.lives) + " " + (level).toString()
534575
myLife.update();
535576
myPiece.removeCastle(yourPiece.myCastles[j])
536577
if ( myPiece.lives < 1 ) {
537578
// 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+
}
541593
for (i = 0; i < myPiece.myBullets.length; i += 1) {
542594
myPiece.myBullets[i].active = 0
543595
}
544-
myGame.text="GAME OVER"
545596
myGame.update();
546597
return true
547598
}
@@ -551,9 +602,23 @@
551602
return false;
552603
}
553604

605+
function pause() {
606+
pause_game = 1 - pause_game
607+
}
608+
554609
function updateGameArea() {
555610
var x, height, gap, minHeight, maxHeight, minGap, maxGap;
556611

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+
557622
if ( gameover == 1 ) return;
558623

559624
// check if your arrows collide with myGamePiece
@@ -571,6 +636,7 @@
571636
// fire my arrows from alien
572637
if (myGameArea.frameNo == 1 || everyinterval(Math.floor(Math.random()*600))) {
573638
myGame.text=""
639+
myGame2.text=""
574640
yourGamePiece.clearArrows()
575641
if ( yourGamePiece.myBullets.length <= maxEnemyArrows ) {
576642
// fire from your leader
@@ -587,6 +653,7 @@
587653
for (i = 0; i < yourGamePiece.myCastles.length; i += 1) {
588654
if (everyinterval(Math.floor(Math.random()*5000))) {
589655
myGame.text=""
656+
myGame2.text=""
590657
yourGamePiece.clearArrows()
591658
x = yourGamePiece.myCastles[i].x
592659
y = yourGamePiece.myCastles[i].y
@@ -622,16 +689,16 @@
622689
myGamePiece.removeBullet(myGamePiece.myBullets[i])
623690
myGameArea.score += 100
624691
myGame.text="BONUS 100"
692+
myGame2.text=""
625693
myGame.update();
626-
//myGame.text=""
627694
}
628695
}
629696

630697
// advance the score and update
631698
myScore.text="SCORE: " + myGameArea.score;
632699
myScore.update();
633700

634-
myLife.text="❤️".repeat(myGamePiece.lives)
701+
myLife.text="❤️".repeat(myGamePiece.lives) + " " + (level).toString()
635702
myLife.update();
636703

637704
// move on the piece and update
@@ -654,13 +721,22 @@
654721
// test for lose
655722
for (i = 0; i < yourGamePiece.myCastles.length; i += 1) {
656723
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+
}
660737
for (i = 0; i < myGamePiece.myBullets.length; i += 1) {
661738
myGamePiece.myBullets[i].active = 0
662739
}
663-
myGame.text="GAME OVER"
664740
myGame.update();
665741
return true
666742
}
@@ -701,7 +777,7 @@
701777
}
702778

703779

704-
function reset(){
780+
function reset_level1(){
705781
myGamePiece.reset()
706782
//myGameArea.frameNo = 1;
707783
gameover=0;
@@ -727,6 +803,43 @@
727803
startGame()
728804
}
729805

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+
}
730843

731844
</script>
732845
<br>
@@ -737,11 +850,17 @@
737850
<br>
738851
<button onmousedown="myGamePiece.down(1)" onmouseover="myGamePiece.down(1)" onmouseup="myGamePiece.stopy()" ontouchstart="myGamePiece.down(1)">DOWN</button>
739852
<br>
740-
<button onmouseover="myGamePiece.stop()">STOP</button>
741-
<button onmousedown="reset()">reset</button>
742853
<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>
744861

862+
<button onmousedown="myGamePiece.cheat()">cheat</button>
863+
<br>
745864
<audio id="myAudio" controls>
746865
<source src="greensleeves-flute-and-guitar.mp3" type="audio/mpeg">
747866
Your browser does not support the audio element.

0 commit comments

Comments
 (0)