Untitled diff

Criado O diff nunca expira
9 remoções
209 linhas
13 adições
213 linhas
var Game = function()
var Game = function()
{
{
this.bgLayers = {};
this.bgLayers = {};
this.barWidth = 530;
this.barWidth = 530;
this.init = false;
this.init = false;
this.queue = new createjs.LoadQueue(false, "assets/");
this.queue = new createjs.LoadQueue(false, "assets/");
this.queue.installPlugin(createjs.Sound);
this.queue.installPlugin(createjs.Sound);
this.queue.addEventListener("complete", createjs.proxy(this.run, this));
this.queue.addEventListener("complete", createjs.proxy(this.run, this));
this.queue.addEventListener("progress", function(e) { $("#loader").text("Loading: " + Math.round(e.progress * 100) + "%"); });
this.queue.addEventListener("progress", function(e) { $("#loader").text("Loading: " + Math.round(e.progress * 100) + "%"); });
createjs.Sound.alternateExtensions = ["mp3"];
createjs.Sound.alternateExtensions = ["mp3"];
createjs.Ticker.addEventListener("tick", createjs.proxy(this.tick, this));
createjs.Ticker.addEventListener("tick", createjs.proxy(this.tick, this));
};
};


Game.prototype =
Game.prototype =
{
{
load: function load()
load: function load()
{
{
this.queue.loadManifest([
this.queue.loadManifest([
{ id: "bg", src: "img/parallax-mountain-bg.png" },
{ id: "bg", src: "img/parallax-mountain-bg.png" },
{ id: "mountain", src: "img/parallax-mountain-montain-far.png" },
{ id: "mountain", src: "img/parallax-mountain-montain-far.png" },
{ id: "mountains", src: "img/parallax-mountain-mountains.png" },
{ id: "mountains", src: "img/parallax-mountain-mountains.png" },
{ id: "trees", src: "img/parallax-mountain-trees.png" },
{ id: "trees", src: "img/parallax-mountain-trees.png" },
{ id: "player-icon", src: "img/player-icon.png" },
{ id: "player-icon", src: "img/player-icon.png" },
{ id: "player", src: "img/player.png" },
{ id: "player", src: "img/player.png" },
{ id: "baddies", src: "img/baddies.png" },
{ id: "baddies", src: "img/baddies.png" },
{ id: "goal", src: "img/goal.png" },
{ id: "goal", src: "img/goal.png" },
{ id: "bgm", src: "bgm.ogg" }
{ id: "bgm", src: "bgm.ogg" }
]);
]);
},
},
run: function run()
run: function run()
{
{
$("#loader").remove();
$("#loader").remove();
$("#intro").css("display", "block");
$("#intro").css("display", "block");
createjs.Sound.play("bgm", { loop: -1 });
},
},
start: function start()
start: function start()
{
{
createjs.Sound.play("bgm", { loop: -1 });
$("#intro").remove();
$("#intro").remove();
$("#wrapper").css("display", "block");
$("#wrapper").css("display", "block");
this.baddies = 0;
this.baddies = 0;


this.player = {
this.player = {
distance: 250,
distance: 250,
strength: 1,
strength: 1,
food: 3,
food: 3,
water: 5
water: 5
}
}


this.sleeping = false;
this.sleeping = false;
this.stop = false;
this.stop = false;
this.bgLayers = {
this.bgLayers = {
bg: {
bg: {
x: 0,
x: 0,
y: -62,
y: -62,
speed: 25
speed: 25
},
},
mountain: {
mountain: {
x: 0,
x: 0,
y: -40,
y: -40,
speed: 50
speed: 50
},
},
mountains: {
mountains: {
x: 0,
x: 0,
y: -40,
y: -40,
speed: 75
speed: 75
},
},
trees: {
trees: {
x: 0,
x: 0,
y: -40,
y: -40,
speed: 100
speed: 100
}
}
};
};
$("#food-count").text(this.player.food);
$("#food-count").text(this.player.food);
$("#water-count").text(this.player.water);
$("#water-count").text(this.player.water);
$("#action-eat").click(this.eat.bind(this));
$("#action-eat").click(this.eat.bind(this));
$("#action-drink").click(this.drink.bind(this));
$("#action-drink").click(this.drink.bind(this));
$("#action-sleep").click(this.sleep.bind(this));
$("#action-sleep").click(this.sleep.bind(this));
$("#message").empty();
$("#player").css("animation", "play .5s steps(2) infinite");
this.init = true;
this.init = true;
},
},
tick: function tick(e)
tick: function tick(e)
{
{
if (this.stop || !this.init)
if (this.stop || !this.init)
return;
return;
if (this.sleeping)
if (this.sleeping)
this.player.strength = this.addStrength(e.delta / 8000);
this.player.strength = this.addStrength(e.delta / 8000);