Game Development Reference
In-Depth Information
Listing 11-24. The render Functions Put the Game Sprites in their New Positions
p.renderStars = function () {
var i, star;
for (i = 0; i < this.stars.length; i++) {
star = this.stars[i];
star.y = star.nextY;
}
}
p.renderHeroShip = function () {
this.heroShip.x = this.heroShip.nextX;
this.heroShip.y = this.heroShip.nextY;
}
p.renderHeroBullets = function () {
var bullet, i;
var len = this.heroBullets.length - 1;
for (i = len; i >= 0; i--) {
bullet = this.heroBullets[i];
if (bullet.shouldDie) {
this.removeChild(bullet);
bullet.reset();
this.heroBulletPool.returnSprite(bullet);
this.heroBullets.splice(i, 1);
}
else {
bullet.y = bullet.nextY;
}
}
}
p.renderEnemyBullets = function () {
var bullet, i;
var len = this.enemyBullets.length - 1;
for (i = len; i >= 0; i--) {
bullet = this.enemyBullets[i];
if (bullet.shouldDie) {
this.removeChild(bullet);
bullet.reset();
this.enemyBulletPool.returnSprite(bullet);
this.enemyBullets.splice(i, 1);
}
else {
bullet.y = bullet.nextY;
}
}
}
p.renderEnemies = function () {
var enemy, i;
var len = this.enemies.length - 1;
for (i = len; i >= 0; i--) {
enemy = this.enemies[i];
if (enemy.shouldDie) {
this.scoreboard.updateScore(enemy.points);
 
Search WWH ::




Custom Search