Code edit (10 edits merged)
Please save this source code
User prompt
create a global function mainSpawner with the same code as giftSpawnTimer
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: secondsBeforeChristmasTxt is not defined' in this line: 'secondsBeforeChristmasTxt.setText(formatTime(secondsBeforeChristmas));' Line Number: 30
User prompt
Fix Bug: 'Timeout.tick error: secondsBeforeChristmasTxt is undefined' in this line: 'secondsBeforeChristmasTxt.setText(formatTime(secondsBeforeChristmas));' Line Number: 30
User prompt
Fix Bug: 'Timeout.tick error: giftWrapper is not defined' in this line: 'giftWrapper.destroy();' Line Number: 49
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'uncaught exception: timeout callback must be a function' in this line: 'if (availableGiftsCounter > 0) {' Line Number: 68
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: gifts is not defined' in this line: 'gifts.push(newGift);' Line Number: 75
User prompt
Fix Bug: 'ReferenceError: gifts is not defined' in this line: 'for (var a = gifts.length - 1; a >= 0; a--) {' Line Number: 273
User prompt
Fix Bug: 'Timeout.tick error: self.gifts is undefined' in this line: 'self.gifts.push(newGift);' Line Number: 75
User prompt
Fix Bug: 'ReferenceError: gifts is not defined' in this line: 'for (var a = gifts.length - 1; a >= 0; a--) {' Line Number: 273
User prompt
Fix Bug: 'uncaught exception: timeout callback must be a function' in this line: 'if (availableGiftsCounter > 0) {' Line Number: 68
User prompt
Now along with everything related to elves (hireElfButton, elves, WorkingElf, workingElves, ElfGift , newElfGift, elvesTxt, elfCostTxt ) create every thing to handle the new additional worker : Gingerbread Boy (hireGingerButton, gingerBoys, WorkingGinger, workingGingers, GingerGift , newGingerGift, gingersTxt, gingerCostTxt )
Code edit (11 edits merged)
Please save this source code
User prompt
like for hireElfbutton, set the hireGingerButton alpha to 0.5 and inactive when score < ginger Cost
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: workingGingers is undefined' in this line: 'if (workingGingers.length < gingerBoys) {' Line Number: 310
User prompt
Fix Bug: 'Timeout.tick error: workingGingers is undefined' in this line: 'if (workingGingers.length < gingerBoys) {' Line Number: 311
User prompt
Fix Bug: 'Timeout.tick error: workingGingers is undefined' in this line: 'if (workingGingers.length < gingerBoys) {' Line Number: 310
User prompt
Fix Bug: 'Timeout.tick error: workingGingers is undefined' in this line: 'if (workingGingers.length < gingerBoys) {' Line Number: 311
User prompt
Fix Bug: 'Timeout.tick error: workingGingers is undefined' in this line: 'if (workingGingers.length < gingerBoys) {' Line Number: 310
Code edit (7 edits merged)
Please save this source code
Code edit (18 edits merged)
Please save this source code
var score = 0;
var gameWinStatus = 0;
var elves = 0;
var availableGiftsCounter = 0;
var secondsBeforeChristmas = 86400 * 25;
var giftsNeeded = 8000000;
function formatTime(nbSeconds) {
var days = Math.floor(nbSeconds / 86400);
var hours = Math.floor(nbSeconds % 86400 / 3600);
var minutes = Math.floor(nbSeconds % 3600 / 60);
var seconds = nbSeconds % 60;
days = days.toString().padStart(2, '0');
hours = hours.toString().padStart(2, '0');
minutes = minutes.toString().padStart(2, '0');
seconds = seconds.toString().padStart(2, '0');
if (nbSeconds > 86400) {
return days + 'd ' + hours + 'h ' + minutes + 'min';
} else {
return hours + 'h ' + minutes + 'min ' + seconds + 'sec';
}
}
var SantaClaus = Container.expand(function () {
var self = Container.call(this);
var santaGraphics = self.createAsset('santaClaus', 'Santa Claus Graphics', 0.5, 0.5);
self.speed = 6;
self.move = function () {
self.x += self.speed;
};
LK.on('tick', function () {
self.move();
});
});
var Raindrop = Container.expand(function () {
var self = Container.call(this);
var raindropGraphics = self.createAsset('raindrop', 'Raindrop Graphics', 0.5, 0.5);
self.speed = Math.random() * 5 + 5;
self.move = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
LK.on('tick', function () {
self.move();
});
});
var Confetti = Container.expand(function () {
var self = Container.call(this);
var colors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF];
var confettiGraphics = self.createAsset('confetti', 'Confetti Graphics', 0.5, 0.5);
confettiGraphics.tint = colors[Math.floor(Math.random() * colors.length)];
self.speed = Math.random() * 5 + 2;
self.rotationSpeed = Math.random() * 0.1;
self.move = function () {
self.y += self.speed;
self.rotation += self.rotationSpeed;
if (self.y > 2732) {
self.destroy();
}
};
LK.on('tick', function () {
self.move();
});
});
var WorkingElf = Container.expand(function () {
var self = Container.call(this);
var elfGraphics = self.createAsset('workingElf1', 'Working Elf Graphics', .5, .5);
self.speed = 3;
self.move = function () {
if (self.startFromLeft) {
self.x += self.speed;
} else {
self.x -= self.speed;
self.scale.x = -1;
}
};
});
var ElfGift = Container.expand(function () {
var self = Container.call(this);
var elfGiftGraphics = self.createAsset('elfGift', 'Elf Gift Graphics', .5, .5);
self.speed = 5;
self.move = function () {
self.y += self.speed;
};
});
var Gift = Container.expand(function () {
var self = Container.call(this);
var giftGraphics = self.createAsset('gift', 'Gift Graphics', .5, .5);
self.speed = 5;
self.move = function () {
self.y += self.speed;
};
});
var HireElfButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.createAsset('hireElf', 'Hire Elf Button', 0.5, 0.5);
buttonGraphics.scale.set(2);
buttonGraphics.tint = 0xffff00;
self.on('down', function () {
var elfCost = Math.pow(2, elves) * 5;
if (score >= elfCost) {
score -= elfCost;
elves += 1;
}
});
});
var Game = Container.expand(function () {
var self = Container.call(this);
self.showRainAnimation = function () {
for (var i = 0; i < 100; i++) {
var raindrop = new Raindrop();
raindrop.x = Math.random() * 2048;
raindrop.y = -Math.random() * 2732;
self.addChild(raindrop);
}
};
self.showConfettiAnimation = function () {
for (var i = 0; i < 50; i++) {
var confettiPiece = new Confetti();
confettiPiece.x = Math.random() * 2048;
confettiPiece.y = Math.random() * 2732;
self.addChild(confettiPiece);
}
};
var background = self.createAsset('background', 'Background Image', 0, 0);
background.scale.set(2, 3);
self.addChildAt(background, 0);
var giftWrapper = self.createAsset('giftWrapper', 'Big central button', 0.5, 0.5);
giftWrapper.scale.set(5);
giftWrapper.x = 2048 / 2;
giftWrapper.y = 2732 / 2;
giftWrapper.on('down', function () {
clickCount++;
score++;
availableGiftsCounter++;
giftWrapper.scale.set(4.5);
LK.setTimeout(function () {
giftWrapper.scale.set(5);
}, 300);
});
var gifts = [];
var workingElves = [];
var giftsPerSecond = 0;
var clickCount = 0;
var startTime = Date.now();
var santaClaus = new SantaClaus();
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
var elvesTxt = new Text2('0', {
size: 100,
fill: "#ffffff"
});
var giftsPerSecondTxt = new Text2('0', {
size: 50,
fill: "#ffffff"
});
var hireElfButton = self.addChild(new HireElfButton());
var giftsNeededTxt = new Text2(giftsNeeded + '', {
size: 50,
fill: "#ffffff"
});
giftsNeededTxt.anchor.set(1.2, 1);
LK.gui.bottomRight.addChild(giftsNeededTxt);
var giftsNeededLabel = new Text2('Gifts needed', {
size: 50,
fill: "#ffffff"
});
giftsNeededLabel.anchor.set(1, 2);
LK.gui.bottomRight.addChild(giftsNeededLabel);
var xmasCountdownLabel = new Text2('Xmas Countdown', {
size: 50,
fill: "#ffffff"
});
xmasCountdownLabel.anchor.set(0, 2);
LK.gui.bottomLeft.addChild(xmasCountdownLabel);
var secondsBeforeChristmasTxt = new Text2(formatTime(secondsBeforeChristmas), {
size: 50,
fill: "#ffffff"
});
secondsBeforeChristmasTxt.anchor.set(-0.1, 1);
LK.gui.bottomLeft.addChild(secondsBeforeChristmasTxt);
var elfCostTxt = new Text2('5', {
size: 50,
fill: "#ffffff"
});
elfCostTxt.anchor.set(0.5, 0);
hireElfButton.x = 2048 - hireElfButton.width / 2 - 40;
hireElfButton.y = hireElfButton.height / 2 + 40;
elfCostTxt.x = 1340;
elfCostTxt.y = 175;
LK.gui.addChild(elfCostTxt);
var giftsNeededLabel = new Text2('Gifts wrapped', {
size: 50,
fill: "#ffffff"
});
giftsNeededLabel.anchor.set(.5, 0);
LK.gui.topCenter.addChild(giftsNeededLabel);
scoreTxt.anchor.set(.5, -0.2);
LK.gui.topCenter.addChild(scoreTxt);
LK.gui.topCenter.addChild(elvesTxt);
elvesTxt.x = scoreTxt.x + 460;
elvesTxt.y = scoreTxt.y + 40;
LK.gui.topLeft.addChild(giftsPerSecondTxt);
giftsPerSecondTxt.anchor.set(0, -1);
var giftSpawnTimer = LK.setInterval(function () {
secondsBeforeChristmas = Math.max(0, secondsBeforeChristmas - 480);
if (score > giftsNeeded) {
gameWinStatus = 1;
giftWrapper.visible = false;
var winBackground = self.createAsset('winBackground', 'Win Background Image', 0, 0.05);
winBackground.scale.set(2, 3);
self.addChildAt(winBackground, 1);
self.showConfettiAnimation();
if (!self.santaAdded) {
santaClaus.x = -100;
santaClaus.y = 2732 * 0.25;
self.santaAdded = true;
}
self.addChild(santaClaus);
LK.setTimeout(function () {
LK.showGameOver(false);
santaClaus.destroy();
}, 7000);
} else if (secondsBeforeChristmas === 0 && score < giftsNeeded) {
gameWinStatus = -1;
var lostBackground = self.createAsset('lostBackground', 'Lost Background Image', 0, 0.06);
lostBackground.scale.set(2, 3);
self.addChildAt(lostBackground, 1);
self.showRainAnimation();
LK.setTimeout(function () {
LK.showGameOver();
}, 5000);
}
secondsBeforeChristmasTxt.setText(formatTime(secondsBeforeChristmas));
if (elves > 0) {
score += elves;
var newElfGift = new ElfGift();
newElfGift.x = Math.random() * 2048;
newElfGift.y = 0;
gifts.push(newElfGift);
self.addChild(newElfGift);
if (workingElves.length < elves) {
var workingElf = new WorkingElf();
workingElf.startFromLeft = Math.random() < 0.5;
workingElf.x = workingElf.startFromLeft ? -workingElf.width : 2048 + workingElf.width;
workingElf.y = 2732 - Math.random() * (2732 / 3 - workingElf.height);
workingElves.push(workingElf);
self.addChild(workingElf);
}
}
if (availableGiftsCounter > 0) {
availableGiftsCounter--;
giftWrapper.destroy();
hireElfButton.destroy();
var newGift = new Gift();
newGift.x = Math.random() * 2048;
newGift.y = 0;
gifts.push(newGift);
self.addChild(newGift);
self.addChild(giftWrapper);
self.addChild(hireElfButton);
}
}, 1000);
LK.on('tick', function () {
var currentTime = Date.now();
var elapsedTime = (currentTime - startTime) / 1000;
giftsPerSecond = (clickCount + elves * elapsedTime) / elapsedTime;
for (var a = gifts.length - 1; a >= 0; a--) {
gifts[a].move();
if (gifts[a].y > 2732 + gifts[a].height) {
gifts[a].destroy();
gifts.splice(a, 1);
}
}
for (var e = workingElves.length - 1; e >= 0; e--) {
workingElves[e].move();
if (workingElves[e].startFromLeft && workingElves[e].x > 2048 + workingElves[e].width || !workingElves[e].startFromLeft && workingElves[e].x < -200) {
workingElves[e].destroy();
workingElves.splice(e, 1);
}
}
scoreTxt.setText(score);
elvesTxt.setText(elves);
var elfCost = Math.pow(2, elves) * 5;
elfCostTxt.setText(elfCost);
hireElfButton.alpha = score < elfCost ? 0.5 : 1;
hireElfButton.interactive = score >= elfCost;
giftsPerSecondTxt.setText('Gifts/sec: ' + Math.round(giftsPerSecond));
giftsNeededTxt.setText(Math.max(0, giftsNeeded - score));
});
stage.on('down', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
for (var a = gifts.length - 1; a >= 0; a--) {
if (gifts[a].intersects({
x: pos.x,
y: pos.y,
width: 1,
height: 1
})) {
clickCount++;
gifts[a].destroy();
gifts.splice(a, 1);
score++;
}
}
});
});
A big red christmas gift, isometric view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Top view of a round gift box with a ribbon Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute elf Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A big green christmas gift, isometric view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Profil view of a cute little elf with a green hat, standing with his hands in front of him.no background . no floor. In-Game asset. 2d. Blank background. High contrast. No shadows.
A feerical landscape with santa's house, pines, snow, glowing lights, at night. In the front, cute elves with gree hats, gingerbread boys, teddy bears, celebrating, but no Santa Clauss in the image. Background image. High contrast. No shadows.
Provile view of Santa clauss in his sleigh with reindeer, smiling and making a sign with his hand game Asset. High contrast. No shadows.
A sad landscape with santa's house, pines, snow, mountains in the back, at night. A cute sad santa crying with big tears in the front. clean feeric style. Background image. 2d. Blank background. Color. High contrast. No shadows.
a cute gingerbread boy Single Game Texture. 2d. Transparent background. High contrast. No shadows.
A big gingerbread christmas gift, isometric view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A right profile drawing of one single cute little gingerbread boy, standing with his hands in front of him. In-Game asset. 2d. No background. High contrast. No shadows. Color. digital art
a cute smiling teddy bear standing Single Game Texture. 2d. Transparent background. High contrast. No shadows. No border.
A cute brown teddy bear from his right profile, standing, looking to the right direction and smiling with his hands in front of him. Feeric style. No background. No shadows. No back light. High contrast. Single Game Texture. In-Game asset. 2d.
a little green soldier toy standing Single Game Texture. 2d. Transparent background. High contrast. No shadows.
Profil view of a little green soldier toy, walking. no background . no floor. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute little santa's reindeer with a red nose sitting Single Game Texture. 2d. Transparent background. High contrast. No shadows.
A big white and red dotted christmas gift, isometric view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Profil view of a cute little santa's reindeer with a red nose, walking in the right direction. no background . no floor. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute little grinch standing with a santa's hat Single Game Texture. 2d. Transparent background. High contrast. No shadows.
A big purple and green dotted christmas gift, isometric view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Profile view of a mischievous little green grinch with a red scarf, big ears but no tail. Walking in the right direction. no background . no floor. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute little fairy standing with a santa hat and a magic wand Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A big light blue decorated christmas gift, isometric view Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Profile view of a cute little fairy with a santa hat and a magic wand. Flying in the right direction. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a landscape with santa's house on the left, pines with chistmas lights, snow, at night Background image. 2d. High contrast.
a big light brown and yellow christmas gift decorated with holly leaf. isometric view. no floor. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a big green and white christmas gift ornated. isometric view. nothing under. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.