/****
* 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.cuts = [];
self.getCutAccuracy = function (cutPosition) {
var accuracy = Math.abs(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 isDragging = false;
var dragStartY = 0;
var currentLevel = 1;
var perfectCuts = 0;
var gameActive = true;
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 titleText = new Text2('Just a game about cutting a slice of meat', {
size: 70,
fill: 0x000000
});
titleText.anchor.set(0.5, 0);
titleText.x = 0;
titleText.y = 50;
LK.gui.top.addChild(titleText);
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.cuts = [];
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);
}
var randomOffset = (Math.random() - 0.5) * 100;
guideline.x = 1024 + randomOffset;
}
function makeCut(cutY) {
if (!gameActive) return;
var cutPosition = (cutY - (meat.y - meat.height / 2)) / meat.height;
cutPosition = Math.max(0, Math.min(1, cutPosition));
// Add this cut to the meat's cuts array
meat.cuts.push({
position: cutPosition,
y: cutY
});
var cutLine = game.addChild(new CutLine());
cutLine.x = meat.x;
cutLine.y = cutY;
cutLine.show();
cutLines.push(cutLine);
LK.getSound('slice').play();
var accuracy = meat.getCutAccuracy(cutPosition);
var points = Math.floor(accuracy * 100 * currentLevel);
if (accuracy > 0.6) {
perfectCuts++;
points *= 2;
LK.getSound('success').play();
LK.effects.flashObject(meat, 0x00FF00, 500);
instructionText.setText('Perfect Cut! +' + points);
} else if (accuracy > 0.3) {
instructionText.setText('Good Cut! +' + points);
LK.effects.flashObject(meat, 0xFFFF00, 500);
} else {
instructionText.setText('Poor Cut! +' + points);
LK.effects.flashObject(meat, 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;
// Check if we're clicking on the meat
if (meat.visible) {
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) {
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);
isDragging = false;
knife.isActive = false;
}
}
};
game.up = function (x, y, obj) {
if (isDragging) {
isDragging = false;
knife.isActive = false;
}
};
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(); /****
* 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.cuts = [];
self.getCutAccuracy = function (cutPosition) {
var accuracy = Math.abs(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 isDragging = false;
var dragStartY = 0;
var currentLevel = 1;
var perfectCuts = 0;
var gameActive = true;
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 titleText = new Text2('Just a game about cutting a slice of meat', {
size: 70,
fill: 0x000000
});
titleText.anchor.set(0.5, 0);
titleText.x = 0;
titleText.y = 50;
LK.gui.top.addChild(titleText);
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.cuts = [];
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);
}
var randomOffset = (Math.random() - 0.5) * 100;
guideline.x = 1024 + randomOffset;
}
function makeCut(cutY) {
if (!gameActive) return;
var cutPosition = (cutY - (meat.y - meat.height / 2)) / meat.height;
cutPosition = Math.max(0, Math.min(1, cutPosition));
// Add this cut to the meat's cuts array
meat.cuts.push({
position: cutPosition,
y: cutY
});
var cutLine = game.addChild(new CutLine());
cutLine.x = meat.x;
cutLine.y = cutY;
cutLine.show();
cutLines.push(cutLine);
LK.getSound('slice').play();
var accuracy = meat.getCutAccuracy(cutPosition);
var points = Math.floor(accuracy * 100 * currentLevel);
if (accuracy > 0.6) {
perfectCuts++;
points *= 2;
LK.getSound('success').play();
LK.effects.flashObject(meat, 0x00FF00, 500);
instructionText.setText('Perfect Cut! +' + points);
} else if (accuracy > 0.3) {
instructionText.setText('Good Cut! +' + points);
LK.effects.flashObject(meat, 0xFFFF00, 500);
} else {
instructionText.setText('Poor Cut! +' + points);
LK.effects.flashObject(meat, 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;
// Check if we're clicking on the meat
if (meat.visible) {
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) {
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);
isDragging = false;
knife.isActive = false;
}
}
};
game.up = function (x, y, obj) {
if (isDragging) {
isDragging = false;
knife.isActive = false;
}
};
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();