Skip to content

Commit

Permalink
Added help screen
Browse files Browse the repository at this point in the history
Added new controllers
Removed AdMob banners from game screen
Removed AdMob banners from game over screen
  • Loading branch information
alexandresgf committed Nov 19, 2015
1 parent a80ffff commit 4870ec2
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 55 deletions.
Binary file modified www/assets/btn_exit.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 www/assets/btn_help.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 modified www/assets/btn_newgame.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 www/assets/btn_play.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 www/assets/how_to_p01.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 www/assets/how_to_p02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions www/js/Ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@ define(['phaser'], function (Phaser) {
function Ads (game) {
// listen when ad is closed
document.addEventListener('onAdDismiss', function (data) {
if (localStorage.quit == 0)
game.state.start('Game');
else if (localStorage.quit == 1)
var quit = Number(localStorage.getItem('quit'));

if (quit)
game.state.start('Menu');
else
game.state.start('Game');
});
}

Ads.prototype.constructor = Ads;

Ads.prototype.create = function () {
var quit = Number(localStorage.getItem('quit'));

// set backscreen color
this.game.stage.backgroundColor = '#000';

// start admob
if (AdMob && navigator.connection.type !== Connection.NONE)
AdMob.showInterstitial();
else if (localStorage.quit == 0)
this.game.state.start('Game');
else if (localStorage.quit == 1)
else if (quit)
this.game.state.start('Menu');
else
this.game.state.start('Game');
};

return Ads;
Expand Down
21 changes: 11 additions & 10 deletions www/js/Boot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['phaser', 'Preloader', 'Menu', 'Game', 'GameOver', 'Ads'], function (Phaser, Preloader, Menu, Game, GameOver, Ads) {
define(['phaser', 'Preloader', 'Menu', 'Help', 'Game', 'GameOver', 'Ads'], function (Phaser, Preloader, Menu, Help, Game, GameOver, Ads) {
'use strict';

function Boot (game) {
Expand All @@ -18,25 +18,26 @@ define(['phaser', 'Preloader', 'Menu', 'Game', 'GameOver', 'Ads'], function (Pha
window.analytics.startTrackerWithId('UA-70227806-2');

// start admob
if (AdMob) {
AdMob.createBanner({
adId: 'ca-app-pub-7403543083567100/2876399875',
autoShow: false,
isTesting: false,
overlap: true
});

if (AdMob)
AdMob.prepareInterstitial({
adId: 'ca-app-pub-7403543083567100/4353133078',
autoShow: false,
isTesting: false,
overlap: true
});
}

// setup counters to show admob
localStorage.setItem('showAdsCounter', this.game.rnd.integerInRange(1, 3));
localStorage.setItem('newGameCounter', 0);

// remove last counter if exists
if (localStorage.getItem('newGameCount'))
localStorage.removeItem('newGameCount');

// setup game states
this.game.state.add('Preloader', Preloader);
this.game.state.add('Menu', Menu);
this.game.state.add('Help', Help);
this.game.state.add('Game', Game);
this.game.state.add('GameOver', GameOver);
this.game.state.add('Ads', Ads);
Expand Down
16 changes: 10 additions & 6 deletions www/js/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ define(['phaser'], function (Phaser) {

Game.prototype.init = function () {
// google analytics track game screen
window.analytics.trackView('Game Screen');

// show admob
if (AdMob)
AdMob.showBanner(AdMob.AD_POSITION.BOTTOM_CENTER);
window.analytics.trackView('Embaixadinha - Game Screen');

// the ball
this._ball = null;
Expand Down Expand Up @@ -126,8 +122,16 @@ define(['phaser'], function (Phaser) {
Game.prototype.kickUp = function () {
if (this.game.time.now > this._kickTimer) {
this._sfxKick.play();

if (this.game.input.x > this._ball.x - 30 && this.game.input.x < this._ball.x + 30)
this._ball.body.velocity.x = 0;
else if (this.game.input.x > this._ball.x)
this._ball.body.velocity.x -= 250;
else if (this.game.input.x < this._ball.x)
this._ball.body.velocity.x += 250;

this._ball.body.velocity.y = -500;
this._kickTimer = this.game.time.now + 850;
this._kickTimer = this.game.time.now + 500;
}
};

Expand Down
31 changes: 11 additions & 20 deletions www/js/GameOver.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,22 @@ define(['phaser'], function (Phaser) {
};

GameOver.prototype.newGame = function () {
if (localStorage.newGameCount) {
localStorage.newGameCount = Number(localStorage.newGameCount) + 1;

if (localStorage.newGameCount == 3) {
if (AdMob)
AdMob.hideBanner();

localStorage.newGameCount = 0;
localStorage.quit = 0;
this.game.state.start('Ads');

return;
}
var showAdsCounter = Number(localStorage.getItem('showAdsCounter'));
var newGameCounter = Number(localStorage.getItem('newGameCounter'));

if (newGameCounter === showAdsCounter) {
localStorage.setItem('quit', 0);
localStorage.setItem('showAdsCounter', this.game.rnd.integerInRange(1, 3));
localStorage.setItem('newGameCounter', 0);
this.game.state.start('Ads');
} else {
localStorage.newGameCount = 1;
localStorage.setItem('newGameCounter', ++newGameCounter);
this.game.state.start('Game');
}

this.game.state.start('Game');
};

GameOver.prototype.exit = function () {
if (AdMob)
AdMob.hideBanner();

localStorage.quit = 1;
localStorage.setItem('quit', 1);
this.game.state.start('Ads');
};

Expand Down
45 changes: 45 additions & 0 deletions www/js/Help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
define(['phaser'], function (Phaser) {
'use strict';

function Help (game) {
// use init method!
}

Help.prototype.constructor = Help;

Help.prototype.create = function () {
// step counter
this._step = 1;

// page 01
this.game.add.sprite(0, 0, 'how_to_p01');

// page 02
this._page02 = this.game.add.sprite(this.game.width, 0, 'how_to_p02');

// add text label
var label = 'TAP para continuar';
var labelConf = { font: '30px Lucida Console', fill: '#fff', align: 'center' };
this._label = this.game.add.text(this.game.camera.width / 2, this.game.camera.height - 200, label, labelConf);
this._label.anchor.set(0.5);

// add the blinking text
this.game.add.tween(this._label).to({ alpha: 0 }, 1000, Phaser.Easing.Linear.None, true, 0, 500, true);

// tap to next page
this.input.onTap.add(function () {
switch (this._step) {
case 1:
this.game.add.tween(this._page02).to({ x: 0 }, 100, Phaser.Easing.Linear.None, true);
this._step++;
break;

case 2:
this.game.state.start('Game');
break;
}
}, this);
};

return Help;
});
26 changes: 13 additions & 13 deletions www/js/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ define(['phaser'], function (Phaser) {
// add foreground
this.game.add.sprite(0, 0, 'fg_menu');

// add text label
var label = 'TAP para começar';
var labelConf = { font: '30px Lucida Console', fill: '#fff', align: 'center' };
this._label = this.game.add.text(this.game.camera.width / 2, this.game.camera.height - 200, label, labelConf);
this._label.anchor.set(0.5);

// add the blinking text
this.game.add.tween(this._label).to({ alpha: 0 }, 1000, Phaser.Easing.Linear.None, true, 0, 500, true);

// tap to start
this.input.onTap.add(function () {
this.game.state.start('Game');
}, this);
// add buttons
this._btnNewGame = this.game.add.button(this.game.camera.width / 2, this.game.camera.height / 2 + 150, 'btn_play', this.play, this);
this._btnExit = this.game.add.button(this.game.camera.width / 2, this.game.camera.height / 2 + 250, 'btn_help', this.help, this);
this._btnNewGame.anchor.set(0.5);
this._btnExit.anchor.set(0.5);
};

Menu.prototype.play = function () {
this.game.state.start('Game');
};

Menu.prototype.help = function () {
this.game.state.start('Help');
};

return Menu;
Expand Down
5 changes: 5 additions & 0 deletions www/js/Preloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ define(['phaser'], function (Phaser) {
this.load.image('fg_black', 'assets/fg_black.png');
this.load.image('btn_newgame', 'assets/btn_newgame.png');
this.load.image('btn_exit', 'assets/btn_exit.png');
this.load.image('btn_play', 'assets/btn_play.png');
this.load.image('btn_help', 'assets/btn_help.png');
this.load.image('btn_help', 'assets/btn_help.png');
this.load.image('how_to_p01', 'assets/how_to_p01.png');
this.load.image('how_to_p02', 'assets/how_to_p02.png');
};

Preloader.prototype.create = function () {
Expand Down

0 comments on commit 4870ec2

Please sign in to comment.