Skip to content

Commit

Permalink
Grid Gunner: Book demo game
Browse files Browse the repository at this point in the history
  • Loading branch information
photonstorm committed Nov 19, 2013
1 parent e435719 commit 6ed6820
Show file tree
Hide file tree
Showing 15 changed files with 436 additions and 28 deletions.
45 changes: 17 additions & 28 deletions examples/games/invaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,23 @@ function create() {

createAliens();

// The score :
// The score
scoreString = 'Score : ';
scoreText = game.add.text(10,10,scoreString+score,{fontSize : '34px',fill : '#fff'});
scoreText = game.add.text(10, 10, scoreString + score, { fontSize: '34px', fill: '#fff' });

// Lives
// Lives
lives = game.add.group();
game.add.text(game.world.width-100,10,'Lives : ',{fontSize : '34px',fill : '#fff'});
game.add.text(game.world.width - 100, 10, 'Lives : ', { fontSize: '34px', fill: '#fff' });

//state text
stateText = game.add.text(game.world.centerX,game.world.centerY,'',{fontSize : '84px',fill : '#fff'});
stateText.anchor.setTo(0.5,0.5);
stateText.visible=false;


// Text
stateText = game.add.text(game.world.centerX,game.world.centerY,'', { fontSize: '84px', fill: '#fff' });
stateText.anchor.setTo(0.5, 0.5);
stateText.visible = false;

for (var i = 0; i < 3; i++)
{

var ship = lives.create(game.world.width-100+(30*i),60,'ship');
ship.anchor.setTo(0.5,0.5);
var ship = lives.create(game.world.width - 100 + (30 * i), 60, 'ship');
ship.anchor.setTo(0.5, 0.5);
ship.angle = 90;
ship.alpha = 0.4;
}
Expand All @@ -90,7 +87,6 @@ function create() {
// And some controls to play the game with
cursors = game.input.keyboard.createCursorKeys();
fireButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);

}

