User prompt
Сделаем по новому, добавь новый счётчик показаны наличие пять топоров снизу слева, и с каждым бросание топора уменьшается наличие топоров на 1%, когда процент доходит до нуля, топоры больше нельзя использовать
User prompt
И так каждый раз
User prompt
Измени пять на одну секунду
User prompt
Сделай так чтобы через 5 секунд можно было снова бросать топор
User prompt
Сделай так чтобы после одного нажатие экрана дождаться чтобы топор коснулся целый или упал
User prompt
уменьшить множество топоров
User prompt
Добавь функцию, аналогичную той, что у кнопки-1. Но вместо уничтожения врагов эта кнопка активирует множество топоров, которые разлетаются в разные стороны, поражая врагов и цели. Эффект длится всего 5 минут. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
чуть меньше
User prompt
добавить кнопку-2 рядом с кнопкой-1 сверху
User prompt
добавить кнопку-2 рядом с кнопкой-1 сверху
User prompt
создать новый фон
User prompt
В начале игры должно быть меню. Создайте фон для меню и добавьте кнопку "Играть". При нажатии на неё должна запускаться основная игра.
User prompt
переместите на правам угле
User prompt
добавьте текст (уровень) и щёт 1, каждый 3 попадание цели, щёт уровня увеличивается
User prompt
добавьте текст (уровень) и щёт, и каждый по 3 попадания цели щёт убавляет ещё 1 щёт
User prompt
цифру цены разукрасьте красным
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toString')' in or related to this line: 'var buttonPriceTxt = new Text2(buttonCost.toString(), {' Line Number: 115
User prompt
рядом с кнопки добавьте цифру цены
User prompt
добавить звук кнопки
User prompt
при нажатье кнопки топор не должен срабатывать, если хватит цена на нажатие
User prompt
при нажатье кнопки топор не должен срабатывать, если хватит цена на нажатие
User prompt
Please fix the bug: 'TypeError: button1.containsPoint is not a function' in or related to this line: 'if (!button1.containsPoint(pos) && !button1.down) {' Line Number: 171
User prompt
при нажатье кнопки топор не должен срабатывать, господи это же очевидно
User prompt
Please fix the bug: 'TypeError: button1.containsPoint is not a function' in or related to this line: 'if (!button1.containsPoint(pos)) {' Line Number: 171
User prompt
при нажатье кнопки топор не должен срабатывать
/**** * Classes ****/ var Axe = Container.expand(function () { var self = Container.call(this); var axeGraphics = self.attachAsset('axe', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 40; self.gravity = 0.3; // Adjusted gravity effect self.velocityY = -self.speed; // Initial upward velocity self._move_migrated = function () { self.velocityY += self.gravity; // Apply gravity to velocity self.y += self.velocityY; // Update position with velocity self.rotation += 0.1; }; }); var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.direction = 1; self.scaleFactor = 0.1; // Initial small scale self.growthRate = 0.01; // Rate at which the enemy grows self._move_migrated = function () { // Randomize direction change if (Math.random() < 0.05) { self.direction = Math.random() * 2 * Math.PI; // Random angle } // Update position based on direction self.x += self.speed * Math.cos(self.direction); self.y += self.speed * Math.sin(self.direction); // Keep enemy within bounds if (self.x <= 0 || self.x >= 2048) { self.direction = Math.PI - self.direction; // Reflect horizontally } if (self.y <= 0 || self.y >= 2732) { self.direction = -self.direction; // Reflect vertically } // Increase size until normal size is reached if (self.scaleFactor < 1) { self.scaleFactor += self.growthRate; self.scale.set(self.scaleFactor, self.scaleFactor); } }; }); var Target = Container.expand(function () { var self = Container.call(this); var targetGraphics = self.attachAsset('target', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.direction = 1; self._move_migrated = function () { self.x += self.speed * self.direction; if (self.x <= 0 || self.x >= 2048) { self.direction *= -1; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Game state management var gameState = 'menu'; // 'menu' or 'playing' // Menu background var menuBackground = game.attachAsset('green_grass_field', {}); menuBackground.width = 2048; menuBackground.height = 2732; // Play button for menu var playButton = game.attachAsset('button-1', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(playButton); // Play button text var playButtonTxt = new Text2('Играть', { size: 120, fill: 0xFFFFFF, font: "Impact", dropShadow: true, dropShadowColor: 0x000000 }); playButtonTxt.anchor.set(0.5, 0.5); playButtonTxt.x = playButton.x; playButtonTxt.y = playButton.y; game.addChild(playButtonTxt); // Game background (initially hidden) var background = game.attachAsset('green_grass_field', {}); background.width = 2048; background.height = 2732; background.visible = false; var targets = []; var axes = []; var score = 0; var kills = 0; var level = 1; var levelTxt = new Text2('Level: 1', { size: 100, fill: 0xFFFFFF, font: "Impact", dropShadow: true, dropShadowColor: 0x000000 }); levelTxt.anchor.set(1, 0); levelTxt.visible = false; // Hide initially LK.gui.topRight.addChild(levelTxt); var targetSpeed = 5; var enemies = []; var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF, font: "Impact", dropShadow: true, dropShadowColor: 0x000000 }); scoreTxt.anchor.set(.5, 0); scoreTxt.visible = false; // Hide initially LK.gui.top.addChild(scoreTxt); // Add button-1 to the bottom right corner var button1 = game.attachAsset('button-1', { anchorX: 1.0, anchorY: 1.0, x: 2048, y: 2732 }); button1.visible = false; // Hide initially game.addChild(button1); // Initialize button cost var buttonCost = 100; // Display the price next to button-1 var buttonPriceTxt = new Text2(buttonCost.toString(), { size: 100, fill: 0xFF0000, font: "Impact", dropShadow: true, dropShadowColor: 0x000000 }); buttonPriceTxt.anchor.set(1, 1); buttonPriceTxt.x = button1.x - button1.width / 2; buttonPriceTxt.y = button1.y - button1.height / 2; buttonPriceTxt.visible = false; // Hide initially game.addChild(buttonPriceTxt); // Initialize button cost var buttonCost = 100; // Add event listener for play button playButton.down = function (x, y, obj) { if (gameState === 'menu') { // Start the game gameState = 'playing'; // Hide menu elements playButton.visible = false; playButtonTxt.visible = false; menuBackground.visible = false; // Show game elements background.visible = true; levelTxt.visible = true; scoreTxt.visible = true; button1.visible = true; buttonPriceTxt.visible = true; // Play button sound LK.getSound('button-1').play(); // Initialize first targets spawnTargets(); } }; // Add event listener for button-1 button1.down = function (x, y, obj) { if (score >= buttonCost) { // Play button sound LK.getSound('button-1').play(); // Shrink button button1.scale.set(0.9, 0.9); LK.setTimeout(function () { // Expand button back to normal size button1.scale.set(1.0, 1.0); }, 100); score -= buttonCost; scoreTxt.setText(score); buttonCost += 50; buttonPriceTxt.setText(buttonCost.toString()); // Vaporize enemies with spinning and falling effect for (var i = 0; i < enemies.length; i++) { (function (enemy) { var _spinAndFall = function spinAndFall() { enemy.rotation += 0.1; enemy.speed = (enemy.speed || 10) * 1.05; // Increase speed by 5% each frame enemy.y += enemy.speed; if (enemy.y > 2732) { enemy.destroy(); } else { LK.setTimeout(_spinAndFall, 16); } }; _spinAndFall(); })(enemies[i]); } enemies = []; } }; var spawnTargets = function spawnTargets() { for (var i = 0; i < 3; i++) { var target = game.addChild(new Target()); target.speed = targetSpeed; target.x = Math.random() * 2048; target.y = Math.random() * (2732 - target.height * 2); targets.push(target); } for (var i = 0; i < 1; i++) { var enemy = game.addChild(new Enemy()); enemy.speed = targetSpeed; enemy.x = Math.random() * 2048; enemy.y = Math.random() * (2732 - enemy.height * 2); enemies.push(enemy); } }; LK.on('tick', function () { if (gameState === 'playing' && targets.length == 0) { spawnTargets(); } }); var axe; game.on('down', function (x, y, obj) { if (gameState === 'playing') { var pos = game.toLocal(obj.global); axe = game.addChild(new Axe()); LK.getSound('axe').play(); axe.x = pos.x; axe.y = 2732 - axe.height + 295; axes.push(axe); } }); LK.on('tick', function () { if (gameState === 'playing') { for (var i = 0; i < targets.length; i++) { targets[i]._move_migrated(); } for (var i = 0; i < axes.length; i++) { axes[i]._move_migrated(); if (axes[i].y < -50) { axes[i].destroy(); axes.splice(i, 1); } if (axes[i].y <= 0) { LK.showGameOver(); } } for (var i = 0; i < enemies.length; i++) { enemies[i]._move_migrated(); for (var j = 0; j < axes.length; j++) { if (axes[j].intersects(enemies[i])) { LK.showGameOver(); return; } } } for (var i = 0; i < axes.length; i++) { for (var j = 0; j < targets.length; j++) { if (axes[i].intersects(targets[j])) { var distance = Math.sqrt(Math.pow(axes[i].x - targets[j].x, 2) + Math.pow(axes[i].y - targets[j].y, 2)); score += Math.max(0, 100 - distance) + 50; scoreTxt.setText(score); axes[i].destroy(); axes.splice(i, 1); targets[j].destroy(); targets.splice(j, 1); kills++; if (kills % 3 == 0) { targetSpeed += 1; level++; levelTxt.setText('Level: ' + level); } break; } } } } });
===================================================================
--- original.js
+++ change.js
@@ -73,60 +73,113 @@
/****
* Game Code
****/
+// Game state management
+var gameState = 'menu'; // 'menu' or 'playing'
+// Menu background
+var menuBackground = game.attachAsset('green_grass_field', {});
+menuBackground.width = 2048;
+menuBackground.height = 2732;
+// Play button for menu
+var playButton = game.attachAsset('button-1', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 2048 / 2,
+ y: 2732 / 2
+});
+game.addChild(playButton);
+// Play button text
+var playButtonTxt = new Text2('Играть', {
+ size: 120,
+ fill: 0xFFFFFF,
+ font: "Impact",
+ dropShadow: true,
+ dropShadowColor: 0x000000
+});
+playButtonTxt.anchor.set(0.5, 0.5);
+playButtonTxt.x = playButton.x;
+playButtonTxt.y = playButton.y;
+game.addChild(playButtonTxt);
+// Game background (initially hidden)
var background = game.attachAsset('green_grass_field', {});
background.width = 2048;
background.height = 2732;
+background.visible = false;
var targets = [];
var axes = [];
var score = 0;
var kills = 0;
var level = 1;
var levelTxt = new Text2('Level: 1', {
size: 100,
- fill: "#ffffff",
+ fill: 0xFFFFFF,
font: "Impact",
dropShadow: true,
- dropShadowColor: "#000000"
+ dropShadowColor: 0x000000
});
levelTxt.anchor.set(1, 0);
+levelTxt.visible = false; // Hide initially
LK.gui.topRight.addChild(levelTxt);
var targetSpeed = 5;
var enemies = [];
var scoreTxt = new Text2('0', {
size: 150,
- fill: "#ffffff",
+ fill: 0xFFFFFF,
font: "Impact",
dropShadow: true,
- dropShadowColor: "#000000"
+ dropShadowColor: 0x000000
});
scoreTxt.anchor.set(.5, 0);
+scoreTxt.visible = false; // Hide initially
LK.gui.top.addChild(scoreTxt);
// Add button-1 to the bottom right corner
var button1 = game.attachAsset('button-1', {
anchorX: 1.0,
anchorY: 1.0,
x: 2048,
y: 2732
});
+button1.visible = false; // Hide initially
game.addChild(button1);
// Initialize button cost
var buttonCost = 100;
// Display the price next to button-1
var buttonPriceTxt = new Text2(buttonCost.toString(), {
size: 100,
- fill: "#ff0000",
+ fill: 0xFF0000,
font: "Impact",
dropShadow: true,
- dropShadowColor: "#000000"
+ dropShadowColor: 0x000000
});
buttonPriceTxt.anchor.set(1, 1);
buttonPriceTxt.x = button1.x - button1.width / 2;
buttonPriceTxt.y = button1.y - button1.height / 2;
+buttonPriceTxt.visible = false; // Hide initially
game.addChild(buttonPriceTxt);
// Initialize button cost
var buttonCost = 100;
+// Add event listener for play button
+playButton.down = function (x, y, obj) {
+ if (gameState === 'menu') {
+ // Start the game
+ gameState = 'playing';
+ // Hide menu elements
+ playButton.visible = false;
+ playButtonTxt.visible = false;
+ menuBackground.visible = false;
+ // Show game elements
+ background.visible = true;
+ levelTxt.visible = true;
+ scoreTxt.visible = true;
+ button1.visible = true;
+ buttonPriceTxt.visible = true;
+ // Play button sound
+ LK.getSound('button-1').play();
+ // Initialize first targets
+ spawnTargets();
+ }
+};
// Add event listener for button-1
button1.down = function (x, y, obj) {
if (score >= buttonCost) {
// Play button sound
@@ -176,61 +229,65 @@
enemies.push(enemy);
}
};
LK.on('tick', function () {
- if (targets.length == 0) {
+ if (gameState === 'playing' && targets.length == 0) {
spawnTargets();
}
});
var axe;
game.on('down', function (x, y, obj) {
- var pos = game.toLocal(obj.global);
- axe = game.addChild(new Axe());
- LK.getSound('axe').play();
- axe.x = pos.x;
- axe.y = 2732 - axe.height + 295;
- axes.push(axe);
+ if (gameState === 'playing') {
+ var pos = game.toLocal(obj.global);
+ axe = game.addChild(new Axe());
+ LK.getSound('axe').play();
+ axe.x = pos.x;
+ axe.y = 2732 - axe.height + 295;
+ axes.push(axe);
+ }
});
LK.on('tick', function () {
- for (var i = 0; i < targets.length; i++) {
- targets[i]._move_migrated();
- }
- for (var i = 0; i < axes.length; i++) {
- axes[i]._move_migrated();
- if (axes[i].y < -50) {
- axes[i].destroy();
- axes.splice(i, 1);
+ if (gameState === 'playing') {
+ for (var i = 0; i < targets.length; i++) {
+ targets[i]._move_migrated();
}
- if (axes[i].y <= 0) {
- LK.showGameOver();
- }
- }
- for (var i = 0; i < enemies.length; i++) {
- enemies[i]._move_migrated();
- for (var j = 0; j < axes.length; j++) {
- if (axes[j].intersects(enemies[i])) {
+ for (var i = 0; i < axes.length; i++) {
+ axes[i]._move_migrated();
+ if (axes[i].y < -50) {
+ axes[i].destroy();
+ axes.splice(i, 1);
+ }
+ if (axes[i].y <= 0) {
LK.showGameOver();
- return;
}
}
- }
- for (var i = 0; i < axes.length; i++) {
- for (var j = 0; j < targets.length; j++) {
- if (axes[i].intersects(targets[j])) {
- var distance = Math.sqrt(Math.pow(axes[i].x - targets[j].x, 2) + Math.pow(axes[i].y - targets[j].y, 2));
- score += Math.max(0, 100 - distance) + 50;
- scoreTxt.setText(score);
- axes[i].destroy();
- axes.splice(i, 1);
- targets[j].destroy();
- targets.splice(j, 1);
- kills++;
- if (kills % 3 == 0) {
- targetSpeed += 1;
- level++;
- levelTxt.setText('Level: ' + level);
+ for (var i = 0; i < enemies.length; i++) {
+ enemies[i]._move_migrated();
+ for (var j = 0; j < axes.length; j++) {
+ if (axes[j].intersects(enemies[i])) {
+ LK.showGameOver();
+ return;
}
- break;
}
}
+ for (var i = 0; i < axes.length; i++) {
+ for (var j = 0; j < targets.length; j++) {
+ if (axes[i].intersects(targets[j])) {
+ var distance = Math.sqrt(Math.pow(axes[i].x - targets[j].x, 2) + Math.pow(axes[i].y - targets[j].y, 2));
+ score += Math.max(0, 100 - distance) + 50;
+ scoreTxt.setText(score);
+ axes[i].destroy();
+ axes.splice(i, 1);
+ targets[j].destroy();
+ targets.splice(j, 1);
+ kills++;
+ if (kills % 3 == 0) {
+ targetSpeed += 1;
+ level++;
+ levelTxt.setText('Level: ' + level);
+ }
+ break;
+ }
+ }
+ }
}
});
\ No newline at end of file