Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Migrate to the latest version of LK
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'includes')' in this line: 'if (child instanceof Text2 && child.text.includes('Tap on ingredients')) {' Line Number: 76
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'setText')' in this line: 'self.parent.instructionText.setText('Good job! Bon appetit!\nGame Completed');' Line Number: 75
Code edit (4 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: instructionsText is not defined' in this line: 'instructionsText.visible = false;' Line Number: 131
Code edit (2 edits merged)
Please save this source code
User prompt
before gameover create and show an image
Code edit (1 edits merged)
Please save this source code
User prompt
when 80 cookieseaten, show gameover
User prompt
Fix Bug: 'ReferenceError: scoreManager is not defined' in this line: 'var cookie = new Cookie(scoreManager);' Line Number: 125
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Uncaught ReferenceError: ScoreManager is not defined' in this line: 'var scoreManager = new ScoreManager();' Line Number: 180
Code edit (1 edits merged)
Please save this source code
User prompt
make a global int called cookiesEaten
User prompt
Fix Bug: 'ReferenceError: scoreText is not defined' in this line: 'scoreText.setText(self.score);' Line Number: 35
User prompt
Fix Bug: 'ReferenceError: scoreText is not defined' in this line: 'scoreText.setText(self.score);' Line Number: 35
===================================================================
--- original.js
+++ change.js
@@ -1,8 +1,12 @@
-var cookiesEaten = 0;
+/****
+* Classes
+****/
var Bowl = Container.expand(function () {
var self = Container.call(this);
- var bowlGraphics = self.createAsset('bowl', 'Bowl Graphics', 0, 1);
+ var bowlGraphics = self.attachAsset('bowl', {
+ anchorY: 1
+ });
self.x = 0;
self.y = 2732 - bowlGraphics.height;
self.height = bowlGraphics.height;
self.containsPoint = function (point) {
@@ -11,70 +15,61 @@
self.hasEgg = false;
self.hasSugar = false;
self.hasButter = false;
});
-var Egg = Container.expand(function () {
- var self = Container.call(this);
- var eggGraphics = self.createAsset('egg', 'Egg Graphics', .5, .5);
- self.containsPoint = function (point) {
- return point.x >= this.x - this.width / 2 && point.x <= this.x + this.width / 2 && point.y >= this.y - this.height / 2 && point.y <= this.y + this.height / 2;
- };
- self.crack = function () {
- var crackedEggGraphics = self.createAsset('cracked_egg', 'Cracked Egg Graphics', .5, .5);
- self.removeChild(eggGraphics);
- self.addChild(crackedEggGraphics);
- };
-});
-var Sugar = Container.expand(function () {
- var self = Container.call(this);
- var sugarGraphics = self.createAsset('sugar', 'Sugar Graphics', .5, .5);
- self.containsPoint = function (point) {
- return point.x >= this.x - this.width / 2 && point.x <= this.x + this.width / 2 && point.y >= this.y - this.height / 2 && point.y <= this.y + this.height / 2;
- };
- self.pour = function (bowl) {
- var pouredSugarGraphics = self.createAsset('poured_sugar', 'Poured Sugar Graphics', .5, .5);
- self.removeChild(sugarGraphics);
- self.addChild(pouredSugarGraphics);
- };
-});
var Butter = Container.expand(function () {
var self = Container.call(this);
- var butterGraphics = self.createAsset('butter', 'Butter Graphics', .5, .5);
+ var butterGraphics = self.attachAsset('butter', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.containsPoint = function (point) {
return point.x >= this.x - this.width / 2 && point.x <= this.x + this.width / 2 && point.y >= this.y - this.height / 2 && point.y <= this.y + this.height / 2;
};
self.unpack = function (bowl) {
- var unpackedButterGraphics = self.createAsset('unpacked_butter', 'Unpacked Butter Graphics', .5, .5);
+ var unpackedButterGraphics = self.attachAsset('unpacked_butter', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.removeChild(butterGraphics);
self.addChild(unpackedButterGraphics);
};
});
var Cookie = Container.expand(function (scoreManager) {
var self = Container.call(this);
self.scoreManager = scoreManager;
- var cookieGraphics = self.createAsset('cookie', 'Cookie Graphics', .5, .5);
+ var cookieGraphics = self.attachAsset('cookie', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.bake = function () {};
self.bitesLeft = 2;
self.addBiteMark = function () {
self.bitesLeft--;
if (self.bitesLeft > 0) {
- var biteMarkGraphics = self.createAsset('bitemark', 'Bite Mark Graphics', .5, .5);
+ var biteMarkGraphics = self.attachAsset('bitemark', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
biteMarkGraphics.x = cookieGraphics.x;
biteMarkGraphics.y = cookieGraphics.y;
var h = 3 / 32;
var s = 0.8;
var v = 0.8;
self.removeChild(cookieGraphics);
self.addChild(biteMarkGraphics);
} else {
- cookiesEaten += 20;
+ cookiesEaten++;
if (cookiesEaten >= 24) {
- var gameOverImage = self.createAsset('game_over_image', 'Game Over Image', 0.5, 0.5);
+ var gameOverImage = self.attachAsset('game_over_image', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
gameOverImage.x = 1024;
gameOverImage.y = 1366;
self.parent.addChild(gameOverImage);
- LK.gui.topCenter.children.forEach(function (child) {
- if (child instanceof Text2 && child.text) {
+ LK.gui.top.children.forEach(function (child) {
+ if (child instanceof Text2) {
child.setText('Good job! Bon appetit!\nGame Completed');
child.visible = true;
}
});
@@ -93,9 +88,11 @@
var delta = end - start;
var startTime = LK.ticks;
function easeInOutElastic(t, b, c, d) {
t /= d / 2;
- if (t < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
+ if (t < 1) {
+ return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
+ }
t--;
return c / 2 * (-Math.pow(2, -10 * t) + 2) + b;
}
LK.on('tick', function () {
@@ -116,103 +113,148 @@
self.x = newX;
});
};
});
-var Game = Container.expand(function () {
+var Egg = Container.expand(function () {
var self = Container.call(this);
- var background = self.createAsset('background', 'Background Image', 0, 0);
- background.width = 2048;
- background.height = 2732;
- background.alpha = 0.5;
- self.addChildAt(background, 0);
- var instructionText = new Text2('Tap on ingredients to add them to the bowls\nThen tap to mix, bake and eat the cookies :)', {
- size: 60,
- fill: '#ffdddd',
- align: 'center',
- dropShadow: true
+ var eggGraphics = self.attachAsset('egg', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- instructionText.anchor.set(0.5, 0.4);
- instructionText.y = 50;
- LK.gui.topCenter.addChild(instructionText);
- stage.on('down', function (obj) {
- instructionText.visible = false;
- var pos = obj.event.getLocalPosition(self);
- bowls.forEach(function (bowl, index) {
- if (bowl.containsPoint(pos) && bowl.hasEgg && bowl.hasSugar && bowl.hasButter) {
- for (var j = 0; j < 3; j++) {
- var cookie = new Cookie();
- cookie.bake();
- cookie.x = bowl.x + bowl.width / 2;
- cookie.y = bowl.y - cookie.height / 2;
- cookie.rotation = Math.random() * (Math.PI * 2);
- self.addChild(cookie);
- cookies.push(cookie);
- cookie.flyToRandomPosition();
- cookie.on('down', function () {
- this.addBiteMark();
- });
- }
- bowls[index].destroy();
- bowls.splice(index, 1);
- sugars[index].destroy();
- sugars.splice(index, 1);
- butters[index].destroy();
- butters.splice(index, 1);
- eggs[index].destroy();
- eggs.splice(index, 1);
- }
+ self.containsPoint = function (point) {
+ return point.x >= this.x - this.width / 2 && point.x <= this.x + this.width / 2 && point.y >= this.y - this.height / 2 && point.y <= this.y + this.height / 2;
+ };
+ self.crack = function () {
+ var crackedEggGraphics = self.attachAsset('cracked_egg', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- eggs.forEach(function (egg, index) {
- if (egg.containsPoint(pos)) {
- egg.crack();
- var targetBowl = bowls[index % bowls.length];
- egg.x = targetBowl.x + targetBowl.width / 2 + 60;
- egg.y = targetBowl.y - egg.height - 50;
- targetBowl.hasEgg = true;
- }
+ self.removeChild(eggGraphics);
+ self.addChild(crackedEggGraphics);
+ };
+});
+var Sugar = Container.expand(function () {
+ var self = Container.call(this);
+ var sugarGraphics = self.attachAsset('sugar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.containsPoint = function (point) {
+ return point.x >= this.x - this.width / 2 && point.x <= this.x + this.width / 2 && point.y >= this.y - this.height / 2 && point.y <= this.y + this.height / 2;
+ };
+ self.pour = function (bowl) {
+ var pouredSugarGraphics = self.attachAsset('poured_sugar', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- butters.forEach(function (butter, index) {
- if (butter.containsPoint(pos)) {
- var targetBowl = bowls[index % bowls.length];
- butter.unpack(targetBowl);
- butter.x = targetBowl.x + targetBowl.width / 2 - 60;
- butter.y = targetBowl.y - butter.height - 50;
- targetBowl.hasButter = true;
+ self.removeChild(sugarGraphics);
+ self.addChild(pouredSugarGraphics);
+ };
+});
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+var cookiesEaten = 0;
+var background = game.attachAsset('background', {});
+background.width = 2048;
+background.height = 2732;
+background.alpha = 0.5;
+game.addChildAt(background, 0);
+var instructionText = new Text2('Tap on ingredients to add them to the bowls\nThen tap to mix, bake and eat the cookies :)', {
+ size: 60,
+ fill: '#ffdddd',
+ align: 'center',
+ dropShadow: true
+});
+instructionText.anchor.set(0.5, 0.4);
+instructionText.y = 50;
+LK.gui.top.addChild(instructionText);
+game.on('down', function (x, y, obj) {
+ instructionText.visible = false;
+ var pos = game.toLocal(obj.global);
+ bowls.forEach(function (bowl, index) {
+ if (bowl.containsPoint(pos) && bowl.hasEgg && bowl.hasSugar && bowl.hasButter) {
+ for (var j = 0; j < 3; j++) {
+ var cookie = new Cookie();
+ cookie.bake();
+ cookie.x = bowl.x + bowl.width / 2;
+ cookie.y = bowl.y - cookie.height / 2;
+ cookie.rotation = Math.random() * (Math.PI * 2);
+ game.addChild(cookie);
+ cookies.push(cookie);
+ cookie.flyToRandomPosition();
+ cookie.on('down', function () {
+ this.addBiteMark();
+ });
}
- });
- sugars.forEach(function (sugar, index) {
- if (sugar.containsPoint(pos)) {
- var targetBowl = bowls[index % bowls.length];
- sugar.pour();
- sugar.x = targetBowl.x + targetBowl.width / 2;
- sugar.y = targetBowl.y - sugar.height;
- targetBowl.hasSugar = true;
- }
- });
+ bowls[index].destroy();
+ bowls.splice(index, 1);
+ sugars[index].destroy();
+ sugars.splice(index, 1);
+ butters[index].destroy();
+ butters.splice(index, 1);
+ eggs[index].destroy();
+ eggs.splice(index, 1);
+ }
});
- var bowls = [];
- var sugars = [];
- var eggs = [];
- var butters = [];
- var cookies = [];
- for (var i = 0; i < 8; i++) {
- var bowl = new Bowl();
- bowl.x = i * (bowl.width + 10);
- bowls.push(bowl);
- self.addChild(bowl);
- var sugar = new Sugar();
- sugar.x = 200 + Math.random() * 1600;
- sugar.y = 200 + Math.random() * 2032;
- sugars.push(sugar);
- self.addChild(sugar);
- var butter = new Butter();
- butter.x = 200 + Math.random() * 1600;
- butter.y = 200 + Math.random() * 2032;
- butters.push(butter);
- self.addChild(butter);
- var egg = new Egg();
- egg.x = 200 + Math.random() * 1600;
- egg.y = 200 + Math.random() * 2032;
- eggs.push(egg);
- self.addChild(egg);
- }
+ eggs.forEach(function (egg, index) {
+ if (egg.containsPoint(pos)) {
+ egg.crack();
+ var targetBowl = bowls[index % bowls.length];
+ egg.x = targetBowl.x + targetBowl.width / 2 + 60;
+ egg.y = targetBowl.y - egg.height - 50;
+ targetBowl.hasEgg = true;
+ }
+ });
+ butters.forEach(function (butter, index) {
+ if (butter.containsPoint(pos)) {
+ var targetBowl = bowls[index % bowls.length];
+ butter.unpack(targetBowl);
+ butter.x = targetBowl.x + targetBowl.width / 2 - 60;
+ butter.y = targetBowl.y - butter.height - 50;
+ targetBowl.hasButter = true;
+ }
+ });
+ sugars.forEach(function (sugar, index) {
+ if (sugar.containsPoint(pos)) {
+ var targetBowl = bowls[index % bowls.length];
+ sugar.pour();
+ sugar.x = targetBowl.x + targetBowl.width / 2;
+ sugar.y = targetBowl.y - sugar.height;
+ targetBowl.hasSugar = true;
+ }
+ });
});
+var bowls = [];
+var sugars = [];
+var eggs = [];
+var butters = [];
+var cookies = [];
+for (var i = 0; i < 8; i++) {
+ var bowl = new Bowl();
+ bowl.x = i * (bowl.width + 10);
+ bowls.push(bowl);
+ game.addChild(bowl);
+ var sugar = new Sugar();
+ sugar.x = 200 + Math.random() * 1600;
+ sugar.y = 200 + Math.random() * 2032;
+ sugars.push(sugar);
+ game.addChild(sugar);
+ var butter = new Butter();
+ butter.x = 200 + Math.random() * 1600;
+ butter.y = 200 + Math.random() * 2032;
+ butters.push(butter);
+ game.addChild(butter);
+ var egg = new Egg();
+ egg.x = 200 + Math.random() * 1600;
+ egg.y = 200 + Math.random() * 2032;
+ eggs.push(egg);
+ game.addChild(egg);
+}
\ No newline at end of file
egg. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
sugar in a bag. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a butter stik in its wrapper. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a pink kithen bowl. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pile of sugar. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cracked egg white and yolk seeping. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
soft butter stick. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A delicious plain vanilla cookie. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A delicious plain vanilla cookie, where three bites have been taken. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cute kawaian bakery interior with strawberry tiles. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A cute girl happily eating way too many vanilla cookies. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.