User prompt
Make a “just a game about cutting a slice of meat” at the top of the screen
User prompt
Don’t make the meat multiply just make the meat be able to cut wherever the knife swipes on the meat ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the meat be able to be cut as many times as you want not like resetting but you can split the meat more than once ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the meat not reset once it’s split apart
User prompt
Please fix the bug: 'TypeError: easing is not a function. (In 'easing(t)', 'easing' is "easeOutQuad")' in or related to this line: 'if (isDragging) {' Line Number: 301 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the meat actually split apart when you cut it
User prompt
Make the controls a bit easier
User prompt
Remove the timer and make the cutting object a butcher knife with a brown rectangle for the handle and make the meat a red meat shaped object made out of ovals
Code edit (1 edits merged)
Please save this source code
User prompt
Slice Master: Precision Butcher
Initial prompt
A game about cutting a slice of meat
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var CutLine = Container.expand(function () {
var self = Container.call(this);
var lineGraphics = self.attachAsset('cutLine', {
anchorX: 0.5,
anchorY: 0.5
});
lineGraphics.alpha = 0;
self.show = function () {
tween(lineGraphics, {
alpha: 1
}, {
duration: 200
});
};
return self;
});
var Knife = Container.expand(function () {
var self = Container.call(this);
var knifeHandle = self.attachAsset('knifeHandle', {
anchorX: 0.5,
anchorY: 1.0,
y: 0
});
var knifeBlade = self.attachAsset('knifeBlade', {
anchorX: 0.5,
anchorY: 1.0,
y: -60
});
self.isActive = false;
return self;
});
var Meat = Container.expand(function () {
var self = Container.call(this);
var meatOval1 = self.attachAsset('meatOval1', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
var meatOval2 = self.attachAsset('meatOval2', {
anchorX: 0.5,
anchorY: 0.5,
x: -30,
y: -20
});
var meatOval3 = self.attachAsset('meatOval3', {
anchorX: 0.5,
anchorY: 0.5,
x: 40,
y: 30
});
self.width = 350;
self.height = 250;
self.targetWeight = 100;
self.currentWeight = 100;
self.isCut = false;
self.cutPosition = 0;
self.getCutAccuracy = function () {
var accuracy = Math.abs(self.cutPosition - 0.5) * 1.5;
return Math.max(0, 1 - accuracy);
};
return self;
});
var MeatPiece = Container.expand(function (isTopPart, cutPosition) {
var self = Container.call(this);
var meatOval1 = self.attachAsset('meatOval1', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0
});
var meatOval2 = self.attachAsset('meatOval2', {
anchorX: 0.5,
anchorY: 0.5,
x: -30,
y: -20
});
var meatOval3 = self.attachAsset('meatOval3', {
anchorX: 0.5,
anchorY: 0.5,
x: 40,
y: 30
});
// Create mask based on cut position
if (isTopPart) {
// Top piece - mask bottom portion
meatOval1.height = meatOval1.height * cutPosition;
meatOval2.height = meatOval2.height * cutPosition;
meatOval3.height = meatOval3.height * cutPosition;
} else {
// Bottom piece - mask top portion and adjust position
var remainingHeight = 1 - cutPosition;
meatOval1.height = meatOval1.height * remainingHeight;
meatOval2.height = meatOval2.height * remainingHeight;
meatOval3.height = meatOval3.height * remainingHeight;
meatOval1.y = 250 * cutPosition / 2;
meatOval2.y = -20 + 200 * cutPosition / 2;
meatOval3.y = 30 + 150 * cutPosition / 2;
}
// Add properties needed for cutting
self.width = 350;
self.height = 250;
self.isCut = false;
self.cutPosition = 0;
self.getCutAccuracy = function () {
var accuracy = Math.abs(self.cutPosition - 0.5) * 1.5;
return Math.max(0, 1 - accuracy);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xF5F5DC
});
/****
* Game Code
****/
var cuttingBoard = game.addChild(LK.getAsset('cuttingBoard', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var guideline = game.addChild(LK.getAsset('guideline', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var meat = game.addChild(new Meat());
meat.x = 1024;
meat.y = 1366;
var knife = game.addChild(new Knife());
knife.x = 1024;
knife.y = 1200;
var cutLines = [];
var meatPieces = [];
var isDragging = false;
var dragStartY = 0;
var currentLevel = 1;
var perfectCuts = 0;
var gameActive = true;
var currentCuttingTarget = null;
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0x000000
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
var levelText = new Text2('Level: 1', {
size: 80,
fill: 0x000000
});
levelText.anchor.set(0, 0);
LK.gui.topLeft.addChild(levelText);
var instructionText = new Text2('Drag to cut along the red line!', {
size: 60,
fill: 0x333333
});
instructionText.anchor.set(0.5, 0);
instructionText.x = 0;
instructionText.y = 200;
LK.gui.bottom.addChild(instructionText);
function resetMeat() {
meat.isCut = false;
meat.cutPosition = 0;
meat.targetWeight = 80 + Math.random() * 40;
meat.alpha = 1;
meat.visible = true;
tween(meat, {
scaleX: 1,
scaleY: 1,
alpha: 1
}, {
duration: 300
});
for (var i = cutLines.length - 1; i >= 0; i--) {
cutLines[i].destroy();
cutLines.splice(i, 1);
}
for (var i = meatPieces.length - 1; i >= 0; i--) {
meatPieces[i].destroy();
meatPieces.splice(i, 1);
}
var randomOffset = (Math.random() - 0.5) * 100;
guideline.x = 1024 + randomOffset;
}
function makeCut(cutY, targetObject) {
if (!targetObject || targetObject.isCut || !gameActive) return;
targetObject.isCut = true;
var cutPosition = (cutY - (targetObject.y - targetObject.height / 2)) / targetObject.height;
cutPosition = Math.max(0, Math.min(1, cutPosition));
targetObject.cutPosition = cutPosition;
var cutLine = game.addChild(new CutLine());
cutLine.x = targetObject.x;
cutLine.y = cutY;
cutLine.show();
cutLines.push(cutLine);
// Hide original object and create split pieces
targetObject.visible = false;
// Create top piece
var topPiece = game.addChild(new MeatPiece(true, cutPosition));
topPiece.x = targetObject.x;
topPiece.y = targetObject.y;
meatPieces.push(topPiece);
// Create bottom piece
var bottomPiece = game.addChild(new MeatPiece(false, cutPosition));
bottomPiece.x = targetObject.x;
bottomPiece.y = targetObject.y;
meatPieces.push(bottomPiece);
// Animate pieces splitting apart
tween(topPiece, {
x: targetObject.x - 100,
y: targetObject.y - 50,
rotation: -0.3
}, {
duration: 800,
easing: tween.easeOutQuad
});
tween(bottomPiece, {
x: targetObject.x + 100,
y: targetObject.y + 50,
rotation: 0.3
}, {
duration: 800,
easing: tween.easeOutQuad
});
LK.getSound('slice').play();
var accuracy = targetObject.getCutAccuracy();
var points = Math.floor(accuracy * 100 * currentLevel);
if (accuracy > 0.6) {
perfectCuts++;
points *= 2;
LK.getSound('success').play();
LK.effects.flashObject(topPiece, 0x00FF00, 500);
LK.effects.flashObject(bottomPiece, 0x00FF00, 500);
instructionText.setText('Perfect Cut! +' + points);
} else if (accuracy > 0.3) {
instructionText.setText('Good Cut! +' + points);
LK.effects.flashObject(topPiece, 0xFFFF00, 500);
LK.effects.flashObject(bottomPiece, 0xFFFF00, 500);
} else {
instructionText.setText('Poor Cut! +' + points);
LK.effects.flashObject(topPiece, 0xFF0000, 500);
LK.effects.flashObject(bottomPiece, 0xFF0000, 500);
}
LK.setScore(LK.getScore() + points);
scoreText.setText('Score: ' + LK.getScore());
LK.setTimeout(function () {
if (perfectCuts >= 5) {
currentLevel++;
perfectCuts = 0;
levelText.setText('Level: ' + currentLevel);
instructionText.setText('Level Up!');
}
LK.setTimeout(function () {
instructionText.setText('Drag to cut along the red line!');
}, 1000);
}, 1500);
}
game.down = function (x, y, obj) {
if (!gameActive) return;
currentCuttingTarget = null;
// Check if we're clicking on the original meat
if (meat.visible && !meat.isCut) {
var localPos = meat.toLocal(game.toGlobal({
x: x,
y: y
}));
if (Math.abs(localPos.x) < meat.width * 0.8 && Math.abs(localPos.y) < meat.height * 0.8) {
currentCuttingTarget = meat;
}
}
// Check if we're clicking on any meat pieces
if (!currentCuttingTarget) {
for (var i = 0; i < meatPieces.length; i++) {
var piece = meatPieces[i];
if (piece.visible && !piece.isCut) {
var pieceLocalPos = piece.toLocal(game.toGlobal({
x: x,
y: y
}));
if (Math.abs(pieceLocalPos.x) < piece.width * 0.8 && Math.abs(pieceLocalPos.y) < piece.height * 0.8) {
currentCuttingTarget = piece;
break;
}
}
}
}
if (currentCuttingTarget) {
isDragging = true;
dragStartY = y;
knife.isActive = true;
knife.x = x;
knife.y = y;
}
};
game.move = function (x, y, obj) {
if (!gameActive) return;
if (isDragging) {
knife.x = x;
knife.y = y;
if (Math.abs(y - dragStartY) > 20) {
makeCut(y, currentCuttingTarget);
isDragging = false;
knife.isActive = false;
currentCuttingTarget = null;
}
}
};
game.up = function (x, y, obj) {
if (isDragging) {
isDragging = false;
knife.isActive = false;
currentCuttingTarget = null;
}
};
game.update = function () {
if (knife.isActive) {
knife.rotation = Math.sin(LK.ticks * 0.3) * 0.1;
} else {
knife.rotation = 0;
}
guideline.alpha = 0.3 + Math.sin(LK.ticks * 0.1) * 0.2;
if (isDragging) {
var trailEffect = Math.sin(LK.ticks * 0.5) * 0.1;
knife.scaleX = 1 + trailEffect;
} else {
knife.scaleX = 1;
}
};
resetMeat(); ===================================================================
--- original.js
+++ change.js
@@ -105,8 +105,17 @@
meatOval1.y = 250 * cutPosition / 2;
meatOval2.y = -20 + 200 * cutPosition / 2;
meatOval3.y = 30 + 150 * cutPosition / 2;
}
+ // Add properties needed for cutting
+ self.width = 350;
+ self.height = 250;
+ self.isCut = false;
+ self.cutPosition = 0;
+ self.getCutAccuracy = function () {
+ var accuracy = Math.abs(self.cutPosition - 0.5) * 1.5;
+ return Math.max(0, 1 - accuracy);
+ };
return self;
});
/****
@@ -143,8 +152,9 @@
var dragStartY = 0;
var currentLevel = 1;
var perfectCuts = 0;
var gameActive = true;
+var currentCuttingTarget = null;
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0x000000
});
@@ -187,50 +197,50 @@
}
var randomOffset = (Math.random() - 0.5) * 100;
guideline.x = 1024 + randomOffset;
}
-function makeCut(cutY) {
- if (meat.isCut || !gameActive) return;
- meat.isCut = true;
- var cutPosition = (cutY - (meat.y - meat.height / 2)) / meat.height;
+function makeCut(cutY, targetObject) {
+ if (!targetObject || targetObject.isCut || !gameActive) return;
+ targetObject.isCut = true;
+ var cutPosition = (cutY - (targetObject.y - targetObject.height / 2)) / targetObject.height;
cutPosition = Math.max(0, Math.min(1, cutPosition));
- meat.cutPosition = cutPosition;
+ targetObject.cutPosition = cutPosition;
var cutLine = game.addChild(new CutLine());
- cutLine.x = meat.x;
+ cutLine.x = targetObject.x;
cutLine.y = cutY;
cutLine.show();
cutLines.push(cutLine);
- // Hide original meat and create split pieces
- meat.visible = false;
+ // Hide original object and create split pieces
+ targetObject.visible = false;
// Create top piece
var topPiece = game.addChild(new MeatPiece(true, cutPosition));
- topPiece.x = meat.x;
- topPiece.y = meat.y;
+ topPiece.x = targetObject.x;
+ topPiece.y = targetObject.y;
meatPieces.push(topPiece);
// Create bottom piece
var bottomPiece = game.addChild(new MeatPiece(false, cutPosition));
- bottomPiece.x = meat.x;
- bottomPiece.y = meat.y;
+ bottomPiece.x = targetObject.x;
+ bottomPiece.y = targetObject.y;
meatPieces.push(bottomPiece);
// Animate pieces splitting apart
tween(topPiece, {
- x: meat.x - 100,
- y: meat.y - 50,
+ x: targetObject.x - 100,
+ y: targetObject.y - 50,
rotation: -0.3
}, {
duration: 800,
easing: tween.easeOutQuad
});
tween(bottomPiece, {
- x: meat.x + 100,
- y: meat.y + 50,
+ x: targetObject.x + 100,
+ y: targetObject.y + 50,
rotation: 0.3
}, {
duration: 800,
easing: tween.easeOutQuad
});
LK.getSound('slice').play();
- var accuracy = meat.getCutAccuracy();
+ var accuracy = targetObject.getCutAccuracy();
var points = Math.floor(accuracy * 100 * currentLevel);
if (accuracy > 0.6) {
perfectCuts++;
points *= 2;
@@ -262,13 +272,36 @@
}, 1500);
}
game.down = function (x, y, obj) {
if (!gameActive) return;
- var localPos = meat.toLocal(game.toGlobal({
- x: x,
- y: y
- }));
- if (Math.abs(localPos.x) < meat.width * 0.8 && Math.abs(localPos.y) < meat.height * 0.8) {
+ currentCuttingTarget = null;
+ // Check if we're clicking on the original meat
+ if (meat.visible && !meat.isCut) {
+ var localPos = meat.toLocal(game.toGlobal({
+ x: x,
+ y: y
+ }));
+ if (Math.abs(localPos.x) < meat.width * 0.8 && Math.abs(localPos.y) < meat.height * 0.8) {
+ currentCuttingTarget = meat;
+ }
+ }
+ // Check if we're clicking on any meat pieces
+ if (!currentCuttingTarget) {
+ for (var i = 0; i < meatPieces.length; i++) {
+ var piece = meatPieces[i];
+ if (piece.visible && !piece.isCut) {
+ var pieceLocalPos = piece.toLocal(game.toGlobal({
+ x: x,
+ y: y
+ }));
+ if (Math.abs(pieceLocalPos.x) < piece.width * 0.8 && Math.abs(pieceLocalPos.y) < piece.height * 0.8) {
+ currentCuttingTarget = piece;
+ break;
+ }
+ }
+ }
+ }
+ if (currentCuttingTarget) {
isDragging = true;
dragStartY = y;
knife.isActive = true;
knife.x = x;
@@ -280,18 +313,20 @@
if (isDragging) {
knife.x = x;
knife.y = y;
if (Math.abs(y - dragStartY) > 20) {
- makeCut(y);
+ makeCut(y, currentCuttingTarget);
isDragging = false;
knife.isActive = false;
+ currentCuttingTarget = null;
}
}
};
game.up = function (x, y, obj) {
if (isDragging) {
isDragging = false;
knife.isActive = false;
+ currentCuttingTarget = null;
}
};
game.update = function () {
if (knife.isActive) {