mirror of
https://github.com/Cola-Echo/memory-manager-concurrent.git
synced 2026-06-06 08:55:52 +00:00
Update memory-manager-concurrent
This commit is contained in:
110
games/clumsyBird/js/screens/gameover.js
Normal file
110
games/clumsyBird/js/screens/gameover.js
Normal file
@@ -0,0 +1,110 @@
|
||||
game.GameOverScreen = me.ScreenObject.extend({
|
||||
init: function() {
|
||||
this.savedData = null;
|
||||
this.handler = null;
|
||||
},
|
||||
|
||||
onResetEvent: function() {
|
||||
//save section
|
||||
this.savedData = {
|
||||
score: game.data.score,
|
||||
steps: game.data.steps
|
||||
};
|
||||
me.save.add(this.savedData);
|
||||
|
||||
if (!me.save.topSteps) me.save.add({topSteps: game.data.steps});
|
||||
if (game.data.steps > me.save.topSteps) {
|
||||
me.save.topSteps = game.data.steps;
|
||||
game.data.newHiScore = true;
|
||||
}
|
||||
me.input.bindKey(me.input.KEY.ENTER, "enter", true);
|
||||
me.input.bindKey(me.input.KEY.SPACE, "enter", false)
|
||||
me.input.bindPointer(me.input.pointer.LEFT, me.input.KEY.ENTER);
|
||||
|
||||
this.handler = me.event.subscribe(me.event.KEYDOWN,
|
||||
function (action, keyCode, edge) {
|
||||
if (action === "enter") {
|
||||
me.state.change(me.state.MENU);
|
||||
}
|
||||
});
|
||||
|
||||
me.game.world.addChild(new me.Sprite(
|
||||
me.game.viewport.width/2,
|
||||
me.game.viewport.height/2 - 100,
|
||||
{image: 'gameover'}
|
||||
), 12);
|
||||
|
||||
var gameOverBG = new me.Sprite(
|
||||
me.game.viewport.width/2,
|
||||
me.game.viewport.height/2,
|
||||
{image: 'gameoverbg'}
|
||||
);
|
||||
me.game.world.addChild(gameOverBG, 10);
|
||||
|
||||
me.game.world.addChild(new BackgroundLayer('bg', 1));
|
||||
|
||||
// ground
|
||||
this.ground1 = me.pool.pull('ground', 0, me.game.viewport.height - 96);
|
||||
this.ground2 = me.pool.pull('ground', me.game.viewport.width,
|
||||
me.video.renderer.getHeight() - 96);
|
||||
me.game.world.addChild(this.ground1, 11);
|
||||
me.game.world.addChild(this.ground2, 11);
|
||||
|
||||
// add the dialog witht he game information
|
||||
if (game.data.newHiScore) {
|
||||
var newRect = new me.Sprite(
|
||||
gameOverBG.width/2,
|
||||
gameOverBG.height/2,
|
||||
{image: 'new'}
|
||||
);
|
||||
me.game.world.addChild(newRect, 12);
|
||||
}
|
||||
|
||||
this.dialog = new (me.Renderable.extend({
|
||||
// constructor
|
||||
init: function() {
|
||||
this._super(me.Renderable, 'init',
|
||||
[0, 0, me.game.viewport.width/2, me.game.viewport.height/2]
|
||||
);
|
||||
this.font = new me.Font('gamefont', 40, 'black', 'left');
|
||||
this.steps = 'Steps: ' + game.data.steps.toString();
|
||||
this.topSteps= 'Higher Step: ' + me.save.topSteps.toString();
|
||||
},
|
||||
|
||||
draw: function (renderer) {
|
||||
var stepsText = this.font.measureText(renderer, this.steps);
|
||||
var topStepsText = this.font.measureText(renderer, this.topSteps);
|
||||
var scoreText = this.font.measureText(renderer, this.score);
|
||||
|
||||
//steps
|
||||
this.font.draw(
|
||||
renderer,
|
||||
this.steps,
|
||||
me.game.viewport.width/2 - stepsText.width/2 - 60,
|
||||
me.game.viewport.height/2
|
||||
);
|
||||
|
||||
//top score
|
||||
this.font.draw(
|
||||
renderer,
|
||||
this.topSteps,
|
||||
me.game.viewport.width/2 - stepsText.width/2 - 60,
|
||||
me.game.viewport.height/2 + 50
|
||||
);
|
||||
}
|
||||
}));
|
||||
me.game.world.addChild(this.dialog, 12);
|
||||
},
|
||||
|
||||
onDestroyEvent: function() {
|
||||
// unregister the event
|
||||
me.event.unsubscribe(this.handler);
|
||||
me.input.unbindKey(me.input.KEY.ENTER);
|
||||
me.input.unbindKey(me.input.KEY.SPACE);
|
||||
me.input.unbindPointer(me.input.pointer.LEFT);
|
||||
this.ground1 = null;
|
||||
this.ground2 = null;
|
||||
this.font = null;
|
||||
me.audio.stop("theme");
|
||||
}
|
||||
});
|
||||
67
games/clumsyBird/js/screens/play.js
Normal file
67
games/clumsyBird/js/screens/play.js
Normal file
@@ -0,0 +1,67 @@
|
||||
game.PlayScreen = me.ScreenObject.extend({
|
||||
init: function() {
|
||||
me.audio.play("theme", true);
|
||||
// lower audio volume on firefox browser
|
||||
var vol = me.device.ua.indexOf("Firefox") !== -1 ? 0.3 : 0.5;
|
||||
me.audio.setVolume(vol);
|
||||
this._super(me.ScreenObject, 'init');
|
||||
},
|
||||
|
||||
onResetEvent: function() {
|
||||
me.game.reset();
|
||||
me.audio.stop("theme");
|
||||
if (!game.data.muted){
|
||||
me.audio.play("theme", true);
|
||||
}
|
||||
|
||||
me.input.bindKey(me.input.KEY.SPACE, "fly", true);
|
||||
game.data.score = 0;
|
||||
game.data.steps = 0;
|
||||
game.data.start = false;
|
||||
game.data.newHiscore = false;
|
||||
|
||||
me.game.world.addChild(new BackgroundLayer('bg', 1));
|
||||
|
||||
this.ground1 = me.pool.pull('ground', 0, me.game.viewport.height - 96);
|
||||
this.ground2 = me.pool.pull('ground', me.game.viewport.width,
|
||||
me.game.viewport.height - 96);
|
||||
me.game.world.addChild(this.ground1, 11);
|
||||
me.game.world.addChild(this.ground2, 11);
|
||||
|
||||
this.HUD = new game.HUD.Container();
|
||||
me.game.world.addChild(this.HUD, 11);
|
||||
|
||||
this.bird = me.pool.pull("clumsy", 60, me.game.viewport.height/2 - 100);
|
||||
me.game.world.addChild(this.bird, 10);
|
||||
|
||||
//inputs
|
||||
me.input.bindPointer(me.input.pointer.LEFT, me.input.KEY.SPACE);
|
||||
|
||||
this.getReady = new me.Sprite(
|
||||
me.game.viewport.width/2,
|
||||
me.game.viewport.height/2,
|
||||
{image: 'getready'}
|
||||
);
|
||||
me.game.world.addChild(this.getReady, 11);
|
||||
|
||||
var that = this;
|
||||
var fadeOut = new me.Tween(this.getReady).to({alpha: 0}, 2000)
|
||||
.easing(me.Tween.Easing.Linear.None)
|
||||
.onComplete(function() {
|
||||
game.data.start = true;
|
||||
me.game.world.addChild(new game.PipeGenerator(), 0);
|
||||
me.game.world.removeChild(that.getReady);
|
||||
}).start();
|
||||
},
|
||||
|
||||
onDestroyEvent: function() {
|
||||
me.audio.stopTrack('theme');
|
||||
// free the stored instance
|
||||
this.HUD = null;
|
||||
this.bird = null;
|
||||
this.ground1 = null;
|
||||
this.ground2 = null;
|
||||
me.input.unbindKey(me.input.KEY.SPACE);
|
||||
me.input.unbindPointer(me.input.pointer.LEFT);
|
||||
}
|
||||
});
|
||||
73
games/clumsyBird/js/screens/title.js
Normal file
73
games/clumsyBird/js/screens/title.js
Normal file
@@ -0,0 +1,73 @@
|
||||
game.TitleScreen = me.ScreenObject.extend({
|
||||
init: function(){
|
||||
this._super(me.ScreenObject, 'init');
|
||||
this.font = null;
|
||||
this.ground1 = null;
|
||||
this.ground2 = null;
|
||||
this.logo = null;
|
||||
},
|
||||
|
||||
onResetEvent: function() {
|
||||
me.audio.stop("theme");
|
||||
game.data.newHiScore = false;
|
||||
|
||||
me.game.world.addChild(new BackgroundLayer('bg', 1));
|
||||
me.input.bindKey(me.input.KEY.ENTER, "enter", true);
|
||||
me.input.bindKey(me.input.KEY.SPACE, "enter", true);
|
||||
me.input.bindPointer(me.input.pointer.LEFT, me.input.KEY.ENTER);
|
||||
|
||||
this.handler = me.event.subscribe(me.event.KEYDOWN, function (action, keyCode, edge) {
|
||||
if (action === "enter") {
|
||||
me.state.change(me.state.PLAY);
|
||||
}
|
||||
});
|
||||
|
||||
//logo
|
||||
this.logo = new me.Sprite(
|
||||
me.game.viewport.width/2,
|
||||
me.game.viewport.height/2 - 20,
|
||||
{image: 'logo'}
|
||||
);
|
||||
me.game.world.addChild(this.logo, 10);
|
||||
|
||||
var that = this;
|
||||
var logoTween = me.pool.pull("me.Tween", this.logo.pos)
|
||||
.to({y: me.game.viewport.height/2 - 100}, 1000)
|
||||
.easing(me.Tween.Easing.Exponential.InOut).start();
|
||||
|
||||
this.ground1 = me.pool.pull("ground", 0, me.video.renderer.getHeight() - 96);
|
||||
this.ground2 = me.pool.pull("ground", me.video.renderer.getWidth(),
|
||||
me.video.renderer.getHeight() - 96);
|
||||
me.game.world.addChild(this.ground1, 11);
|
||||
me.game.world.addChild(this.ground2, 11);
|
||||
|
||||
me.game.world.addChild(new (me.Renderable.extend ({
|
||||
// constructor
|
||||
init: function() {
|
||||
// size does not matter, it's just to avoid having a zero size
|
||||
// renderable
|
||||
this._super(me.Renderable, 'init', [0, 0, 100, 100]);
|
||||
this.text = me.device.touch ? 'Tap to start' : 'PRESS SPACE OR CLICK LEFT MOUSE BUTTON TO START \n\t\t\t\t\t\t\t\t\t\t\tPRESS "M" TO MUTE SOUND';
|
||||
this.font = new me.Font('gamefont', 20, '#000');
|
||||
},
|
||||
draw: function (renderer) {
|
||||
var measure = this.font.measureText(renderer, this.text);
|
||||
var xpos = me.game.viewport.width/2 - measure.width/2;
|
||||
var ypos = me.game.viewport.height/2 + 50;
|
||||
this.font.draw(renderer, this.text, xpos, ypos);
|
||||
}
|
||||
})), 12);
|
||||
},
|
||||
|
||||
onDestroyEvent: function() {
|
||||
// unregister the event
|
||||
me.event.unsubscribe(this.handler);
|
||||
me.input.unbindKey(me.input.KEY.ENTER);
|
||||
me.input.unbindKey(me.input.KEY.SPACE);
|
||||
me.input.unbindPointer(me.input.pointer.LEFT);
|
||||
this.ground1 = null;
|
||||
this.ground2 = null;
|
||||
me.game.world.removeChild(this.logo);
|
||||
this.logo = null;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user