Skip to content

Commit 28a7cbc

Browse files
authored
Merge pull request #36 from marcins1/master
Dodanie pistoletu, poprawa bledu z rysowaniem sie wrogow
2 parents 440f68f + 835049a commit 28a7cbc

File tree

7 files changed

+51
-9
lines changed

7 files changed

+51
-9
lines changed

assets/pistol.png

387 Bytes
Loading

assets/pistol2.png

1.35 KB
Loading

assets/pistol3.png

1.3 KB
Loading

assets/pistol4.png

392 Bytes
Loading

assets/pistol5.png

1.32 KB
Loading

assets/pistol6.png

1.33 KB
Loading

js/app_p5.js

+51-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var direction = [];
5151
direction[0] = true;
5252

5353
//Bullets size
54-
var bsize = 20;
54+
var bsize = 12;
5555
//Max number of bullets
5656
var bmax = 10;
5757
//Bullets speed
@@ -142,6 +142,7 @@ var livebar;
142142
var bar1;
143143
var bar2;
144144
var heart;
145+
var pistol = [];
145146

146147
//Load Images
147148
function preload() {
@@ -151,6 +152,12 @@ function preload() {
151152
bar1 = loadImage('./assets/bar1.png');
152153
bar2 = loadImage('./assets/bar2.png');
153154
heart = loadImage('./assets/heart.png');
155+
pistol[0] = loadImage('./assets/pistol.png');
156+
pistol[1] = loadImage('./assets/pistol2.png');
157+
pistol[2] = loadImage('./assets/pistol3.png');
158+
pistol[3] = loadImage('./assets/pistol4.png');
159+
pistol[4] = loadImage('./assets/pistol5.png');
160+
pistol[5] = loadImage('./assets/pistol6.png');
154161
}
155162

156163
function setup() {
@@ -369,7 +376,22 @@ function drawObjects() {
369376
}
370377

371378
function drawPlayer() {
372-
if (!nodamage) rect(px, py, sx, sy);
379+
if (!nodamage) {
380+
rect(px, py, sx, sy);
381+
if (direction[0] && direction[2]) {
382+
image(pistol[1], px + 25, py);
383+
} else if (direction[0] && direction[3]) {
384+
image(pistol[2], px + 25, py + 20);
385+
} else if (direction[1] && direction[2]) {
386+
image(pistol[4], px - 12, py);
387+
} else if (direction[1] && direction[3]) {
388+
image(pistol[5], px - 7, py + 20);
389+
} else if (direction[0]) {
390+
image(pistol[0], px + 25, py + 20);
391+
} else if (direction[1]) {
392+
image(pistol[3], px - 19, py + 20);
393+
}
394+
}
373395
else noDamage();
374396
}
375397

@@ -611,25 +633,30 @@ function newBullet(enumber) {
611633
if (!bullets[i][5]) {
612634
if (enumber === -1) {
613635
noshot++;
614-
bullets[i][1] = py;
615636
bullets[i][2] = bsize;
616637
if (direction[0] && direction[2]) {
617638
bullets[i][0] = spos + px + sx;
639+
bullets[i][1] = py + 10;
618640
bullets[i][3] = 0;
619641
} else if (direction[0] && direction[3]) {
620-
bullets[i][0] = spos + px + sx;
642+
bullets[i][0] = spos + px + sx - 3;
643+
bullets[i][1] = py + 45;
621644
bullets[i][3] = 1;
622645
} else if (direction[1] && direction[2]) {
623646
bullets[i][0] = spos + px;
647+
bullets[i][1] = py + 10;
624648
bullets[i][3] = 2;
625649
} else if (direction[1] && direction[3]) {
626-
bullets[i][0] = spos + px;
650+
bullets[i][0] = spos + px + 3;
651+
bullets[i][1] = py + 45;
627652
bullets[i][3] = 3;
628653
} else if (direction[0]) {
629-
bullets[i][0] = spos + px + sx;
654+
bullets[i][0] = spos + px + sx + 10;
655+
bullets[i][1] = py + 25;
630656
bullets[i][3] = 4;
631657
} else if (direction[1]) {
632-
bullets[i][0] = spos + px;
658+
bullets[i][0] = spos + px - 10;
659+
bullets[i][1] = py + 25;
633660
bullets[i][3] = 5;
634661
}
635662
bullets[i][6] = false;
@@ -754,7 +781,7 @@ function drawEnemies() {
754781
function activeEnemies() {
755782
if (enemiesCounter > -1) {
756783
for (p = 0; p <= enemiesCounter; p++) {
757-
if (!enemies[stageid][drawingenemies[enemiesCounter][2]][8]) {
784+
if (!enemies[stageid][drawingenemies[p][2]][8]) {
758785
if (enemiesCounter === 0) enemiesCounter--;
759786
else {
760787
drawingenemies[p][0] = drawingenemies[enemiesCounter][0];
@@ -852,7 +879,22 @@ function lifePoints(id, number) {
852879

853880
function noDamage() {
854881
ndcounter++;
855-
if (ndcounter % 10 === 0) rect(px, py, sx, sy);
882+
if (ndcounter % 10 === 0) {
883+
rect(px, py, sx, sy);
884+
if (direction[0] && direction[2]) {
885+
image(pistol[1], px + 25, py);
886+
} else if (direction[0] && direction[3]) {
887+
image(pistol[2], px + 25, py + 20);
888+
} else if (direction[1] && direction[2]) {
889+
image(pistol[4], px - 12, py);
890+
} else if (direction[1] && direction[3]) {
891+
image(pistol[5], px - 7, py + 20);
892+
} else if (direction[0]) {
893+
image(pistol[0], px + 25, py + 20);
894+
} else if (direction[1]) {
895+
image(pistol[3], px - 19, py + 20);
896+
}
897+
}
856898
if (ndcounter === 60 * 1.5) {
857899
nodamage = false;
858900
ndcounter = 0;

0 commit comments

Comments
 (0)