User prompt
add a function to compute computerCandiesCount. Call it when it's computer turn
Code edit (11 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: self.candyCanes is undefined' in this line: 'self.player.y = self.candyCanes[0].y + 120;' Line Number: 51
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: LK.gui.centerLeft is undefined' in this line: 'LK.gui.centerLeft.addChild(self.playerYPositionText);' Line Number: 109
Code edit (1 edits merged)
Please save this source code
User prompt
move handleSelection out of Game function, add all required arguments
Code edit (10 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: self.fade is not a function' in this line: 'self.fade(self.computerPlayer, 500, true);' Line Number: 151
Code edit (1 edits merged)
Please save this source code
User prompt
use the fade function instead of fadein/fadeout
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Show computer
User prompt
Fix can’t see computer
User prompt
Dix can’t see computer
User prompt
Invert the fade calls
User prompt
On up. Both fadein and fadeout should be called in both playerturn cases
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'self')' in this line: 'self.fadeOut = function (target, duration) {' Line Number: 81
User prompt
Fix fadein/out calls on up event
User prompt
Add a new fadeout function
User prompt
Add a fadeIn function same principle as fadeout but inverted
User prompt
Fix gui nb selected no updated
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'LK.gui.bottomCenter.addChild')' in this line: 'LK.gui.bottomCenter.addChild(self.candyCaneYPositionText);' Line Number: 129
User prompt
Fix Bug: 'TypeError: undefined is not an object (evaluating 'LK.gui.bottomCenter.addChild')' in this line: 'LK.gui.bottomCenter.addChild(self.candyCaneYPositionText);' Line Number: 129
var LastCandyCane = Container.expand(function () {
var self = Container.call(this);
var candyCaneGraphics = self.createAsset('lastCandyCane', 'Last Candy Cane', .5, .5);
var shadow = new Container();
var shadowAlpha = 0.8;
shadow.createAsset('candyCaneShadow', 'Candy Cane Shadow', 0, 0);
shadow.width = shadow.width / 4;
shadow.x = -400;
shadow.y = -10;
shadow.alpha = shadowAlpha;
self.addChildAt(shadow, 0);
var shadow2 = new Container();
shadow2.createAsset('candyCaneShadow', 'Candy Cane Shadow', 0, 0);
shadow2.width = shadow2.width / 4;
shadow2.x = 25;
shadow2.y = -10;
shadow2.alpha = shadowAlpha;
self.addChildAt(shadow2, 0);
var shadowCentral = new Container();
shadowCentral.createAsset('candyCaneShadowCentral', 'Candy Cane Shadow Central', 0, 0);
shadowCentral.x = -305;
shadowCentral.y = -10;
shadowCentral.alpha = shadowAlpha;
self.addChildAt(shadowCentral, 0);
});
var CandyCane = Container.expand(function () {
var self = Container.call(this);
var candyCaneGraphics = self.createAsset('candyCane', 'Candy Cane', .5, .5);
var shadow = new Container();
var shadowAlpha = 0.8;
shadow.createAsset('candyCaneShadow', 'Candy Cane Shadow', 0, 0);
shadow.width = shadow.width / 4;
shadow.x = -320;
shadow.y = -10;
shadow.alpha = shadowAlpha;
self.addChildAt(shadow, 0);
var shadow2 = new Container();
shadow2.createAsset('candyCaneShadow', 'Candy Cane Shadow', 0, 0);
shadow2.width = shadow2.width / 4;
shadow2.x = 120;
shadow2.y = -10;
shadow2.alpha = shadowAlpha;
self.addChildAt(shadow2, 0);
var shadowCentral = new Container();
shadowCentral.createAsset('candyCaneShadowCentral', 'Candy Cane Shadow Central', 0, 0);
shadowCentral.x = -225;
shadowCentral.y = -10;
shadowCentral.alpha = shadowAlpha;
self.addChildAt(shadowCentral, 0);
self.pick = function () {
self.parent.selectedCandiesCount++;
var selectedCandiesText = LK.gui.topCenter.children[0];
selectedCandiesText.setText(self.parent.selectedCandiesCount.toString());
console.log("Picked ", self);
};
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player', .5, .5);
self.pickCandyCane = function () {
self.computerPlayer.pickCandyCane();
self.alpha = 0;
};
});
var ComputerPlayer = Container.expand(function () {
var self = Container.call(this);
var computerPlayerGraphics = self.createAsset('computerPlayer', 'Computer Player', .5, .5);
self.pickCandyCane = function () {
playerTurn = !playerTurn;
if (playerTurn) {
self.alpha = 0;
} else {
self.alpha = 1;
self.parent.addChild(self);
}
self.alpha = 0;
};
self.update = function () {};
});
var Game = Container.expand(function () {
var self = Container.call(this);
self.fadeOut = function (target, duration) {
var alphaDelta = target.alpha / (duration / (1000 / 60));
var fadeInterval = LK.setInterval(function () {
if (target.alpha > 0) {
target.alpha -= alphaDelta;
if (target.alpha <= 0) {
target.alpha = 0;
LK.clearInterval(fadeInterval);
}
}
}, 1000 / 60);
};
var background = self.createAsset('background', 'Game Background', 0.2545, 0.215);
self.addChildAt(background, 0);
LK.on('tick', function () {
if (self.player && self.playerYPositionText) {
self.playerYPositionText.setText('Y: ' + Math.round(self.player.y));
}
});
self.selectedCandiesCount = 0;
var selectedCandiesText = new Text2(self.selectedCandiesCount.toString(), {
size: 100,
fill: "#ffffff"
});
selectedCandiesText.anchor.set(.5, 0);
LK.gui.topRight.addChild(selectedCandiesText);
var candyCanes = [];
for (var i = 0; i < 12; i++) {
var candyCane = new CandyCane();
candyCane.x = 2048 / 2;
candyCane.y = 300 + i * 190;
candyCanes.push(candyCane);
self.addChild(candyCane);
}
var lastCandyCane = new LastCandyCane();
lastCandyCane.x = 2048 / 2 + 80;
lastCandyCane.y = 250 + 12 * 190;
candyCanes.push(lastCandyCane);
self.addChild(lastCandyCane);
self.player = self.addChild(new Player());
self.player.x = 400;
self.player.y = 70;
self.candyCaneYPositionText = new Text2('', {
size: 100,
fill: "#ffffff"
});
self.candyCaneYPositionText.anchor.set(0.5, 0);
LK.gui.bottomCenter.addChild(self.candyCaneYPositionText);
LK.on('tick', function () {
if (candyCanes.length > 0 && self.candyCaneYPositionText) {
self.candyCaneYPositionText.setText('Y: ' + Math.round(candyCanes[0].y));
}
});
var playerTurn = true;
self.computerPlayer = new ComputerPlayer();
self.computerPlayer.x = 1648;
self.computerPlayer.y = 1324;
stage.on('down', function (obj) {
console.log('Mouse down event:', obj);
stage.on('move', handleSelection);
});
function handleSelection(obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
var topCandyIndex = 0;
var minY = candyCanes[0].y;
var maxY = candyCanes[2].y + 140;
self.player.y = Math.max(minY, Math.min(maxY, pos.y));
if (self.player.y < candyCanes[0].y + 120) {
self.selectedCandiesCount = 1;
} else if (self.player.y < candyCanes[1].y + 120) {
self.selectedCandiesCount = 2;
} else if (self.player.y < candyCanes[2].y + 120) {
self.selectedCandiesCount = 3;
}
for (var i = 0; i < candyCanes.length; i++) {
if (i < self.selectedCandiesCount) {
candyCanes[i].scale.set(1.1);
} else {
candyCanes[i].scale.set(1);
}
}
var selectedCandiesText = LK.gui.topCenter.children[0];
selectedCandiesText.setText(self.selectedCandiesCount.toString());
}
stage.on('up', function (obj) {
console.log('Mouse up event:', obj);
stage.off('move', handleSelection);
for (var i = 0; i < self.selectedCandiesCount; i++) {
if (candyCanes.length > 0) {
var candyToRemove = candyCanes.shift();
candyToRemove.destroy();
}
}
self.selectedCandiesCount = 0;
var selectedCandiesText = LK.gui.topCenter.children[0];
selectedCandiesText.setText(self.selectedCandiesCount.toString());
if (playerTurn) {
self.fadeOut(self.player, 500);
self.computerPlayer.alpha = 1;
self.addChild(self.computerPlayer);
} else {
self.fadeOut(self.player, 500);
self.computerPlayer.alpha = 0;
self.computerPlayer.parent.removeChild(self.computerPlayer);
}
playerTurn = !playerTurn;
});
});
a christmas wooden board Background image. High contrast. No shadows.
a vertical christmas wooden board with snow, and decorations on its sides Background image. High contrast. No shadows.
a photo-realistic white and red vertical candy stick slice Single Game Texture. No background. High contrast. No shadows.
a horizontal santa's arm with a white glove and the index pointing to the right Single Game Texture. No background. High contrast. No shadows.
an green hairy grinch's arm, pointing in the horizontal direction, the index finger pointing to the left Single Game Texture. No background. High contrast. No shadows.
a photo-realistic white and red twisted candy stick slice in vertical position and with an extinguished wick. At its center, a simple white rectangular "TNT" sticker in the same direction as the stick Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a top view of a TNT explosion fire Background image. High contrast. No shadows.
A funny Santa Claus disheveled and covered by black soot after an explosion. stary night. High contrast.
a futuristic white robot arm. horizontal direction. the index finger pointing to the left. Single Game Texture. No background. High contrast. No shadows.
A old super hero Santa Claus holding a candy cane in his hand High contrast.
frame of an empty christmas themed popup with a decorated border User interface
a single mat rounded empty button User interface