User prompt
make the plant, pot and table lamp more realistic
User prompt
Remove the laws button
User prompt
enlarge control buttons
User prompt
Finally, there will be a table lamp next to both plants. The light from the first plant's table lamp will change to purple, green, and yellow. The green plant will be small, the yellow plant will be medium, and the purple plant will be large. The second plant's table lamp will turn purple. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Also, the water level and the amount of light will be proportional. If any of them are zero, the plant will not grow at all. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
The second plant will be the largest plant it needs to be, meaning it will receive the most sunlight and water and will remain stable.
User prompt
We will also change the light. As the light intensity increases, the plant will grow. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Plant Growth Experiment
Initial prompt
I want to design an experiment game. We will have two plants in two pots. We will be able to change the amount of water for these plants. By increasing the amount of water, the first plant will grow larger, but we can only change the properties of the second plant. The properties of the first plant will remain the same.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var ControlPanel = Container.expand(function () {
var self = Container.call(this);
// Lamp color controls only
self.lampGreenBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
y: 0,
tint: 0x32cd32
});
self.lampYellowBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
y: 60,
tint: 0xffd700
});
self.lampPurpleBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
y: 120,
tint: 0x9932cc
});
self.onLampColorChange = null;
self.lampGreenBtn.down = function () {
if (self.onLampColorChange) self.onLampColorChange(0x32cd32);
};
self.lampYellowBtn.down = function () {
if (self.onLampColorChange) self.onLampColorChange(0xffd700);
};
self.lampPurpleBtn.down = function () {
if (self.onLampColorChange) self.onLampColorChange(0x9932cc);
};
return self;
});
var JanIngenhouzExperiment = Container.expand(function () {
var self = Container.call(this);
// Time of day state: 'morning', 'noon', 'night'
self.timeOfDay = 'morning';
// Create sun in upper left corner
self.sun = self.attachAsset('sun', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
self.sun.x = 200;
self.sun.y = 300;
// Create time control buttons
self.morningBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1,
tint: 0xffa500
});
self.morningBtn.x = 600;
self.morningBtn.y = 500;
self.noonBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1,
tint: 0xffff00
});
self.noonBtn.x = 800;
self.noonBtn.y = 500;
self.nightBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1,
tint: 0x2c3e50
});
self.nightBtn.x = 1000;
self.nightBtn.y = 500;
// Create glass beaker using the glassbeaker image asset - positioned at bottom and made larger
self.glassContainer = self.attachAsset('glassbeaker', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 12,
scaleY: 12
});
self.glassContainer.x = 1024;
self.glassContainer.y = 2200;
// Create water fill inside the glass beaker
self.water = self.attachAsset('waterDrop', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 18,
scaleY: 15,
tint: 0x87CEEB,
alpha: 0.6
});
self.water.x = 1024;
self.water.y = 2200;
// Create plant using plant2 image asset positioned at bottom of glass beaker
self.plant = self.attachAsset('plant2', {
anchorX: 0.5,
anchorY: 1,
scaleX: 4,
scaleY: 4
});
self.plant.x = 1024;
self.plant.y = 2400;
// Set time of day function
self.setTimeOfDay = function (time) {
self.timeOfDay = time;
// Update sun appearance based on time
if (time === 'morning') {
tween(self.sun, {
alpha: 0.7,
tint: 0xffa500,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 1000,
easing: tween.easeOut
});
} else if (time === 'noon') {
tween(self.sun, {
alpha: 1.0,
tint: 0xffff00,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 1000,
easing: tween.easeOut
});
} else if (time === 'night') {
tween(self.sun, {
alpha: 0.2,
tint: 0x2c3e50,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 1000,
easing: tween.easeOut
});
}
};
// Button event handlers
self.morningBtn.down = function () {
self.setTimeOfDay('morning');
};
self.noonBtn.down = function () {
self.setTimeOfDay('noon');
};
self.nightBtn.down = function () {
self.setTimeOfDay('night');
};
// Create oxygen bubbles periodically
self.bubbles = [];
self.bubbleTimer = 0;
self.update = function () {
self.bubbleTimer++;
// Determine bubble production rate based on time of day
var bubbleRate = 0;
if (self.timeOfDay === 'morning') {
bubbleRate = 180; // Few bubbles - every 3 seconds
} else if (self.timeOfDay === 'noon') {
bubbleRate = 45; // Many bubbles - every 0.75 seconds
} else if (self.timeOfDay === 'night') {
bubbleRate = 0; // No bubbles
}
// Create oxygen bubbles based on time of day
if (bubbleRate > 0 && self.bubbleTimer % bubbleRate === 0) {
var bubble = LK.getAsset('waterDrop', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 + (Math.random() - 0.5) * 150,
y: 2350,
tint: 0x87CEEB,
scaleX: 0.8,
scaleY: 0.8
});
self.bubbles.push(bubble);
self.addChild(bubble);
// Animate bubble rising
tween(bubble, {
y: bubble.y - 800,
alpha: 0
}, {
duration: 3000,
easing: tween.easeOut,
onFinish: function onFinish() {
bubble.destroy();
}
});
}
// Clean up old bubbles
for (var i = self.bubbles.length - 1; i >= 0; i--) {
if (self.bubbles[i].alpha <= 0) {
self.bubbles.splice(i, 1);
}
}
};
return self;
});
var LightSlider = Container.expand(function () {
var self = Container.call(this);
self.value = 0;
self.isDragging = false;
var track = self.attachAsset('sliderTrack', {
anchorX: 0.5,
anchorY: 0.5
});
self.handle = self.attachAsset('sliderHandle', {
anchorX: 0.5,
anchorY: 0.5,
x: -180
});
self.lightBulb = self.attachAsset('lightBulb', {
anchorX: 0.5,
anchorY: 0.5,
x: -220,
y: 0
});
self.updateHandle = function () {
self.handle.x = -180 + self.value * 360;
// Update light bulb brightness based on value
var brightness = 0.3 + self.value * 0.7;
self.lightBulb.alpha = brightness;
tween(self.lightBulb, {
scaleX: 1 + self.value * 0.3,
scaleY: 1 + self.value * 0.3
}, {
duration: 200
});
};
self.setValue = function (value) {
self.value = Math.max(0, Math.min(1, value));
self.updateHandle();
};
self.down = function (x, y, obj) {
self.isDragging = true;
var localX = x + 180;
self.setValue(localX / 360);
};
self.onValueChange = null;
self.update = function () {
if (self.isDragging && self.onValueChange) {
self.onValueChange(self.value);
}
};
return self;
});
var Plant = Container.expand(function (isAutomatic) {
var self = Container.call(this);
// Plant properties
self.isAutomatic = isAutomatic || false;
self.waterLevel = 0;
self.lightLevel = 0;
self.size = 1;
self.leafColor = 0x32CD32;
self.leafCount = 2;
self.lampColor = 0xffd700; // Default yellow
// Create plant components
var pot = self.attachAsset('pot', {
anchorX: 0.5,
anchorY: 1,
alpha: 0.3
});
var soil = self.attachAsset('soil', {
anchorX: 0.5,
anchorY: 1,
y: -20
});
self.stem = self.attachAsset('stem', {
anchorX: 0.5,
anchorY: 1,
y: -20
});
self.leaves = [];
// Add table lamp
self.tableLamp = self.addChild(new TableLamp());
self.tableLamp.x = -200;
self.tableLamp.y = -100;
self.createLeaves = function () {
// Remove existing leaves
for (var i = 0; i < self.leaves.length; i++) {
self.leaves[i].destroy();
}
self.leaves = [];
// Create new leaves
for (var i = 0; i < self.leafCount; i++) {
var leaf = self.attachAsset('leaf', {
anchorX: 0.5,
anchorY: 0.5,
tint: self.leafColor
});
var angle = i / self.leafCount * Math.PI * 2;
leaf.x = Math.cos(angle) * 30;
leaf.y = -80 + Math.sin(angle) * 10;
leaf.rotation = angle;
self.leaves.push(leaf);
}
};
self.createLeaves();
self.updatePlant = function () {
if (self.isAutomatic) {
// Base growth from water alone (reduced), plus bonus from light
var baseGrowth = self.waterLevel * 0.3; // Plant grows with water alone but less
var lightBonus = self.waterLevel * self.lightLevel * 0.7; // Additional growth with light
var growthFactor = baseGrowth + lightBonus;
var targetSize = 0.1; // Seed size when no growth
// Determine size based on lamp color
if (self.lampColor === 0x32cd32) {
// Green - smallest max size
targetSize = 0.1 + growthFactor * 1.4; // Small
self.tableLamp.setLampColor(0x32cd32);
} else if (self.lampColor === 0xffd700) {
// Yellow - medium max size
targetSize = 0.1 + growthFactor * 2.1; // Medium
self.tableLamp.setLampColor(0xffd700);
} else if (self.lampColor === 0x9932cc) {
// Purple - matches right plant when at 100% water and light
targetSize = 0.1 + growthFactor * 2.8; // Large - matches controlledPlant size 3.0
self.tableLamp.setLampColor(0x9932cc);
}
// Smooth transition to new size with tween
tween(self, {
size: targetSize
}, {
duration: 800,
easing: tween.easeOut
});
}
// Animate plant components with smooth transitions
tween(self.stem, {
scaleY: self.size,
scaleX: Math.max(0.5, self.size * 0.8)
}, {
duration: 600,
easing: tween.easeOut
});
for (var i = 0; i < self.leaves.length; i++) {
var leaf = self.leaves[i];
var targetY = -60 - self.size * 30 + Math.sin(i / self.leafCount * Math.PI * 2) * 10;
tween(leaf, {
scaleX: self.size,
scaleY: self.size,
y: targetY
}, {
duration: 600,
easing: tween.easeOut
});
leaf.tint = self.leafColor;
}
};
self.setWaterLevel = function (level) {
self.waterLevel = Math.max(0, Math.min(1, level));
self.updatePlant();
};
self.setLightLevel = function (level) {
self.lightLevel = Math.max(0, Math.min(1, level));
self.updatePlant();
};
self.setSize = function (size) {
if (!self.isAutomatic) {
self.size = Math.max(0.3, Math.min(3, size));
self.updatePlant();
}
};
self.setLeafColor = function (color) {
if (!self.isAutomatic) {
self.leafColor = color;
self.updatePlant();
}
};
self.setLeafCount = function (count) {
if (!self.isAutomatic) {
self.leafCount = Math.max(1, Math.min(8, count));
self.createLeaves();
self.updatePlant();
}
};
self.setLampColor = function (color) {
self.lampColor = color;
if (self.tableLamp) {
self.tableLamp.setLampColor(color);
}
self.updatePlant();
};
self.wipeLeaf = function (leafIndex) {
if (leafIndex >= 0 && leafIndex < self.leaves.length) {
var leaf = self.leaves[leafIndex];
// Create wiping animation - scale down and fade out briefly
tween(leaf, {
scaleX: leaf.scaleX * 0.8,
scaleY: leaf.scaleY * 0.8,
alpha: 0.5
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
// Scale back up and fade in to show clean leaf
tween(leaf, {
scaleX: self.size,
scaleY: self.size,
alpha: 1.0,
tint: 0x32ff32 // Brighter green to show cleanliness
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// Fade back to normal color after a moment
tween(leaf, {
tint: self.leafColor
}, {
duration: 1000,
easing: tween.easeOut
});
}
});
}
});
}
};
// Add down event handler for leaf wiping
self.down = function (x, y, obj) {
// Check if click is on any leaf
for (var i = 0; i < self.leaves.length; i++) {
var leaf = self.leaves[i];
var leafGlobalPos = leaf.parent.toGlobal(leaf.position);
var distance = Math.sqrt(Math.pow(leafGlobalPos.x - x, 2) + Math.pow(leafGlobalPos.y - y, 2));
// If click is within leaf radius (approximately 50 pixels when scaled)
if (distance < 50 * leaf.scaleX) {
self.wipeLeaf(i);
break;
}
}
};
return self;
});
var StartScreen = Container.expand(function () {
var self = Container.call(this);
// Create semi-transparent background
var background = self.attachAsset('soil', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 10,
scaleY: 50,
alpha: 0.8,
tint: 0x2C3E50
});
background.x = 1024;
background.y = 1366;
// Create title
var titleText = new Text2('Photosynthesis Experiments', {
size: 100,
fill: 0x27AE60
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 700;
self.addChild(titleText);
// Create first option button - Plant Growing Experience
self.plantGrowingButton = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 2,
tint: 0x27AE60
});
self.plantGrowingButton.x = 1024;
self.plantGrowingButton.y = 1100;
// Plant Growing button text
var plantGrowingText = new Text2('Plant Growing\nExperience', {
size: 50,
fill: 0xFFFFFF
});
plantGrowingText.anchor.set(0.5, 0.5);
plantGrowingText.x = 1024;
plantGrowingText.y = 1100;
self.addChild(plantGrowingText);
// Create second option button - Jan Ingenhousz Experience
self.janIngenhouzButton = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 2,
tint: 0x3498DB
});
self.janIngenhouzButton.x = 1024;
self.janIngenhouzButton.y = 1400;
// Jan Ingenhousz button text
var janIngenhouzText = new Text2('Jan Ingenhousz\nExperience', {
size: 50,
fill: 0xFFFFFF
});
janIngenhouzText.anchor.set(0.5, 0.5);
janIngenhouzText.x = 1024;
janIngenhouzText.y = 1400;
self.addChild(janIngenhouzText);
// Instructions text
var instructText = new Text2('Choose your photosynthesis experiment:', {
size: 45,
fill: 0xFFFFFF
});
instructText.anchor.set(0.5, 0.5);
instructText.x = 1024;
instructText.y = 900;
self.addChild(instructText);
// Plant Growing button handler
self.plantGrowingButton.down = function () {
if (self.onModeSelected) {
self.onModeSelected('plantGrowing');
}
};
// Jan Ingenhousz button handler
self.janIngenhouzButton.down = function () {
if (self.onModeSelected) {
self.onModeSelected('janIngenhousz');
}
};
self.onModeSelected = null;
return self;
});
var TableLamp = Container.expand(function () {
var self = Container.call(this);
// Create lamp components
self.base = self.attachAsset('lampBase', {
anchorX: 0.5,
anchorY: 1
});
self.lamp = self.attachAsset('tableLamp', {
anchorX: 0.5,
anchorY: 1,
y: -20
});
self.setLampColor = function (color) {
tween(self.lamp, {
tint: color
}, {
duration: 500,
easing: tween.easeOut
});
};
return self;
});
var WaterSlider = Container.expand(function () {
var self = Container.call(this);
self.value = 0;
self.isDragging = false;
var track = self.attachAsset('sliderTrack', {
anchorX: 0.5,
anchorY: 0.5
});
self.handle = self.attachAsset('sliderHandle', {
anchorX: 0.5,
anchorY: 0.5,
x: -180
});
self.updateHandle = function () {
self.handle.x = -180 + self.value * 360;
};
self.setValue = function (value) {
self.value = Math.max(0, Math.min(1, value));
self.updateHandle();
};
self.down = function (x, y, obj) {
self.isDragging = true;
var localX = x + 180;
self.setValue(localX / 360);
};
self.onValueChange = null;
self.update = function () {
if (self.isDragging && self.onValueChange) {
self.onValueChange(self.value);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state management
var gameState = 'start'; // 'start' or 'playing'
var startScreen = null;
// No laws button found to remove - the code remains unchanged
var automaticPlant = new Plant(true);
automaticPlant.x = 600;
automaticPlant.y = 1800;
game.addChild(automaticPlant);
var controlledPlant = new Plant(false);
controlledPlant.x = 1400;
controlledPlant.y = 1800;
// Set second plant to maximum size with optimal conditions
controlledPlant.setWaterLevel(1.0); // Maximum water
controlledPlant.setLightLevel(1.0); // Maximum light
controlledPlant.setSize(3.0); // Set to largest possible size
game.addChild(controlledPlant);
// Create water slider
var waterSlider = new WaterSlider();
waterSlider.x = 1024;
waterSlider.y = 2200;
game.addChild(waterSlider);
// Create light slider
var lightSlider = new LightSlider();
lightSlider.x = 1024;
lightSlider.y = 2450;
game.addChild(lightSlider);
// Create control panel for second plant
var controlPanel = new ControlPanel();
controlPanel.x = 1750;
controlPanel.y = 1200;
game.addChild(controlPanel);
// Create labels
var titleText = new Text2('Plant Growth Experiment', {
size: 80,
fill: 0x2C3E50
});
titleText.anchor.set(0.5, 0);
titleText.x = 1024;
titleText.y = 100;
game.addChild(titleText);
var autoLabel = new Text2('Automatic Plant', {
size: 50,
fill: 0x27AE60
});
autoLabel.anchor.set(0.5, 0);
autoLabel.x = 600;
autoLabel.y = 1850;
game.addChild(autoLabel);
var controlLabel = new Text2('Controlled Plant', {
size: 50,
fill: 0xE67E22
});
controlLabel.anchor.set(0.5, 0);
controlLabel.x = 1400;
controlLabel.y = 1850;
game.addChild(controlLabel);
var waterLabel = new Text2('Water Level', {
size: 40,
fill: 0x34495E
});
waterLabel.anchor.set(0.5, 0);
waterLabel.x = 1024;
waterLabel.y = 2300;
game.addChild(waterLabel);
var lightLabel = new Text2('Light Level', {
size: 40,
fill: 0x34495E
});
lightLabel.anchor.set(0.5, 0);
lightLabel.x = 1024;
lightLabel.y = 2550;
game.addChild(lightLabel);
var controlsLabel = new Text2('Controls', {
size: 40,
fill: 0x34495E
});
controlsLabel.anchor.set(0.5, 0);
controlsLabel.x = 1750;
controlsLabel.y = 1000;
game.addChild(controlsLabel);
// Lamp color button labels only
var lampGreenLabel = new Text2('Green', {
size: 36,
fill: 0xFFFFFF
});
lampGreenLabel.anchor.set(0.5, 0.5);
lampGreenLabel.x = 1750;
lampGreenLabel.y = 1200;
game.addChild(lampGreenLabel);
var lampYellowLabel = new Text2('Yellow', {
size: 36,
fill: 0xFFFFFF
});
lampYellowLabel.anchor.set(0.5, 0.5);
lampYellowLabel.x = 1750;
lampYellowLabel.y = 1260;
game.addChild(lampYellowLabel);
var lampPurpleLabel = new Text2('Purple', {
size: 36,
fill: 0xFFFFFF
});
lampPurpleLabel.anchor.set(0.5, 0.5);
lampPurpleLabel.x = 1750;
lampPurpleLabel.y = 1320;
game.addChild(lampPurpleLabel);
// Water level display
var waterLevelText = new Text2('0%', {
size: 60,
fill: 0x2980B9
});
waterLevelText.anchor.set(0.5, 0);
waterLevelText.x = 1024;
waterLevelText.y = 2350;
game.addChild(waterLevelText);
// Light level display
var lightLevelText = new Text2('0%', {
size: 60,
fill: 0xFFD700
});
lightLevelText.anchor.set(0.5, 0);
lightLevelText.x = 1024;
lightLevelText.y = 2600;
game.addChild(lightLevelText);
// Initialize sliders to zero position for seed state
waterSlider.setValue(0.0);
lightSlider.setValue(0.0);
// Create and show start screen initially
startScreen = new StartScreen();
game.addChild(startScreen);
// Hide game elements initially
automaticPlant.visible = false;
controlledPlant.visible = false;
waterSlider.visible = false;
lightSlider.visible = false;
controlPanel.visible = false;
titleText.visible = false;
autoLabel.visible = false;
controlLabel.visible = false;
waterLabel.visible = false;
lightLabel.visible = false;
controlsLabel.visible = false;
lampGreenLabel.visible = false;
lampYellowLabel.visible = false;
lampPurpleLabel.visible = false;
waterLevelText.visible = false;
lightLevelText.visible = false;
// Add Jan Ingenhousz experiment
var janIngenhouzExperiment = new JanIngenhouzExperiment();
game.addChild(janIngenhouzExperiment);
janIngenhouzExperiment.visible = false;
// Create labels for Jan Ingenhousz time controls
var janTimeLabel = new Text2('Time of Day:', {
size: 50,
fill: 0x2C3E50
});
janTimeLabel.anchor.set(0.5, 0);
janTimeLabel.x = 800;
janTimeLabel.y = 400;
game.addChild(janTimeLabel);
janTimeLabel.visible = false;
var janMorningLabel = new Text2('Morning\n(Few bubbles)', {
size: 30,
fill: 0xFFFFFF
});
janMorningLabel.anchor.set(0.5, 0.5);
janMorningLabel.x = 600;
janMorningLabel.y = 500;
game.addChild(janMorningLabel);
janMorningLabel.visible = false;
var janNoonLabel = new Text2('Noon\n(Many bubbles)', {
size: 30,
fill: 0xFFFFFF
});
janNoonLabel.anchor.set(0.5, 0.5);
janNoonLabel.x = 800;
janNoonLabel.y = 500;
game.addChild(janNoonLabel);
janNoonLabel.visible = false;
var janNightLabel = new Text2('Night\n(No bubbles)', {
size: 30,
fill: 0xFFFFFF
});
janNightLabel.anchor.set(0.5, 0.5);
janNightLabel.x = 1000;
janNightLabel.y = 500;
game.addChild(janNightLabel);
janNightLabel.visible = false;
// Start screen mode selection handler
startScreen.onModeSelected = function (mode) {
gameState = 'playing';
// Hide start screen with fade out animation
tween(startScreen, {
alpha: 0
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
startScreen.visible = false;
if (mode === 'plantGrowing') {
// Show plant growing experiment elements
automaticPlant.visible = true;
controlledPlant.visible = true;
waterSlider.visible = true;
lightSlider.visible = true;
controlPanel.visible = true;
titleText.visible = true;
autoLabel.visible = true;
controlLabel.visible = true;
waterLabel.visible = true;
lightLabel.visible = true;
controlsLabel.visible = true;
lampGreenLabel.visible = true;
lampYellowLabel.visible = true;
lampPurpleLabel.visible = true;
waterLevelText.visible = true;
lightLevelText.visible = true;
// Hide Jan Ingenhousz labels
janTimeLabel.visible = false;
janMorningLabel.visible = false;
janNoonLabel.visible = false;
janNightLabel.visible = false;
// Fade in plant growing elements
var elementsToFade = [automaticPlant, controlledPlant, waterSlider, lightSlider, controlPanel, titleText, autoLabel, controlLabel, waterLabel, lightLabel, controlsLabel, lampGreenLabel, lampYellowLabel, lampPurpleLabel, waterLevelText, lightLevelText];
for (var i = 0; i < elementsToFade.length; i++) {
elementsToFade[i].alpha = 0;
tween(elementsToFade[i], {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
}
} else if (mode === 'janIngenhousz') {
// Show Jan Ingenhousz experiment
janIngenhouzExperiment.visible = true;
janIngenhouzExperiment.alpha = 0;
tween(janIngenhouzExperiment, {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
// Show time control labels
janMorningLabel.visible = true;
janNoonLabel.visible = true;
janNightLabel.visible = true;
janTimeLabel.visible = true;
janMorningLabel.alpha = 0;
janNoonLabel.alpha = 0;
janNightLabel.alpha = 0;
janTimeLabel.alpha = 0;
tween(janMorningLabel, {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
tween(janNoonLabel, {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
tween(janNightLabel, {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
tween(janTimeLabel, {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
}
}
});
};
// Set initial plant states - automatic plant starts as seed
automaticPlant.setWaterLevel(0.0); // Start with no water
automaticPlant.setLightLevel(0.0); // Start with no light
automaticPlant.size = 0.1; // Start as just a seed
automaticPlant.updatePlant(); // Update to reflect seed state
automaticPlant.setLampColor(0x32cd32); // Start with green lamp for small size
controlledPlant.setLampColor(0x9932cc); // Set controlled plant lamp to purple
// Variables for tracking
var dragNode = null;
var currentWaterLevel = 0.0; // Start with no water for seed state
var currentLightLevel = 0.0; // Start with no light for seed state
// Event handlers
waterSlider.onValueChange = function (value) {
currentWaterLevel = value;
automaticPlant.setWaterLevel(value);
controlledPlant.setWaterLevel(value);
waterLevelText.setText(Math.round(value * 100) + '%');
};
lightSlider.onValueChange = function (value) {
currentLightLevel = value;
automaticPlant.setLightLevel(value);
controlledPlant.setLightLevel(value);
lightLevelText.setText(Math.round(value * 100) + '%');
};
controlPanel.onLampColorChange = function (color) {
automaticPlant.setLampColor(color);
};
// Game move handler for slider dragging
game.move = function (x, y, obj) {
if (waterSlider.isDragging) {
var localPos = waterSlider.toLocal({
x: x,
y: y
});
var newValue = (localPos.x + 180) / 360;
waterSlider.setValue(newValue);
waterSlider.onValueChange(waterSlider.value);
}
if (lightSlider.isDragging) {
var localPos = lightSlider.toLocal({
x: x,
y: y
});
var newValue = (localPos.x + 180) / 360;
lightSlider.setValue(newValue);
lightSlider.onValueChange(lightSlider.value);
}
};
game.up = function (x, y, obj) {
waterSlider.isDragging = false;
lightSlider.isDragging = false;
};
// Create some water drops for visual effect
var waterDrops = [];
var dropTimer = 0;
game.update = function () {
dropTimer++;
// Create water drops periodically if water level > 0
if (currentWaterLevel > 0.1 && dropTimer % 60 == 0) {
for (var i = 0; i < 3; i++) {
var drop = LK.getAsset('waterDrop', {
anchorX: 0.5,
anchorY: 0.5,
x: 800 + Math.random() * 500,
y: 400 + Math.random() * 200
});
drop.speedY = 2 + Math.random() * 3;
drop.alpha = 0.7;
waterDrops.push(drop);
game.addChild(drop);
// Fade and animate the drop
tween(drop, {
y: drop.y + 200,
alpha: 0
}, {
duration: 2000,
onFinish: function onFinish() {
drop.destroy();
}
});
}
// Clean up old drops
for (var j = waterDrops.length - 1; j >= 0; j--) {
if (waterDrops[j].alpha <= 0) {
waterDrops.splice(j, 1);
}
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var ControlPanel = Container.expand(function () {
var self = Container.call(this);
// Lamp color controls only
self.lampGreenBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
y: 0,
tint: 0x32cd32
});
self.lampYellowBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
y: 60,
tint: 0xffd700
});
self.lampPurpleBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
y: 120,
tint: 0x9932cc
});
self.onLampColorChange = null;
self.lampGreenBtn.down = function () {
if (self.onLampColorChange) self.onLampColorChange(0x32cd32);
};
self.lampYellowBtn.down = function () {
if (self.onLampColorChange) self.onLampColorChange(0xffd700);
};
self.lampPurpleBtn.down = function () {
if (self.onLampColorChange) self.onLampColorChange(0x9932cc);
};
return self;
});
var JanIngenhouzExperiment = Container.expand(function () {
var self = Container.call(this);
// Time of day state: 'morning', 'noon', 'night'
self.timeOfDay = 'morning';
// Create sun in upper left corner
self.sun = self.attachAsset('sun', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
self.sun.x = 200;
self.sun.y = 300;
// Create time control buttons
self.morningBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1,
tint: 0xffa500
});
self.morningBtn.x = 600;
self.morningBtn.y = 500;
self.noonBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1,
tint: 0xffff00
});
self.noonBtn.x = 800;
self.noonBtn.y = 500;
self.nightBtn = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1,
tint: 0x2c3e50
});
self.nightBtn.x = 1000;
self.nightBtn.y = 500;
// Create glass beaker using the glassbeaker image asset - positioned at bottom and made larger
self.glassContainer = self.attachAsset('glassbeaker', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 12,
scaleY: 12
});
self.glassContainer.x = 1024;
self.glassContainer.y = 2200;
// Create water fill inside the glass beaker
self.water = self.attachAsset('waterDrop', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 18,
scaleY: 15,
tint: 0x87CEEB,
alpha: 0.6
});
self.water.x = 1024;
self.water.y = 2200;
// Create plant using plant2 image asset positioned at bottom of glass beaker
self.plant = self.attachAsset('plant2', {
anchorX: 0.5,
anchorY: 1,
scaleX: 4,
scaleY: 4
});
self.plant.x = 1024;
self.plant.y = 2400;
// Set time of day function
self.setTimeOfDay = function (time) {
self.timeOfDay = time;
// Update sun appearance based on time
if (time === 'morning') {
tween(self.sun, {
alpha: 0.7,
tint: 0xffa500,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 1000,
easing: tween.easeOut
});
} else if (time === 'noon') {
tween(self.sun, {
alpha: 1.0,
tint: 0xffff00,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 1000,
easing: tween.easeOut
});
} else if (time === 'night') {
tween(self.sun, {
alpha: 0.2,
tint: 0x2c3e50,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 1000,
easing: tween.easeOut
});
}
};
// Button event handlers
self.morningBtn.down = function () {
self.setTimeOfDay('morning');
};
self.noonBtn.down = function () {
self.setTimeOfDay('noon');
};
self.nightBtn.down = function () {
self.setTimeOfDay('night');
};
// Create oxygen bubbles periodically
self.bubbles = [];
self.bubbleTimer = 0;
self.update = function () {
self.bubbleTimer++;
// Determine bubble production rate based on time of day
var bubbleRate = 0;
if (self.timeOfDay === 'morning') {
bubbleRate = 180; // Few bubbles - every 3 seconds
} else if (self.timeOfDay === 'noon') {
bubbleRate = 45; // Many bubbles - every 0.75 seconds
} else if (self.timeOfDay === 'night') {
bubbleRate = 0; // No bubbles
}
// Create oxygen bubbles based on time of day
if (bubbleRate > 0 && self.bubbleTimer % bubbleRate === 0) {
var bubble = LK.getAsset('waterDrop', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 + (Math.random() - 0.5) * 150,
y: 2350,
tint: 0x87CEEB,
scaleX: 0.8,
scaleY: 0.8
});
self.bubbles.push(bubble);
self.addChild(bubble);
// Animate bubble rising
tween(bubble, {
y: bubble.y - 800,
alpha: 0
}, {
duration: 3000,
easing: tween.easeOut,
onFinish: function onFinish() {
bubble.destroy();
}
});
}
// Clean up old bubbles
for (var i = self.bubbles.length - 1; i >= 0; i--) {
if (self.bubbles[i].alpha <= 0) {
self.bubbles.splice(i, 1);
}
}
};
return self;
});
var LightSlider = Container.expand(function () {
var self = Container.call(this);
self.value = 0;
self.isDragging = false;
var track = self.attachAsset('sliderTrack', {
anchorX: 0.5,
anchorY: 0.5
});
self.handle = self.attachAsset('sliderHandle', {
anchorX: 0.5,
anchorY: 0.5,
x: -180
});
self.lightBulb = self.attachAsset('lightBulb', {
anchorX: 0.5,
anchorY: 0.5,
x: -220,
y: 0
});
self.updateHandle = function () {
self.handle.x = -180 + self.value * 360;
// Update light bulb brightness based on value
var brightness = 0.3 + self.value * 0.7;
self.lightBulb.alpha = brightness;
tween(self.lightBulb, {
scaleX: 1 + self.value * 0.3,
scaleY: 1 + self.value * 0.3
}, {
duration: 200
});
};
self.setValue = function (value) {
self.value = Math.max(0, Math.min(1, value));
self.updateHandle();
};
self.down = function (x, y, obj) {
self.isDragging = true;
var localX = x + 180;
self.setValue(localX / 360);
};
self.onValueChange = null;
self.update = function () {
if (self.isDragging && self.onValueChange) {
self.onValueChange(self.value);
}
};
return self;
});
var Plant = Container.expand(function (isAutomatic) {
var self = Container.call(this);
// Plant properties
self.isAutomatic = isAutomatic || false;
self.waterLevel = 0;
self.lightLevel = 0;
self.size = 1;
self.leafColor = 0x32CD32;
self.leafCount = 2;
self.lampColor = 0xffd700; // Default yellow
// Create plant components
var pot = self.attachAsset('pot', {
anchorX: 0.5,
anchorY: 1,
alpha: 0.3
});
var soil = self.attachAsset('soil', {
anchorX: 0.5,
anchorY: 1,
y: -20
});
self.stem = self.attachAsset('stem', {
anchorX: 0.5,
anchorY: 1,
y: -20
});
self.leaves = [];
// Add table lamp
self.tableLamp = self.addChild(new TableLamp());
self.tableLamp.x = -200;
self.tableLamp.y = -100;
self.createLeaves = function () {
// Remove existing leaves
for (var i = 0; i < self.leaves.length; i++) {
self.leaves[i].destroy();
}
self.leaves = [];
// Create new leaves
for (var i = 0; i < self.leafCount; i++) {
var leaf = self.attachAsset('leaf', {
anchorX: 0.5,
anchorY: 0.5,
tint: self.leafColor
});
var angle = i / self.leafCount * Math.PI * 2;
leaf.x = Math.cos(angle) * 30;
leaf.y = -80 + Math.sin(angle) * 10;
leaf.rotation = angle;
self.leaves.push(leaf);
}
};
self.createLeaves();
self.updatePlant = function () {
if (self.isAutomatic) {
// Base growth from water alone (reduced), plus bonus from light
var baseGrowth = self.waterLevel * 0.3; // Plant grows with water alone but less
var lightBonus = self.waterLevel * self.lightLevel * 0.7; // Additional growth with light
var growthFactor = baseGrowth + lightBonus;
var targetSize = 0.1; // Seed size when no growth
// Determine size based on lamp color
if (self.lampColor === 0x32cd32) {
// Green - smallest max size
targetSize = 0.1 + growthFactor * 1.4; // Small
self.tableLamp.setLampColor(0x32cd32);
} else if (self.lampColor === 0xffd700) {
// Yellow - medium max size
targetSize = 0.1 + growthFactor * 2.1; // Medium
self.tableLamp.setLampColor(0xffd700);
} else if (self.lampColor === 0x9932cc) {
// Purple - matches right plant when at 100% water and light
targetSize = 0.1 + growthFactor * 2.8; // Large - matches controlledPlant size 3.0
self.tableLamp.setLampColor(0x9932cc);
}
// Smooth transition to new size with tween
tween(self, {
size: targetSize
}, {
duration: 800,
easing: tween.easeOut
});
}
// Animate plant components with smooth transitions
tween(self.stem, {
scaleY: self.size,
scaleX: Math.max(0.5, self.size * 0.8)
}, {
duration: 600,
easing: tween.easeOut
});
for (var i = 0; i < self.leaves.length; i++) {
var leaf = self.leaves[i];
var targetY = -60 - self.size * 30 + Math.sin(i / self.leafCount * Math.PI * 2) * 10;
tween(leaf, {
scaleX: self.size,
scaleY: self.size,
y: targetY
}, {
duration: 600,
easing: tween.easeOut
});
leaf.tint = self.leafColor;
}
};
self.setWaterLevel = function (level) {
self.waterLevel = Math.max(0, Math.min(1, level));
self.updatePlant();
};
self.setLightLevel = function (level) {
self.lightLevel = Math.max(0, Math.min(1, level));
self.updatePlant();
};
self.setSize = function (size) {
if (!self.isAutomatic) {
self.size = Math.max(0.3, Math.min(3, size));
self.updatePlant();
}
};
self.setLeafColor = function (color) {
if (!self.isAutomatic) {
self.leafColor = color;
self.updatePlant();
}
};
self.setLeafCount = function (count) {
if (!self.isAutomatic) {
self.leafCount = Math.max(1, Math.min(8, count));
self.createLeaves();
self.updatePlant();
}
};
self.setLampColor = function (color) {
self.lampColor = color;
if (self.tableLamp) {
self.tableLamp.setLampColor(color);
}
self.updatePlant();
};
self.wipeLeaf = function (leafIndex) {
if (leafIndex >= 0 && leafIndex < self.leaves.length) {
var leaf = self.leaves[leafIndex];
// Create wiping animation - scale down and fade out briefly
tween(leaf, {
scaleX: leaf.scaleX * 0.8,
scaleY: leaf.scaleY * 0.8,
alpha: 0.5
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
// Scale back up and fade in to show clean leaf
tween(leaf, {
scaleX: self.size,
scaleY: self.size,
alpha: 1.0,
tint: 0x32ff32 // Brighter green to show cleanliness
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// Fade back to normal color after a moment
tween(leaf, {
tint: self.leafColor
}, {
duration: 1000,
easing: tween.easeOut
});
}
});
}
});
}
};
// Add down event handler for leaf wiping
self.down = function (x, y, obj) {
// Check if click is on any leaf
for (var i = 0; i < self.leaves.length; i++) {
var leaf = self.leaves[i];
var leafGlobalPos = leaf.parent.toGlobal(leaf.position);
var distance = Math.sqrt(Math.pow(leafGlobalPos.x - x, 2) + Math.pow(leafGlobalPos.y - y, 2));
// If click is within leaf radius (approximately 50 pixels when scaled)
if (distance < 50 * leaf.scaleX) {
self.wipeLeaf(i);
break;
}
}
};
return self;
});
var StartScreen = Container.expand(function () {
var self = Container.call(this);
// Create semi-transparent background
var background = self.attachAsset('soil', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 10,
scaleY: 50,
alpha: 0.8,
tint: 0x2C3E50
});
background.x = 1024;
background.y = 1366;
// Create title
var titleText = new Text2('Photosynthesis Experiments', {
size: 100,
fill: 0x27AE60
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 700;
self.addChild(titleText);
// Create first option button - Plant Growing Experience
self.plantGrowingButton = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 2,
tint: 0x27AE60
});
self.plantGrowingButton.x = 1024;
self.plantGrowingButton.y = 1100;
// Plant Growing button text
var plantGrowingText = new Text2('Plant Growing\nExperience', {
size: 50,
fill: 0xFFFFFF
});
plantGrowingText.anchor.set(0.5, 0.5);
plantGrowingText.x = 1024;
plantGrowingText.y = 1100;
self.addChild(plantGrowingText);
// Create second option button - Jan Ingenhousz Experience
self.janIngenhouzButton = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 2,
tint: 0x3498DB
});
self.janIngenhouzButton.x = 1024;
self.janIngenhouzButton.y = 1400;
// Jan Ingenhousz button text
var janIngenhouzText = new Text2('Jan Ingenhousz\nExperience', {
size: 50,
fill: 0xFFFFFF
});
janIngenhouzText.anchor.set(0.5, 0.5);
janIngenhouzText.x = 1024;
janIngenhouzText.y = 1400;
self.addChild(janIngenhouzText);
// Instructions text
var instructText = new Text2('Choose your photosynthesis experiment:', {
size: 45,
fill: 0xFFFFFF
});
instructText.anchor.set(0.5, 0.5);
instructText.x = 1024;
instructText.y = 900;
self.addChild(instructText);
// Plant Growing button handler
self.plantGrowingButton.down = function () {
if (self.onModeSelected) {
self.onModeSelected('plantGrowing');
}
};
// Jan Ingenhousz button handler
self.janIngenhouzButton.down = function () {
if (self.onModeSelected) {
self.onModeSelected('janIngenhousz');
}
};
self.onModeSelected = null;
return self;
});
var TableLamp = Container.expand(function () {
var self = Container.call(this);
// Create lamp components
self.base = self.attachAsset('lampBase', {
anchorX: 0.5,
anchorY: 1
});
self.lamp = self.attachAsset('tableLamp', {
anchorX: 0.5,
anchorY: 1,
y: -20
});
self.setLampColor = function (color) {
tween(self.lamp, {
tint: color
}, {
duration: 500,
easing: tween.easeOut
});
};
return self;
});
var WaterSlider = Container.expand(function () {
var self = Container.call(this);
self.value = 0;
self.isDragging = false;
var track = self.attachAsset('sliderTrack', {
anchorX: 0.5,
anchorY: 0.5
});
self.handle = self.attachAsset('sliderHandle', {
anchorX: 0.5,
anchorY: 0.5,
x: -180
});
self.updateHandle = function () {
self.handle.x = -180 + self.value * 360;
};
self.setValue = function (value) {
self.value = Math.max(0, Math.min(1, value));
self.updateHandle();
};
self.down = function (x, y, obj) {
self.isDragging = true;
var localX = x + 180;
self.setValue(localX / 360);
};
self.onValueChange = null;
self.update = function () {
if (self.isDragging && self.onValueChange) {
self.onValueChange(self.value);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state management
var gameState = 'start'; // 'start' or 'playing'
var startScreen = null;
// No laws button found to remove - the code remains unchanged
var automaticPlant = new Plant(true);
automaticPlant.x = 600;
automaticPlant.y = 1800;
game.addChild(automaticPlant);
var controlledPlant = new Plant(false);
controlledPlant.x = 1400;
controlledPlant.y = 1800;
// Set second plant to maximum size with optimal conditions
controlledPlant.setWaterLevel(1.0); // Maximum water
controlledPlant.setLightLevel(1.0); // Maximum light
controlledPlant.setSize(3.0); // Set to largest possible size
game.addChild(controlledPlant);
// Create water slider
var waterSlider = new WaterSlider();
waterSlider.x = 1024;
waterSlider.y = 2200;
game.addChild(waterSlider);
// Create light slider
var lightSlider = new LightSlider();
lightSlider.x = 1024;
lightSlider.y = 2450;
game.addChild(lightSlider);
// Create control panel for second plant
var controlPanel = new ControlPanel();
controlPanel.x = 1750;
controlPanel.y = 1200;
game.addChild(controlPanel);
// Create labels
var titleText = new Text2('Plant Growth Experiment', {
size: 80,
fill: 0x2C3E50
});
titleText.anchor.set(0.5, 0);
titleText.x = 1024;
titleText.y = 100;
game.addChild(titleText);
var autoLabel = new Text2('Automatic Plant', {
size: 50,
fill: 0x27AE60
});
autoLabel.anchor.set(0.5, 0);
autoLabel.x = 600;
autoLabel.y = 1850;
game.addChild(autoLabel);
var controlLabel = new Text2('Controlled Plant', {
size: 50,
fill: 0xE67E22
});
controlLabel.anchor.set(0.5, 0);
controlLabel.x = 1400;
controlLabel.y = 1850;
game.addChild(controlLabel);
var waterLabel = new Text2('Water Level', {
size: 40,
fill: 0x34495E
});
waterLabel.anchor.set(0.5, 0);
waterLabel.x = 1024;
waterLabel.y = 2300;
game.addChild(waterLabel);
var lightLabel = new Text2('Light Level', {
size: 40,
fill: 0x34495E
});
lightLabel.anchor.set(0.5, 0);
lightLabel.x = 1024;
lightLabel.y = 2550;
game.addChild(lightLabel);
var controlsLabel = new Text2('Controls', {
size: 40,
fill: 0x34495E
});
controlsLabel.anchor.set(0.5, 0);
controlsLabel.x = 1750;
controlsLabel.y = 1000;
game.addChild(controlsLabel);
// Lamp color button labels only
var lampGreenLabel = new Text2('Green', {
size: 36,
fill: 0xFFFFFF
});
lampGreenLabel.anchor.set(0.5, 0.5);
lampGreenLabel.x = 1750;
lampGreenLabel.y = 1200;
game.addChild(lampGreenLabel);
var lampYellowLabel = new Text2('Yellow', {
size: 36,
fill: 0xFFFFFF
});
lampYellowLabel.anchor.set(0.5, 0.5);
lampYellowLabel.x = 1750;
lampYellowLabel.y = 1260;
game.addChild(lampYellowLabel);
var lampPurpleLabel = new Text2('Purple', {
size: 36,
fill: 0xFFFFFF
});
lampPurpleLabel.anchor.set(0.5, 0.5);
lampPurpleLabel.x = 1750;
lampPurpleLabel.y = 1320;
game.addChild(lampPurpleLabel);
// Water level display
var waterLevelText = new Text2('0%', {
size: 60,
fill: 0x2980B9
});
waterLevelText.anchor.set(0.5, 0);
waterLevelText.x = 1024;
waterLevelText.y = 2350;
game.addChild(waterLevelText);
// Light level display
var lightLevelText = new Text2('0%', {
size: 60,
fill: 0xFFD700
});
lightLevelText.anchor.set(0.5, 0);
lightLevelText.x = 1024;
lightLevelText.y = 2600;
game.addChild(lightLevelText);
// Initialize sliders to zero position for seed state
waterSlider.setValue(0.0);
lightSlider.setValue(0.0);
// Create and show start screen initially
startScreen = new StartScreen();
game.addChild(startScreen);
// Hide game elements initially
automaticPlant.visible = false;
controlledPlant.visible = false;
waterSlider.visible = false;
lightSlider.visible = false;
controlPanel.visible = false;
titleText.visible = false;
autoLabel.visible = false;
controlLabel.visible = false;
waterLabel.visible = false;
lightLabel.visible = false;
controlsLabel.visible = false;
lampGreenLabel.visible = false;
lampYellowLabel.visible = false;
lampPurpleLabel.visible = false;
waterLevelText.visible = false;
lightLevelText.visible = false;
// Add Jan Ingenhousz experiment
var janIngenhouzExperiment = new JanIngenhouzExperiment();
game.addChild(janIngenhouzExperiment);
janIngenhouzExperiment.visible = false;
// Create labels for Jan Ingenhousz time controls
var janTimeLabel = new Text2('Time of Day:', {
size: 50,
fill: 0x2C3E50
});
janTimeLabel.anchor.set(0.5, 0);
janTimeLabel.x = 800;
janTimeLabel.y = 400;
game.addChild(janTimeLabel);
janTimeLabel.visible = false;
var janMorningLabel = new Text2('Morning\n(Few bubbles)', {
size: 30,
fill: 0xFFFFFF
});
janMorningLabel.anchor.set(0.5, 0.5);
janMorningLabel.x = 600;
janMorningLabel.y = 500;
game.addChild(janMorningLabel);
janMorningLabel.visible = false;
var janNoonLabel = new Text2('Noon\n(Many bubbles)', {
size: 30,
fill: 0xFFFFFF
});
janNoonLabel.anchor.set(0.5, 0.5);
janNoonLabel.x = 800;
janNoonLabel.y = 500;
game.addChild(janNoonLabel);
janNoonLabel.visible = false;
var janNightLabel = new Text2('Night\n(No bubbles)', {
size: 30,
fill: 0xFFFFFF
});
janNightLabel.anchor.set(0.5, 0.5);
janNightLabel.x = 1000;
janNightLabel.y = 500;
game.addChild(janNightLabel);
janNightLabel.visible = false;
// Start screen mode selection handler
startScreen.onModeSelected = function (mode) {
gameState = 'playing';
// Hide start screen with fade out animation
tween(startScreen, {
alpha: 0
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
startScreen.visible = false;
if (mode === 'plantGrowing') {
// Show plant growing experiment elements
automaticPlant.visible = true;
controlledPlant.visible = true;
waterSlider.visible = true;
lightSlider.visible = true;
controlPanel.visible = true;
titleText.visible = true;
autoLabel.visible = true;
controlLabel.visible = true;
waterLabel.visible = true;
lightLabel.visible = true;
controlsLabel.visible = true;
lampGreenLabel.visible = true;
lampYellowLabel.visible = true;
lampPurpleLabel.visible = true;
waterLevelText.visible = true;
lightLevelText.visible = true;
// Hide Jan Ingenhousz labels
janTimeLabel.visible = false;
janMorningLabel.visible = false;
janNoonLabel.visible = false;
janNightLabel.visible = false;
// Fade in plant growing elements
var elementsToFade = [automaticPlant, controlledPlant, waterSlider, lightSlider, controlPanel, titleText, autoLabel, controlLabel, waterLabel, lightLabel, controlsLabel, lampGreenLabel, lampYellowLabel, lampPurpleLabel, waterLevelText, lightLevelText];
for (var i = 0; i < elementsToFade.length; i++) {
elementsToFade[i].alpha = 0;
tween(elementsToFade[i], {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
}
} else if (mode === 'janIngenhousz') {
// Show Jan Ingenhousz experiment
janIngenhouzExperiment.visible = true;
janIngenhouzExperiment.alpha = 0;
tween(janIngenhouzExperiment, {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
// Show time control labels
janMorningLabel.visible = true;
janNoonLabel.visible = true;
janNightLabel.visible = true;
janTimeLabel.visible = true;
janMorningLabel.alpha = 0;
janNoonLabel.alpha = 0;
janNightLabel.alpha = 0;
janTimeLabel.alpha = 0;
tween(janMorningLabel, {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
tween(janNoonLabel, {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
tween(janNightLabel, {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
tween(janTimeLabel, {
alpha: 1
}, {
duration: 800,
easing: tween.easeOut
});
}
}
});
};
// Set initial plant states - automatic plant starts as seed
automaticPlant.setWaterLevel(0.0); // Start with no water
automaticPlant.setLightLevel(0.0); // Start with no light
automaticPlant.size = 0.1; // Start as just a seed
automaticPlant.updatePlant(); // Update to reflect seed state
automaticPlant.setLampColor(0x32cd32); // Start with green lamp for small size
controlledPlant.setLampColor(0x9932cc); // Set controlled plant lamp to purple
// Variables for tracking
var dragNode = null;
var currentWaterLevel = 0.0; // Start with no water for seed state
var currentLightLevel = 0.0; // Start with no light for seed state
// Event handlers
waterSlider.onValueChange = function (value) {
currentWaterLevel = value;
automaticPlant.setWaterLevel(value);
controlledPlant.setWaterLevel(value);
waterLevelText.setText(Math.round(value * 100) + '%');
};
lightSlider.onValueChange = function (value) {
currentLightLevel = value;
automaticPlant.setLightLevel(value);
controlledPlant.setLightLevel(value);
lightLevelText.setText(Math.round(value * 100) + '%');
};
controlPanel.onLampColorChange = function (color) {
automaticPlant.setLampColor(color);
};
// Game move handler for slider dragging
game.move = function (x, y, obj) {
if (waterSlider.isDragging) {
var localPos = waterSlider.toLocal({
x: x,
y: y
});
var newValue = (localPos.x + 180) / 360;
waterSlider.setValue(newValue);
waterSlider.onValueChange(waterSlider.value);
}
if (lightSlider.isDragging) {
var localPos = lightSlider.toLocal({
x: x,
y: y
});
var newValue = (localPos.x + 180) / 360;
lightSlider.setValue(newValue);
lightSlider.onValueChange(lightSlider.value);
}
};
game.up = function (x, y, obj) {
waterSlider.isDragging = false;
lightSlider.isDragging = false;
};
// Create some water drops for visual effect
var waterDrops = [];
var dropTimer = 0;
game.update = function () {
dropTimer++;
// Create water drops periodically if water level > 0
if (currentWaterLevel > 0.1 && dropTimer % 60 == 0) {
for (var i = 0; i < 3; i++) {
var drop = LK.getAsset('waterDrop', {
anchorX: 0.5,
anchorY: 0.5,
x: 800 + Math.random() * 500,
y: 400 + Math.random() * 200
});
drop.speedY = 2 + Math.random() * 3;
drop.alpha = 0.7;
waterDrops.push(drop);
game.addChild(drop);
// Fade and animate the drop
tween(drop, {
y: drop.y + 200,
alpha: 0
}, {
duration: 2000,
onFinish: function onFinish() {
drop.destroy();
}
});
}
// Clean up old drops
for (var j = waterDrops.length - 1; j >= 0; j--) {
if (waterDrops[j].alpha <= 0) {
waterDrops.splice(j, 1);
}
}
}
};
sun. In-Game asset. 2d. High contrast. No shadows
sun. In-Game asset. 2d. High contrast. No shadows
pot. In-Game asset. 2d. High contrast. No shadows
leaf. In-Game asset. 2d. High contrast. No shadows
work lamp. In-Game asset. 2d. High contrast. No shadows
empty glass beaker. In-Game asset. 2d. High contrast. No shadows
a long, thin plant. In-Game asset. 2d. High contrast. No shadows