/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Boss = Container.expand(function () { var self = Container.call(this); var bossGraphics = self.attachAsset('boss', { anchorX: 0.5, anchorY: 0.5 }); self.health = 250; self.maxHealth = 250; self.shootTimer = 0; self.shootInterval = 90; // 1.5 seconds at 60fps self.moveTimer = 0; self.moveDirection = 1; self.baseY = self.y; self.update = function () { // Boss movement pattern self.moveTimer++; self.y = self.baseY + Math.sin(self.moveTimer * 0.02) * 1300; // Shooting pattern self.shootTimer++; if (self.shootTimer >= self.shootInterval) { self.shoot(); self.shootTimer = 0; } // Flash when hit if (self.hitFlash > 0) { self.hitFlash--; bossGraphics.tint = self.hitFlash % 10 < 5 ? 0xff0000 : 0xffffff; } else { bossGraphics.tint = 0xffffff; } }; self.hitFlash = 0; self.shoot = function () { LK.getSound('bossShoot').play(); // Create three boss bullets in spread pattern for (var i = 0; i < 3; i++) { var bullet = new BossBullet(); bullet.x = self.x - 150; bullet.y = self.y; // Calculate direction to player var deltaX = player.x - bullet.x; var deltaY = player.y - bullet.y; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); var speed = 12; // Add spread angle (-20 degrees for first bullet, 0 degrees for second bullet, +20 degrees for third bullet) var spreadAngle = i === 0 ? -0.35 : i === 1 ? 0 : 0.35; // -20, 0, and +20 degrees in radians var baseAngle = Math.atan2(deltaY, deltaX); var finalAngle = baseAngle + spreadAngle; bullet.speedX = Math.cos(finalAngle) * speed; bullet.speedY = Math.sin(finalAngle) * speed; bossBullets.push(bullet); game.addChild(bullet); } // Flash effect tween(bossGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 100, onFinish: function onFinish() { tween(bossGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } }); }; self.takeDamage = function () { self.health--; self.hitFlash = 30; LK.getSound('hit').play(); if (self.health <= 0) { // Level up instead of winning currentLevel++; score += 100; // Bonus for completing level LK.setScore(score); // Spawn new boss with increased difficulty self.destroy(); spawnNewBoss(); } }; return self; }); var BossBullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bossBullet', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 0; self.speedY = 0; self.lifetime = 0; self.maxLifetime = 600; self.update = function () { self.x += self.speedX; self.y += self.speedY; self.lifetime++; if (self.lifetime >= self.maxLifetime || self.x < -50) { self.shouldDestroy = true; } }; return self; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 12; self.lifetime = 0; self.maxLifetime = 300; // 5 seconds at 60fps self.update = function () { self.x += self.speed; self.lifetime++; if (self.lifetime >= self.maxLifetime || self.x > 2200) { self.shouldDestroy = true; } }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.velocityY = 0; self.gravity = 0.8; self.jumpPower = -15; self.isGrounded = false; self.isDead = false; self.moveSpeed = 6; self.shootCooldown = 0; self.lastGrounded = false; self.jumpsRemaining = 7; self.maxJumps = 7; self.update = function () { // Apply gravity if (!self.isGrounded) { self.velocityY += self.gravity; } // Apply vertical movement self.y += self.velocityY; // Ground collision detection self.isGrounded = false; // Ground floor collision if (self.y > 2600) { self.y = 2600; self.velocityY = 0; self.isGrounded = true; } // Landing sound effect if (!self.lastGrounded && self.isGrounded && self.velocityY >= 0) { LK.getSound('jump').play(); } self.lastGrounded = self.isGrounded; // Boundary checking if (self.x < 30) self.x = 30; if (self.x > 800) self.x = 800; // Keep player on left side of screen if (self.y < 30) self.y = 30; // Reduce shoot cooldown if (self.shootCooldown > 0) { self.shootCooldown--; } // Auto-shooting if (self.shootCooldown <= 0) { self.shoot(); } }; self.jump = function () { self.velocityY = self.jumpPower; self.isGrounded = false; LK.getSound('jump').play(); }; self.shoot = function () { if (self.shootCooldown <= 0) { var bullet = new Bullet(); bullet.x = self.x + 30; bullet.y = self.y; bullets.push(bullet); game.addChild(bullet); self.shootCooldown = 15; // Quarter second cooldown LK.getSound('shoot').play(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ var player; var boss; var bullets = []; var bossBullets = []; var score = 0; var scrollSpeed = 2; var gameStarted = false; var currentLevel = 1; // UI elements var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var healthTxt = new Text2('Boss Health: 20', { size: 60, fill: 0xFF0000 }); healthTxt.anchor.set(0, 0); healthTxt.x = 120; healthTxt.y = 20; LK.gui.topLeft.addChild(healthTxt); var levelTxt = new Text2('Level: 1', { size: 60, fill: 0x00FF00 }); levelTxt.anchor.set(1, 0); levelTxt.x = 2048 - 120; levelTxt.y = 20; LK.gui.topRight.addChild(levelTxt); // Initialize game objects function initializeGame() { // Add background var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); // Create player player = game.addChild(new Player()); player.x = 200; player.y = 2500; // Create boss using spawn function spawnNewBoss(); // Start background music LK.playMusic('gameMusic'); gameStarted = true; } // Touch controls for jumping and shooting var jumpPressed = false; var shootPressed = false; game.down = function (x, y, obj) { if (!gameStarted || player.isDead) return; // Allow jumping from anywhere on screen if (!jumpPressed) { player.jump(); jumpPressed = true; } }; game.up = function (x, y, obj) { jumpPressed = false; shootPressed = false; }; // Main game update game.update = function () { if (!gameStarted || player.isDead) return; // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; if (bullet.shouldDestroy) { bullet.destroy(); bullets.splice(i, 1); continue; } // Check bullet vs boss collision if (bullet.intersects(boss)) { boss.takeDamage(); bullet.destroy(); bullets.splice(i, 1); score += 10; LK.setScore(score); } } // Update boss bullets for (var i = bossBullets.length - 1; i >= 0; i--) { var bossBullet = bossBullets[i]; if (bossBullet.shouldDestroy) { bossBullet.destroy(); bossBullets.splice(i, 1); continue; } // Check boss bullet vs player collision if (bossBullet.intersects(player) && !player.isDead) { player.isDead = true; // Player death effect LK.effects.flashScreen(0xff0000, 1000); tween(player, { scaleX: 2, scaleY: 2, alpha: 0 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { LK.showGameOver(); } }); } } // Update UI scoreTxt.setText('Score: ' + score); if (boss && boss.health !== undefined) { healthTxt.setText('Boss Health: ' + boss.health); } levelTxt.setText('Level: ' + currentLevel); // Check if player falls off screen if (player.y > 2800) { player.isDead = true; LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }; // Spawn new boss with level-based difficulty function spawnNewBoss() { boss = game.addChild(new Boss()); boss.x = 1700; boss.y = 1000; boss.baseY = boss.y; // Set boss health to 250 hits boss.maxHealth = 250; boss.health = boss.maxHealth; boss.shootInterval = Math.max(30, 90 - (currentLevel - 1) * 10); // Faster shooting, minimum 0.5 seconds } // Initialize the game initializeGame(); ;
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Boss = Container.expand(function () {
var self = Container.call(this);
var bossGraphics = self.attachAsset('boss', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 250;
self.maxHealth = 250;
self.shootTimer = 0;
self.shootInterval = 90; // 1.5 seconds at 60fps
self.moveTimer = 0;
self.moveDirection = 1;
self.baseY = self.y;
self.update = function () {
// Boss movement pattern
self.moveTimer++;
self.y = self.baseY + Math.sin(self.moveTimer * 0.02) * 1300;
// Shooting pattern
self.shootTimer++;
if (self.shootTimer >= self.shootInterval) {
self.shoot();
self.shootTimer = 0;
}
// Flash when hit
if (self.hitFlash > 0) {
self.hitFlash--;
bossGraphics.tint = self.hitFlash % 10 < 5 ? 0xff0000 : 0xffffff;
} else {
bossGraphics.tint = 0xffffff;
}
};
self.hitFlash = 0;
self.shoot = function () {
LK.getSound('bossShoot').play();
// Create three boss bullets in spread pattern
for (var i = 0; i < 3; i++) {
var bullet = new BossBullet();
bullet.x = self.x - 150;
bullet.y = self.y;
// Calculate direction to player
var deltaX = player.x - bullet.x;
var deltaY = player.y - bullet.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
var speed = 12;
// Add spread angle (-20 degrees for first bullet, 0 degrees for second bullet, +20 degrees for third bullet)
var spreadAngle = i === 0 ? -0.35 : i === 1 ? 0 : 0.35; // -20, 0, and +20 degrees in radians
var baseAngle = Math.atan2(deltaY, deltaX);
var finalAngle = baseAngle + spreadAngle;
bullet.speedX = Math.cos(finalAngle) * speed;
bullet.speedY = Math.sin(finalAngle) * speed;
bossBullets.push(bullet);
game.addChild(bullet);
}
// Flash effect
tween(bossGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100,
onFinish: function onFinish() {
tween(bossGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
};
self.takeDamage = function () {
self.health--;
self.hitFlash = 30;
LK.getSound('hit').play();
if (self.health <= 0) {
// Level up instead of winning
currentLevel++;
score += 100; // Bonus for completing level
LK.setScore(score);
// Spawn new boss with increased difficulty
self.destroy();
spawnNewBoss();
}
};
return self;
});
var BossBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bossBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.lifetime = 0;
self.maxLifetime = 600;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.lifetime++;
if (self.lifetime >= self.maxLifetime || self.x < -50) {
self.shouldDestroy = true;
}
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.lifetime = 0;
self.maxLifetime = 300; // 5 seconds at 60fps
self.update = function () {
self.x += self.speed;
self.lifetime++;
if (self.lifetime >= self.maxLifetime || self.x > 2200) {
self.shouldDestroy = true;
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 0.8;
self.jumpPower = -15;
self.isGrounded = false;
self.isDead = false;
self.moveSpeed = 6;
self.shootCooldown = 0;
self.lastGrounded = false;
self.jumpsRemaining = 7;
self.maxJumps = 7;
self.update = function () {
// Apply gravity
if (!self.isGrounded) {
self.velocityY += self.gravity;
}
// Apply vertical movement
self.y += self.velocityY;
// Ground collision detection
self.isGrounded = false;
// Ground floor collision
if (self.y > 2600) {
self.y = 2600;
self.velocityY = 0;
self.isGrounded = true;
}
// Landing sound effect
if (!self.lastGrounded && self.isGrounded && self.velocityY >= 0) {
LK.getSound('jump').play();
}
self.lastGrounded = self.isGrounded;
// Boundary checking
if (self.x < 30) self.x = 30;
if (self.x > 800) self.x = 800; // Keep player on left side of screen
if (self.y < 30) self.y = 30;
// Reduce shoot cooldown
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
// Auto-shooting
if (self.shootCooldown <= 0) {
self.shoot();
}
};
self.jump = function () {
self.velocityY = self.jumpPower;
self.isGrounded = false;
LK.getSound('jump').play();
};
self.shoot = function () {
if (self.shootCooldown <= 0) {
var bullet = new Bullet();
bullet.x = self.x + 30;
bullet.y = self.y;
bullets.push(bullet);
game.addChild(bullet);
self.shootCooldown = 15; // Quarter second cooldown
LK.getSound('shoot').play();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var player;
var boss;
var bullets = [];
var bossBullets = [];
var score = 0;
var scrollSpeed = 2;
var gameStarted = false;
var currentLevel = 1;
// UI elements
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var healthTxt = new Text2('Boss Health: 20', {
size: 60,
fill: 0xFF0000
});
healthTxt.anchor.set(0, 0);
healthTxt.x = 120;
healthTxt.y = 20;
LK.gui.topLeft.addChild(healthTxt);
var levelTxt = new Text2('Level: 1', {
size: 60,
fill: 0x00FF00
});
levelTxt.anchor.set(1, 0);
levelTxt.x = 2048 - 120;
levelTxt.y = 20;
LK.gui.topRight.addChild(levelTxt);
// Initialize game objects
function initializeGame() {
// Add background
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
}));
// Create player
player = game.addChild(new Player());
player.x = 200;
player.y = 2500;
// Create boss using spawn function
spawnNewBoss();
// Start background music
LK.playMusic('gameMusic');
gameStarted = true;
}
// Touch controls for jumping and shooting
var jumpPressed = false;
var shootPressed = false;
game.down = function (x, y, obj) {
if (!gameStarted || player.isDead) return;
// Allow jumping from anywhere on screen
if (!jumpPressed) {
player.jump();
jumpPressed = true;
}
};
game.up = function (x, y, obj) {
jumpPressed = false;
shootPressed = false;
};
// Main game update
game.update = function () {
if (!gameStarted || player.isDead) return;
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
if (bullet.shouldDestroy) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check bullet vs boss collision
if (bullet.intersects(boss)) {
boss.takeDamage();
bullet.destroy();
bullets.splice(i, 1);
score += 10;
LK.setScore(score);
}
}
// Update boss bullets
for (var i = bossBullets.length - 1; i >= 0; i--) {
var bossBullet = bossBullets[i];
if (bossBullet.shouldDestroy) {
bossBullet.destroy();
bossBullets.splice(i, 1);
continue;
}
// Check boss bullet vs player collision
if (bossBullet.intersects(player) && !player.isDead) {
player.isDead = true;
// Player death effect
LK.effects.flashScreen(0xff0000, 1000);
tween(player, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
LK.showGameOver();
}
});
}
}
// Update UI
scoreTxt.setText('Score: ' + score);
if (boss && boss.health !== undefined) {
healthTxt.setText('Boss Health: ' + boss.health);
}
levelTxt.setText('Level: ' + currentLevel);
// Check if player falls off screen
if (player.y > 2800) {
player.isDead = true;
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
// Spawn new boss with level-based difficulty
function spawnNewBoss() {
boss = game.addChild(new Boss());
boss.x = 1700;
boss.y = 1000;
boss.baseY = boss.y;
// Set boss health to 250 hits
boss.maxHealth = 250;
boss.health = boss.maxHealth;
boss.shootInterval = Math.max(30, 90 - (currentLevel - 1) * 10); // Faster shooting, minimum 0.5 seconds
}
// Initialize the game
initializeGame();
;
monglkey king raja kera di atas awan kinton menyerang dengan tongkat sakti. side scroller image. In-Game asset. 2d. High contrast. No shadows
erlang shen. the sun wukong enemy. side scroller image. atack with fire In-Game asset. 2d. High contrast. No shadows
dari jauh terlihat istana langit di atas awan luas versi fantasy china. In-Game asset. 2d. High contrast. No shadows