Skip to content

Games - Space Demo #129

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions code/games/space_demo/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body {
font-family: Verdana;
font-size: 10pt;
margin:50px;
padding:0px;
background:#000;
}
30 changes: 30 additions & 0 deletions code/games/space_demo/gameInfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
1. Controls

- Left Arrow key : Move Left
- Right Arrow key : Move Right
- Space Bar : Shoot

2. Player placed at the bottom of canvas and is firing on press of spacebar

3. The player moves in two directions (left, right) within canvas bounds.

4. Enemies are continoulsy falling from top

5. Enemies disapppear as soon as they are hit with the bullet

6. Each successful enemy kill adds 10 points to the score, the score is displayed on the top right corner

7. The Player has 3 Lifes, displayed at the top left corner of screen , and a life keeps reducing with each player crossing the player without being Hit

8. Levels are displayed on the top right corner of screen and keeps increasing when the main score reaches multiples of 500. Level is responsible for Enemy and Special Enemy falling speed and number of bullets required to destroy Special Enemy. Level also changes the Enemy type.

9. Another type of enemy, Special Enemy different from normal 10 pointer Enemies also falls with a lesser frequency. They need more bullets to be destroyed depending on the level.And adds a bonus of 20 points to the displayed total score.

10. Enemies Hit, bullet fire, Game end, all make sounds saved in the sound folder.

11. Game ends under following cases :
- Player looses all 3 lifes (When 3 Enemies are missed)
- Special Enemy is missed and it crosses the canvas
- Enemy/Special Enemy hits the player

12. Game Restarts on clicking anywhere on the canvas when the game ends.
Binary file added code/games/space_demo/images/bg3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/enemy0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/enemy1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/enemy2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/ex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/explode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/favicon.ico
Binary file not shown.
Binary file added code/games/space_demo/images/gameover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/gameover1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/life3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added code/games/space_demo/images/se3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions code/games/space_demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html><!-- <!DOCTYPE html> -->
<html>
<head>

<title>Space Demo</title>

<link rel='shortcut icon' type='image/x-icon' href='images/favicon.ico' />
<link href="css/style.css" media="all" rel="stylesheet" type="text/css"/>


<script language="javascript" src="../../js/jquery.js" type="text/javascript"></script>
<script language="javascript" src="scripts/util.js" type="text/javascript"></script>
<script language="javascript" src="scripts/sprite.js" type="text/javascript"></script>
<script type="text/javascript" src="scripts/hotkey/jquery.hotkeys.js"></script>
<script language="javascript" type="text/javascript" src="scripts/general_functions.js"></script>
<script language="javascript" type="text/javascript" src="scripts/canvas.js"></script>
<script language="javascript" type="text/javascript" src="scripts/special_enemy.js"></script>
<script language="javascript" type="text/javascript" src="scripts/life.js"></script>
<script language="javascript" type="text/javascript" src="scripts/score.js"></script>
<script language="javascript" type="text/javascript" src="scripts/bullets.js"></script>
<script language="javascript" type="text/javascript" src="scripts/enemies.js"></script>
<script language="javascript" type="text/javascript" src="scripts/collision.js"></script>
<script language="javascript" type="text/javascript" src="scripts/player.js"></script>


</head>



<style type="text/css">

canvas {
display:block;
background-image: url("images/bg3.jpg");
background-size: cover;
background-repeat: no-repeat;
margin:2px auto;
border:1px dashed #a100fd;
background-attachment: fixed;
background-position: center;
}
</style>

<body>
</body>
</html>
55 changes: 55 additions & 0 deletions code/games/space_demo/info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<title>Space Demo Info</title>
</head>
<body>

<p>
1. Controls
<pre>
- Left Arrow key : Move Left
- Right Arrow key : Move Right
- Space Bar : Shoot
</pre>
</p>

