User prompt
Use the particle explosion asset to make the effect after the flower match or pop. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Now make the particle explosion asset.
User prompt
Fix 1,2,34,5 then. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add effect when the flowers pop. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make a background, a flower garden background.
Code edit (1 edits merged)
Please save this source code
User prompt
Blossom Match
Initial prompt
Lets make a game a flower match game, like candy crush but instead of candy it's flower, different kinds of flower.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Flower = Container.expand(function (type) {
var self = Container.call(this);
self.flowerType = type;
self.gridX = 0;
self.gridY = 0;
var flowerGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
// Add subtle glow effect
flowerGraphics.alpha = 0.9;
self.down = function (x, y, obj) {
if (!game.isSwapping && !game.isMatching) {
game.selectFlower(self);
}
};
self.animateMatch = function () {
tween(flowerGraphics, {
scaleX: 1.3,
scaleY: 1.3,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
self.visible = false;
}
});
};
self.animateFall = function (targetY, callback) {
tween(self, {
y: targetY
}, {
duration: 200,
easing: tween.easeIn,
onFinish: callback
});
};
return self;
});
var Grid = Container.expand(function () {
var self = Container.call(this);
self.gridSize = 8;
self.cellSize = 200;
self.flowers = [];
self.flowerTypes = ['rose', 'tulip', 'daisy', 'sunflower', 'lily'];
// Initialize 2D array
for (var i = 0; i < self.gridSize; i++) {
self.flowers[i] = [];
for (var j = 0; j < self.gridSize; j++) {
self.flowers[i][j] = null;
}
}
self.createFlower = function (gridX, gridY) {
var randomType = self.flowerTypes[Math.floor(Math.random() * self.flowerTypes.length)];
var flower = new Flower(randomType);
flower.gridX = gridX;
flower.gridY = gridY;
flower.x = gridX * self.cellSize + self.cellSize / 2;
flower.y = gridY * self.cellSize + self.cellSize / 2;
self.flowers[gridY][gridX] = flower;
self.addChild(flower);
return flower;
};
self.initializeGrid = function () {
for (var y = 0; y < self.gridSize; y++) {
for (var x = 0; x < self.gridSize; x++) {
self.createFlower(x, y);
}
}
};
self.swapFlowers = function (flower1, flower2, callback) {
var tempX = flower1.gridX;
var tempY = flower1.gridY;
// Update grid positions
flower1.gridX = flower2.gridX;
flower1.gridY = flower2.gridY;
flower2.gridX = tempX;
flower2.gridY = tempY;
// Update array
self.flowers[flower1.gridY][flower1.gridX] = flower1;
self.flowers[flower2.gridY][flower2.gridX] = flower2;
// Animate swap
var targetX1 = flower1.gridX * self.cellSize + self.cellSize / 2;
var targetY1 = flower1.gridY * self.cellSize + self.cellSize / 2;
var targetX2 = flower2.gridX * self.cellSize + self.cellSize / 2;
var targetY2 = flower2.gridY * self.cellSize + self.cellSize / 2;
var completed = 0;
function onComplete() {
completed++;
if (completed === 2 && callback) {
callback();
}
}
tween(flower1, {
x: targetX1,
y: targetY1
}, {
duration: 250,
easing: tween.easeInOut,
onFinish: onComplete
});
tween(flower2, {
x: targetX2,
y: targetY2
}, {
duration: 250,
easing: tween.easeInOut,
onFinish: onComplete
});
};
self.findMatches = function () {
var matches = [];
// Check horizontal matches
for (var y = 0; y < self.gridSize; y++) {
var count = 1;
var currentType = self.flowers[y][0] ? self.flowers[y][0].flowerType : null;
for (var x = 1; x < self.gridSize; x++) {
var flower = self.flowers[y][x];
if (flower && flower.flowerType === currentType) {
count++;
} else {
if (count >= 3 && currentType) {
for (var i = x - count; i < x; i++) {
matches.push({
x: i,
y: y
});
}
}
count = 1;
currentType = flower ? flower.flowerType : null;
}
}
if (count >= 3 && currentType) {
for (var i = self.gridSize - count; i < self.gridSize; i++) {
matches.push({
x: i,
y: y
});
}
}
}
// Check vertical matches
for (var x = 0; x < self.gridSize; x++) {
var count = 1;
var currentType = self.flowers[0][x] ? self.flowers[0][x].flowerType : null;
for (var y = 1; y < self.gridSize; y++) {
var flower = self.flowers[y][x];
if (flower && flower.flowerType === currentType) {
count++;
} else {
if (count >= 3 && currentType) {
for (var i = y - count; i < y; i++) {
matches.push({
x: x,
y: i
});
}
}
count = 1;
currentType = flower ? flower.flowerType : null;
}
}
if (count >= 3 && currentType) {
for (var i = self.gridSize - count; i < self.gridSize; i++) {
matches.push({
x: x,
y: i
});
}
}
}
return matches;
};
self.removeMatches = function (matches, callback) {
if (matches.length === 0) {
if (callback) callback();
return;
}
var completed = 0;
var total = matches.length;
function onAnimationComplete() {
completed++;
if (completed === total && callback) {
callback();
}
}
for (var i = 0; i < matches.length; i++) {
var match = matches[i];
var flower = self.flowers[match.y][match.x];
if (flower) {
flower.animateMatch();
self.flowers[match.y][match.x] = null;
LK.setTimeout(function () {
onAnimationComplete();
}, 300);
}
}
};
self.dropFlowers = function (callback) {
var animations = 0;
for (var x = 0; x < self.gridSize; x++) {
var writeIndex = self.gridSize - 1;
// Move existing flowers down
for (var y = self.gridSize - 1; y >= 0; y--) {
if (self.flowers[y][x]) {
if (y !== writeIndex) {
self.flowers[writeIndex][x] = self.flowers[y][x];
self.flowers[y][x] = null;
var flower = self.flowers[writeIndex][x];
flower.gridY = writeIndex;
var targetY = writeIndex * self.cellSize + self.cellSize / 2;
animations++;
(function (f, ty) {
f.animateFall(ty, function () {
animations--;
if (animations === 0 && callback) {
callback();
}
});
})(flower, targetY);
}
writeIndex--;
}
}
// Create new flowers to fill empty spaces
for (var y = 0; y <= writeIndex; y++) {
var newFlower = self.createFlower(x, y);
newFlower.y = -self.cellSize;
var targetY = y * self.cellSize + self.cellSize / 2;
animations++;
(function (f, ty) {
f.animateFall(ty, function () {
animations--;
if (animations === 0 && callback) {
callback();
}
});
})(newFlower, targetY);
}
}
if (animations === 0 && callback) {
callback();
}
};
self.isAdjacent = function (flower1, flower2) {
var dx = Math.abs(flower1.gridX - flower2.gridX);
var dy = Math.abs(flower1.gridY - flower2.gridY);
return dx === 1 && dy === 0 || dx === 0 && dy === 1;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x98fb98
});
/****
* Game Code
****/
var grid = new Grid();
var selectedFlower = null;
var score = 0;
var isSwapping = false;
var isMatching = false;
// Position grid in center of screen
grid.x = (2048 - grid.gridSize * grid.cellSize) / 2;
grid.y = (2732 - grid.gridSize * grid.cellSize) / 2 + 200;
game.addChild(grid);
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 120,
fill: 0x2D5016
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize grid
grid.initializeGrid();
game.isSwapping = false;
game.isMatching = false;
game.selectFlower = function (flower) {
if (selectedFlower === null) {
// First selection
selectedFlower = flower;
tween(flower, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 150,
easing: tween.easeOut
});
} else if (selectedFlower === flower) {
// Deselect same flower
tween(flower, {
scaleX: 1,
scaleY: 1
}, {
duration: 150,
easing: tween.easeOut
});
selectedFlower = null;
} else if (grid.isAdjacent(selectedFlower, flower)) {
// Valid swap
game.isSwapping = true;
var firstFlower = selectedFlower;
tween(firstFlower, {
scaleX: 1,
scaleY: 1
}, {
duration: 150,
easing: tween.easeOut
});
LK.getSound('swap').play();
grid.swapFlowers(firstFlower, flower, function () {
selectedFlower = null;
game.isSwapping = false;
game.checkForMatches();
});
} else {
// Invalid swap - select new flower
tween(selectedFlower, {
scaleX: 1,
scaleY: 1
}, {
duration: 150,
easing: tween.easeOut
});
selectedFlower = flower;
tween(flower, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 150,
easing: tween.easeOut
});
}
};
game.checkForMatches = function () {
var matches = grid.findMatches();
if (matches.length > 0) {
game.isMatching = true;
LK.getSound('match').play();
// Update score
score += matches.length * 10;
LK.setScore(score);
scoreTxt.setText('Score: ' + score);
grid.removeMatches(matches, function () {
grid.dropFlowers(function () {
game.isMatching = false;
// Check for cascading matches
LK.setTimeout(function () {
game.checkForMatches();
}, 100);
});
});
}
};
// Initial match check after grid creation
LK.setTimeout(function () {
game.checkForMatches();
}, 500);
game.update = function () {
// Game runs automatically through event-driven mechanics
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,376 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Flower = Container.expand(function (type) {
+ var self = Container.call(this);
+ self.flowerType = type;
+ self.gridX = 0;
+ self.gridY = 0;
+ var flowerGraphics = self.attachAsset(type, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Add subtle glow effect
+ flowerGraphics.alpha = 0.9;
+ self.down = function (x, y, obj) {
+ if (!game.isSwapping && !game.isMatching) {
+ game.selectFlower(self);
+ }
+ };
+ self.animateMatch = function () {
+ tween(flowerGraphics, {
+ scaleX: 1.3,
+ scaleY: 1.3,
+ alpha: 0
+ }, {
+ duration: 300,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.visible = false;
+ }
+ });
+ };
+ self.animateFall = function (targetY, callback) {
+ tween(self, {
+ y: targetY
+ }, {
+ duration: 200,
+ easing: tween.easeIn,
+ onFinish: callback
+ });
+ };
+ return self;
+});
+var Grid = Container.expand(function () {
+ var self = Container.call(this);
+ self.gridSize = 8;
+ self.cellSize = 200;
+ self.flowers = [];
+ self.flowerTypes = ['rose', 'tulip', 'daisy', 'sunflower', 'lily'];
+ // Initialize 2D array
+ for (var i = 0; i < self.gridSize; i++) {
+ self.flowers[i] = [];
+ for (var j = 0; j < self.gridSize; j++) {
+ self.flowers[i][j] = null;
+ }
+ }
+ self.createFlower = function (gridX, gridY) {
+ var randomType = self.flowerTypes[Math.floor(Math.random() * self.flowerTypes.length)];
+ var flower = new Flower(randomType);
+ flower.gridX = gridX;
+ flower.gridY = gridY;
+ flower.x = gridX * self.cellSize + self.cellSize / 2;
+ flower.y = gridY * self.cellSize + self.cellSize / 2;
+ self.flowers[gridY][gridX] = flower;
+ self.addChild(flower);
+ return flower;
+ };
+ self.initializeGrid = function () {
+ for (var y = 0; y < self.gridSize; y++) {
+ for (var x = 0; x < self.gridSize; x++) {
+ self.createFlower(x, y);
+ }
+ }
+ };
+ self.swapFlowers = function (flower1, flower2, callback) {
+ var tempX = flower1.gridX;
+ var tempY = flower1.gridY;
+ // Update grid positions
+ flower1.gridX = flower2.gridX;
+ flower1.gridY = flower2.gridY;
+ flower2.gridX = tempX;
+ flower2.gridY = tempY;
+ // Update array
+ self.flowers[flower1.gridY][flower1.gridX] = flower1;
+ self.flowers[flower2.gridY][flower2.gridX] = flower2;
+ // Animate swap
+ var targetX1 = flower1.gridX * self.cellSize + self.cellSize / 2;
+ var targetY1 = flower1.gridY * self.cellSize + self.cellSize / 2;
+ var targetX2 = flower2.gridX * self.cellSize + self.cellSize / 2;
+ var targetY2 = flower2.gridY * self.cellSize + self.cellSize / 2;
+ var completed = 0;
+ function onComplete() {
+ completed++;
+ if (completed === 2 && callback) {
+ callback();
+ }
+ }
+ tween(flower1, {
+ x: targetX1,
+ y: targetY1
+ }, {
+ duration: 250,
+ easing: tween.easeInOut,
+ onFinish: onComplete
+ });
+ tween(flower2, {
+ x: targetX2,
+ y: targetY2
+ }, {
+ duration: 250,
+ easing: tween.easeInOut,
+ onFinish: onComplete
+ });
+ };
+ self.findMatches = function () {
+ var matches = [];
+ // Check horizontal matches
+ for (var y = 0; y < self.gridSize; y++) {
+ var count = 1;
+ var currentType = self.flowers[y][0] ? self.flowers[y][0].flowerType : null;
+ for (var x = 1; x < self.gridSize; x++) {
+ var flower = self.flowers[y][x];
+ if (flower && flower.flowerType === currentType) {
+ count++;
+ } else {
+ if (count >= 3 && currentType) {
+ for (var i = x - count; i < x; i++) {
+ matches.push({
+ x: i,
+ y: y
+ });
+ }
+ }
+ count = 1;
+ currentType = flower ? flower.flowerType : null;
+ }
+ }
+ if (count >= 3 && currentType) {
+ for (var i = self.gridSize - count; i < self.gridSize; i++) {
+ matches.push({
+ x: i,
+ y: y
+ });
+ }
+ }
+ }
+ // Check vertical matches
+ for (var x = 0; x < self.gridSize; x++) {
+ var count = 1;
+ var currentType = self.flowers[0][x] ? self.flowers[0][x].flowerType : null;
+ for (var y = 1; y < self.gridSize; y++) {
+ var flower = self.flowers[y][x];
+ if (flower && flower.flowerType === currentType) {
+ count++;
+ } else {
+ if (count >= 3 && currentType) {
+ for (var i = y - count; i < y; i++) {
+ matches.push({
+ x: x,
+ y: i
+ });
+ }
+ }
+ count = 1;
+ currentType = flower ? flower.flowerType : null;
+ }
+ }
+ if (count >= 3 && currentType) {
+ for (var i = self.gridSize - count; i < self.gridSize; i++) {
+ matches.push({
+ x: x,
+ y: i
+ });
+ }
+ }
+ }
+ return matches;
+ };
+ self.removeMatches = function (matches, callback) {
+ if (matches.length === 0) {
+ if (callback) callback();
+ return;
+ }
+ var completed = 0;
+ var total = matches.length;
+ function onAnimationComplete() {
+ completed++;
+ if (completed === total && callback) {
+ callback();
+ }
+ }
+ for (var i = 0; i < matches.length; i++) {
+ var match = matches[i];
+ var flower = self.flowers[match.y][match.x];
+ if (flower) {
+ flower.animateMatch();
+ self.flowers[match.y][match.x] = null;
+ LK.setTimeout(function () {
+ onAnimationComplete();
+ }, 300);
+ }
+ }
+ };
+ self.dropFlowers = function (callback) {
+ var animations = 0;
+ for (var x = 0; x < self.gridSize; x++) {
+ var writeIndex = self.gridSize - 1;
+ // Move existing flowers down
+ for (var y = self.gridSize - 1; y >= 0; y--) {
+ if (self.flowers[y][x]) {
+ if (y !== writeIndex) {
+ self.flowers[writeIndex][x] = self.flowers[y][x];
+ self.flowers[y][x] = null;
+ var flower = self.flowers[writeIndex][x];
+ flower.gridY = writeIndex;
+ var targetY = writeIndex * self.cellSize + self.cellSize / 2;
+ animations++;
+ (function (f, ty) {
+ f.animateFall(ty, function () {
+ animations--;
+ if (animations === 0 && callback) {
+ callback();
+ }
+ });
+ })(flower, targetY);
+ }
+ writeIndex--;
+ }
+ }
+ // Create new flowers to fill empty spaces
+ for (var y = 0; y <= writeIndex; y++) {
+ var newFlower = self.createFlower(x, y);
+ newFlower.y = -self.cellSize;
+ var targetY = y * self.cellSize + self.cellSize / 2;
+ animations++;
+ (function (f, ty) {
+ f.animateFall(ty, function () {
+ animations--;
+ if (animations === 0 && callback) {
+ callback();
+ }
+ });
+ })(newFlower, targetY);
+ }
+ }
+ if (animations === 0 && callback) {
+ callback();
+ }
+ };
+ self.isAdjacent = function (flower1, flower2) {
+ var dx = Math.abs(flower1.gridX - flower2.gridX);
+ var dy = Math.abs(flower1.gridY - flower2.gridY);
+ return dx === 1 && dy === 0 || dx === 0 && dy === 1;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x98fb98
+});
+
+/****
+* Game Code
+****/
+var grid = new Grid();
+var selectedFlower = null;
+var score = 0;
+var isSwapping = false;
+var isMatching = false;
+// Position grid in center of screen
+grid.x = (2048 - grid.gridSize * grid.cellSize) / 2;
+grid.y = (2732 - grid.gridSize * grid.cellSize) / 2 + 200;
+game.addChild(grid);
+// Score display
+var scoreTxt = new Text2('Score: 0', {
+ size: 120,
+ fill: 0x2D5016
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Initialize grid
+grid.initializeGrid();
+game.isSwapping = false;
+game.isMatching = false;
+game.selectFlower = function (flower) {
+ if (selectedFlower === null) {
+ // First selection
+ selectedFlower = flower;
+ tween(flower, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 150,
+ easing: tween.easeOut
+ });
+ } else if (selectedFlower === flower) {
+ // Deselect same flower
+ tween(flower, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 150,
+ easing: tween.easeOut
+ });
+ selectedFlower = null;
+ } else if (grid.isAdjacent(selectedFlower, flower)) {
+ // Valid swap
+ game.isSwapping = true;
+ var firstFlower = selectedFlower;
+ tween(firstFlower, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 150,
+ easing: tween.easeOut
+ });
+ LK.getSound('swap').play();
+ grid.swapFlowers(firstFlower, flower, function () {
+ selectedFlower = null;
+ game.isSwapping = false;
+ game.checkForMatches();
+ });
+ } else {
+ // Invalid swap - select new flower
+ tween(selectedFlower, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 150,
+ easing: tween.easeOut
+ });
+ selectedFlower = flower;
+ tween(flower, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 150,
+ easing: tween.easeOut
+ });
+ }
+};
+game.checkForMatches = function () {
+ var matches = grid.findMatches();
+ if (matches.length > 0) {
+ game.isMatching = true;
+ LK.getSound('match').play();
+ // Update score
+ score += matches.length * 10;
+ LK.setScore(score);
+ scoreTxt.setText('Score: ' + score);
+ grid.removeMatches(matches, function () {
+ grid.dropFlowers(function () {
+ game.isMatching = false;
+ // Check for cascading matches
+ LK.setTimeout(function () {
+ game.checkForMatches();
+ }, 100);
+ });
+ });
+ }
+};
+// Initial match check after grid creation
+LK.setTimeout(function () {
+ game.checkForMatches();
+}, 500);
+game.update = function () {
+ // Game runs automatically through event-driven mechanics
+};
\ No newline at end of file
Tulip. The flower is facing at the center. Make it vibrant. In-Game asset. 2d. High contrast. No shadows
Rose. Front. Make it vibrant. In-Game asset. 2d. High contrast. No shadows
Daisy. Front. Make it vibrant.. In-Game asset. 2d. High contrast. No shadows
Sunflower. Front. Make it vibrant.. In-Game asset. 2d. High contrast. No shadows
Lily. Front. Make it vibrant.. In-Game asset. 2d. High contrast. No shadows
Grass background.. In-Game asset. 2d. High contrast. No shadows
Flowery particle. Vibrant.. In-Game asset. 2d. High contrast. No shadows
Shimmer effect. Vibrant.. In-Game asset. 2d. High contrast. No shadows
Rainbow effect. Vibrant.. In-Game asset. 2d. High contrast. No shadows
Blossom match with rose,lily,sunflower,tulips,and daisy. Vibrant.. In-Game asset. 2d. High contrast. No shadows