User prompt
Don't add to the target score while jumping
User prompt
Don't add to the score while the plant is jumping
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'setText')' in this line: 'self.scoreShadowTxt.setText(self.currentScore);' Line Number: 151
User prompt
There should be two score variables, current score and target score. When a fly is caught update target score. The current score should be used to update the displayed score and should increase by 5 every tick.
User prompt
Fix Bug: 'TypeError: self.scoreTxt.getText is not a function' in this line: 'var currentScore = parseInt(self.scoreTxt.getText(), 10);' Line Number: 140
User prompt
Fix Bug: 'TypeError: parseInt is not a function' in this line: 'var currentScore = parseInt(self.scoreTxt.text, 10);' Line Number: 140
User prompt
Fix Bug: 'TypeError: self.scoreTxt.getText is not a function' in this line: 'var currentScore = parseInt(self.scoreTxt.getText(), 10);' Line Number: 140
User prompt
Fix Bug: 'TypeError: parseInt is not a function' in this line: 'var currentScore = parseInt(self.scoreTxt.text, 10);' Line Number: 140
User prompt
Fix Bug: 'TypeError: parseInt is not a function' in this line: 'var currentScore = parseInt(self.scoreTxt.text);' Line Number: 140
User prompt
Fix Bug: 'TypeError: self.scoreTxt.getText is not a function' in this line: 'var currentScore = parseInt(self.scoreTxt.getText());' Line Number: 140
User prompt
The score isn't working
User prompt
Move the score background to the top right, at the front
User prompt
Move the score to the front
User prompt
move it to the front
User prompt
move the score background to the ame position as the score
User prompt
Fix Bug: 'Uncaught TypeError: Graphics is not a constructor' in this line: 'var graphics = new Graphics();' Line Number: 185
User prompt
Fix Bug: 'Uncaught TypeError: scoreBackground.beginFill is not a function' in this line: 'scoreBackground.beginFill(0x000000);' Line Number: 185
User prompt
Fix Bug: 'Uncaught TypeError: scoreBackground.setBackgroundColor is not a function' in this line: 'scoreBackground.setBackgroundColor(0x000000);' Line Number: 185
User prompt
Fix Bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'x')' in this line: 'scoreBackground.x = self.scoreTxt.x - 150;' Line Number: 179
User prompt
put a very dark box behind the score
User prompt
remove the score shadow
User prompt
Fix Bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'x')' in this line: 'self.scoreShadowTxt.x = self.scoreTxt.x + 5;' Line Number: 182
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: fliesCaught.forEach is not a function' in this line: 'fliesCaught.forEach(function (fly) {' Line Number: 142
User prompt
Fix Bug: 'TypeError: self.parent.incrementScore is not a function' in this line: 'self.parent.incrementScore(self.fliesCaughtInJump, fly);' Line Number: 113
var RightBee = Container.expand(function () { var self = Container.call(this); var beeGraphics = self.createAsset('bee', 'Bee Graphics', .5, .5); beeGraphics.scale.x = 1.2; beeGraphics.scale.y = 1.2; self.spawnBee = function () { self.x = 2048 + 100; self.y = Math.random() * (2732 / 2); self.xSpeed = -(Math.random() * 7 + 3); }; self.spawnBee(); self.move = function () { self.x += self.xSpeed; if (self.x < -50) { self.y = Math.random() * (2732 / 2); self.xSpeed = -(Math.random() * 7 + 3); self.x = 2048 + 100; } }; }); var LeftBee = Container.expand(function () { var self = Container.call(this); var beeGraphics = self.createAsset('bee', 'Bee Graphics', .5, .5); beeGraphics.scale.x = -1.2; beeGraphics.scale.y = 1.2; self.spawnBee = function () { self.x = -100; self.y = Math.random() * (2732 / 2); self.xSpeed = Math.random() * 7 + 3; }; self.spawnBee(); self.move = function () { self.x += self.xSpeed; if (self.x > 2048 + 50) { self.y = Math.random() * (2732 / 2); self.xSpeed = Math.random() * 7 + 3; self.x = -100; } }; }); var Bee = Container.expand(function () { var self = Container.call(this); var beeGraphics = self.createAsset('bee', 'Bee Graphics', .5, .5); beeGraphics.scale.x = 1.8; beeGraphics.scale.y = 1.2; self.spawnBee(); }); var Heart = Container.expand(function () { var self = Container.call(this); var heartGraphics = self.createAsset('heart', 'Heart Graphics', .5, .5); }); var Fly = Container.expand(function () { var self = Container.call(this); var flyGraphics = self.createAsset('fly', 'Fly Graphics', .5, .5); self.spawnFly = function () { var direction = Math.random() < 0.5 ? -1 : 1; self.xSpeed = direction * (Math.random() * 10 + 5); self.x = direction > 0 ? -50 : 2048 + 50; self.y = Math.random() * (2732 * 3 / 4 - self.height - LK.gui.topRight.height); var scale = 1 + self.y / (2732 * 3 / 4) * 0.2; self.scale.x = self.scale.y = scale; }; self.spawnFly(); self.move = function () { if (self.xSpeed > 0 && self.x > 2048 / 2 && !self.changedDirection || self.xSpeed < 0 && self.x < 2048 / 2 && !self.changedDirection) { self.xSpeed *= -1; self.changedDirection = true; } if (self.xSpeed > 0) { flyGraphics.scale.x = 1; } else if (self.xSpeed < 0) { flyGraphics.scale.x = -1; } self.x += self.xSpeed; if (self.x > 2048 + 50 || self.x < -50) { self.spawnFly(); } }; }); var Plant = Container.expand(function () { var self = Container.call(this); self.isMoving = false; self.launchAt = function (x, y) { var startX = self.x; var startY = self.y; var endX = x; var endY = y; var time = 0; self.isMoving = true; self.fliesCaughtInJump = 0; self.moveTowards = function () { if (time <= 60) { self.x = startX + (endX - startX) * (time / 60); self.y = startY - (startY - endY) * (time / 60); time++; } else if (time <= 120) { self.x = endX - (endX - startX) * ((time - 60) / 60); self.y = endY + (startY - endY) * ((time - 60) / 60); time++; } else { self.isMoving = false; self.moveTowards = null; self.parent.updateScore(self.fliesCaughtInJump); self.fliesCaughtInJump = 0; } }; }; var plantGraphics = self.createAsset('plant', 'Plant Graphics', .5, .5); self.catchFly = function (fly) { if (self.intersects(fly)) { fly.destroy(); self.fliesCaughtInJump = (self.fliesCaughtInJump || 0) + 1; self.parent.updateScore(self.fliesCaughtInJump); return true; } return false; }; self.hitByBee = function (bee) { if (self.intersects(bee) && !self.hit) { self.hit = true; LK.effects.flashObject(self, 0xff0000, 1000); self.x = 2048 / 2; self.y = 2732 - self.height; self.parent.loseHeart(); if (self.isMoving) { self.isMoving = false; self.moveTowards = null; } LK.setTimeout(function () { self.hit = false; }, 1000); return true; } return false; }; }); var Game = Container.expand(function () { var self = Container.call(this); self.updateScore = function (fliesCaught) { var currentScore = parseInt(self.scoreTxt.text, 10); var targetScore = currentScore + fliesCaught * (fliesCaught > 1 ? 150 : 100); var increment = function () { if (currentScore < targetScore) { currentScore += 5; self.scoreTxt.setText(currentScore); self.scoreShadowTxt.setText(currentScore); if (currentScore < targetScore) { LK.setTimeout(increment, 10); } } else { LK.gui.topRight.score = currentScore; } }; increment(); }; stage.on('down', function (obj) { if (!plant.isMoving && !plant.hit) { var pos = obj.event.getLocalPosition(self); plant.launchAt(pos.x, pos.y); } }); var background = self.createAsset('background', 'Background Graphics', 0, 0); background.width = 2048; background.height = 2732; self.addChildAt(background, 0); var flies = []; var plant = self.addChild(new Plant()); plant.x = 2048 / 2; plant.y = 2732 - plant.height; self.scoreTxt = new Text2('0', { size: 120, fill: "#ffff00" }); LK.gui.topRight.addChild(self.scoreTxt); self.scoreTxt.x -= 240; LK.gui.topRight.score = 0; self.incrementScoreAmount = 100; var hearts = []; self.loseHeart = function () { if (hearts.length > 0) { var lostHeart = hearts.pop(); lostHeart.destroy(); } if (hearts.length === 0) { isGameOver = true; } }; for (var i = 0; i < 3; i++) { var heart = new Heart(); heart.x = (i + 1) * (heart.width + 10) + 10; heart.y = 120; LK.gui.topLeft.addChild(heart); hearts.push(heart); } var isGameOver = false; var flySpawnTimer = 0; var bees = []; var leftBee = new LeftBee(); bees.push(leftBee); self.addChild(leftBee); var rightBee = new RightBee(); bees.push(rightBee); self.addChild(rightBee); LK.on('tick', function () { for (var a = flies.length - 1; a >= 0; a--) { if (flies[a]) { flies[a].move(); if (flies[a].x > 2048 + 50) { flies[a].destroy(); flies.splice(a, 1); } } } flySpawnTimer++; if (flySpawnTimer >= 120 && flies.length < 5) { var newFly = new Fly(); flies.push(newFly); self.addChild(newFly); flySpawnTimer = 0; } for (var a = flies.length - 1; a >= 0; a--) { if (plant.catchFly(flies[a])) { flies.splice(a, 1); } } if (plant.moveTowards) { plant.moveTowards(); } bees.forEach(function (bee) { bee.move(); if (plant.hitByBee(bee)) {} }); if (isGameOver) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); });
===================================================================
--- original.js
+++ change.js
@@ -136,9 +136,9 @@
});
var Game = Container.expand(function () {
var self = Container.call(this);
self.updateScore = function (fliesCaught) {
- var currentScore = parseInt(self.scoreTxt.getText(), 10);
+ var currentScore = parseInt(self.scoreTxt.text, 10);
var targetScore = currentScore + fliesCaught * (fliesCaught > 1 ? 150 : 100);
var increment = function () {
if (currentScore < targetScore) {
currentScore += 5;
Simple side view of a pixel art fly on a sky blue background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Head of a carnivorous plant, mouth open at top, pixel art Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art heart green Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a jungle with light streaming in from above, pixel art Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a pixel art bee, cute, side view, flying, no shadow Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a dark green box surrounded by vines, pixel art Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a blackened cracked heart, pixel art, no shadow Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute orange-yellow spider, side view, pixel art, fangs, no shadow Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.