Ω500

back

// Inherit our player from Ω.Entity
var Player = Ω.Entity.extend({

sheet: new Ω.SpriteSheet("../platformer/res/charzera.png", 25, 45),

tick: function () {

this.z--;
if (this.z <= 0) {
this.z = 199;
this.x = Ω.utils.rand(Ω.env.w);
this.y = Ω.utils.rand(Ω.env.h);
}

this.x += this.xspeed;
this.y += this.yspeed;
this.z += this.zspeed;
},

render: function (gfx) {

if (!this.z) {
return;
}

this.sheet.render(
gfx,
0,
0,
gfx.w / 2 + (this.x * 3.9 / this.z),
gfx.h / 2 + (this.y * 1 / this.z),
1,
1,
1 - (this.z / 200)
);

}

});

// Now make a screen to show a couple of Players
var MainScreen = Ω.Screen.extend({

stars: [],

init: function () {

var nums = 15,
star,
i;

for (i = 0; i < nums; i++) {

star = new Player(
Ω.utils.rand(Ω.env.w),
Ω.utils.rand(Ω.env.h)
);
star.z = i * (200 / nums);

star.xspeed = Ω.utils.rand(10) - 5;
star.yspeed = Ω.utils.rand(10) - 5;
star.zspeed = Ω.utils.rand(10) / 10;

this.stars.push(star);

}

},

tick: function () {

this.stars.map(function (s) {

s.tick();

});

},

render: function (gfx) {

var c = gfx.ctx;

this.clear(gfx, "#888");

this.stars
.sort(function (a, b) {
// Z sort
return a.z < b.z ? 1 : -1
})
.map(function (s) {

s.render(gfx);

});

}

});