Skip to content

Commit 76bdbbe

Browse files
authored
Merge pull request #28 from marcins1/master
Edycja timer'a, dodanie punktów za ukończenie poziomu
2 parents 6fe3c98 + f3b0199 commit 76bdbbe

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

js/app_p5.js

+37-10
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ var espeed = 2;
119119
//Every second the opponent can shoot
120120
var ttshot = 2;
121121

122-
var minutes = 0;
122+
var minutes = 3;
123123
var seconds = 0;
124124
var tcounter = 0;
125+
var maxtime = minutes * 60 + seconds;
126+
127+
//Number of shot
128+
var noshot = 0;
129+
var score = [];
125130

126131
//Images
127132
var enemyimg;
@@ -280,6 +285,8 @@ function stageCompleted() {
280285
textSize(50);
281286
fill('#000000');
282287
text("Congratulations!!!", 500, 100);
288+
text("Your score:", 575, 175);
289+
text(score, 640, 250);
283290
text("Level " + (stageid + 1) + " Completed", 500, 400);
284291
text("Press SPACE to Continue", 500, 700);
285292
fill('#FFFFFF');
@@ -482,7 +489,10 @@ function gravity(maxy, maxid) {
482489
else
483490
py = maxy - sy - 1;
484491
} else {
485-
if (maxid === maxp[stageid]) completed = true;
492+
if (maxid === maxp[stageid]) {
493+
completed = true;
494+
countPoints();
495+
}
486496
}
487497
}
488498

@@ -582,6 +592,7 @@ function newBullet(enumber) {
582592
for (i = 0; i < bmax; i++) {
583593
if (!bullets[i][5]) {
584594
if (enumber === -1) {
595+
noshot++;
585596
bullets[i][1] = py;
586597
bullets[i][2] = bsize;
587598
if (direction[0] && direction[2]) {
@@ -663,7 +674,9 @@ function restartGame() {
663674
}
664675
for (j = 0; j < bmax; j++) bullets[j][5] = 0;
665676
seconds = 0;
666-
minutes = 0;
677+
minutes = 3;
678+
score[stageid] = 0;
679+
noshot = 0;
667680
lastp = getLastPlatform();
668681
}
669682

@@ -723,16 +736,18 @@ function drawHUD() {
723736
fill('black');
724737
text(plifep, 82, 65);
725738
drawTimer();
739+
fill('#FFFFFF');
726740
}
727741

728742
function drawTimer() {
729-
if (tcounter < 60) tcounter++;
730-
else if (tcounter === 60) {
743+
if (tcounter < 59) tcounter++;
744+
else if (tcounter === 59) {
731745
tcounter = 0;
732-
seconds++;
733-
if (seconds === 60) {
734-
minutes++;
735-
seconds = 0;
746+
seconds--;
747+
if (minutes === 0 && seconds === 0) lose();
748+
if (seconds === -1) {
749+
seconds = 59;
750+
minutes--;
736751
}
737752
}
738753
text(minutes, 647, 65);
@@ -743,7 +758,6 @@ function drawTimer() {
743758
text('0', 707, 65);
744759
text(seconds, 732, 65);
745760
}
746-
fill('#FFFFFF');
747761
}
748762

749763
function damage() {
@@ -768,6 +782,10 @@ function damage() {
768782
if (bullets[j][0] >= enemies[stageid][l][0] - bullets[j][2] / 2 && bullets[j][0] <= enemies[stageid][l][0] + esize + bullets[j][2] / 2) {
769783
bullets[j][5] = false;
770784
lifePoints(l, -1);
785+
if (enemies[stageid][l][7] === 0) {
786+
if (enemies[stageid][l][5] === 0) score[stageid] += 150;
787+
else score[stageid] += 250;
788+
}
771789
}
772790
}
773791
}
@@ -833,3 +851,12 @@ function spikesCollision() {
833851
if ((spikes[stageid][i][2] === 2 && pposx >= spikes[stageid][i][0] - sheight - sx / 3 && pposx <= spikes[stageid][i][0] + sx) || (spikes[stageid][i][2] === 3 && pposx >= spikes[stageid][i][0] && pposx <= spikes[stageid][i][0] + sheight)) lifePoints(-1, -1);
834852
}
835853
}
854+
855+
function countPoints() {
856+
for (k = 1; k <= plifep; k++) score[stageid] += 75;
857+
var points = (60 * minutes + seconds) * 300 / maxtime;
858+
if (noshot === 0) noshot++;
859+
var points2 = 350 / noshot;
860+
score[stageid] = score[stageid] + points + points2;
861+
score[stageid] = Math.round(score[stageid]);
862+
}

0 commit comments

Comments
 (0)