function createAliens () {
Expand All @@ -100,8 +96,8 @@ function createAliens () {
for (var x = 0; x < 10; x++)
{
var alien = aliens.create(x * 48, y * 50, 'invader');
alien.anchor.setTo(0.5,0.5);
alien.animations.add('fly', [0,1,2,3], 20, true);
alien.anchor.setTo(0.5, 0.5);
alien.animations.add('fly', [ 0, 1, 2, 3 ], 20, true);
alien.play('fly');
}
}
Expand All @@ -110,7 +106,7 @@ function createAliens () {
aliens.y = 50;

// All this does is basically start the invaders moving. Notice we're moving the Group they belong to, rather than the invaders directly.
var tween = game.add.tween(aliens).to({x: 200}, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
var tween = game.add.tween(aliens).to( { x: 200 }, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);

// When the tween completes it calls descend, before looping again
tween.onComplete.add(descend, this);
Expand Down Expand Up @@ -153,7 +149,7 @@ function update() {
fireBullet();
}

if(game.time.now > firingTimer)
if (game.time.now > firingTimer)
{
enemyFires();
}
Expand All @@ -162,7 +158,6 @@ function update() {
game.physics.collide(bullets, aliens, collisionHandler, null, this);
game.physics.collide(enemyBullets, player, enemyHitsPlayer, null, this);


}

function collisionHandler (bullet, alien) {
Expand All @@ -182,7 +177,6 @@ function collisionHandler (bullet, alien) {

if (aliens.countLiving() == 0)
{

score += 1000;
scoreText.content = scoreString + score;

Expand All @@ -192,8 +186,6 @@ function collisionHandler (bullet, alien) {

//the "click to restart" handler
game.input.onTap.addOnce(restart,this);


}

}
Expand All @@ -204,21 +196,19 @@ function enemyHitsPlayer (player,bullet) {

live = lives.getFirstAlive();

if(live)
if (live)
{
live.kill();
}


// And create an explosion :)
var explosion = explosions.getFirstDead();
explosion.reset(player.body.x, player.body.y);
explosion.play('kaboom', 30, false, true);

// When the player dies
if(lives.countLiving() < 1)
if (lives.countLiving() < 1)
{

player.kill();
enemyBullets.callAll('kill');

Expand All @@ -227,8 +217,6 @@ function enemyHitsPlayer (player,bullet) {

//the "click to restart" handler
game.input.onTap.addOnce(restart,this);


}

}
Expand All @@ -247,6 +235,7 @@ function enemyFires () {
game.physics.moveToObject(enemyBullet,player,120);
firingTimer = game.time.now + 2000;
}

}

function fireBullet () {
Expand Down
Binary file added examples/wip/book/audio/explode.wav
Binary file not shown.
Binary file added examples/wip/book/audio/shot.wav
Binary file not shown.
Binary file added examples/wip/book/audio/title.mp3
Binary file not shown.
Binary file added examples/wip/book/images/bullet.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 examples/wip/book/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 examples/wip/book/images/invader32x32x4.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 examples/wip/book/images/landscape.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 examples/wip/book/images/logo.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 removed examples/wip/book/images/picture.png
Binary file not shown.
Binary file added examples/wip/book/images/robofont.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions examples/wip/book/images/robofont.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0"?>
<font>
<info face="AtomicRoboKid" size="64" bold="0" italic="0" charset="" unicode="1" stretchH="100" smooth="0" aa="1" padding="0,0,0,0" spacing="1,1" outline="0"/>
<common lineHeight="64" base="56" scaleW="512" scaleH="512" pages="1" packed="0" alphaChnl="1" redChnl="0" greenChnl="0" blueChnl="0"/>
<pages>
<page id="0" file="robofont_0.png" />
</pages>
<chars count="90">
<char id="32" x="504" y="0" width="3" height="1" xoffset="-1" yoffset="63" xadvance="63" page="0" chnl="15" />
<char id="33" x="472" y="280" width="31" height="55" xoffset="24" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="34" x="178" y="392" width="23" height="24" xoffset="16" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="39" x="145" y="392" width="16" height="31" xoffset="8" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="40" x="465" y="336" width="16" height="47" xoffset="16" yoffset="9" xadvance="63" page="0" chnl="15" />
<char id="41" x="482" y="336" width="16" height="47" xoffset="16" yoffset="9" xadvance="63" page="0" chnl="15" />
<char id="43" x="48" y="392" width="39" height="39" xoffset="16" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="44" x="162" y="392" width="15" height="31" xoffset="24" yoffset="17" xadvance="63" page="0" chnl="15" />
<char id="45" x="242" y="392" width="39" height="16" xoffset="8" yoffset="24" xadvance="63" page="0" chnl="15" />
<char id="46" x="282" y="392" width="15" height="16" xoffset="24" yoffset="32" xadvance="63" page="0" chnl="15" />
<char id="47" x="0" y="392" width="47" height="47" xoffset="8" yoffset="9" xadvance="63" page="0" chnl="15" />
<char id="48" x="0" y="0" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="49" x="449" y="336" width="15" height="55" xoffset="24" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="50" x="224" y="56" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="51" x="280" y="56" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="52" x="336" y="56" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="53" x="392" y="56" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="54" x="448" y="56" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="55" x="336" y="336" width="47" height="55" xoffset="8" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="56" x="56" y="112" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="57" x="328" y="280" width="47" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="58" x="128" y="392" width="16" height="39" xoffset="16" yoffset="9" xadvance="63" page="0" chnl="15" />
<char id="59" x="432" y="336" width="16" height="55" xoffset="16" yoffset="9" xadvance="63" page="0" chnl="15" />
<char id="61" x="202" y="392" width="39" height="23" xoffset="8" yoffset="17" xadvance="63" page="0" chnl="15" />
<char id="63" x="336" y="112" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="64" x="392" y="112" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="65" x="448" y="112" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="66" x="0" y="168" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="67" x="56" y="168" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="68" x="112" y="168" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="69" x="48" y="336" width="47" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="70" x="224" y="168" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="71" x="280" y="168" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="72" x="336" y="168" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="73" x="384" y="336" width="23" height="55" xoffset="16" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="74" x="96" y="336" width="47" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="75" x="0" y="224" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="76" x="144" y="336" width="47" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="77" x="112" y="224" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="78" x="192" y="336" width="47" height="55" xoffset="8" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="79" x="224" y="224" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="80" x="280" y="224" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="81" x="336" y="224" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="82" x="392" y="224" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="83" x="448" y="224" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="84" x="392" y="168" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="85" x="56" y="280" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="86" x="112" y="280" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="87" x="168" y="280" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="88" x="224" y="280" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="89" x="288" y="336" width="47" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="90" x="56" y="0" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="95" x="298" y="392" width="55" height="8" xoffset="0" yoffset="48" xadvance="63" page="0" chnl="15" />
<char id="97" x="112" y="0" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="98" x="168" y="0" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="99" x="224" y="0" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="100" x="112" y="56" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="101" x="0" y="336" width="47" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="102" x="280" y="0" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="103" x="336" y="0" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="104" x="392" y="0" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="105" x="408" y="336" width="23" height="55" xoffset="16" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="106" x="280" y="280" width="47" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="107" x="448" y="0" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="108" x="424" y="280" width="47" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="109" x="0" y="56" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="110" x="376" y="280" width="47" height="55" xoffset="8" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="111" x="56" y="56" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="112" x="168" y="56" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="113" x="0" y="112" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="114" x="112" y="112" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="115" x="168" y="112" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="116" x="224" y="112" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="117" x="280" y="112" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="118" x="168" y="168" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="119" x="448" y="168" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="120" x="56" y="224" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="121" x="240" y="336" width="47" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="122" x="0" y="280" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="160" x="508" y="0" width="3" height="1" xoffset="-1" yoffset="63" xadvance="63" page="0" chnl="15" />
<char id="169" x="168" y="224" width="55" height="55" xoffset="0" yoffset="1" xadvance="63" page="0" chnl="15" />
<char id="215" x="88" y="392" width="39" height="39" xoffset="16" yoffset="9" xadvance="63" page="0" chnl="15" />
<char id="119155" x="504" y="2" width="3" height="1" xoffset="-1" yoffset="63" xadvance="63" page="0" chnl="15" />
<char id="119156" x="508" y="2" width="3" height="1" xoffset="-1" yoffset="63" xadvance="63" page="0" chnl="15" />
<char id="119157" x="504" y="4" width="3" height="1" xoffset="-1" yoffset="63" xadvance="63" page="0" chnl="15" />
<char id="119158" x="508" y="4" width="3" height="1" xoffset="-1" yoffset="63" xadvance="63" page="0" chnl="15" />
<char id="119159" x="504" y="6" width="3" height="1" xoffset="-1" yoffset="63" xadvance="63" page="0" chnl="15" />
<char id="119160" x="508" y="6" width="3" height="1" xoffset="-1" yoffset="63" xadvance="63" page="0" chnl="15" />
<char id="119161" x="504" y="8" width="3" height="1" xoffset="-1" yoffset="63" xadvance="63" page="0" chnl="15" />
<char id="119162" x="508" y="8" width="3" height="1" xoffset="-1" yoffset="63" xadvance="63" page="0" chnl="15" />
</chars>
</font>
Binary file added examples/wip/book/images/ship.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 examples/wip/book/images/sky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6ed6820

Please sign in to comment.