-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from Rinevitable/main
Covid_Survivor
- Loading branch information
Showing
8 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Covid_Survivor | ||
|
||
You can PlAY it on:- | ||
## https://rinevitable.github.io/Covid_Survivor/covid_survivor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" dir="ltr"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Made by Rishabh Jain</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
<body> | ||
<div class="text"> | ||
<h1>Covid Survivor </h1> | ||
<h4>Welcome to year "2020" you have to avoid Corona Particles to survive. Survive or your Imunity will run out .</h4> | ||
|
||
</div> | ||
<div class="my_canvas"> | ||
<canvas id="mcanvas"></canvas> | ||
</div> | ||
<p> | ||
<strong>Rules: </strong> You can move by Clicking Mouse Button, "Just like <em>Life goes in one Direction ,no turning back".</em> | ||
</p> | ||
<h4>PRESS F5 for Replay</h4> | ||
<script src="covid_survivor.js" charset="utf-8"></script> | ||
|
||
</body> | ||
</html> | ||
|
||
//contributed by Rishabh Jain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
function load_images(){ | ||
|
||
enemy_image=new Image; | ||
enemy_image.src="data/v1.png"; | ||
|
||
gem_image=new Image; | ||
gem_image.src="data/gem.png"; | ||
|
||
fighter_image=new Image; | ||
fighter_image.src= "data/superhero.png"; | ||
|
||
} | ||
|
||
function init(){ | ||
//preparing canvas and 2d context | ||
canvas=document.getElementById("mcanvas"); | ||
W=700; canvas.width=W; | ||
H=400; canvas.height=H; | ||
|
||
pen =canvas.getContext('2d'); | ||
|
||
game_over=false;//game check | ||
|
||
//defining objects; | ||
e1={ | ||
x:150, | ||
y:100, | ||
w:60, | ||
h:60, | ||
speed:20, | ||
}; | ||
e2={ | ||
x:315, | ||
y:175, | ||
w:60, | ||
h:60, | ||
speed:30, | ||
}; | ||
e3={ | ||
x:450, | ||
y:300, | ||
w:60, | ||
h:60, | ||
speed:40, | ||
}; | ||
|
||
enemy=[e1,e2,e3]; | ||
|
||
fighter={ | ||
x:20, | ||
y:H/2, | ||
w:60, | ||
h:60, | ||
speed:20, | ||
moving:false, | ||
health:100, | ||
}; | ||
gem={ | ||
x:W-100, | ||
y:H/2, | ||
w:60, | ||
h:60, | ||
}; | ||
|
||
//Adding Event listener | ||
canvas.addEventListener('mousedown',function(){ | ||
fighter.moving=true; | ||
console.log("mouse pressed"); | ||
}); | ||
canvas.addEventListener('mouseup',function(){ | ||
fighter.moving=false; | ||
console.log("mouse Released"); | ||
}); | ||
|
||
} | ||
|
||
function isTouching(rect1,rect2){ | ||
|
||
if(rect1.x<rect2.x+rect2.w && rect1.x+rect1.w>rect2.x && | ||
rect1.y<rect2.y+rect2.h && rect1.y+rect1.h>rect2.y){ | ||
return true | ||
} | ||
return false; | ||
|
||
} | ||
|
||
function draw(){ | ||
//clearing frame | ||
pen.clearRect(0,0,W,H); | ||
//draw gem and fighter_image | ||
pen.drawImage(fighter_image,fighter.x,fighter.y,fighter.w,fighter.h); | ||
pen.drawImage(gem_image,gem.x,gem.y,gem.w,gem.h); | ||
//enemy images | ||
for(let i=0;i<enemy.length;i++){ | ||
pen.drawImage(enemy_image,enemy[i].x,enemy[i].y,enemy[i].w,enemy[i].h); | ||
} | ||
//Score | ||
pen.fillStyle="white"; | ||
pen.fillText("Score "+fighter.health,10,10); | ||
} | ||
|
||
function update(){ | ||
//fighter move | ||
if(fighter.moving==true){ | ||
fighter.x+=fighter.speed; | ||
fighter.health+=20; | ||
} | ||
|
||
for(var i =0 ;i<enemy.length;i++){ | ||
if(isTouching(enemy[i],fighter)){ | ||
fighter.health-=50; | ||
if(fighter.health<0){ | ||
game_over=true; | ||
alert(" Game Over Your Score: " + fighter.health); | ||
} | ||
} | ||
} | ||
|
||
if(isTouching(fighter,gem)){ | ||
game_over=true; | ||
alert("You Won and Survived!"); | ||
return ; | ||
} | ||
|
||
for(var i=0;i<enemy.length;i++){ | ||
enemy[i].y+=enemy[i].speed; | ||
if(enemy[i].y>H-enemy[i].h || enemy[i].y<0){ | ||
enemy[i].speed *= -1; | ||
} | ||
} | ||
} | ||
|
||
function gameloop(){ | ||
|
||
if(game_over==true){ | ||
clearInterval(t); | ||
} | ||
draw(); | ||
update(); | ||
console.log("inside loop"); | ||
|
||
} | ||
|
||
load_images(); | ||
init(); | ||
t = setInterval(gameloop,100); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.text{ | ||
text-align: center; | ||
color: #04D64E; | ||
} | ||
h4{ | ||
color: #D604D6; | ||
} | ||
p{ | ||
color: #D604D6; | ||
} | ||
.my_canvas{ | ||
text-align: center; | ||
} | ||
#mcanvas{ | ||
border: 5px green solid; | ||
text-align: center; | ||
background-image: url(data/back.jpeg); | ||
} | ||
*{ | ||
background-color: black; | ||
} |