/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
kills: 0,
bestKills: 0
});
/****
* Classes
****/
var Checkpoint = Container.expand(function () {
var self = Container.call(this);
var checkpointGraphics = self.attachAsset('checkpoint', {
anchorX: 0.5,
anchorY: 0.5
});
self.isCheckpoint = true;
self.lastIntersecting = false;
return self;
});
var Hazard = Container.expand(function () {
var self = Container.call(this);
var hazardGraphics = self.attachAsset('hazard', {
anchorX: 0.5,
anchorY: 0.5
});
self.isDangerous = true;
self.lastIntersecting = false;
return self;
});
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.isSolid = true;
self.lastIntersecting = false;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
var player = game.addChild(new Container());
var playerGraphics = player.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
player.x = 100;
player.y = 2600;
player.velocityX = 0;
player.velocityY = 0;
player.isJumping = false;
player.isGrounded = false;
player.canWallRun = false;
player.wallRunDirection = 0; // -1 left, 1 right
player.moveLeft = false;
player.moveRight = false;
player.jumpPressed = false;
var platforms = [];
var hazards = [];
var checkpoints = [];
var currentCheckpoint = 0;
var gameTime = 0;
var levelStartTime = 0;
var levelComplete = false;
var statusText = new Text2('Reach the finish!', {
size: 80,
fill: '#ffffff'
});
statusText.anchor.set(0.5, 0);
LK.gui.top.addChild(statusText);
var timerText = new Text2('0.00s', {
size: 100,
fill: '#ffff00'
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
function updateUI() {
var elapsedTime = (gameTime - levelStartTime) / 1000;
timerText.setText(elapsedTime.toFixed(2) + 's');
if (levelComplete) {
statusText.setText('Level Complete!');
}
}
function createLevel() {
// Starting platform
var startPlatform = game.addChild(new Platform());
startPlatform.x = 200;
startPlatform.y = 2650;
platforms.push(startPlatform);
// Platform sequence
var platformSequence = [{
x: 500,
y: 2450,
w: 250,
h: 40
}, {
x: 800,
y: 2200,
w: 250,
h: 40
}, {
x: 1100,
y: 2000,
w: 250,
h: 40
}, {
x: 1400,
y: 1750,
w: 250,
h: 40
}, {
x: 1600,
y: 1500,
w: 200,
h: 40
}, {
x: 1300,
y: 1300,
w: 200,
h: 40
}, {
x: 900,
y: 1100,
w: 200,
h: 40
}, {
x: 600,
y: 900,
w: 250,
h: 40
}, {
x: 800,
y: 650,
w: 250,
h: 40
}, {
x: 1200,
y: 400,
w: 300,
h: 40
}];
for (var i = 0; i < platformSequence.length; i++) {
var p = platformSequence[i];
var platform = game.addChild(new Platform());
platform.x = p.x;
platform.y = p.y;
platform.width = p.w;
platform.height = p.h;
platforms.push(platform);
}
// Add hazards
var hazardSequence = [{
x: 900,
y: 1600
}, {
x: 1500,
y: 900
}, {
x: 400,
y: 500
}];
for (var h = 0; h < hazardSequence.length; h++) {
var hazard = game.addChild(new Hazard());
hazard.x = hazardSequence[h].x;
hazard.y = hazardSequence[h].y;
hazards.push(hazard);
}
// Add checkpoints
var checkpoint1 = game.addChild(new Checkpoint());
checkpoint1.x = 1100;
checkpoint1.y = 2000;
checkpoints.push(checkpoint1);
var checkpoint2 = game.addChild(new Checkpoint());
checkpoint2.x = 600;
checkpoint2.y = 900;
checkpoints.push(checkpoint2);
var finishCheckpoint = game.addChild(new Checkpoint());
finishCheckpoint.x = 1200;
finishCheckpoint.y = 300;
checkpoints.push(finishCheckpoint);
}
var GRAVITY = 0.5;
var JUMP_FORCE = -12;
var WALL_JUMP_FORCE = 8;
var MOVE_SPEED = 5;
var MAX_FALL_SPEED = 15;
function applyGravity() {
if (!player.isGrounded && !player.canWallRun) {
player.velocityY += GRAVITY;
if (player.velocityY > MAX_FALL_SPEED) {
player.velocityY = MAX_FALL_SPEED;
}
}
player.y += player.velocityY;
}
function checkCollisions() {
player.isGrounded = false;
player.canWallRun = false;
// Check platform collisions
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (player.intersects(platform)) {
// Landing on top of platform
if (player.velocityY >= 0 && player.lastY + 30 <= platform.y) {
player.y = platform.y - 30;
player.velocityY = 0;
player.isGrounded = true;
} else if (player.velocityY < 0) {
// Hit bottom of platform
player.y = platform.y + 20;
player.velocityY = 0;
}
}
}
// Check hazard collisions
for (var h = 0; h < hazards.length; h++) {
var hazard = hazards[h];
if (!hazard.lastIntersecting && player.intersects(hazard)) {
LK.effects.flashObject(player, 0xff0000, 300);
LK.getSound('hit').play();
// Reset to last checkpoint
player.x = checkpoints[Math.max(0, currentCheckpoint - 1)].x;
player.y = checkpoints[Math.max(0, currentCheckpoint - 1)].y + 100;
player.velocityY = 0;
}
hazard.lastIntersecting = player.intersects(hazard);
}
// Check checkpoint collisions
for (var c = 0; c < checkpoints.length; c++) {
var checkpoint = checkpoints[c];
if (!checkpoint.lastIntersecting && player.intersects(checkpoint)) {
currentCheckpoint = c;
LK.getSound('checkpoint').play();
if (c === checkpoints.length - 1) {
levelComplete = true;
}
}
checkpoint.lastIntersecting = player.intersects(checkpoint);
}
}
function handleJump() {
if (player.jumpPressed) {
if (player.isGrounded) {
player.velocityY = JUMP_FORCE;
player.isJumping = true;
LK.getSound('jump').play();
} else if (player.canWallRun) {
player.velocityY = JUMP_FORCE;
player.velocityX = WALL_JUMP_FORCE * -player.wallRunDirection;
LK.getSound('jump').play();
}
player.jumpPressed = false;
}
}
function endGame() {
var finalTime = (gameTime - levelStartTime) / 1000;
storage.bestTime = storage.bestTime || finalTime;
if (finalTime < storage.bestTime) {
storage.bestTime = finalTime;
}
LK.showGameOver();
}
game.down = function (x, y, obj) {
var centerX = 2048 / 2;
if (x < centerX) {
player.moveLeft = true;
} else {
player.moveRight = true;
}
player.jumpPressed = true;
};
game.up = function (x, y, obj) {
player.moveLeft = false;
player.moveRight = false;
};
game.move = function (x, y, obj) {
var centerX = 2048 / 2;
if (x < centerX) {
player.moveLeft = true;
player.moveRight = false;
} else {
player.moveRight = true;
player.moveLeft = false;
}
};
game.update = function () {
if (levelStartTime === 0) {
levelStartTime = gameTime;
}
gameTime += 16.67;
// Player horizontal movement
if (player.moveLeft) {
player.x = Math.max(0, player.x - MOVE_SPEED);
}
if (player.moveRight) {
player.x = Math.min(2048, player.x + MOVE_SPEED);
}
// Apply gravity and check collisions
player.lastY = player.y;
applyGravity();
checkCollisions();
// Handle jump input
handleJump();
// Fall off screen
if (player.y > 2732) {
LK.effects.flashObject(player, 0xff0000, 300);
LK.getSound('hit').play();
player.x = 100;
player.y = 2600;
player.velocityY = 0;
currentCheckpoint = 0;
levelStartTime = 0;
}
// Update UI
if (LK.ticks % 10 === 0) {
updateUI();
}
// End game condition
if (levelComplete) {
endGame();
}
};
createLevel();
LK.playMusic('bgmusic', {
loop: true
}); ===================================================================
--- original.js
+++ change.js
@@ -9,63 +9,35 @@
/****
* Classes
****/
-var Enemy = Container.expand(function () {
+var Checkpoint = Container.expand(function () {
var self = Container.call(this);
- var enemyGraphics = self.attachAsset('enemy', {
+ var checkpointGraphics = self.attachAsset('checkpoint', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 2;
- self.health = 1;
- self.targetX = 1024;
- self.targetY = 1366;
- self.lastX = self.x;
- self.lastY = self.y;
+ self.isCheckpoint = true;
self.lastIntersecting = false;
- self.moveTowardTarget = function () {
- var dx = self.targetX - self.x;
- var dy = self.targetY - self.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance > 5) {
- self.x += dx / distance * self.speed;
- self.y += dy / distance * self.speed;
- }
- };
- self.update = function () {
- self.lastX = self.x;
- self.lastY = self.y;
- self.moveTowardTarget();
- };
return self;
});
-var PlayerBullet = Container.expand(function () {
+var Hazard = Container.expand(function () {
var self = Container.call(this);
- var bulletGraphics = self.attachAsset('bullet', {
+ var hazardGraphics = self.attachAsset('hazard', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 10;
- self.velocityX = 0;
- self.velocityY = -1;
- self.lastX = self.x;
- self.lastY = self.y;
- self.update = function () {
- self.lastX = self.x;
- self.lastY = self.y;
- self.x += self.velocityX * self.speed;
- self.y += self.velocityY * self.speed;
- };
+ self.isDangerous = true;
+ self.lastIntersecting = false;
return self;
});
-var PowerUp = Container.expand(function () {
+var Platform = Container.expand(function () {
var self = Container.call(this);
- var powerUpGraphics = self.attachAsset('powerUp', {
+ var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
- self.type = 'shield'; // shield, ammo, speed
+ self.isSolid = true;
self.lastIntersecting = false;
return self;
});
@@ -83,304 +55,284 @@
var playerGraphics = player.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
-player.x = 1024;
-player.y = 1366;
-player.speed = 5;
-player.health = 100;
-player.maxHealth = 100;
-player.ammo = 30;
-player.maxAmmo = 30;
-player.isMovingUp = false;
-player.isMovingDown = false;
-player.isMovingLeft = false;
-player.isMovingRight = false;
-var bullets = [];
-var enemies = [];
-var powerUps = [];
+player.x = 100;
+player.y = 2600;
+player.velocityX = 0;
+player.velocityY = 0;
+player.isJumping = false;
+player.isGrounded = false;
+player.canWallRun = false;
+player.wallRunDirection = 0; // -1 left, 1 right
+player.moveLeft = false;
+player.moveRight = false;
+player.jumpPressed = false;
+var platforms = [];
+var hazards = [];
+var checkpoints = [];
+var currentCheckpoint = 0;
var gameTime = 0;
-var matchDuration = 180000; // 3 minutes in ms
-var kills = 0;
-var arenaSize = 1800;
-var minArenaSize = 400;
-var boundaryContractionInterval = 30000; // 30 seconds
-var lastBoundaryContraction = 0;
-var boundaryX = 1024;
-var boundaryY = 1366;
-var scoreText = new Text2('Kills: 0', {
- size: 100,
- fill: '#ffffff'
-});
-scoreText.anchor.set(0, 0);
-LK.gui.topRight.addChild(scoreText);
-var healthText = new Text2('HP: 100/100', {
+var levelStartTime = 0;
+var levelComplete = false;
+var statusText = new Text2('Reach the finish!', {
size: 80,
fill: '#ffffff'
});
-healthText.anchor.set(0, 0);
-LK.gui.topRight.addChild(healthText);
-var timerText = new Text2('3:00', {
+statusText.anchor.set(0.5, 0);
+LK.gui.top.addChild(statusText);
+var timerText = new Text2('0.00s', {
size: 100,
- fill: '#ffffff'
+ fill: '#ffff00'
});
timerText.anchor.set(0.5, 0);
LK.gui.top.addChild(timerText);
-var ammoText = new Text2('Ammo: 30/30', {
- size: 80,
- fill: '#ffff00'
-});
-ammoText.anchor.set(1, 0);
-LK.gui.topRight.addChild(ammoText);
function updateUI() {
- scoreText.setText('Kills: ' + kills);
- healthText.setText('HP: ' + Math.max(0, player.health) + '/' + player.maxHealth);
- ammoText.setText('Ammo: ' + player.ammo + '/' + player.maxAmmo);
- var timeRemaining = Math.max(0, matchDuration - gameTime);
- var minutes = Math.floor(timeRemaining / 60000);
- var seconds = Math.floor(timeRemaining % 60000 / 1000);
- var secondsStr = seconds < 10 ? '0' + seconds : seconds;
- timerText.setText(minutes + ':' + secondsStr);
+ var elapsedTime = (gameTime - levelStartTime) / 1000;
+ timerText.setText(elapsedTime.toFixed(2) + 's');
+ if (levelComplete) {
+ statusText.setText('Level Complete!');
+ }
}
-function createEnemy() {
- var newEnemy = game.addChild(new Enemy());
- var spawnSide = Math.floor(Math.random() * 4);
- switch (spawnSide) {
- case 0:
- // top
- newEnemy.x = Math.random() * 2048;
- newEnemy.y = -50;
- break;
- case 1:
- // right
- newEnemy.x = 2048 + 50;
- newEnemy.y = Math.random() * 2732;
- break;
- case 2:
- // bottom
- newEnemy.x = Math.random() * 2048;
- newEnemy.y = 2732 + 50;
- break;
- case 3:
- // left
- newEnemy.x = -50;
- newEnemy.y = Math.random() * 2732;
- break;
+function createLevel() {
+ // Starting platform
+ var startPlatform = game.addChild(new Platform());
+ startPlatform.x = 200;
+ startPlatform.y = 2650;
+ platforms.push(startPlatform);
+ // Platform sequence
+ var platformSequence = [{
+ x: 500,
+ y: 2450,
+ w: 250,
+ h: 40
+ }, {
+ x: 800,
+ y: 2200,
+ w: 250,
+ h: 40
+ }, {
+ x: 1100,
+ y: 2000,
+ w: 250,
+ h: 40
+ }, {
+ x: 1400,
+ y: 1750,
+ w: 250,
+ h: 40
+ }, {
+ x: 1600,
+ y: 1500,
+ w: 200,
+ h: 40
+ }, {
+ x: 1300,
+ y: 1300,
+ w: 200,
+ h: 40
+ }, {
+ x: 900,
+ y: 1100,
+ w: 200,
+ h: 40
+ }, {
+ x: 600,
+ y: 900,
+ w: 250,
+ h: 40
+ }, {
+ x: 800,
+ y: 650,
+ w: 250,
+ h: 40
+ }, {
+ x: 1200,
+ y: 400,
+ w: 300,
+ h: 40
+ }];
+ for (var i = 0; i < platformSequence.length; i++) {
+ var p = platformSequence[i];
+ var platform = game.addChild(new Platform());
+ platform.x = p.x;
+ platform.y = p.y;
+ platform.width = p.w;
+ platform.height = p.h;
+ platforms.push(platform);
}
- newEnemy.lastX = newEnemy.x;
- newEnemy.lastY = newEnemy.y;
- newEnemy.lastIntersecting = false;
- enemies.push(newEnemy);
+ // Add hazards
+ var hazardSequence = [{
+ x: 900,
+ y: 1600
+ }, {
+ x: 1500,
+ y: 900
+ }, {
+ x: 400,
+ y: 500
+ }];
+ for (var h = 0; h < hazardSequence.length; h++) {
+ var hazard = game.addChild(new Hazard());
+ hazard.x = hazardSequence[h].x;
+ hazard.y = hazardSequence[h].y;
+ hazards.push(hazard);
+ }
+ // Add checkpoints
+ var checkpoint1 = game.addChild(new Checkpoint());
+ checkpoint1.x = 1100;
+ checkpoint1.y = 2000;
+ checkpoints.push(checkpoint1);
+ var checkpoint2 = game.addChild(new Checkpoint());
+ checkpoint2.x = 600;
+ checkpoint2.y = 900;
+ checkpoints.push(checkpoint2);
+ var finishCheckpoint = game.addChild(new Checkpoint());
+ finishCheckpoint.x = 1200;
+ finishCheckpoint.y = 300;
+ checkpoints.push(finishCheckpoint);
}
-function createPowerUp(x, y, type) {
- var newPowerUp = game.addChild(new PowerUp());
- newPowerUp.x = x;
- newPowerUp.y = y;
- newPowerUp.type = type;
- newPowerUp.lastIntersecting = false;
- powerUps.push(newPowerUp);
-}
-function fireWeapon() {
- if (player.ammo > 0) {
- var newBullet = game.addChild(new PlayerBullet());
- newBullet.x = player.x;
- newBullet.y = player.y - 25;
- // Calculate direction based on player movement or default up
- if (player.isMovingUp) {
- newBullet.velocityY = -1;
- newBullet.velocityX = 0;
- } else if (player.isMovingDown) {
- newBullet.velocityY = 1;
- newBullet.velocityX = 0;
- } else if (player.isMovingLeft) {
- newBullet.velocityX = -1;
- newBullet.velocityY = 0;
- } else if (player.isMovingRight) {
- newBullet.velocityX = 1;
- newBullet.velocityY = 0;
+var GRAVITY = 0.5;
+var JUMP_FORCE = -12;
+var WALL_JUMP_FORCE = 8;
+var MOVE_SPEED = 5;
+var MAX_FALL_SPEED = 15;
+function applyGravity() {
+ if (!player.isGrounded && !player.canWallRun) {
+ player.velocityY += GRAVITY;
+ if (player.velocityY > MAX_FALL_SPEED) {
+ player.velocityY = MAX_FALL_SPEED;
}
- newBullet.lastX = newBullet.x;
- newBullet.lastY = newBullet.y;
- bullets.push(newBullet);
- player.ammo--;
- LK.getSound('shoot').play();
}
+ player.y += player.velocityY;
}
-var fireTimer = LK.setInterval(function () {
- fireWeapon();
-}, 200);
-var enemySpawnTimer = LK.setInterval(function () {
- if (enemies.length < 5 + Math.floor(gameTime / 60000)) {
- createEnemy();
+function checkCollisions() {
+ player.isGrounded = false;
+ player.canWallRun = false;
+ // Check platform collisions
+ for (var i = 0; i < platforms.length; i++) {
+ var platform = platforms[i];
+ if (player.intersects(platform)) {
+ // Landing on top of platform
+ if (player.velocityY >= 0 && player.lastY + 30 <= platform.y) {
+ player.y = platform.y - 30;
+ player.velocityY = 0;
+ player.isGrounded = true;
+ } else if (player.velocityY < 0) {
+ // Hit bottom of platform
+ player.y = platform.y + 20;
+ player.velocityY = 0;
+ }
+ }
}
-}, 2000);
-function contractBoundary() {
- if (arenaSize > minArenaSize) {
- arenaSize = Math.max(minArenaSize, arenaSize - 200);
- // Flash screen to indicate boundary contraction
- LK.effects.flashScreen(0xff6600, 500);
+ // Check hazard collisions
+ for (var h = 0; h < hazards.length; h++) {
+ var hazard = hazards[h];
+ if (!hazard.lastIntersecting && player.intersects(hazard)) {
+ LK.effects.flashObject(player, 0xff0000, 300);
+ LK.getSound('hit').play();
+ // Reset to last checkpoint
+ player.x = checkpoints[Math.max(0, currentCheckpoint - 1)].x;
+ player.y = checkpoints[Math.max(0, currentCheckpoint - 1)].y + 100;
+ player.velocityY = 0;
+ }
+ hazard.lastIntersecting = player.intersects(hazard);
}
+ // Check checkpoint collisions
+ for (var c = 0; c < checkpoints.length; c++) {
+ var checkpoint = checkpoints[c];
+ if (!checkpoint.lastIntersecting && player.intersects(checkpoint)) {
+ currentCheckpoint = c;
+ LK.getSound('checkpoint').play();
+ if (c === checkpoints.length - 1) {
+ levelComplete = true;
+ }
+ }
+ checkpoint.lastIntersecting = player.intersects(checkpoint);
+ }
}
-function checkPlayerInBoundary() {
- var boundaryRadius = arenaSize / 2;
- var dx = player.x - boundaryX;
- var dy = player.y - boundaryY;
- var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance > boundaryRadius) {
- // Player is outside boundary, take damage
- player.health -= 0.5;
- if (player.health <= 0) {
- endGame();
+function handleJump() {
+ if (player.jumpPressed) {
+ if (player.isGrounded) {
+ player.velocityY = JUMP_FORCE;
+ player.isJumping = true;
+ LK.getSound('jump').play();
+ } else if (player.canWallRun) {
+ player.velocityY = JUMP_FORCE;
+ player.velocityX = WALL_JUMP_FORCE * -player.wallRunDirection;
+ LK.getSound('jump').play();
}
+ player.jumpPressed = false;
}
}
-function checkEnemyInBoundary(enemy) {
- var boundaryRadius = arenaSize / 2;
- var dx = enemy.x - boundaryX;
- var dy = enemy.y - boundaryY;
- var distance = Math.sqrt(dx * dx + dy * dy);
- return distance < boundaryRadius;
-}
function endGame() {
- LK.clearInterval(fireTimer);
- LK.clearInterval(enemySpawnTimer);
- storage.kills = kills;
- if (kills > storage.bestKills) {
- storage.bestKills = kills;
+ var finalTime = (gameTime - levelStartTime) / 1000;
+ storage.bestTime = storage.bestTime || finalTime;
+ if (finalTime < storage.bestTime) {
+ storage.bestTime = finalTime;
}
LK.showGameOver();
}
game.down = function (x, y, obj) {
- // Touch controls - moving
var centerX = 2048 / 2;
if (x < centerX) {
- player.isMovingLeft = true;
+ player.moveLeft = true;
} else {
- player.isMovingRight = true;
+ player.moveRight = true;
}
+ player.jumpPressed = true;
};
game.up = function (x, y, obj) {
- player.isMovingLeft = false;
- player.isMovingRight = false;
+ player.moveLeft = false;
+ player.moveRight = false;
};
game.move = function (x, y, obj) {
var centerX = 2048 / 2;
if (x < centerX) {
- player.isMovingLeft = true;
- player.isMovingRight = false;
+ player.moveLeft = true;
+ player.moveRight = false;
} else {
- player.isMovingRight = true;
- player.isMovingLeft = false;
+ player.moveRight = true;
+ player.moveLeft = false;
}
};
game.update = function () {
- gameTime += 16.67; // Approximate ms per frame at 60fps
- // Player movement
- if (player.isMovingLeft) {
- player.x = Math.max(0, player.x - player.speed);
+ if (levelStartTime === 0) {
+ levelStartTime = gameTime;
}
- if (player.isMovingRight) {
- player.x = Math.min(2048, player.x + player.speed);
+ gameTime += 16.67;
+ // Player horizontal movement
+ if (player.moveLeft) {
+ player.x = Math.max(0, player.x - MOVE_SPEED);
}
- if (player.isMovingUp) {
- player.y = Math.max(0, player.y - player.speed);
+ if (player.moveRight) {
+ player.x = Math.min(2048, player.x + MOVE_SPEED);
}
- if (player.isMovingDown) {
- player.y = Math.min(2732, player.y + player.speed);
+ // Apply gravity and check collisions
+ player.lastY = player.y;
+ applyGravity();
+ checkCollisions();
+ // Handle jump input
+ handleJump();
+ // Fall off screen
+ if (player.y > 2732) {
+ LK.effects.flashObject(player, 0xff0000, 300);
+ LK.getSound('hit').play();
+ player.x = 100;
+ player.y = 2600;
+ player.velocityY = 0;
+ currentCheckpoint = 0;
+ levelStartTime = 0;
}
- // Update enemies
- for (var i = enemies.length - 1; i >= 0; i--) {
- var enemy = enemies[i];
- enemy.update();
- enemy.targetX = player.x;
- enemy.targetY = player.y;
- // Check if enemy is in boundary
- if (!checkEnemyInBoundary(enemy)) {
- enemy.destroy();
- enemies.splice(i, 1);
- continue;
- }
- // Check collision with player
- if (!enemy.lastIntersecting && enemy.intersects(player)) {
- player.health -= 10;
- LK.effects.flashObject(player, 0xff0000, 300);
- LK.getSound('hit').play();
- if (player.health <= 0) {
- endGame();
- }
- }
- enemy.lastIntersecting = enemy.intersects(player);
- }
- // Update bullets
- for (var b = bullets.length - 1; b >= 0; b--) {
- var bullet = bullets[b];
- bullet.update();
- if (bullet.lastY === undefined) bullet.lastY = bullet.y;
- // Check if bullet is off screen
- if (bullet.x < -50 || bullet.x > 2048 + 50 || bullet.y < -50 || bullet.y > 2732 + 50) {
- bullet.destroy();
- bullets.splice(b, 1);
- continue;
- }
- // Check collision with enemies
- for (var e = enemies.length - 1; e >= 0; e--) {
- var enemy = enemies[e];
- if (bullet.intersects(enemy)) {
- enemy.destroy();
- enemies.splice(e, 1);
- bullet.destroy();
- bullets.splice(b, 1);
- kills++;
- LK.setScore(LK.getScore() + 10);
- LK.getSound('hit').play();
- // Chance to spawn power up
- if (Math.random() < 0.3) {
- var powerUpType = ['shield', 'ammo', 'speed'][Math.floor(Math.random() * 3)];
- createPowerUp(enemy.lastX, enemy.lastY, powerUpType);
- }
- break;
- }
- }
- }
- // Update power ups
- for (var p = powerUps.length - 1; p >= 0; p--) {
- var powerUp = powerUps[p];
- if (!powerUp.lastIntersecting && powerUp.intersects(player)) {
- switch (powerUp.type) {
- case 'shield':
- player.health = Math.min(player.maxHealth, player.health + 30);
- break;
- case 'ammo':
- player.ammo = player.maxAmmo;
- break;
- case 'speed':
- player.speed = 7;
- LK.setTimeout(function () {
- player.speed = 5;
- }, 5000);
- break;
- }
- LK.getSound('powerup').play();
- powerUp.destroy();
- powerUps.splice(p, 1);
- }
- powerUp.lastIntersecting = powerUp.intersects(player);
- }
- // Boundary contraction logic
- if (gameTime - lastBoundaryContraction > boundaryContractionInterval) {
- contractBoundary();
- lastBoundaryContraction = gameTime;
- }
- // Check if player is in boundary
- checkPlayerInBoundary();
- // End game conditions
- if (gameTime >= matchDuration) {
- endGame();
- }
// Update UI
if (LK.ticks % 10 === 0) {
updateUI();
}
+ // End game condition
+ if (levelComplete) {
+ endGame();
+ }
};
+createLevel();
LK.playMusic('bgmusic', {
loop: true
});
\ No newline at end of file