/**** * Classes ****/ // Coin class var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = -5; self.update = function () { self.x += self.speedX; if (self.x < -coinGraphics.width / 2) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Jetpack character class var JetpackCharacter = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('jetpackCharacter', { anchorX: 0.5, anchorY: 0.5 }); self.speedY = 0; self.gravity = 0.5; self.flapStrength = -10; self.update = function () { self.speedY += self.gravity; self.y += self.speedY; if (self.y > 2732 - characterGraphics.height / 2) { self.y = 2732 - characterGraphics.height / 2; self.speedY = 0; } if (self.y < characterGraphics.height / 2) { self.y = characterGraphics.height / 2; self.speedY = 0; } }; self.flap = function () { self.speedY = self.flapStrength; }; }); // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = -5 - Math.floor(LK.ticks / 1000); self.update = function () { self.x += self.speedX - Math.floor(LK.ticks / 1000); if (self.x < -obstacleGraphics.width / 2) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0 })); var jetpackCharacter = game.addChild(new JetpackCharacter()); jetpackCharacter.x = 200; jetpackCharacter.y = 1366; var obstacles = []; var coins = []; var score = 0; var scoreTxt = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF, stroke: 0x000000, strokeThickness: 5, font: "'Comic Sans MS', cursive, sans-serif" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); game.down = function (x, y, obj) { jetpackCharacter.flap(); LK.getSound('JetpackFly').play(); }; game.update = function () { jetpackCharacter.update(); if (LK.ticks % 100 == 0) { var newObstacle = new Obstacle(); newObstacle.x = 2048 + newObstacle.width / 2; newObstacle.y = Math.random() * (2732 - 400) + 200; obstacles.push(newObstacle); game.addChild(newObstacle); } if (LK.ticks % 150 == 0) { var newCoin = new Coin(); newCoin.x = 2048 + newCoin.width / 2; newCoin.y = Math.random() * (2732 - 400) + 200; coins.push(newCoin); game.addChild(newCoin); } for (var i = obstacles.length - 1; i >= 0; i--) { obstacles[i].update(); if (jetpackCharacter.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } for (var j = coins.length - 1; j >= 0; j--) { coins[j].update(); if (jetpackCharacter.intersects(coins[j])) { score += 10; scoreTxt.setText('Score: ' + score, { size: 100, fill: 0xFFFFFF, stroke: 0x000000, strokeThickness: 5, font: "'Comic Sans MS', cursive, sans-serif" }); LK.getSound('CollectCoin').play(); coins[j].destroy(); coins.splice(j, 1); } } };
/****
* Classes
****/
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = -5;
self.update = function () {
self.x += self.speedX;
if (self.x < -coinGraphics.width / 2) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Jetpack character class
var JetpackCharacter = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('jetpackCharacter', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedY = 0;
self.gravity = 0.5;
self.flapStrength = -10;
self.update = function () {
self.speedY += self.gravity;
self.y += self.speedY;
if (self.y > 2732 - characterGraphics.height / 2) {
self.y = 2732 - characterGraphics.height / 2;
self.speedY = 0;
}
if (self.y < characterGraphics.height / 2) {
self.y = characterGraphics.height / 2;
self.speedY = 0;
}
};
self.flap = function () {
self.speedY = self.flapStrength;
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = -5 - Math.floor(LK.ticks / 1000);
self.update = function () {
self.x += self.speedX - Math.floor(LK.ticks / 1000);
if (self.x < -obstacleGraphics.width / 2) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
var jetpackCharacter = game.addChild(new JetpackCharacter());
jetpackCharacter.x = 200;
jetpackCharacter.y = 1366;
var obstacles = [];
var coins = [];
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 5,
font: "'Comic Sans MS', cursive, sans-serif"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.down = function (x, y, obj) {
jetpackCharacter.flap();
LK.getSound('JetpackFly').play();
};
game.update = function () {
jetpackCharacter.update();
if (LK.ticks % 100 == 0) {
var newObstacle = new Obstacle();
newObstacle.x = 2048 + newObstacle.width / 2;
newObstacle.y = Math.random() * (2732 - 400) + 200;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
if (LK.ticks % 150 == 0) {
var newCoin = new Coin();
newCoin.x = 2048 + newCoin.width / 2;
newCoin.y = Math.random() * (2732 - 400) + 200;
coins.push(newCoin);
game.addChild(newCoin);
}
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (jetpackCharacter.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
for (var j = coins.length - 1; j >= 0; j--) {
coins[j].update();
if (jetpackCharacter.intersects(coins[j])) {
score += 10;
scoreTxt.setText('Score: ' + score, {
size: 100,
fill: 0xFFFFFF,
stroke: 0x000000,
strokeThickness: 5,
font: "'Comic Sans MS', cursive, sans-serif"
});
LK.getSound('CollectCoin').play();
coins[j].destroy();
coins.splice(j, 1);
}
}
};
Gold coin with dollar sign. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Person flying with jetpack with color. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Daytime sky. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Airplane seen from the side looking to the left. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Missile seen from the side. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows