Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: self is undefined' in this line: 'var nutcrackerButton = self.createAsset('nutcrackerButton', 'Nutcracker Build Button', 0.5, 0);' Line Number: 27
Code edit (1 edits merged)
Please save this source code
User prompt
i want a nutcracker build button in the build menu
Code edit (1 edits merged)
Please save this source code
User prompt
Set the x position of the building menu to 0
User prompt
I want a building menu at the top
User prompt
Add three y-levels. One at y=2532, one at 2232 and one at 2032. when a mouse is spawned, spawn it at a random y-level
User prompt
Spawn every 600 ticks seconds a mouse at x= 0- mouse.width. Mouses move every tick 2 steps to the right. Destroy them, when they reach x=2048+mouse.width
User prompt
There are no mouses, mouse traps and nutcrackers at the start
User prompt
Add a background asset
Initial prompt
Nutcrackers VS Mouses
var Nutcracker = Container.expand(function () { var self = Container.call(this); var nutcrackerGraphics = self.createAsset('nutcracker', 'Nutcracker Graphics', .5, .5); self.move = function () {}; self.attack = function () {}; }); var MouseTrap = Container.expand(function () { var self = Container.call(this); var mousetrapGraphics = self.createAsset('mousetrap', 'Mouse Trap Graphics', .5, .5); self.activate = function () {}; }); var Mouse = Container.expand(function () { var self = Container.call(this); var mouseGraphics = self.createAsset('mouse', 'Mouse Graphics', .5, .5); self.move = function () { self.x += 2; }; self.attack = function () {}; }); var BuildingMenu = Container.expand(function () { var self = Container.call(this); self.y = 0; self.x = 1024; var menuBackground = self.createAsset('menuBackground', 'Building Menu Background', 0.5, 0); self.addChild(menuBackground); }); var Game = Container.expand(function () { var self = Container.call(this); var background = self.createAsset('background', 'Background Graphics', 0, 0); self.addChildAt(background, 0); var buildingMenu = self.addChild(new BuildingMenu()); LK.gui.topCenter.addChild(buildingMenu); var nutcrackers = []; var mousetraps = []; var mice = []; var initGame = function () {}; var tickCounter = 0; LK.on('tick', function () { tickCounter++; if (tickCounter % 600 == 0) { var newMouse = new Mouse(); newMouse.x = Math.random() * newMouse.width; var yLevels = [2532, 2232, 2032]; newMouse.y = yLevels[Math.floor(Math.random() * yLevels.length)]; mice.push(newMouse); self.addChild(newMouse); } for (var i = 0; i < nutcrackers.length; i++) { nutcrackers[i].move(); nutcrackers[i].attack(); } for (var i = 0; i < mousetraps.length; i++) { mousetraps[i].activate(); } for (var i = mice.length - 1; i >= 0; i--) { mice[i].move(); mice[i].attack(); if (mice[i].x > 2048 + mice[i].width) { mice[i].destroy(); mice.splice(i, 1); } } }); initGame(); });
===================================================================
--- original.js
+++ change.js
@@ -16,12 +16,21 @@
self.x += 2;
};
self.attack = function () {};
});
+var BuildingMenu = Container.expand(function () {
+ var self = Container.call(this);
+ self.y = 0;
+ self.x = 1024;
+ var menuBackground = self.createAsset('menuBackground', 'Building Menu Background', 0.5, 0);
+ self.addChild(menuBackground);
+});
var Game = Container.expand(function () {
var self = Container.call(this);
var background = self.createAsset('background', 'Background Graphics', 0, 0);
self.addChildAt(background, 0);
+ var buildingMenu = self.addChild(new BuildingMenu());
+ LK.gui.topCenter.addChild(buildingMenu);
var nutcrackers = [];
var mousetraps = [];
var mice = [];
var initGame = function () {};
Nut cracker, side view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Mouse trap, side view, cartoon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a rolling nut, cartoon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a round giant snowball, cartoon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white background