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
как сделать главное меню? Отвечай на русском языке, но код пиши на английском.
Initial prompt
Dungeon Logic System
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 });
===================================================================
--- original.js
+++ change.js
@@ -1,222 +1,6 @@
-/****
-* 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);
- }
-};
\ No newline at end of file
+ backgroundColor: 0x000000
+});
\ No newline at end of file