-
Notifications
You must be signed in to change notification settings - Fork 187
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 #2174 from Damini2004/Space-Gun
Space gun Added
- Loading branch information
Showing
16 changed files
with
1,500 additions
and
5,478 deletions.
There are no files selected for viewing
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,10 @@ | ||
*{ | ||
margin:0; | ||
padding:0; | ||
} | ||
|
||
body,html {height:100%; width:100%;overflow:hidden;} | ||
|
||
#_canvas { | ||
position:absolute; | ||
} |
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,27 @@ | ||
<!DOCTYPE HTML> | ||
<html lang ="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Space-Gum</title> | ||
<meta name="viewport" content="width=device-width,initial-scale=1"> | ||
<meta name="monetization" content="$ilp.uphold.com/kPZD6jHmXDpA"> | ||
<link rel="stylesheet" type="text/css" href="./css/style.css"/> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" /> | ||
</head> | ||
<body> | ||
<div style="text-align: left; | ||
font-size: 30px; | ||
padding: 10px; background-color: rgb(24, 11, 81); "><a href="https://kunjgit.github.io/GameZone/"><i style="color:white;" class="fas fa-home home-icon"></i></a></div> | ||
<canvas id="_canvas"></canvas> | ||
<script src ="js/bg.js"></script> | ||
<script src="js/spaceship_fig.js"></script> | ||
<script src="js/spaceship_favicon.js"></script> | ||
<script src="./js/spaceship.js"></script> | ||
<script src="js/music.js"></script> | ||
<script src="js/interface.js"></script> | ||
<script src="./js/meteor.js"></script> | ||
<script src="./js/weapon.js"></script> | ||
<script src="./js/collision.js"></script> | ||
<script src="./js/game.js"></script> | ||
</body> | ||
</html> |
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,83 @@ | ||
class Star { | ||
constructor(x ,y, r, n, inset, ninth){ | ||
this.x=x; | ||
this.y=y; | ||
this.r=r *_zoom; | ||
this.n=n; | ||
this.inset=inset; | ||
|
||
this.NINTH = ninth; | ||
} | ||
draw (){ | ||
ctx.save(); | ||
ctx.fillStyle = "white"; | ||
ctx.shadowColor = "white"; | ||
ctx.shadowBlur = 5; | ||
ctx.beginPath(); | ||
ctx.translate(this.x,this.y); | ||
ctx.moveTo(0,0-this.r); | ||
for (var i=0;i<this.n;i++){ | ||
ctx.rotate(Math.PI / this.n); | ||
ctx.lineTo(0,0-(this.r*this.inset)); | ||
ctx.rotate(Math.PI / this.n); | ||
ctx.lineTo(0,0 -this.r); | ||
} | ||
ctx.closePath(); | ||
ctx.fill(); | ||
ctx.restore() | ||
} | ||
update (d){ | ||
v = _spaceship.speed; | ||
|
||
dx = v * Math.cos(d*Math.PI); | ||
dy = v * Math.sin(d*Math.PI); | ||
|
||
this.x -= dx; | ||
this.y -= dy; | ||
|
||
var N = calcNINTH (this.x,this.y); | ||
if (this.NINTH[0] != N[0] && this.NINTH[1] != N[1]){ | ||
if (this.NINTH[0] == 0 && this.NINTH[1] == 0) { | ||
var a = Math.floor(Math.random()*3)-1; | ||
var b = Math.floor(Math.random()*3)-1; | ||
this.NINTH[0] = a; | ||
this.NINTH[1] = b; | ||
} | ||
this.x = (Math.random()+-1*this.NINTH[0])*W; | ||
this.y = (Math.random()+-1*this.NINTH[1])*H; | ||
} | ||
} | ||
} | ||
function calcNINTH (x,y){ | ||
//NINTHES are indexed as [-1,0,1]*[-1,0,1] indexes mat | ||
if (-W<=x && x<0) { | ||
if (-H<=y && y<0) return [-1,-1]; | ||
if (0<=y && y<H) return [-1,0]; | ||
if (H<=y && y<2*H) return [-1,1]; | ||
} | ||
else if(0<=x && x<W) { | ||
if (-H<=y && y<0) return [0,-1]; | ||
if (0<=y && y<H) return [0,0]; | ||
if (H<=y && y<2*H) return [0,1]; | ||
} | ||
else if(W<=x && x<2*W) { | ||
if (-H<=y && y<0) return [1,-1]; | ||
if (0<=y && y<H) return [1,0]; | ||
if (H<=y && y< 2*H) return [1,1]; | ||
} | ||
return [-9,-9]; | ||
} | ||
|
||
function stars(t){ | ||
arr = []; | ||
for (var i=0;i<t;i++){ | ||
x = Math.random() * 3 * W - W; | ||
y = Math.random() * 3 * H - H; | ||
r = Math.random() * 7; | ||
n = 5; | ||
inset = 0.5; | ||
var ninth = calcNINTH(x,y); | ||
arr.push(new Star(x,y,r,n,inset, ninth)); | ||
} | ||
return arr; | ||
} |
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,116 @@ | ||
function distance (e1,e2) { | ||
return Math.sqrt((e1.x-e2.x)*(e1.x-e2.x)+(e1.y-e2.y)*(e1.y-e2.y)); | ||
} | ||
|
||
class Circle { | ||
constructor(x,y,r,color){ | ||
this.x=x; | ||
this.y=y; | ||
this.r=r; | ||
this.color=color; | ||
} | ||
draw(){ | ||
ctx.save(); | ||
ctx.fillStyle = this.color; | ||
ctx.strokeStyle = this.color; | ||
ctx.shadowColor = this.color; | ||
ctx.shadowBlur = 30; | ||
ctx.beginPath(); | ||
|
||
ctx.arc(this.x,this.y,this.r,0,2*Math.PI,true); | ||
ctx.closePath(); | ||
ctx.fill(); | ||
ctx.stroke(); | ||
ctx.restore(); | ||
} | ||
} | ||
class Triangle{ | ||
constructor(x,y,d,r,color){ | ||
this.x=x; | ||
this.y=y; | ||
this.d=d; | ||
this.r=r; | ||
this.color=color; | ||
this.random_direction = Math.random()*2*Math.PI; | ||
} | ||
draw(){ | ||
ctx.save(); | ||
ctx.fillStyle = this.color; | ||
ctx.strokeStyle = this.color; | ||
ctx.beginPath(); | ||
ctx.translate(this.x,this.y); | ||
ctx.rotate(this.d); | ||
ctx.moveTo(0,-2*this.r); | ||
ctx.rotate(Math.PI*2/3); | ||
ctx.lineTo(0,-2*this.r); | ||
ctx.rotate(Math.PI*2/3); | ||
ctx.lineTo(0,-2*this.r); | ||
ctx.closePath(); | ||
ctx.fill(); | ||
ctx.restore(); | ||
} | ||
} | ||
_COLLISION_DT=0.01; | ||
class Collision { | ||
constructor(x,y){ | ||
this.x=x; | ||
this.y=y; | ||
this.arr = this.createCollisionFigures(); | ||
this.t = 0; | ||
this.flag = 0; | ||
} | ||
draw() { | ||
for (var i=0;i<this.arr.length;i++){ | ||
this.arr[i].draw(); | ||
} | ||
} | ||
|
||
pickColor(){ | ||
var i = Math.floor(Math.random()*4); | ||
var op = (Math.random()+0.4)/1; | ||
var plate = ["rgba(58,31,91","rgba(200,54,93","rgba(225,82,73","rgba(246,211,101"]; | ||
plate.forEach((el,index,plate)=>plate[index]=el+","+op+")"); | ||
return plate[i]; | ||
} | ||
|
||
createCollisionFigures(){ | ||
var result = []; | ||
var i = Math.floor(Math.random()*40); | ||
for (var j=0;j<i;j++){ | ||
var k = Math.floor(Math.random()*2); | ||
var r = Math.random()*5; | ||
var d = Math.random()*Math.PI*2; | ||
var ddx = Math.random()*8-4; | ||
var ddy = Math.random()*8-4; | ||
if (k==0) result.push(new Circle(this.x+ddx*4,this.y+ddy*4,r*0.2,this.pickColor())); | ||
else result.push(new Triangle(this.x+ddx,this.y+ddy,d,r,this.pickColor())); | ||
} | ||
return result; | ||
} | ||
update(){ | ||
v = _spaceship.speed; | ||
dx = v * Math.cos(d*Math.PI); | ||
dy = v * Math.sin(d*Math.PI); | ||
this.x -= dx; | ||
this.y -= dy; | ||
var arr= this.arr; | ||
for(var i=0;i<this.arr.length;i++){ | ||
arr[i].x -=dx; | ||
arr[i].y -=dy; | ||
if (arr[i] instanceof Triangle){ | ||
arr[i].d+=0.2; | ||
arr[i].x+= Math.cos(arr[i].random_direction) * 0.33; | ||
arr[i].y+= Math.sin(arr[i].random_direction) * 0.33; | ||
} | ||
else { | ||
var r1 = Math.random()/100; | ||
arr[i].r*=1.02+r1; | ||
} | ||
} | ||
this.t += _COLLISION_DT; | ||
|
||
if(this.t>1) { | ||
this.flag = 1; | ||
} | ||
} | ||
} |
Oops, something went wrong.