/**** * Classes ****/ var Exit = Container.expand(function () { var self = Container.call(this); var exitGraphics = self.attachAsset('exit', { anchorX: 0.5, anchorY: 0.5 }); }); var PlayButton = Container.expand(function () { var self = Container.call(this); var playButtonGraphics = self.attachAsset('playbutton', { anchorX: 0.5, anchorY: 0.5 }); }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.invulnerabilityTicks = 16; self.move = function () { self.x += self.speedX; self.y += self.speedY; if (self.x < 0 || self.x > 2048) { self.speedX *= -1; self.x = self.x < 0 ? 0 : 2048; } if (self.y < 0 || self.y > 2732) { self.speedY *= -1; self.y = self.y < 0 ? 0 : 2732; } if (self.invulnerabilityTicks > 0) { self.invulnerabilityTicks--; } }; }); var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 0; self.speedY = 0; self.update = function () { self.x += self.speedX; self.y += self.speedY; if (self.x < 0 || self.x > 2048) { self.speedX *= -1; } if (self.y < 0 || self.y > 2732) { self.speedY *= -1; } }; }); var Monster = Container.expand(function () { var self = Container.call(this); var monsterGraphics = self.attachAsset('monster', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.update = function () { if (hero.visible) { var dx = hero.x - self.x; var dy = hero.y - self.y; var magnitude = Math.sqrt(dx * dx + dy * dy); self.x += self.speed * dx / magnitude; self.y += self.speed * dy / magnitude; } }; }); var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Add the 'Background' image to the visible playing area var background = LK.getAsset('Background', { anchorX: 0.1, anchorY: 0.1, width: 2048 * 1.25, height: 2732 * 1.25, x: 0, y: 0 }); game.addChild(background); // Create border around the visible area of the screen var playButton = game.addChild(new PlayButton()); playButton.x = 2048 / 2; playButton.y = 1200; var hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 / 2; hero.visible = false; var monster = game.addChild(new Monster()); monster.x = 2048 / 2; monster.y = 0; monster.visible = false; var obstacle = game.addChild(new Obstacle()); obstacle.x = 2048 / 2; obstacle.y = 300; LK.on('tick', function () { hero.update(); // heroLocationText.setText('Hero Location: (' + Math.round(hero.x) + ', ' + Math.round(hero.y) + ')'); if (hero.intersects(obstacle)) { obstacle.x = 0; obstacle.y = 2732; var exit = game.addChild(new Exit()); exit.x = 2048 / 2; exit.y = 2732 / 2; LK.setTimeout(function () { exitLocationText = new Text2('Exit Location: (' + Math.round(exit.x) + ', ' + Math.round(exit.y) + ')', { size: 50, fill: '#ffffff' }); exitLocationText.anchor.set(1, 1); exitLocationText.x = -8000; exitLocationText.y = -8000; LK.gui.bottomRight.addChild(exitLocationText); }, 1000); } var exitLocationText; if (typeof exit !== 'undefined') { var dx = hero.x - exit.x; var dy = hero.y - exit.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance <= 500) { var successPopup = new Text2('SUCCESS!', { size: 100, fill: '#00FF00', background: '#000000', alpha: 1 }); successPopup.anchor.set(0.5, 0.5); LK.gui.center.addChild(successPopup); LK.showGameOver(); } } monster.update(); if (Math.abs(hero.x - monster.x) <= 225 && Math.abs(hero.y - monster.y) <= 225) { LK.showGameOver(); } var bulletsToRemove = []; for (var i = bullets.length - 1; i >= 0; i--) { bullets[i].move(); if (bullets[i].y < 0 || hero.intersects(bullets[i]) && bullets[i].invulnerabilityTicks <= 0) { bulletsToRemove.push(i); } } for (var i = 0; i < bulletsToRemove.length; i++) { bullets[bulletsToRemove[i]].destroy(); bullets.splice(bulletsToRemove[i], 1); } bulletCountText.setText('Propulsion Orbs: ' + (11 - bullets.length + 1)); }); var bullets = []; var bulletCountText = new Text2('Propulsion Orbs: 8', { size: 50, fill: '#ffffff' }); bulletCountText.anchor.set(1, 1); LK.gui.bottomRight.addChild(bulletCountText); var instructions1 = new Text2('Grab the green gift before the alien grabs you!', { size: 50, fill: '#FFFF00', background: '#000000', alpha: 1 }); instructions1.anchor.set(0.5, 0.5); LK.gui.center.addChild(instructions1); var instructions2 = new Text2('Tap screen to use propulsion orbs to get around.', { size: 50, fill: '#FFFF00', background: '#000000', alpha: 1 }); instructions2.anchor.set(0.5, 0.5); instructions2.y = instructions1.y + instructions1.height; LK.gui.center.addChild(instructions2); var instructions3 = new Text2(' Grab the bouncing orbs to use them again.', { size: 50, fill: '#FFFF00', background: '#000000', alpha: 1 }); instructions3.anchor.set(0.5, 0.5); instructions3.y = instructions2.y + instructions2.height; LK.gui.center.addChild(instructions3); var instructions4 = new Text2('Tap the play button to start.', { size: 50, fill: '#FFFF00', background: '#000000', alpha: 1 }); instructions4.anchor.set(0.5, 0.5); instructions4.y = instructions3.y + instructions3.height; LK.gui.center.addChild(instructions4); playButton.on('down', function (obj) { playButton.destroy(); instructions1.destroy(); instructions2.destroy(); instructions3.destroy(); instructions4.destroy(); hero.visible = true; monster.visible = true; }); game.on('down', function (obj) { if (hero.visible && bullets.length < 12) { var event = obj.event; var pos = event.getLocalPosition(game); var bullet = new Bullet(); bullet.x = hero.x; bullet.y = hero.y; var dx = pos.x - hero.x; var dy = pos.y - hero.y; var magnitude = Math.sqrt(dx * dx + dy * dy); bullet.speedX = bullet.speed * dx / magnitude; bullet.speedY = bullet.speed * dy / magnitude; bullets.push(bullet); game.addChild(bullet); bulletCountText.setText('Propulsion Orbs: ' + (12 - bullets.length)); // Add velocity to the hero in opposite direction of the bullet hero.speedX += -bullet.speedX / 10; hero.speedY += -bullet.speedY / 10; } });
/****
* Classes
****/
var Exit = Container.expand(function () {
var self = Container.call(this);
var exitGraphics = self.attachAsset('exit', {
anchorX: 0.5,
anchorY: 0.5
});
});
var PlayButton = Container.expand(function () {
var self = Container.call(this);
var playButtonGraphics = self.attachAsset('playbutton', {
anchorX: 0.5,
anchorY: 0.5
});
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.invulnerabilityTicks = 16;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.x < 0 || self.x > 2048) {
self.speedX *= -1;
self.x = self.x < 0 ? 0 : 2048;
}
if (self.y < 0 || self.y > 2732) {
self.speedY *= -1;
self.y = self.y < 0 ? 0 : 2732;
}
if (self.invulnerabilityTicks > 0) {
self.invulnerabilityTicks--;
}
};
});
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.x < 0 || self.x > 2048) {
self.speedX *= -1;
}
if (self.y < 0 || self.y > 2732) {
self.speedY *= -1;
}
};
});
var Monster = Container.expand(function () {
var self = Container.call(this);
var monsterGraphics = self.attachAsset('monster', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
if (hero.visible) {
var dx = hero.x - self.x;
var dy = hero.y - self.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
self.x += self.speed * dx / magnitude;
self.y += self.speed * dy / magnitude;
}
};
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Add the 'Background' image to the visible playing area
var background = LK.getAsset('Background', {
anchorX: 0.1,
anchorY: 0.1,
width: 2048 * 1.25,
height: 2732 * 1.25,
x: 0,
y: 0
});
game.addChild(background);
// Create border around the visible area of the screen
var playButton = game.addChild(new PlayButton());
playButton.x = 2048 / 2;
playButton.y = 1200;
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 / 2;
hero.visible = false;
var monster = game.addChild(new Monster());
monster.x = 2048 / 2;
monster.y = 0;
monster.visible = false;
var obstacle = game.addChild(new Obstacle());
obstacle.x = 2048 / 2;
obstacle.y = 300;
LK.on('tick', function () {
hero.update();
// heroLocationText.setText('Hero Location: (' + Math.round(hero.x) + ', ' + Math.round(hero.y) + ')');
if (hero.intersects(obstacle)) {
obstacle.x = 0;
obstacle.y = 2732;
var exit = game.addChild(new Exit());
exit.x = 2048 / 2;
exit.y = 2732 / 2;
LK.setTimeout(function () {
exitLocationText = new Text2('Exit Location: (' + Math.round(exit.x) + ', ' + Math.round(exit.y) + ')', {
size: 50,
fill: '#ffffff'
});
exitLocationText.anchor.set(1, 1);
exitLocationText.x = -8000;
exitLocationText.y = -8000;
LK.gui.bottomRight.addChild(exitLocationText);
}, 1000);
}
var exitLocationText;
if (typeof exit !== 'undefined') {
var dx = hero.x - exit.x;
var dy = hero.y - exit.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance <= 500) {
var successPopup = new Text2('SUCCESS!', {
size: 100,
fill: '#00FF00',
background: '#000000',
alpha: 1
});
successPopup.anchor.set(0.5, 0.5);
LK.gui.center.addChild(successPopup);
LK.showGameOver();
}
}
monster.update();
if (Math.abs(hero.x - monster.x) <= 225 && Math.abs(hero.y - monster.y) <= 225) {
LK.showGameOver();
}
var bulletsToRemove = [];
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].move();
if (bullets[i].y < 0 || hero.intersects(bullets[i]) && bullets[i].invulnerabilityTicks <= 0) {
bulletsToRemove.push(i);
}
}
for (var i = 0; i < bulletsToRemove.length; i++) {
bullets[bulletsToRemove[i]].destroy();
bullets.splice(bulletsToRemove[i], 1);
}
bulletCountText.setText('Propulsion Orbs: ' + (11 - bullets.length + 1));
});
var bullets = [];
var bulletCountText = new Text2('Propulsion Orbs: 8', {
size: 50,
fill: '#ffffff'
});
bulletCountText.anchor.set(1, 1);
LK.gui.bottomRight.addChild(bulletCountText);
var instructions1 = new Text2('Grab the green gift before the alien grabs you!', {
size: 50,
fill: '#FFFF00',
background: '#000000',
alpha: 1
});
instructions1.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructions1);
var instructions2 = new Text2('Tap screen to use propulsion orbs to get around.', {
size: 50,
fill: '#FFFF00',
background: '#000000',
alpha: 1
});
instructions2.anchor.set(0.5, 0.5);
instructions2.y = instructions1.y + instructions1.height;
LK.gui.center.addChild(instructions2);
var instructions3 = new Text2(' Grab the bouncing orbs to use them again.', {
size: 50,
fill: '#FFFF00',
background: '#000000',
alpha: 1
});
instructions3.anchor.set(0.5, 0.5);
instructions3.y = instructions2.y + instructions2.height;
LK.gui.center.addChild(instructions3);
var instructions4 = new Text2('Tap the play button to start.', {
size: 50,
fill: '#FFFF00',
background: '#000000',
alpha: 1
});
instructions4.anchor.set(0.5, 0.5);
instructions4.y = instructions3.y + instructions3.height;
LK.gui.center.addChild(instructions4);
playButton.on('down', function (obj) {
playButton.destroy();
instructions1.destroy();
instructions2.destroy();
instructions3.destroy();
instructions4.destroy();
hero.visible = true;
monster.visible = true;
});
game.on('down', function (obj) {
if (hero.visible && bullets.length < 12) {
var event = obj.event;
var pos = event.getLocalPosition(game);
var bullet = new Bullet();
bullet.x = hero.x;
bullet.y = hero.y;
var dx = pos.x - hero.x;
var dy = pos.y - hero.y;
var magnitude = Math.sqrt(dx * dx + dy * dy);
bullet.speedX = bullet.speed * dx / magnitude;
bullet.speedY = bullet.speed * dy / magnitude;
bullets.push(bullet);
game.addChild(bullet);
bulletCountText.setText('Propulsion Orbs: ' + (12 - bullets.length));
// Add velocity to the hero in opposite direction of the bullet
hero.speedX += -bullet.speedX / 10;
hero.speedY += -bullet.speedY / 10;
}
});
Create the top down view of what it would look to be inside of a very dark space ship's empty cargo bay.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create a top down view of an astronaut in a bright yellow space suit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
create a round bright orange energy orb. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
create a scary space monster. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Create a yellow Play button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
show a bright green package. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
create an escape hatch with a red exit sign on it. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.