<p>
2. Player placed at the bottom of canvas and is firing on press of spacebar
</p>
<p>
3. The player moves in two directions (left, right) within canvas bounds.
</p>
<p>
4. Enemies are continoulsy falling from top
</p>
<p>
5. Enemies disapppear as soon as they are hit with the bullet
</p>
<p>
6. Each successful enemy kill adds 10 points to the score, the score is displayed on the top right corner
</p>
<p>
7. The Player has 3 Lifes, displayed at the top left corner of screen , and a life keeps reducing with each player crossing the player without being Hit
</p>
<p>
8. Levels are displayed on the top right corner of screen and keeps increasing when the main score reaches
multiples of 500. Level is responsible for Enemy and Special Enemy falling speed and number of bullets required to destroy Special Enemy. Level also changes the Enemy type.
</p>
<p>
9. Another type of enemy, Special Enemy different from normal 10 pointer Enemies also falls with a lesser frequency. They need more bullets to be destroyed depending on the level.And adds a bonus of 20 points to the displayed total score.
</p>
<p>
10. Game ends under following cases :
<pre>
- Player looses all 3 lifes (When 3 Enemies are missed)
- Special Enemy is missed and it crosses the canvas
- Enemy/Special Enemy hits the player
</pre>
</p>
<p>
11. Game Restarts on clicking anywhere on the canvas when the game ends.
</p>

</body>
</html>
54 changes: 54 additions & 0 deletions code/games/space_demo/scripts/bullets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var playerBullets = [];

function draw_bull()
{
playerBullets.forEach(function(bullet){
bullet.draw();
});

}


function update_b()
{
playerBullets.forEach(function(bullet){
bullet.update();
});

playerBullets = playerBullets.filter(function(bullet){
return bullet.active;
})

}


function bullet(I)
{
I.active = true;
I.xVelocity = 0;
I.yVelocity = -I.speed;
I.width = 3;
I.height = 3;
I.color ="#feff51";
I.inBounds = function()
{
return (I.x>=0 && I.x<=width && I.y >=0 && I.y <= height);
};
I.draw = function()
{
canvas.beginPath();
canvas.fillStyle = this.color;
canvas.fillRect(this.x,this.y,this.width,this.height);
canvas.closePath();
};
I.update = function(){

I.x += I.xVelocity;
I.y += I.yVelocity;
I.active = I.active && I.inBounds();
};

return I;


};
45 changes: 45 additions & 0 deletions code/games/space_demo/scripts/canvas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@


/*--------------------------Canvas Area -------------------------*/



var canvas;
var levels = 1;
var go = Sprite("gameover1");
var FPS = 30;




//Height & Width of the screen
var height = 512;
var width = 480;
var speed = 1;

function createCanvas ()
{

//canvas element with Height/Width
var canvas_Element = $("<canvas tabindex='1' id='mainCanvas' width='"+width+"' height='"+height+"'></canvas>");
canvas = canvas_Element.get(0).getContext("2d");

//Add canvas element to body
canvas_Element.appendTo('body');

var btn = $('<button target="_blank" id="infobtn" type="button" style="z-index:2; position:absolute; top:90%; left:44%" >Game Information and Rules</button>')
btn.appendTo('body');

}


function draw()
{
canvas.beginPath();
canvas.clearRect(0,0,width,height);
canvas.closePath();

}



73 changes: 73 additions & 0 deletions code/games/space_demo/scripts/collision.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
var step = 1;

function collides(a,b)
{
var ans = (a.x<b.x + b.width &&
a.x +a.width > b.x &&
a.y < b.y + b.height &&
a.y + a.height >b.y );
return ans;

}


function handleCollisions()
{
playerBullets.forEach(function(bullet){

enemies.forEach(function(enemy){

if(collides(bullet,enemy)&&enemy.active==true){
enemy.explode();
bullet.active = false;
score = score+10;
}
});

s_enemies.forEach(function(senemy){
if(collides(bullet,senemy)){
senemy.hit();
bullet.active = false;
}
});



});

s_enemies.forEach(function(enemy){
if(collides(enemy,player)){

// enemy.explode();
// player.explode();

endGame();
}
});

enemies.forEach(function(enemy){
if(collides(enemy,player)){

// enemy.explode();
// player.explode();

endGame();
}
});

//Change level with score
if(score==500*step)
{
canvas.clearRect(0,0,width,height);
levels++;
enemies.length = 0;
playerBullets.length=0;
s_enemies.length=0;
step++;
p1.x= 220;
p1.y = 480;


}

}
Loading