Code edit (1 edits merged)
Please save this source code
Code edit (1 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 'toString')' in this line: 'var scoreText = new Text2('You got ' + this.playerScore.toString() + ' out of 50\nfruits in the right baskets!', {' Line Number: 255
User prompt
change the scoretext before gameover to display actual playerscore, not 0
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'toString')' in this line: 'var scoreText = new Text2('You got ' + this.playerScore.toString() + ' out of 50\nfruits in the right baskets!', {' Line Number: 255
User prompt
change scoreText to reference playerscore instead og scoreinstance
User prompt
change score to reference a playerscore value stored in game
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'toString')' in this line: 'var scoreText = new Text2('You got ' + (scoreInstance ? scoreInstance.scoreValue.toString() : '0') + ' out of 50\nfruits in the right baskets!', {' Line Number: 254
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'toString')' in this line: 'var scoreText = new Text2('You got ' + scoreInstance.scoreValue.toString() + ' out of 50\nfruits in the right baskets!', {' Line Number: 254
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'scoreValue')' in this line: 'var scoreText = new Text2('You got ' + this.scoreInstance.scoreValue.toString() + ' out of 50\nfruits in the right baskets!', {' Line Number: 254
Code edit (3 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'toString')' in this line: 'var scoreText = new Text2('You got ' + scoreInstance.scoreValue.toString() + ' out of 50\nfruits in the right baskets!', {' Line Number: 254
Code edit (1 edits merged)
Please save this source code
User prompt
before gameover, show a text label: you got X out of 50 fruits in the right baskets! where x is playerscore
User prompt
if spawncount is 100 and no balls exists, show game over text
User prompt
only create new balls while spawncount is less than 100
User prompt
increment spawncount by 1 each time a ball is spawned
User prompt
make a variable spawncount and set it to 0 at start
User prompt
move score label left so it always show all text
User prompt
on click anywhere, hide starttext and set game.gamestarted = true
/**** * Classes ****/ var Bat = Container.expand(function () { var self = Container.call(this); var batGraphics = self.attachAsset('bat', { anchorX: 0.5, anchorY: 0.5 }); batGraphics.scale.set(2); self._move_migrated = function () {}; }); var BlueGoal = Container.expand(function () { var self = Container.call(this); var goalGraphics = self.attachAsset('goal_blue', { anchorX: 0.5, anchorY: 0.5 }); self.checkScore = function (ball, score) { if (this.intersects(ball)) { if (ball.color === 'blue') { score.increaseScore(1); var explosion = new ParticleExplosion('blue'); explosion.x = ball.x; explosion.y = ball.y; self.parent.addChild(explosion); ball.destroy(); self.parent.balls.splice(self.parent.balls.indexOf(ball), 1); } else { ball.destroy(); self.parent.balls.splice(self.parent.balls.indexOf(ball), 1); } } }; }); var ColoredBall = Container.expand(function (color) { var self = Container.call(this); self.lastHitTime = 0; self.color = color; var ballGraphics = self.createAsset('ball_' + color, { anchorX: 0.5, anchorY: 0.5 }); ballGraphics.scale.set(1.5); self.speed = 15; var angle = Math.random() * 360; angle += angle % 90 < 7 ? 7 : 0; self.vx = self.speed * Math.cos(angle * Math.PI / 180); self.vy = self.speed * Math.sin(angle * Math.PI / 180); self._move_migrated = function () { self.x += self.vx; self.y += self.vy; if (self.x - ballGraphics.width / 2 <= 0 || self.x + ballGraphics.width / 2 >= 2048) { self.vx *= -1; } if (self.y - ballGraphics.height / 2 <= 0 || self.y + ballGraphics.height / 2 >= 2732) { self.vy *= -1; } self.vx += (self.vx > 0 ? -0.1 : 0.1) * (Math.abs(self.vx) > self.speed ? 1 : 0); self.vy += (self.vy > 0 ? -0.1 : 0.1) * (Math.abs(self.vy) > self.speed ? 1 : 0); }; self.reset = function () {}; }); var GreenGoal = Container.expand(function () { var self = Container.call(this); var goalGraphics = self.attachAsset('goal_green', { anchorX: 0.5, anchorY: 0.5 }); self.checkScore = function (ball, score) { if (this.intersects(ball)) { if (ball.color === 'green') { score.increaseScore(1); var explosion = new ParticleExplosion('green'); explosion.x = ball.x; explosion.y = ball.y; self.parent.addChild(explosion); ball.destroy(); self.parent.balls.splice(self.parent.balls.indexOf(ball), 1); } else { ball.destroy(); self.parent.balls.splice(self.parent.balls.indexOf(ball), 1); } } }; }); var ParticleExplosion = Container.expand(function (color) { var self = Container.call(this); self.particles = []; for (var i = 0; i < 20; i++) { var particle = self.createAsset('particle_' + color, { anchorX: 0.5, anchorY: 0.5 }); particle.vx = (Math.random() - 0.5) * 20; particle.vy = (Math.random() - 0.5) * 20; self.particles.push(particle); self.addChild(particle); } self._update_migrated = function () { for (var i = self.particles.length - 1; i >= 0; i--) { var p = self.particles[i]; p.x += p.vx; p.y += p.vy; p.alpha -= 0.05; if (p.alpha <= 0) { p.destroy(); self.particles.splice(i, 1); } } if (self.particles.length === 0) { self.destroy(); } }; }); var RedGoal = Container.expand(function () { var self = Container.call(this); var goalGraphics = self.attachAsset('goal_red', { anchorX: 0.5, anchorY: 0.5 }); self.checkScore = function (ball, score) { if (this.intersects(ball)) { if (ball.color === 'red') { score.increaseScore(1); var explosion = new ParticleExplosion('red'); explosion.x = ball.x; explosion.y = ball.y; self.parent.addChild(explosion); ball.destroy(); self.parent.balls.splice(self.parent.balls.indexOf(ball), 1); } else { ball.destroy(); self.parent.balls.splice(self.parent.balls.indexOf(ball), 1); } } }; }); var Score = Container.expand(function () { var self = Container.call(this); var scoreValue = 0; var scoreText = new Text2('0', { size: 150, fill: "#ffffff" }); scoreText.anchor.set(0.5, 0); self.addChild(scoreText); self.x = 2048 - scoreText.width - 20; self.y = 20; self.increaseScore = function (points) { self.parent.playerScore += points; scoreText.setText(self.parent.playerScore.toString()); }; }); var YellowGoal = Container.expand(function () { var self = Container.call(this); var goalGraphics = self.attachAsset('goal_yellow', { anchorX: 0.5, anchorY: 0.5 }); self.checkScore = function (ball, score) { if (this.intersects(ball)) { if (ball.color === 'yellow') { score.increaseScore(1); var explosion = new ParticleExplosion('yellow'); explosion.x = ball.x; explosion.y = ball.y; self.parent.addChild(explosion); ball.destroy(); self.parent.balls.splice(self.parent.balls.indexOf(ball), 1); } else { ball.destroy(); self.parent.balls.splice(self.parent.balls.indexOf(ball), 1); } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ function reflectBall(ball, hitSide) { if (hitSide === 'left' || hitSide === 'right') { ball.vx *= -1.5; } else if (hitSide === 'top' || hitSide === 'bottom') { ball.vy *= -1.5; } } function determineHitSide(ballBounds, batBounds) { var dx = ballBounds.x - batBounds.x; var dy = ballBounds.y - batBounds.y; if (Math.abs(dx) > Math.abs(dy)) { return dx < 0 ? 'left' : 'right'; } else { return dy < 0 ? 'top' : 'bottom'; } } game.playerScore = 0; game.balls = []; var goals = []; var bat = null; var gameStarted = false; var spawncount = 0; function setup() { var background = game.attachAsset('background', {}); background.width = 2048; background.height = 2732; background.alpha = 0.6; game.addChildAt(background, 0); var startText = new Text2('Sort fruits into the right baskets\n(Tap to begin)', { size: 100, fill: '#ffffff', align: 'center' }); startText.anchor.set(0.5, 0.5); startText.x = 2048 / 2; startText.y = 2732 / 2; game.addChild(startText); game.on('down', function () { gameStarted = true; startText.visible = false; }); var redGoal = game.addChild(new RedGoal()); redGoal.x = 2048 / 2; redGoal.y = redGoal.height / 2; var blueGoal = game.addChild(new BlueGoal()); blueGoal.x = 2048 / 2; blueGoal.y = 2732 - blueGoal.height / 2; var greenGoal = game.addChild(new GreenGoal()); var greenGoalWidth = greenGoal.width; greenGoal.x = greenGoalWidth / 2; greenGoal.y = 2732 / 2 - greenGoalWidth / 2; var yellowGoal = game.addChild(new YellowGoal()); yellowGoal.x = 2048 - yellowGoal.width / 2; yellowGoal.y = 2732 / 2; goals.push(redGoal, blueGoal, greenGoal, yellowGoal); bat = game.addChild(new Bat()); bat.x = 2048 / 2; bat.y = 2732 - 100; var colors = ['red', 'blue', 'green', 'yellow']; LK.setInterval(function () { if (gameStarted && spawncount < 20) { if (game.balls.length < 20) { var colorIndex = Math.floor(Math.random() * colors.length); var newBall = new ColoredBall(colors[colorIndex]); newBall.x = 200 + Math.random() * (2048 - 400); newBall.y = 200 + Math.random() * (2732 - 400); game.balls.push(newBall); game.addChild(newBall); spawncount++; } } }, 2000); } function reset() { for (var i = 0; i < game.balls.length; i++) { balls[i].reset(); } } LK.on('tick', function () { for (var i = 0; i < game.balls.length; i++) { game.balls[i]._move_migrated(); var currentTime = LK.ticks; if (currentTime - game.balls[i].lastHitTime > 30) { var ballBounds = game.balls[i]; var batBounds = bat; if (batBounds.intersects(ballBounds)) { game.balls[i].lastHitTime = currentTime; var hitSide = determineHitSide(ballBounds, batBounds); reflectBall(game.balls[i], hitSide); } } } for (var i = 0; i < game.balls.length; i++) { for (var j = 0; j < goals.length; j++) { goals[j].checkScore(game.balls[i], scoreInstance); } } for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof ParticleExplosion) { game.children[i]._update_migrated(); } } if (spawncount >= 10 && game.balls.length === 0) { var scoreText = new Text2('You got ' + game.playerScore.toString() + ' fruits\nin the right baskets!', { size: 80, fill: '#ffffff', align: 'center' }); scoreText.anchor.set(0.5, 0.5); scoreText.x = 2048 / 2; scoreText.y = 2732 / 2 - 500; game.addChild(scoreText); LK.setScore(game.playerScore); LK.showGameOver(); } }); game.on('move', function (x, y, obj) { var pos = game.toLocal(obj.global); bat.x = pos.x; bat.y = pos.y; }); var scoreInstance = new Score(); scoreInstance.name = 'scoreInstance'; game.addChild(scoreInstance); setup();
===================================================================
--- original.js
+++ change.js
@@ -288,9 +288,9 @@
game.children[i]._update_migrated();
}
}
if (spawncount >= 10 && game.balls.length === 0) {
- var scoreText = new Text2('You got ' + game.playerScore.toString() + ' out of 10\nfruits in the right baskets!', {
+ var scoreText = new Text2('You got ' + game.playerScore.toString() + ' fruits\nin the right baskets!', {
size: 80,
fill: '#ffffff',
align: 'center'
});
raspberry Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
lemon slice. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
black currant. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
green apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
yellow plastic tray. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
green plastic tray. topdown view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
blue plastic tray. topdown view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red plastic tray. topdown view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
top down forest clearing with small bushes.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
lighter color blue.
A little farmer that is comically square shaped.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.