From 6b0f5207951916d523682632b5b832fdfd1c1309 Mon Sep 17 00:00:00 2001 From: mrpkdeveloper Date: Fri, 31 Jul 2020 13:54:32 +0530 Subject: [PATCH] added health part --- assets/trophy.png | Bin 0 -> 1693 bytes game.js | 32 ++++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 assets/trophy.png diff --git a/assets/trophy.png b/assets/trophy.png new file mode 100644 index 0000000000000000000000000000000000000000..cf9eb5aa1b30db641ef67f1f8b4883b5668be197 GIT binary patch literal 1693 zcmV;O24eY%P) z&rcgi6vw~s?O;%PfL?onwwK&WZ@q=wdJC!4C~7MO3Y6aB`~{_d0dOP1NaRu_9D@4~ zROOai;Xk0aN>wFW>My`MubN%EalqcS!|wAsJ0J9fVq(wC*W;Nt^WKa}eloYO9KNRZU{pmk9XS{HG*e7t&a(#|7HfU5#L zkl2CmX=NlNdH~Q;V&8_;LsMynrUHftB7@ye(~Ce`fzX{m2)(R)@EroD>K2II3dFkK zZcrvTtF0V7P4&q^GnS}si5^-aT(&Y{DR3I3rvJK;Bc$LcqyWxdo9S4>#E(W7TLL+B zt5CLQ=vXO`)@(?8=rkClxq*ZmfrRK78?orv-pcbMLFxn=L7+v;lc$y^HUZ4O^;%17 z))H;HHoLYD_@oU>d}N8yG2^_HZi3eNk~Njnv|0BRT(vw|b#D{_jcYcma9H9c0jflk zLoNX2m|N#pJ_Q`@TXmUR2(ie}yM*z(o;+KRC$uzpkM1B17Fj|t(L^wTZsT75opTf0 zM=d-<6N&A#JL&aICS0JGJz4$Xh(#9N3wY57C0T4lf?I=rw)^$7ALAGBQK59AF?$Z- z#RO(spyt&|)S+9NG_ayST z3O?*fg)7f&+thPE{7ubmboDDp z?7vyoTMbKm(j6kZu3d@vT-*9><^J8{;q#Ovfsy0dl3|Z@nO8Y9si)xb*GtI7Z?FFC zmi2$WEUMBSGLHio$~a}pZSYX9*rvP1?f0Fr%Ft?WR%J@&M;2TTo!e-C8*pvOx*1GX zkfrUey=caJ<>QX*TT^LTQ$dzyIO{RRy^F2$sx_6w{qbTW4cCS|s+j41csFZ%_a6?L z4pu;%*xPwjD|@%FZM&<_w#Rd5i9(0lS-XS(yM=B<$;)ah&zHwb^r)`Od6vLp1$o-; z^0VdmBUad*4$Gyw06+|8e7jSML%_vy@q3pLO$fibVYJzv@MEU_*jE|OU zdot39kJm`O?Pse9-61zGC2Q99?x*>$V-XHFE)n0ODEQ@sd{54TQw}RlPlDi(mX}8n zBbX>nV~c=^55;=4FmZ;sM@?`JeGk{f*ueL2O-%c~6ps>q;iHUkXEHr{ct2bjf8<0N zKWQpsTBW=?X>|CNrZV0qRK^RgjQ7Kp@jYA_FSs&=ywd)g+84JjKV}gmK8Gc|@|-L$ zCCG|G2<`-S*VT2d07( zBlRf1veFr;;H!II{Q|J!m)l1-M7#2C>y`OBMrbs_wqu#->JW(CRcuqTWx;=b-_p@nhCJS&T zKk{DQ)h^YL@@}CulLbl0r-4l&;_+x}M?iS3~EA#P=<# ndMk!VH+!~N*JLZ-?*iaIdp3!z(wmW500000NkvXXu0mjfDg{jH literal 0 HcmV?d00001 diff --git a/game.js b/game.js index 60a331e..d297930 100644 --- a/game.js +++ b/game.js @@ -5,7 +5,9 @@ function intit() { H = canvas.height = 500 cw = 60 score = 0 - health = 100 + health = { + value: 100 + } gameover = false //fighter @@ -27,14 +29,17 @@ function intit() { }, prize_update: function () { if (this.x == fighter.x && this.y == fighter.y) { - // alert("u won") score++ this.random_prize() - // gameover = true } } } + + //score_img + score_img = new Image() + score_img.src = "./assets/trophy.png" + prize.random_prize() //virus image virus_img = new Image() @@ -53,22 +58,25 @@ function intit() { } this.y += this.speed } + + //collison detection algorithim this.attack = function () { if (this.x < fighter.x + cw && this.x + cw > fighter.x && this.y < fighter.y + cw && this.y + cw > fighter.y) { // collision detected! - health -= 10 + health.value -= 10 + } } } } //virus objects created - virus1 = new virusclass(W / 3 - 100, 0, "down", 30) - virus2 = new virusclass(W / 2, H - cw, "up", 30) - virus3 = new virusclass(W - 210, 0, "down", 30) + virus1 = new virusclass(W / 3 - 100, 0, "down", 50) + virus2 = new virusclass(W / 2, H - cw, "up", 20) + virus3 = new virusclass(W - 210, 0, "down", 60) @@ -99,10 +107,14 @@ function draw() { //score pen.fillStyle = "black" pen.font = "25px roboto" + pen.drawImage(score_img, 25, 20, cw, cw) pen.fillText(score, 50, 50) //health - pen.fillText(health, 100, 50) + pen.font = "15px roboto" + pen.fillText("Health", 100, 25) + pen.fillStyle = "red" + pen.fillRect(100, 30, health.value, 20) } function update() { @@ -114,7 +126,11 @@ function update() { virus3.update_virus() virus3.attack() prize.prize_update() + if (health.value <= 0) { + gameover = true + } if (gameover == true) { + alert("game over") clearInterval(game) } }