Code edit (1 edits merged)
Please save this source code
User prompt
take out the minigame of slicing the tuna, just leave the original
Code edit (1 edits merged)
Please save this source code
User prompt
i want make the move in the belt faster and i want to add a feature that when you clic on 5 defective products you must stop production and pass to a mini game when you should slice the products ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
The Quality Inspector
Initial prompt
i want to make a game of a inspector in a Fabric of tuna cans, watching out a transporting band, taking out malproductions clicing on them and stoping the production when the coute is completed or when three in arow malproduction appears, getting points whenever you stop the production correctly avoiding making products in excess or when the failed products appear, the tittle "the quality inspector"
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var StopButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('stopButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
stopProduction();
};
return self;
});
var TunaCan = Container.expand(function (isDefective) {
var self = Container.call(this);
self.isDefective = isDefective || false;
self.isClicked = false;
self.speed = 10;
var canGraphics = self.attachAsset(self.isDefective ? 'defectCan' : 'goodCan', {
anchorX: 0.5,
anchorY: 0.5
});
// Add visual indicator for defective cans
if (self.isDefective) {
canGraphics.alpha = 0.8;
}
self.update = function () {
self.x += self.speed;
};
self.down = function (x, y, obj) {
if (self.isDefective && !self.isClicked) {
self.isClicked = true;
LK.getSound('click').play();
self.visible = false;
defectsRemoved++;
updateDefectStreak();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x34495e
});
/****
* Game Code
****/
// Game variables
var cans = [];
var currentQuota = 10;
var goodCansProduced = 0;
var defectsRemoved = 0;
var consecutiveDefects = 0;
var gameSpeed = 1;
var spawnTimer = 0;
var spawnRate = 60; // frames between spawns
var isProductionRunning = true;
var level = 1;
// UI Elements
var quotaText = new Text2('Quota: 0/0', {
size: 60,
fill: 0xFFFFFF
});
quotaText.anchor.set(0.5, 0);
LK.gui.top.addChild(quotaText);
var levelText = new Text2('Level: 1', {
size: 50,
fill: 0xFFFFFF
});
levelText.anchor.set(0, 0);
levelText.x = 150;
levelText.y = 50;
LK.gui.topLeft.addChild(levelText);
var defectStreakText = new Text2('Consecutive Defects: 0', {
size: 40,
fill: 0xFF6B35
});
defectStreakText.anchor.set(0.5, 0);
defectStreakText.y = 80;
LK.gui.top.addChild(defectStreakText);
// Conveyor belt
var conveyorBelt = game.addChild(LK.getAsset('conveyorBelt', {
anchorX: 0.5,
anchorY: 0.5
}));
conveyorBelt.x = 1024;
conveyorBelt.y = 1400;
// Stop button
var stopButton = game.addChild(new StopButton());
stopButton.x = 1024;
stopButton.y = 1600;
// Stop button label
var stopButtonText = new Text2('STOP PRODUCTION', {
size: 40,
fill: 0xFFFFFF
});
stopButtonText.anchor.set(0.5, 0.5);
stopButtonText.x = stopButton.x;
stopButtonText.y = stopButton.y;
game.addChild(stopButtonText);
function spawnCan() {
if (!isProductionRunning) {
return;
}
var isDefective = Math.random() < 0.3; // 30% chance of defect
var can = new TunaCan(isDefective);
can.x = -100;
can.y = conveyorBelt.y;
can.speed = 2 + gameSpeed * 0.5;
cans.push(can);
game.addChild(can);
}
function updateDefectStreak() {
consecutiveDefects = 0;
defectStreakText.setText('Consecutive Defects: ' + consecutiveDefects);
}
function checkConsecutiveDefects() {
var recentCans = cans.slice(-3);
if (recentCans.length >= 3) {
var allDefective = true;
for (var i = 0; i < 3; i++) {
if (!recentCans[i].isDefective || recentCans[i].isClicked) {
allDefective = false;
break;
}
}
if (allDefective) {
consecutiveDefects = 3;
defectStreakText.setText('Consecutive Defects: ' + consecutiveDefects);
// Auto-stop production
LK.setTimeout(function () {
if (isProductionRunning) {
stopProduction();
}
}, 100);
}
}
}
function stopProduction() {
if (!isProductionRunning) {
return;
}
isProductionRunning = false;
// Check if quota was met
var quotaMet = goodCansProduced >= currentQuota && goodCansProduced <= currentQuota + 2;
var defectControl = consecutiveDefects >= 3;
if (quotaMet || defectControl) {
// Success
LK.getSound('success').play();
var points = quotaMet ? 100 + level * 10 : 50;
if (defectControl) {
points += 25;
}
LK.setScore(LK.getScore() + points);
// Next level
level++;
currentQuota += 5;
gameSpeed += 0.2;
spawnRate = Math.max(30, spawnRate - 2);
// Flash screen green
LK.effects.flashScreen(0x27ae60, 500);
// Reset for next level
LK.setTimeout(function () {
resetLevel();
}, 1000);
} else {
// Failure
LK.getSound('fail').play();
LK.effects.flashScreen(0xe74c3c, 1000);
LK.showGameOver();
}
}
function resetLevel() {
// Clear all cans
for (var i = cans.length - 1; i >= 0; i--) {
cans[i].destroy();
}
cans = [];
// Reset counters
goodCansProduced = 0;
defectsRemoved = 0;
consecutiveDefects = 0;
isProductionRunning = true;
// Update UI
updateUI();
}
function updateUI() {
quotaText.setText('Quota: ' + goodCansProduced + '/' + currentQuota);
levelText.setText('Level: ' + level);
defectStreakText.setText('Consecutive Defects: ' + consecutiveDefects);
}
// Initialize UI
updateUI();
game.update = function () {
if (!isProductionRunning) {
return;
}
// Spawn cans
spawnTimer++;
if (spawnTimer >= spawnRate) {
spawnTimer = 0;
spawnCan();
}
// Update cans and check for removal
for (var i = cans.length - 1; i >= 0; i--) {
var can = cans[i];
// Remove cans that are off screen
if (can.x > 2148) {
if (!can.isDefective && !can.isClicked) {
goodCansProduced++;
}
can.destroy();
cans.splice(i, 1);
continue;
}
// Check if unclicked defective cans passed through
if (can.x > 2048 && can.isDefective && !can.isClicked) {
checkConsecutiveDefects();
}
}
// Update UI
updateUI();
// Check win condition
if (goodCansProduced >= currentQuota + 5) {
// Over-production penalty
LK.getSound('fail').play();
LK.effects.flashScreen(0xe74c3c, 1000);
LK.showGameOver();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -20,9 +20,9 @@
var TunaCan = Container.expand(function (isDefective) {
var self = Container.call(this);
self.isDefective = isDefective || false;
self.isClicked = false;
- self.speed = 7;
+ self.speed = 10;
var canGraphics = self.attachAsset(self.isDefective ? 'defectCan' : 'goodCan', {
anchorX: 0.5,
anchorY: 0.5
});