var HeroBullet = Container.expand(function() { var self = Container.call(this); //{0} var bulletGraphics = XS.getAsset('heroBullet', 'Hero Bullet Graphics', 0.5, 0.5); self.addChild(bulletGraphics); //{1} //{2} self.speed = 10; //{3} self.move = function() { //{4} self.y -= self.speed; }; //{5} }); //{6} //{7} var EnemyBullet = Container.expand(function() { var self = Container.call(this); //{8} var bulletGraphics = XS.getAsset('enemyBullet', 'Enemy Bullet Graphics', 0.5, 0.5); self.addChild(bulletGraphics); //{9} //{10} self.speed = 5; //{11} self.move = function() { //{12} self.y += self.speed; //{13} }; //{14} }); //{15} //{16} var Hero = Container.expand(function() { var self = Container.call(this); //{17} var heroGraphics = XS.getAsset('hero', 'Hero Spaceship', 0.5, 0.5); self.addChild(heroGraphics); }); //{18} //{19} var Enemy = Container.expand(function() { var self = Container.call(this); //{20} var enemyGraphics = XS.getAsset('enemy', 'Enemy Spaceship', 0.5, 0.5); self.addChild(enemyGraphics); //{21} self.speed = 3; //{22} self.move = function() { //{23} self.y += self.speed; //{24} }; //{25} }); //{26} //{27} var Game = Container.expand(function() { var self = Container.call(this); //{28} // Add stars to the background for (var i = 0; i < 100; i++) { var star = XS.getAsset('star', 'Star', 0, 0); star.x = Math.random() * 2048; star.y = Math.random() * 2732; star.alpha = Math.random() * 0.5 + 0.5; self.addChild(star); } //{29} //{30} var hero = self.addChild(new Hero()); hero.x = 1024; hero.y = 2400; //{31} var enemies = []; var heroBullets = []; var enemyBullets = []; var score = 0; //{32} var scoreText = new Text2('0', { size: 100, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma", fill: "#ffffff" }); //{33} scoreText.anchor.set(0.5, 0); XS.gui.topCenter.addChild(scoreText); //{34} function spawnEnemy() { var enemy = new Enemy(); enemy.x = Math.random() * 2048; enemy.y = -100; enemies.push(enemy); self.addChild(enemy); } //{35} //{36} function fireHeroBullet() { var bullet = new HeroBullet(); bullet.x = hero.x; bullet.y = hero.y - 50; heroBullets.push(bullet); self.addChild(bullet); //{37} } //{38} //{39} function fireEnemyBullet(enemy) { var bullet = new EnemyBullet(); bullet.x = enemy.x; bullet.y = enemy.y + 50; enemyBullets.push(bullet); self.addChild(bullet); //{40} } //{41} //{42} function updateGameObjects() { enemies.forEach(function(enemy, index) { enemy.move(); if (enemy.y > 2732) { enemy.destroy(); //{43} enemies.splice(index, 1); } //{44} }); //{45} //{46} heroBullets.forEach(function(bullet, index) { bullet.move(); //{47} if (bullet.y < 0) { bullet.destroy(); //{48} heroBullets.splice(index, 1); } //{49} }); //{50} //{51} enemyBullets.forEach(function(bullet, index) { bullet.move(); //{52} if (bullet.y > 2732) { bullet.destroy(); //{53} enemyBullets.splice(index, 1); //{54} } //{55} }); //{56} } //{57} //{58} function checkCollisions() { // Check collisions between hero bullets and enemies heroBullets.forEach(function(heroBullet, hIndex) { enemies.forEach(function(enemy, eIndex) { if (heroBullet.intersects(enemy)) { heroBullet.destroy(); heroBullets.splice(hIndex, 1); enemy.destroy(); //{59} enemies.splice(eIndex, 1); score += 100; scoreText.setText(score); } //{60} }); //{61} }); //{62} //{63} // Check collisions between enemy bullets and hero enemyBullets.forEach(function(enemyBullet, index) { if (enemyBullet.intersects(hero)) { enemyBullet.destroy(); enemyBullets.splice(index, 1); //{64} XS.showGameOver(); // Handle hero hit by enemy bullet } //{65} }); //{66} } //{67} //{68} function handleTick() { updateGameObjects(); checkCollisions(); //{69} if (XS.ticks % 60 === 0) { spawnEnemy(); } //{70} //{71} if (XS.ticks % 30 === 0) { fireHeroBullet(); } //{72} //{73} enemies.forEach(function(enemy) { if (XS.ticks % 90 === 0) { fireEnemyBullet(enemy); } //{74} }); //{75} } //{76} //{77} XS.on('tick', handleTick); //{78} stage.on('down', function(obj) { var pos = obj.event.getLocalPosition(self); //{79} hero.x = pos.x; //{80} hero.y = pos.y; //{81} }); //{82} //{83} stage.on('move', function(obj) { var pos = obj.event.getLocalPosition(self); //{84} hero.x = pos.x; //{85} hero.y = pos.y; //{86} }); //{87} }); //{88}
===================================================================
--- original.js
+++ change.js
@@ -41,131 +41,139 @@
}); //{26}
//{27}
var Game = Container.expand(function() {
var self = Container.call(this); //{28}
- //{29}
+ // Add stars to the background
+ for (var i = 0; i < 100; i++) {
+ var star = XS.getAsset('star', 'Star', 0, 0);
+ star.x = Math.random() * 2048;
+ star.y = Math.random() * 2732;
+ star.alpha = Math.random() * 0.5 + 0.5;
+ self.addChild(star);
+ } //{29}
+ //{30}
var hero = self.addChild(new Hero());
hero.x = 1024;
hero.y = 2400;
- //{30}
+ //{31}
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
var score = 0;
- //{31}
+ //{32}
var scoreText = new Text2('0', {
size: 100,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
fill: "#ffffff"
- }); //{32}
+ }); //{33}
scoreText.anchor.set(0.5, 0);
XS.gui.topCenter.addChild(scoreText);
- //{33}
+ //{34}
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -100;
enemies.push(enemy);
self.addChild(enemy);
- } //{34}
- //{35}
+ } //{35}
+ //{36}
function fireHeroBullet() {
var bullet = new HeroBullet();
bullet.x = hero.x;
bullet.y = hero.y - 50;
heroBullets.push(bullet);
- self.addChild(bullet); //{36}
- } //{37}
- //{38}
+ self.addChild(bullet); //{37}
+ } //{38}
+ //{39}
function fireEnemyBullet(enemy) {
var bullet = new EnemyBullet();
bullet.x = enemy.x;
bullet.y = enemy.y + 50;
enemyBullets.push(bullet);
- self.addChild(bullet); //{39}
- } //{40}
- //{41}
+ self.addChild(bullet); //{40}
+ } //{41}
+ //{42}
function updateGameObjects() {
enemies.forEach(function(enemy, index) {
enemy.move();
if (enemy.y > 2732) {
- enemy.destroy(); //{42}
+ enemy.destroy(); //{43}
enemies.splice(index, 1);
- } //{43}
- }); //{44}
- //{45}
+ } //{44}
+ }); //{45}
+ //{46}
heroBullets.forEach(function(bullet, index) {
- bullet.move(); //{46}
+ bullet.move(); //{47}
if (bullet.y < 0) {
- bullet.destroy(); //{47}
+ bullet.destroy(); //{48}
heroBullets.splice(index, 1);
- } //{48}
- }); //{49}
- //{50}
+ } //{49}
+ }); //{50}
+ //{51}
enemyBullets.forEach(function(bullet, index) {
- bullet.move(); //{51}
+ bullet.move(); //{52}
if (bullet.y > 2732) {
- bullet.destroy(); //{52}
- enemyBullets.splice(index, 1); //{53}
- } //{54}
- }); //{55}
- } //{56}
- //{57}
+ bullet.destroy(); //{53}
+ enemyBullets.splice(index, 1); //{54}
+ } //{55}
+ }); //{56}
+ } //{57}
+ //{58}
function checkCollisions() {
// Check collisions between hero bullets and enemies
heroBullets.forEach(function(heroBullet, hIndex) {
enemies.forEach(function(enemy, eIndex) {
if (heroBullet.intersects(enemy)) {
heroBullet.destroy();
heroBullets.splice(hIndex, 1);
- enemy.destroy(); //{58}
+ enemy.destroy(); //{59}
enemies.splice(eIndex, 1);
score += 100;
scoreText.setText(score);
- } //{59}
- }); //{60}
- }); //{61}
- //{62}
+ } //{60}
+ }); //{61}
+ }); //{62}
+ //{63}
// Check collisions between enemy bullets and hero
enemyBullets.forEach(function(enemyBullet, index) {
if (enemyBullet.intersects(hero)) {
enemyBullet.destroy();
- enemyBullets.splice(index, 1); //{63}
+ enemyBullets.splice(index, 1); //{64}
XS.showGameOver();
// Handle hero hit by enemy bullet
- } //{64}
- }); //{65}
- } //{66}
- //{67}
+ } //{65}
+ }); //{66}
+ } //{67}
+ //{68}
function handleTick() {
updateGameObjects();
checkCollisions();
- //{68}
+ //{69}
if (XS.ticks % 60 === 0) {
spawnEnemy();
- } //{69}
- //{70}
+ } //{70}
+ //{71}
if (XS.ticks % 30 === 0) {
fireHeroBullet();
- } //{71}
- //{72}
+ } //{72}
+ //{73}
enemies.forEach(function(enemy) {
if (XS.ticks % 90 === 0) {
fireEnemyBullet(enemy);
- } //{73}
- }); //{74}
- } //{75}
- //{76}
- XS.on('tick', handleTick);
+ } //{74}
+ }); //{75}
+ } //{76}
//{77}
+ XS.on('tick', handleTick);
+ //{78}
stage.on('down', function(obj) {
- var pos = obj.event.getLocalPosition(self); //{78}
- hero.x = pos.x; //{79}
- hero.y = pos.y; //{80}
- }); //{81}
- //{82}
+ var pos = obj.event.getLocalPosition(self); //{79}
+ hero.x = pos.x; //{80}
+ hero.y = pos.y; //{81}
+ }); //{82}
+ //{83}
stage.on('move', function(obj) {
- var pos = obj.event.getLocalPosition(self); //{83}
- hero.x = pos.x; //{84}
- hero.y = pos.y; //{85}
- }); //{86}
-}); //{87}
\ No newline at end of file
+ var pos = obj.event.getLocalPosition(self); //{84}
+ hero.x = pos.x; //{85}
+ hero.y = pos.y; //{86}
+ }); //{87}
+}); //{88}
\ No newline at end of file
Round powerup. Shield icon Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Extra missile powerup circle. Missile and plus sign. Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Single space torpedo flying upwards Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Background galaxy nebulas and galaxies Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast. --ar 1:10
Round powerup. Green health icon Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Blue glowing powerup circle with s in center Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Round powerup. Lightning icon pointing up. Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Stylish hero spaceship facing upwards, with a single cannon in the center. Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
single alien enemy spaceship facing down, looking like space alien adopted to living in space. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Single enemy slime bullet, seen from above facing upwards. Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Round powerup icon with bullseye Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Clean plasma bubble Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.