User prompt
daha daha sola kaydır
User prompt
daha da sola kaydır
User prompt
daha sola kaydır
User prompt
move the level bar to the left on the screen
User prompt
move the level bar and score to the left on the x-axis
User prompt
the level bar should be next to the stop button and not move
User prompt
Please fix the bug: 'LK.showMenu is not a function' in or related to this line: 'LK.showMenu({' Line Number: 494
User prompt
Let the game have a menu
User prompt
Level bar and numbers should not extend beyond the screen
User prompt
Let the dipstick be on top of the rocket
User prompt
The level bar should be a little more to the left
User prompt
The dipstick should be fixed in the middle and not move at all.
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'x')' in or related to this line: 'levelBarContainer.x = rocket.x;' Line Number: 218
User prompt
hatayı düzelt
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'x')' in or related to this line: 'levelBarContainer.x = rocket.x;' Line Number: 218
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'x')' in or related to this line: 'levelBarContainer.x = rocket.x;' Line Number: 218
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'x')' in or related to this line: 'levelBarContainer.x = rocket.x;' Line Number: 218
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'x')' in or related to this line: 'levelBarContainer.x = rocket.x;' Line Number: 218
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'x')' in or related to this line: 'levelBarContainer.x = rocket.x;' Line Number: 218
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'x')' in or related to this line: 'levelBarContainer.x = rocket.x;' Line Number: 218
User prompt
Please fix the bug: 'Cannot read properties of null (reading 'x')' in or related to this line: 'levelBarContainer.x = rocket.x;' Line Number: 218
User prompt
roketin hizasına getir
User prompt
level barı ekrana ortala
User prompt
level bar fit screen
User prompt
Let there be one level bar
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Alien class
var Alien = Container.expand(function () {
var self = Container.call(this);
var alienAsset = self.attachAsset('alien', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = alienAsset.width;
self.height = alienAsset.height;
self.hp = 2; // Each alien takes 2 hits
self.isHit = false;
self.hitTween = null;
// For hit flash
self.flash = function () {
if (self.hitTween) {
tween.stop(alienAsset, {
tint: true
});
}
alienAsset.tint = 0xff5252;
self.hitTween = tween(alienAsset, {
tint: 0x8d3abf
}, {
duration: 200,
easing: tween.linear,
onFinish: function onFinish() {
self.hitTween = null;
}
});
};
// For movement
self.speed = 8 + Math.random() * 4; // Slightly random speed
self.update = function () {
self.y += self.speed;
};
return self;
});
// Boss Alien class (for level 7)
var BossAlien = Container.expand(function () {
var self = Container.call(this);
var bossAsset = self.attachAsset('alien', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.7,
scaleY: 1.7
});
self.width = bossAsset.width * 1.7;
self.height = bossAsset.height * 1.7;
self.hp = 6; // Boss takes 6 hits
self.isHit = false;
self.hitTween = null;
self.flash = function () {
if (self.hitTween) {
tween.stop(bossAsset, {
tint: true
});
}
bossAsset.tint = 0xff5252;
self.hitTween = tween(bossAsset, {
tint: 0x8d3abf
}, {
duration: 200,
easing: tween.linear,
onFinish: function onFinish() {
self.hitTween = null;
}
});
};
self.speed = 10; // Boss is faster
self.update = function () {
self.y += self.speed;
};
return self;
});
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletAsset = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -32; // Upwards
self.update = function () {
self.y += self.speed;
};
return self;
});
// Rocket (player) class
var Rocket = Container.expand(function () {
var self = Container.call(this);
var rocketAsset = self.attachAsset('rocket', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = rocketAsset.width;
self.height = rocketAsset.height;
// For hit flash
self.flashTween = null;
// Show hit flash
self.flash = function () {
if (self.flashTween) {
tween.stop(rocketAsset, {
tint: true
});
}
rocketAsset.tint = 0xff5252;
self.flashTween = tween(rocketAsset, {
tint: 0x4fc3f7
}, {
duration: 400,
easing: tween.linear,
onFinish: function onFinish() {
self.flashTween = null;
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Life bar background
// Life bar
// Alien hit flash
// Bullet
// Alien (enemy)
// Rocket (player)
// Game constants
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
var ROCKET_START_LIFE = 3;
var LEVEL_TO_BOSS = 7;
// Game state
var rocket = null;
var bullets = [];
var aliens = [];
var level = 1;
var rocketLife = ROCKET_START_LIFE;
var canShoot = true;
var shootCooldown = 0;
var dragNode = null;
var lastMoveX = 0;
var lastMoveY = 0;
var score = 0;
var bossSpawned = false;
// GUI elements
var scoreTxt = new Text2('0', {
size: 90,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.topRight.addChild(scoreTxt);
var lifeBarBg = LK.getAsset('lifeBarBg', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
var lifeBar = LK.getAsset('lifeBar', {
anchorX: 0,
anchorY: 0.5,
x: -200,
y: 0
});
var lifeBarContainer = new Container();
lifeBarContainer.addChild(lifeBarBg);
lifeBarContainer.addChild(lifeBar);
lifeBarContainer.x = GAME_WIDTH / 2;
lifeBarContainer.y = 180;
LK.gui.top.addChild(lifeBarContainer);
// Level bar background and bar
// Centered level bar (not full width)
var LEVEL_BAR_WIDTH = 900;
var levelBarBg = LK.getAsset('lifeBarBg', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
width: LEVEL_BAR_WIDTH
});
var levelBar = LK.getAsset('lifeBar', {
anchorX: 0,
anchorY: 0.5,
x: -LEVEL_BAR_WIDTH / 2,
y: 0,
width: 0 // Start empty, will be set by updateLevelBar
});
levelBar.tint = 0x1976d2; // blue for level bar
var levelBarContainer = new Container();
levelBarContainer.addChild(levelBarBg);
levelBarContainer.addChild(levelBar);
levelBarContainer.x = rocket.x;
levelBarContainer.y = 240; // below the life bar
LK.gui.top.addChild(levelBarContainer);
// Helper to update life bar
function updateLifeBar() {
var percent = rocketLife / ROCKET_START_LIFE;
if (percent < 0) percent = 0;
lifeBar.width = 400 * percent;
if (percent > 0.5) {
lifeBar.tint = 0x43a047;
} else if (percent > 0.2) {
lifeBar.tint = 0xffc107;
} else {
lifeBar.tint = 0xd32f2f;
}
}
// Helper to update level bar
function updateLevelBar() {
// Level progress: 0 to 1, based on kills in this level
var killsThisLevel = score % 10;
var percent = killsThisLevel / 10;
if (percent < 0) percent = 0;
if (percent > 1) percent = 1;
levelBar.width = LEVEL_BAR_WIDTH * percent;
// Color: blue if not full, green if full
if (percent >= 1) {
levelBar.tint = 0x43a047;
} else {
levelBar.tint = 0x1976d2;
}
}
// Helper to update level text (removed levelTxt, now only bar)
function updateLevelText() {
// No text, only bar
}
// Helper to update score text
function updateScoreText() {
scoreTxt.setText(score);
updateLevelBar();
}
// Spawn a new alien
function spawnAlien() {
var alien;
if (level === LEVEL_TO_BOSS && !bossSpawned) {
alien = new BossAlien();
bossSpawned = true;
} else {
alien = new Alien();
}
// Random x, but keep inside screen
var margin = 120;
alien.x = margin + Math.random() * (GAME_WIDTH - margin * 2);
alien.y = -alien.height / 2;
aliens.push(alien);
game.addChild(alien);
}
// Reset game state
function resetGame() {
// Remove all bullets and aliens
for (var i = 0; i < bullets.length; ++i) {
bullets[i].destroy();
}
for (var j = 0; j < aliens.length; ++j) {
aliens[j].destroy();
}
bullets = [];
aliens = [];
level = 1;
rocketLife = ROCKET_START_LIFE;
canShoot = true;
shootCooldown = 0;
dragNode = null;
lastMoveX = 0;
lastMoveY = 0;
score = 0;
bossSpawned = false;
updateLevelText();
updateScoreText();
updateLifeBar();
updateLevelBar();
}
// Initialize rocket
rocket = new Rocket();
rocket.x = GAME_WIDTH / 2;
rocket.y = GAME_HEIGHT - 400;
game.addChild(rocket);
// Initial GUI
updateLevelText();
updateScoreText();
updateLifeBar();
updateLevelBar();
// Touch/move controls
game.down = function (x, y, obj) {
// Only start drag if touch is on rocket
var local = rocket.toLocal(game.toGlobal({
x: x,
y: y
}));
if (local.x > -rocket.width / 2 && local.x < rocket.width / 2 && local.y > -rocket.height / 2 && local.y < rocket.height / 2) {
dragNode = rocket;
lastMoveX = x;
lastMoveY = y;
}
};
game.move = function (x, y, obj) {
// Always move the rocket to the mouse/touch position, clamped to screen
var newX = x;
var halfW = rocket.width / 2;
if (newX < halfW) newX = halfW;
if (newX > GAME_WIDTH - halfW) newX = GAME_WIDTH - halfW;
rocket.x = newX;
// Y position stays fixed at the starting Y
rocket.y = GAME_HEIGHT - 400;
lastMoveX = x;
lastMoveY = y;
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Tap to shoot (left mouse button or tap)
game.down = function (x, y, obj) {
// Only start drag if touch is on rocket
var local = rocket.toLocal(game.toGlobal({
x: x,
y: y
}));
if (local.x > -rocket.width / 2 && local.x < rocket.width / 2 && local.y > -rocket.height / 2 && local.y < rocket.height / 2) {
dragNode = rocket;
lastMoveX = x;
lastMoveY = y;
}
// Always allow shooting with left mouse button/tap, regardless of drag state
if (canShoot) {
shootBullet();
}
};
// Shoot bullet
function shootBullet() {
if (!canShoot) return;
var bullet = new Bullet();
bullet.x = rocket.x;
bullet.y = rocket.y - rocket.height / 2 - 20;
bullets.push(bullet);
game.addChild(bullet);
canShoot = false;
shootCooldown = 10; // 10 ticks cooldown
}
// Main update loop
game.update = function () {
// Shooting cooldown
if (!canShoot) {
shootCooldown--;
if (shootCooldown <= 0) {
canShoot = true;
}
}
// Make level bar follow rocket's X position
if (typeof rocket !== "undefined" && rocket !== null && typeof levelBarContainer !== "undefined" && levelBarContainer !== null && typeof rocket.x !== "undefined" && rocket.x !== null) {
levelBarContainer.x = rocket.x;
}
// Update bullets
for (var i = bullets.length - 1; i >= 0; --i) {
var b = bullets[i];
b.update();
// Remove if off screen
if (b.y < -100) {
b.destroy();
bullets.splice(i, 1);
continue;
}
}
// Update aliens
for (var j = aliens.length - 1; j >= 0; --j) {
var a = aliens[j];
a.update();
// Remove if off screen
if (a.y > GAME_HEIGHT + 200) {
a.destroy();
aliens.splice(j, 1);
continue;
}
// Check collision with rocket
if (a.intersects(rocket)) {
// Rocket hit!
rocketLife--;
updateLifeBar();
rocket.flash();
a.flash();
if (a.hp > 1) {
a.hp--;
// Alien stays, but flashes
} else {
a.destroy();
aliens.splice(j, 1);
score++;
updateScoreText();
// Increase level every 10 kills
if (level < LEVEL_TO_BOSS && score % 10 === 0) {
level++;
updateLevelText();
}
}
// Check for game over
if (rocketLife <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
}
// Bullet-alien collisions
for (var i2 = bullets.length - 1; i2 >= 0; --i2) {
var b2 = bullets[i2];
for (var j2 = aliens.length - 1; j2 >= 0; --j2) {
var a2 = aliens[j2];
if (b2.intersects(a2)) {
a2.hp--;
a2.flash();
b2.destroy();
bullets.splice(i2, 1);
if (a2.hp <= 0) {
a2.destroy();
aliens.splice(j2, 1);
score++;
updateScoreText();
// Increase level every 10 kills
if (level < LEVEL_TO_BOSS && score % 10 === 0) {
level++;
updateLevelText();
}
// If boss defeated, win
if (level === LEVEL_TO_BOSS && bossSpawned && aliens.length === 0) {
LK.effects.flashScreen(0x00e676, 1000);
LK.showYouWin();
return;
}
}
break;
}
}
}
// Alien spawn logic
if (level < LEVEL_TO_BOSS) {
// Spawn aliens at interval, max 2 on screen
if (aliens.length < 2 && LK.ticks % (60 - level * 4) === 0) {
spawnAlien();
}
} else if (level === LEVEL_TO_BOSS && !bossSpawned) {
// Spawn boss
spawnAlien();
}
};
// Initial spawn
spawnAlien(); ===================================================================
--- original.js
+++ change.js
@@ -361,9 +361,9 @@
canShoot = true;
}
}
// Make level bar follow rocket's X position
- if (typeof rocket !== "undefined" && rocket !== null && typeof levelBarContainer !== "undefined" && levelBarContainer !== null) {
+ if (typeof rocket !== "undefined" && rocket !== null && typeof levelBarContainer !== "undefined" && levelBarContainer !== null && typeof rocket.x !== "undefined" && rocket.x !== null) {
levelBarContainer.x = rocket.x;
}
// Update bullets
for (var i = bullets.length - 1; i >= 0; --i) {