Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Space gun Added #2174

Merged
merged 5 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Space Gun/bigImage.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions Space Gun/css/style.css
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;
}
27 changes: 27 additions & 0 deletions Space Gun/index.html
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>
83 changes: 83 additions & 0 deletions Space Gun/js/bg.js
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;
}
116 changes: 116 additions & 0 deletions Space Gun/js/collision.js
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;
}
}
}
Loading
Loading