Code edit (1 edits merged)
Please save this source code
User prompt
Nature World Builder
Initial prompt
Toca nature (2014-2019). Tap on the mountain button ๐บ, the water button ๐ฆฆ, the tree button ๐ฆ, or the axe button ๐ช, or the magnifying glass button ๐, use your finger to swipe on the grass, use the magnifying glass ๐ to see the animals, tap on the camera to take a picture
/**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
/**** 
* Classes
****/ 
var Animal = Container.expand(function () {
	var self = Container.call(this);
	var animalGraphics = self.attachAsset('animal', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.moveSpeed = 1;
	self.targetX = self.x;
	self.targetY = self.y;
	self.moveTimer = 0;
	self.discovered = false;
	self.update = function () {
		self.moveTimer++;
		if (self.moveTimer > 180) {
			self.targetX = Math.random() * 1800 + 124;
			self.targetY = Math.random() * 1800 + 600;
			self.moveTimer = 0;
		}
		var dx = self.targetX - self.x;
		var dy = self.targetY - self.y;
		if (Math.abs(dx) > 5 || Math.abs(dy) > 5) {
			self.x += dx * 0.01;
			self.y += dy * 0.01;
		}
		if (!self.discovered) {
			animalGraphics.alpha = 0.3;
		} else {
			animalGraphics.alpha = 1.0;
		}
	};
	return self;
});
var MagnifyingGlass = Container.expand(function () {
	var self = Container.call(this);
	var glassGraphics = self.attachAsset('magnifyingGlass', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.active = false;
	self.update = function () {
		if (self.active) {
			glassGraphics.alpha = 0.8;
		} else {
			glassGraphics.alpha = 0.3;
		}
	};
	return self;
});
var Mountain = Container.expand(function () {
	var self = Container.call(this);
	var mountainGraphics = self.attachAsset('mountain', {
		anchorX: 0.5,
		anchorY: 1.0
	});
	self.placed = false;
	return self;
});
var ToolButton = Container.expand(function (toolType) {
	var self = Container.call(this);
	var buttonGraphics = self.attachAsset('toolButton', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var toolText = new Text2(toolType, {
		size: 24,
		fill: 0xFFFFFF
	});
	toolText.anchor.set(0.5, 0.5);
	self.addChild(toolText);
	self.toolType = toolType;
	self.selected = false;
	self.setSelected = function (selected) {
		self.selected = selected;
		if (selected) {
			buttonGraphics.tint = 0x2E7D32;
		} else {
			buttonGraphics.tint = 0x4CAF50;
		}
	};
	self.down = function (x, y, obj) {
		selectTool(self.toolType);
	};
	return self;
});
var Tree = Container.expand(function () {
	var self = Container.call(this);
	var treeGraphics = self.attachAsset('tree', {
		anchorX: 0.5,
		anchorY: 1.0
	});
	self.placed = false;
	return self;
});
var Water = Container.expand(function () {
	var self = Container.call(this);
	var waterGraphics = self.attachAsset('water', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.placed = false;
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x87CEEB
});
/**** 
* Game Code
****/ 
var gameBackground = game.attachAsset('background', {
	x: 0,
	y: 0
});
var selectedTool = 'mountain';
var toolButtons = [];
var mountains = [];
var waterSources = [];
var trees = [];
var animals = [];
var magnifyingGlass = null;
var ecosystemTimer = 0;
var tools = ['mountain', 'water', 'tree', 'axe', 'magnify', 'camera'];
function selectTool(toolType) {
	selectedTool = toolType;
	for (var i = 0; i < toolButtons.length; i++) {
		toolButtons[i].setSelected(toolButtons[i].toolType === toolType);
	}
	if (magnifyingGlass) {
		magnifyingGlass.active = toolType === 'magnify';
	}
}
function createToolbar() {
	var startX = 200;
	var startY = 100;
	var spacing = 160;
	for (var i = 0; i < tools.length; i++) {
		var toolButton = new ToolButton(tools[i]);
		toolButton.x = startX + i * spacing;
		toolButton.y = startY;
		toolButtons.push(toolButton);
		LK.gui.addChild(toolButton);
	}
	selectTool('mountain');
}
function placeMountain(x, y) {
	var mountain = new Mountain();
	mountain.x = x;
	mountain.y = y;
	mountain.placed = true;
	mountains.push(mountain);
	game.addChild(mountain);
	LK.getSound('place').play();
}
function placeWater(x, y) {
	var water = new Water();
	water.x = x;
	water.y = y;
	water.placed = true;
	waterSources.push(water);
	game.addChild(water);
	LK.getSound('place').play();
}
function placeTree(x, y) {
	var tree = new Tree();
	tree.x = x;
	tree.y = y;
	tree.placed = true;
	trees.push(tree);
	game.addChild(tree);
	LK.getSound('place').play();
}
function spawnAnimal() {
	if (animals.length < 8) {
		var animal = new Animal();
		animal.x = Math.random() * 1800 + 124;
		animal.y = Math.random() * 1800 + 600;
		animals.push(animal);
		game.addChild(animal);
	}
}
function removeElementAt(x, y) {
	var removed = false;
	for (var i = mountains.length - 1; i >= 0; i--) {
		var mountain = mountains[i];
		var dx = Math.abs(mountain.x - x);
		var dy = Math.abs(mountain.y - y);
		if (dx < 100 && dy < 80) {
			mountain.destroy();
			mountains.splice(i, 1);
			removed = true;
			break;
		}
	}
	if (!removed) {
		for (var i = waterSources.length - 1; i >= 0; i--) {
			var water = waterSources[i];
			var dx = Math.abs(water.x - x);
			var dy = Math.abs(water.y - y);
			if (dx < 50 && dy < 50) {
				water.destroy();
				waterSources.splice(i, 1);
				removed = true;
				break;
			}
		}
	}
	if (!removed) {
		for (var i = trees.length - 1; i >= 0; i--) {
			var tree = trees[i];
			var dx = Math.abs(tree.x - x);
			var dy = Math.abs(tree.y - y);
			if (dx < 40 && dy < 60) {
				tree.destroy();
				trees.splice(i, 1);
				removed = true;
				break;
			}
		}
	}
	if (removed) {
		LK.getSound('remove').play();
	}
}
function discoverAnimals(x, y) {
	for (var i = 0; i < animals.length; i++) {
		var animal = animals[i];
		var dx = Math.abs(animal.x - x);
		var dy = Math.abs(animal.y - y);
		if (dx < 150 && dy < 150) {
			animal.discovered = true;
		}
	}
}
function takeScreenshot() {
	LK.getSound('camera').play();
	LK.effects.flashScreen(0xFFFFFF, 200);
}
createToolbar();
magnifyingGlass = new MagnifyingGlass();
magnifyingGlass.x = 1024;
magnifyingGlass.y = 1366;
game.addChild(magnifyingGlass);
game.down = function (x, y, obj) {
	if (y < 200) return;
	if (selectedTool === 'mountain') {
		placeMountain(x, y);
	} else if (selectedTool === 'water') {
		placeWater(x, y);
	} else if (selectedTool === 'tree') {
		placeTree(x, y);
	} else if (selectedTool === 'axe') {
		removeElementAt(x, y);
	} else if (selectedTool === 'magnify') {
		discoverAnimals(x, y);
		magnifyingGlass.x = x;
		magnifyingGlass.y = y;
	} else if (selectedTool === 'camera') {
		takeScreenshot();
	}
};
game.update = function () {
	ecosystemTimer++;
	if (ecosystemTimer % 600 === 0) {
		var habitatScore = mountains.length + waterSources.length + trees.length;
		if (habitatScore > 2) {
			spawnAnimal();
		}
	}
	for (var i = animals.length - 1; i >= 0; i--) {
		var animal = animals[i];
		if (animal.x < 0 || animal.x > 2048 || animal.y < 500 || animal.y > 2732) {
			animal.x = Math.random() * 1800 + 124;
			animal.y = Math.random() * 1800 + 600;
		}
	}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,288 @@
-/****
+/**** 
+* Plugins
+****/ 
+var tween = LK.import("@upit/tween.v1");
+
+/**** 
+* Classes
+****/ 
+var Animal = Container.expand(function () {
+	var self = Container.call(this);
+	var animalGraphics = self.attachAsset('animal', {
+		anchorX: 0.5,
+		anchorY: 0.5
+	});
+	self.moveSpeed = 1;
+	self.targetX = self.x;
+	self.targetY = self.y;
+	self.moveTimer = 0;
+	self.discovered = false;
+	self.update = function () {
+		self.moveTimer++;
+		if (self.moveTimer > 180) {
+			self.targetX = Math.random() * 1800 + 124;
+			self.targetY = Math.random() * 1800 + 600;
+			self.moveTimer = 0;
+		}
+		var dx = self.targetX - self.x;
+		var dy = self.targetY - self.y;
+		if (Math.abs(dx) > 5 || Math.abs(dy) > 5) {
+			self.x += dx * 0.01;
+			self.y += dy * 0.01;
+		}
+		if (!self.discovered) {
+			animalGraphics.alpha = 0.3;
+		} else {
+			animalGraphics.alpha = 1.0;
+		}
+	};
+	return self;
+});
+var MagnifyingGlass = Container.expand(function () {
+	var self = Container.call(this);
+	var glassGraphics = self.attachAsset('magnifyingGlass', {
+		anchorX: 0.5,
+		anchorY: 0.5
+	});
+	self.active = false;
+	self.update = function () {
+		if (self.active) {
+			glassGraphics.alpha = 0.8;
+		} else {
+			glassGraphics.alpha = 0.3;
+		}
+	};
+	return self;
+});
+var Mountain = Container.expand(function () {
+	var self = Container.call(this);
+	var mountainGraphics = self.attachAsset('mountain', {
+		anchorX: 0.5,
+		anchorY: 1.0
+	});
+	self.placed = false;
+	return self;
+});
+var ToolButton = Container.expand(function (toolType) {
+	var self = Container.call(this);
+	var buttonGraphics = self.attachAsset('toolButton', {
+		anchorX: 0.5,
+		anchorY: 0.5
+	});
+	var toolText = new Text2(toolType, {
+		size: 24,
+		fill: 0xFFFFFF
+	});
+	toolText.anchor.set(0.5, 0.5);
+	self.addChild(toolText);
+	self.toolType = toolType;
+	self.selected = false;
+	self.setSelected = function (selected) {
+		self.selected = selected;
+		if (selected) {
+			buttonGraphics.tint = 0x2E7D32;
+		} else {
+			buttonGraphics.tint = 0x4CAF50;
+		}
+	};
+	self.down = function (x, y, obj) {
+		selectTool(self.toolType);
+	};
+	return self;
+});
+var Tree = Container.expand(function () {
+	var self = Container.call(this);
+	var treeGraphics = self.attachAsset('tree', {
+		anchorX: 0.5,
+		anchorY: 1.0
+	});
+	self.placed = false;
+	return self;
+});
+var Water = Container.expand(function () {
+	var self = Container.call(this);
+	var waterGraphics = self.attachAsset('water', {
+		anchorX: 0.5,
+		anchorY: 0.5
+	});
+	self.placed = false;
+	return self;
+});
+
+/**** 
 * Initialize Game
-****/
+****/ 
 var game = new LK.Game({
-	backgroundColor: 0x000000
-});
\ No newline at end of file
+	backgroundColor: 0x87CEEB
+});
+
+/**** 
+* Game Code
+****/ 
+var gameBackground = game.attachAsset('background', {
+	x: 0,
+	y: 0
+});
+var selectedTool = 'mountain';
+var toolButtons = [];
+var mountains = [];
+var waterSources = [];
+var trees = [];
+var animals = [];
+var magnifyingGlass = null;
+var ecosystemTimer = 0;
+var tools = ['mountain', 'water', 'tree', 'axe', 'magnify', 'camera'];
+function selectTool(toolType) {
+	selectedTool = toolType;
+	for (var i = 0; i < toolButtons.length; i++) {
+		toolButtons[i].setSelected(toolButtons[i].toolType === toolType);
+	}
+	if (magnifyingGlass) {
+		magnifyingGlass.active = toolType === 'magnify';
+	}
+}
+function createToolbar() {
+	var startX = 200;
+	var startY = 100;
+	var spacing = 160;
+	for (var i = 0; i < tools.length; i++) {
+		var toolButton = new ToolButton(tools[i]);
+		toolButton.x = startX + i * spacing;
+		toolButton.y = startY;
+		toolButtons.push(toolButton);
+		LK.gui.addChild(toolButton);
+	}
+	selectTool('mountain');
+}
+function placeMountain(x, y) {
+	var mountain = new Mountain();
+	mountain.x = x;
+	mountain.y = y;
+	mountain.placed = true;
+	mountains.push(mountain);
+	game.addChild(mountain);
+	LK.getSound('place').play();
+}
+function placeWater(x, y) {
+	var water = new Water();
+	water.x = x;
+	water.y = y;
+	water.placed = true;
+	waterSources.push(water);
+	game.addChild(water);
+	LK.getSound('place').play();
+}
+function placeTree(x, y) {
+	var tree = new Tree();
+	tree.x = x;
+	tree.y = y;
+	tree.placed = true;
+	trees.push(tree);
+	game.addChild(tree);
+	LK.getSound('place').play();
+}
+function spawnAnimal() {
+	if (animals.length < 8) {
+		var animal = new Animal();
+		animal.x = Math.random() * 1800 + 124;
+		animal.y = Math.random() * 1800 + 600;
+		animals.push(animal);
+		game.addChild(animal);
+	}
+}
+function removeElementAt(x, y) {
+	var removed = false;
+	for (var i = mountains.length - 1; i >= 0; i--) {
+		var mountain = mountains[i];
+		var dx = Math.abs(mountain.x - x);
+		var dy = Math.abs(mountain.y - y);
+		if (dx < 100 && dy < 80) {
+			mountain.destroy();
+			mountains.splice(i, 1);
+			removed = true;
+			break;
+		}
+	}
+	if (!removed) {
+		for (var i = waterSources.length - 1; i >= 0; i--) {
+			var water = waterSources[i];
+			var dx = Math.abs(water.x - x);
+			var dy = Math.abs(water.y - y);
+			if (dx < 50 && dy < 50) {
+				water.destroy();
+				waterSources.splice(i, 1);
+				removed = true;
+				break;
+			}
+		}
+	}
+	if (!removed) {
+		for (var i = trees.length - 1; i >= 0; i--) {
+			var tree = trees[i];
+			var dx = Math.abs(tree.x - x);
+			var dy = Math.abs(tree.y - y);
+			if (dx < 40 && dy < 60) {
+				tree.destroy();
+				trees.splice(i, 1);
+				removed = true;
+				break;
+			}
+		}
+	}
+	if (removed) {
+		LK.getSound('remove').play();
+	}
+}
+function discoverAnimals(x, y) {
+	for (var i = 0; i < animals.length; i++) {
+		var animal = animals[i];
+		var dx = Math.abs(animal.x - x);
+		var dy = Math.abs(animal.y - y);
+		if (dx < 150 && dy < 150) {
+			animal.discovered = true;
+		}
+	}
+}
+function takeScreenshot() {
+	LK.getSound('camera').play();
+	LK.effects.flashScreen(0xFFFFFF, 200);
+}
+createToolbar();
+magnifyingGlass = new MagnifyingGlass();
+magnifyingGlass.x = 1024;
+magnifyingGlass.y = 1366;
+game.addChild(magnifyingGlass);
+game.down = function (x, y, obj) {
+	if (y < 200) return;
+	if (selectedTool === 'mountain') {
+		placeMountain(x, y);
+	} else if (selectedTool === 'water') {
+		placeWater(x, y);
+	} else if (selectedTool === 'tree') {
+		placeTree(x, y);
+	} else if (selectedTool === 'axe') {
+		removeElementAt(x, y);
+	} else if (selectedTool === 'magnify') {
+		discoverAnimals(x, y);
+		magnifyingGlass.x = x;
+		magnifyingGlass.y = y;
+	} else if (selectedTool === 'camera') {
+		takeScreenshot();
+	}
+};
+game.update = function () {
+	ecosystemTimer++;
+	if (ecosystemTimer % 600 === 0) {
+		var habitatScore = mountains.length + waterSources.length + trees.length;
+		if (habitatScore > 2) {
+			spawnAnimal();
+		}
+	}
+	for (var i = animals.length - 1; i >= 0; i--) {
+		var animal = animals[i];
+		if (animal.x < 0 || animal.x > 2048 || animal.y < 500 || animal.y > 2732) {
+			animal.x = Math.random() * 1800 + 124;
+			animal.y = Math.random() * 1800 + 600;
+		}
+	}
+};
\ No newline at end of file