User prompt
счёт не должен исчезать после клика
User prompt
счёт видно всегда
User prompt
каждый клик уменьшает score на 1
User prompt
вверху видно цифровое значение, там 10 очков.
User prompt
Chest невидимый до того, как кликнешь по нему.
User prompt
Chest визуально не отображается
User prompt
сундук не видно
User prompt
Chest появляется в случайной точке на экране
Code edit (6 edits merged)
Please save this source code
User prompt
когда кликаешь не по цветку - стрелочка не появляется.
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'down')' in or related to this line: 'self.down = function (x, y, obj) {' Line Number: 131
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'down')' in or related to this line: 'self.down = function (x, y, obj) {' Line Number: 119
User prompt
когда кликаешь на цветок, он превращается в Arrow. Все Arrow повёрнуты в сторону Chest.
User prompt
EnvironmentFlower создаются вдали от других объектов
Code edit (3 edits merged)
Please save this source code
User prompt
По всему экрану в случайных местах расположены EnvironmentFlower
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
когда открывается сундук из него вылетают 10 Coin - направление "вверх" + случайное значение от 0 до 90. На Coin действует гравитация, сила гравитации = 1.
Code edit (1 edits merged)
Please save this source code
User prompt
Если кликнуть на сундук, он превращается в ChestOpen
User prompt
Сундук стоит в центре экрана.
User prompt
Курсор мыши в тех же координатах, что и объект Cursor.
Code edit (1 edits merged)
Please save this source code
User prompt
как сделать главное меню? Отвечай на русском языке, но код пиши на английском.
/**** * Classes ****/ // Bullet class var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -10; self.update = function () { self.y += self.speed; }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.update = function () { self.y += self.speed; }; }); //<Assets used in the game will automatically appear here> // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Hero update logic }; self.move = function (x, y) { self.x = x; self.y = y; }; }); // Main Menu class var MainMenu = Container.expand(function () { var self = Container.call(this); // Create menu elements here // For example, we can create a start button var startButton = self.attachAsset('startButton', { anchorX: 0.5, anchorY: 0.5 }); startButton.x = 2048 / 2; startButton.y = 2732 / 2; // Handle start button press startButton.down = function (x, y, obj) { // Start the game self.destroy(); startGame(); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize main menu var mainMenu = game.addChild(new MainMenu()); // Start game function function startGame() { // Initialize variables var hero; var enemies = []; var bullets = []; var score = 0; var scoreTxt; // Initialize hero hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 200; // Initialize score text scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Handle game move event game.move = function (x, y, obj) { hero.move(x, y); }; // Handle game update event game.update = function () { // Update hero hero.update(); // Update enemies for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].update(); if (enemies[i].y > 2732) { enemies[i].destroy(); enemies.splice(i, 1); } } // Update bullets for (var j = bullets.length - 1; j >= 0; j--) { bullets[j].update(); if (bullets[j].y < 0) { bullets[j].destroy(); bullets.splice(j, 1); } } // Check for collisions for (var k = bullets.length - 1; k >= 0; k--) { for (var l = enemies.length - 1; l >= 0; l--) { if (bullets[k].intersects(enemies[l])) { bullets[k].destroy(); enemies[l].destroy(); bullets.splice(k, 1); enemies.splice(l, 1); score++; scoreTxt.setText(score); break; } } } // Spawn enemies if (LK.ticks % 60 == 0) { var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = -50; enemies.push(newEnemy); game.addChild(newEnemy); } // Fire bullets if (LK.ticks % 15 == 0) { var newBullet = new Bullet(); newBullet.x = hero.x; newBullet.y = hero.y; bullets.push(newBullet); game.addChild(newBullet); } }; } // Initialize variables var hero; var enemies = []; var bullets = []; var score = 0; var scoreTxt; // Initialize hero hero = game.addChild(new Hero()); hero.x = 2048 / 2; hero.y = 2732 - 200; // Initialize score text scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Handle game move event game.move = function (x, y, obj) { hero.move(x, y); }; // Handle game update event game.update = function () { // Update hero hero.update(); // Update enemies for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].update(); if (enemies[i].y > 2732) { enemies[i].destroy(); enemies.splice(i, 1); } } // Update bullets for (var j = bullets.length - 1; j >= 0; j--) { bullets[j].update(); if (bullets[j].y < 0) { bullets[j].destroy(); bullets.splice(j, 1); } } // Check for collisions for (var k = bullets.length - 1; k >= 0; k--) { for (var l = enemies.length - 1; l >= 0; l--) { if (bullets[k].intersects(enemies[l])) { bullets[k].destroy(); enemies[l].destroy(); bullets.splice(k, 1); enemies.splice(l, 1); score++; scoreTxt.setText(score); break; } } } // Spawn enemies if (LK.ticks % 60 == 0) { var newEnemy = new Enemy(); newEnemy.x = Math.random() * 2048; newEnemy.y = -50; enemies.push(newEnemy); game.addChild(newEnemy); } // Fire bullets if (LK.ticks % 15 == 0) { var newBullet = new Bullet(); newBullet.x = hero.x; newBullet.y = hero.y; bullets.push(newBullet); game.addChild(newBullet); } };
/****
* Classes
****/
// Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -10;
self.update = function () {
self.y += self.speed;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Hero update logic
};
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
// Main Menu class
var MainMenu = Container.expand(function () {
var self = Container.call(this);
// Create menu elements here
// For example, we can create a start button
var startButton = self.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5
});
startButton.x = 2048 / 2;
startButton.y = 2732 / 2;
// Handle start button press
startButton.down = function (x, y, obj) {
// Start the game
self.destroy();
startGame();
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize main menu
var mainMenu = game.addChild(new MainMenu());
// Start game function
function startGame() {
// Initialize variables
var hero;
var enemies = [];
var bullets = [];
var score = 0;
var scoreTxt;
// Initialize hero
hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 200;
// Initialize score text
scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle game move event
game.move = function (x, y, obj) {
hero.move(x, y);
};
// Handle game update event
game.update = function () {
// Update hero
hero.update();
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].y > 2732) {
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (bullets[j].y < 0) {
bullets[j].destroy();
bullets.splice(j, 1);
}
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(enemies[l])) {
bullets[k].destroy();
enemies[l].destroy();
bullets.splice(k, 1);
enemies.splice(l, 1);
score++;
scoreTxt.setText(score);
break;
}
}
}
// Spawn enemies
if (LK.ticks % 60 == 0) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * 2048;
newEnemy.y = -50;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
// Fire bullets
if (LK.ticks % 15 == 0) {
var newBullet = new Bullet();
newBullet.x = hero.x;
newBullet.y = hero.y;
bullets.push(newBullet);
game.addChild(newBullet);
}
};
}
// Initialize variables
var hero;
var enemies = [];
var bullets = [];
var score = 0;
var scoreTxt;
// Initialize hero
hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 200;
// Initialize score text
scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle game move event
game.move = function (x, y, obj) {
hero.move(x, y);
};
// Handle game update event
game.update = function () {
// Update hero
hero.update();
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].y > 2732) {
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (bullets[j].y < 0) {
bullets[j].destroy();
bullets.splice(j, 1);
}
}
// Check for collisions
for (var k = bullets.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (bullets[k].intersects(enemies[l])) {
bullets[k].destroy();
enemies[l].destroy();
bullets.splice(k, 1);
enemies.splice(l, 1);
score++;
scoreTxt.setText(score);
break;
}
}
}
// Spawn enemies
if (LK.ticks % 60 == 0) {
var newEnemy = new Enemy();
newEnemy.x = Math.random() * 2048;
newEnemy.y = -50;
enemies.push(newEnemy);
game.addChild(newEnemy);
}
// Fire bullets
if (LK.ticks % 15 == 0) {
var newBullet = new Bullet();
newBullet.x = hero.x;
newBullet.y = hero.y;
bullets.push(newBullet);
game.addChild(newBullet);
}
};