/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.update = function () {
// Gentle rotation animation
coinGraphics.rotation += 0.05;
// Gentle floating animation
self.y += Math.sin(LK.ticks * 0.1 + self.x * 0.01) * 0.5;
};
return self;
});
var Jet = Container.expand(function () {
var self = Container.call(this);
var jetGraphics = self.attachAsset('jet', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = 0;
self.targetY = 0;
self.speed = 0.15;
self.direction = 0; // Current movement direction in radians
self.rotationSpeed = 12; // Much faster constant movement speed
self.update = function () {
// Constant fast movement in current direction
self.x += Math.cos(self.direction) * self.rotationSpeed;
self.y += Math.sin(self.direction) * self.rotationSpeed;
// Keep jet within screen bounds and bounce off walls
if (self.x < 40) {
self.x = 40;
self.direction = Math.PI - self.direction; // Bounce horizontally
} else if (self.x > 2008) {
self.x = 2008;
self.direction = Math.PI - self.direction; // Bounce horizontally
}
if (self.y < 40) {
self.y = 40;
self.direction = -self.direction; // Bounce vertically
} else if (self.y > 2692) {
self.y = 2692;
self.direction = -self.direction; // Bounce vertically
}
// Update jet graphics rotation to match movement direction
jetGraphics.rotation = self.direction + Math.PI / 2;
};
// Method to rotate jet when clicked
self.rotate = function () {
// Rotate by 45 degrees (π/4 radians)
var newDirection = self.direction + Math.PI / 4;
// Smooth rotation animation using tween
tween(self, {
direction: newDirection
}, {
duration: 200,
easing: tween.easeOut
});
};
return self;
});
var Missile = Container.expand(function () {
var self = Container.call(this);
var missileGraphics = self.attachAsset('missile', {
anchorX: 0.5,
anchorY: 0.5
});
// Base speed increases after collecting 15 coins
self.speed = LK.getScore() >= 15 ? 6 : 4;
self.targetX = 0;
self.targetY = 0;
self.update = function () {
// Home in on target position
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
// Rotate missile to face movement direction
missileGraphics.rotation = Math.atan2(dy, dx) + Math.PI / 2;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var jet;
var coins = [];
var missiles = [];
var nextCoinSpawn = 0;
var nextMissileSpawn = 180; // 3 seconds at 60fps
var missileSpawnRate = 180;
var minMissileSpawnRate = 60; // Minimum 1 second between missiles
// UI elements
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize jet
jet = game.addChild(new Jet());
jet.x = 2048 / 2;
jet.y = 2732 / 2;
jet.targetX = jet.x;
jet.targetY = jet.y;
// Spawn initial coins
function spawnCoin() {
var coin = new Coin();
coin.x = Math.random() * 1900 + 100; // Keep within screen bounds
coin.y = Math.random() * 2500 + 100;
coins.push(coin);
game.addChild(coin);
}
// Spawn initial missiles
function spawnMissile() {
var missile = new Missile();
// Spawn from random edge of screen
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top
missile.x = Math.random() * 2048;
missile.y = -50;
break;
case 1:
// Right
missile.x = 2098;
missile.y = Math.random() * 2732;
break;
case 2:
// Bottom
missile.x = Math.random() * 2048;
missile.y = 2782;
break;
case 3:
// Left
missile.x = -50;
missile.y = Math.random() * 2732;
break;
}
missile.targetX = jet.x;
missile.targetY = jet.y;
missiles.push(missile);
game.addChild(missile);
}
// Initial coin spawning
for (var i = 0; i < 5; i++) {
spawnCoin();
}
// Game controls - tap anywhere to rotate jet
game.down = function (x, y, obj) {
jet.rotate();
};
// Main game loop
game.update = function () {
// Update missile spawn rate (increase difficulty)
if (LK.ticks % 300 === 0 && missileSpawnRate > minMissileSpawnRate) {
missileSpawnRate -= 5;
}
// Spawn coins
if (LK.ticks >= nextCoinSpawn) {
spawnCoin();
nextCoinSpawn = LK.ticks + Math.random() * 120 + 60; // 1-3 seconds
}
// Spawn missiles
if (LK.ticks >= nextMissileSpawn) {
spawnMissile();
nextMissileSpawn = LK.ticks + missileSpawnRate;
}
// Update missile targets to current jet position and speed
for (var i = 0; i < missiles.length; i++) {
missiles[i].targetX = jet.x;
missiles[i].targetY = jet.y;
// Increase missile speed after collecting 15 coins
missiles[i].speed = LK.getScore() >= 15 ? 6 : 4;
}
// Check coin collection
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (!coin.collected && jet.intersects(coin)) {
coin.collected = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore().toString());
// Coin collection effect
tween(coin, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
coin.destroy();
}
});
coins.splice(i, 1);
LK.getSound('collect').play();
// Spawn new coin
spawnCoin();
}
}
// Check missile-to-missile collisions
for (var i = missiles.length - 1; i >= 0; i--) {
var missile1 = missiles[i];
for (var j = i - 1; j >= 0; j--) {
var missile2 = missiles[j];
if (missile1.intersects(missile2)) {
// Explosion effect for both missiles
LK.effects.flashObject(missile1, 0xff6600, 300);
LK.effects.flashObject(missile2, 0xff6600, 300);
LK.getSound('explosion').play();
// Destroy both missiles
missile1.destroy();
missile2.destroy();
missiles.splice(i, 1);
missiles.splice(j, 1);
break; // Exit inner loop since missile1 is destroyed
}
}
}
// Check missile collisions with jet
for (var i = 0; i < missiles.length; i++) {
var missile = missiles[i];
if (jet.intersects(missile)) {
// Game over
LK.effects.flashScreen(0xff0000, 1000);
LK.getSound('explosion').play();
LK.showGameOver();
return;
}
}
// Clean up off-screen missiles
for (var i = missiles.length - 1; i >= 0; i--) {
var missile = missiles[i];
if (missile.x < -100 || missile.x > 2148 || missile.y < -100 || missile.y > 2832) {
missile.destroy();
missiles.splice(i, 1);
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.update = function () {
// Gentle rotation animation
coinGraphics.rotation += 0.05;
// Gentle floating animation
self.y += Math.sin(LK.ticks * 0.1 + self.x * 0.01) * 0.5;
};
return self;
});
var Jet = Container.expand(function () {
var self = Container.call(this);
var jetGraphics = self.attachAsset('jet', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = 0;
self.targetY = 0;
self.speed = 0.15;
self.direction = 0; // Current movement direction in radians
self.rotationSpeed = 12; // Much faster constant movement speed
self.update = function () {
// Constant fast movement in current direction
self.x += Math.cos(self.direction) * self.rotationSpeed;
self.y += Math.sin(self.direction) * self.rotationSpeed;
// Keep jet within screen bounds and bounce off walls
if (self.x < 40) {
self.x = 40;
self.direction = Math.PI - self.direction; // Bounce horizontally
} else if (self.x > 2008) {
self.x = 2008;
self.direction = Math.PI - self.direction; // Bounce horizontally
}
if (self.y < 40) {
self.y = 40;
self.direction = -self.direction; // Bounce vertically
} else if (self.y > 2692) {
self.y = 2692;
self.direction = -self.direction; // Bounce vertically
}
// Update jet graphics rotation to match movement direction
jetGraphics.rotation = self.direction + Math.PI / 2;
};
// Method to rotate jet when clicked
self.rotate = function () {
// Rotate by 45 degrees (π/4 radians)
var newDirection = self.direction + Math.PI / 4;
// Smooth rotation animation using tween
tween(self, {
direction: newDirection
}, {
duration: 200,
easing: tween.easeOut
});
};
return self;
});
var Missile = Container.expand(function () {
var self = Container.call(this);
var missileGraphics = self.attachAsset('missile', {
anchorX: 0.5,
anchorY: 0.5
});
// Base speed increases after collecting 15 coins
self.speed = LK.getScore() >= 15 ? 6 : 4;
self.targetX = 0;
self.targetY = 0;
self.update = function () {
// Home in on target position
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
// Rotate missile to face movement direction
missileGraphics.rotation = Math.atan2(dy, dx) + Math.PI / 2;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var jet;
var coins = [];
var missiles = [];
var nextCoinSpawn = 0;
var nextMissileSpawn = 180; // 3 seconds at 60fps
var missileSpawnRate = 180;
var minMissileSpawnRate = 60; // Minimum 1 second between missiles
// UI elements
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize jet
jet = game.addChild(new Jet());
jet.x = 2048 / 2;
jet.y = 2732 / 2;
jet.targetX = jet.x;
jet.targetY = jet.y;
// Spawn initial coins
function spawnCoin() {
var coin = new Coin();
coin.x = Math.random() * 1900 + 100; // Keep within screen bounds
coin.y = Math.random() * 2500 + 100;
coins.push(coin);
game.addChild(coin);
}
// Spawn initial missiles
function spawnMissile() {
var missile = new Missile();
// Spawn from random edge of screen
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top
missile.x = Math.random() * 2048;
missile.y = -50;
break;
case 1:
// Right
missile.x = 2098;
missile.y = Math.random() * 2732;
break;
case 2:
// Bottom
missile.x = Math.random() * 2048;
missile.y = 2782;
break;
case 3:
// Left
missile.x = -50;
missile.y = Math.random() * 2732;
break;
}
missile.targetX = jet.x;
missile.targetY = jet.y;
missiles.push(missile);
game.addChild(missile);
}
// Initial coin spawning
for (var i = 0; i < 5; i++) {
spawnCoin();
}
// Game controls - tap anywhere to rotate jet
game.down = function (x, y, obj) {
jet.rotate();
};
// Main game loop
game.update = function () {
// Update missile spawn rate (increase difficulty)
if (LK.ticks % 300 === 0 && missileSpawnRate > minMissileSpawnRate) {
missileSpawnRate -= 5;
}
// Spawn coins
if (LK.ticks >= nextCoinSpawn) {
spawnCoin();
nextCoinSpawn = LK.ticks + Math.random() * 120 + 60; // 1-3 seconds
}
// Spawn missiles
if (LK.ticks >= nextMissileSpawn) {
spawnMissile();
nextMissileSpawn = LK.ticks + missileSpawnRate;
}
// Update missile targets to current jet position and speed
for (var i = 0; i < missiles.length; i++) {
missiles[i].targetX = jet.x;
missiles[i].targetY = jet.y;
// Increase missile speed after collecting 15 coins
missiles[i].speed = LK.getScore() >= 15 ? 6 : 4;
}
// Check coin collection
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (!coin.collected && jet.intersects(coin)) {
coin.collected = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore().toString());
// Coin collection effect
tween(coin, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
coin.destroy();
}
});
coins.splice(i, 1);
LK.getSound('collect').play();
// Spawn new coin
spawnCoin();
}
}
// Check missile-to-missile collisions
for (var i = missiles.length - 1; i >= 0; i--) {
var missile1 = missiles[i];
for (var j = i - 1; j >= 0; j--) {
var missile2 = missiles[j];
if (missile1.intersects(missile2)) {
// Explosion effect for both missiles
LK.effects.flashObject(missile1, 0xff6600, 300);
LK.effects.flashObject(missile2, 0xff6600, 300);
LK.getSound('explosion').play();
// Destroy both missiles
missile1.destroy();
missile2.destroy();
missiles.splice(i, 1);
missiles.splice(j, 1);
break; // Exit inner loop since missile1 is destroyed
}
}
}
// Check missile collisions with jet
for (var i = 0; i < missiles.length; i++) {
var missile = missiles[i];
if (jet.intersects(missile)) {
// Game over
LK.effects.flashScreen(0xff0000, 1000);
LK.getSound('explosion').play();
LK.showGameOver();
return;
}
}
// Clean up off-screen missiles
for (var i = missiles.length - 1; i >= 0; i--) {
var missile = missiles[i];
if (missile.x < -100 || missile.x > 2148 || missile.y < -100 || missile.y > 2832) {
missile.destroy();
missiles.splice(i, 1);
}
}
};