Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 214
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'if (scoreText) {' Line Number: 169
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 169
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 172
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 178
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 173
User prompt
Please fix the bug: 'ReferenceError: scoreText is not defined' in or related to this line: 'scoreText.setText(nouveauScore);' Line Number: 172
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: startPoints is not defined' in or related to this line: 'var randomIndex = Math.floor(Math.random() * startPoints.length);' Line Number: 86
Code edit (1 edits merged)
Please save this source code
Initial prompt
Coco Monkey
/****
* Classes
****/
// Class for the Coconut
var Coconut = Container.expand(function () {
var self = Container.call(this);
var coconutGraphics = self.attachAsset('coconut', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
// Class for the Monkey
var Monkey = Container.expand(function () {
var self = Container.call(this);
var monkeyGraphics = self.attachAsset('monkey', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Monkey logic can be added here
};
});
// Class for the Parasol
var Parasol = Container.expand(function () {
var self = Container.call(this);
var parasolGraphics = self.attachAsset('parasol', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Parasol logic can be added here
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
var monkey = game.addChild(new Monkey());
monkey.x = 2048 / 2;
monkey.y = 200;
var parasol = game.addChild(new Parasol());
parasol.x = 2048 / 2;
parasol.y = 2500;
var coconuts = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.down = function (x, y, obj) {
parasol.x = x;
parasol.y = y;
};
game.move = function (x, y, obj) {
parasol.x = x;
parasol.y = y;
};
game.update = function () {
if (LK.ticks % 60 == 0) {
var newCoconut = new Coconut();
newCoconut.x = monkey.x;
newCoconut.y = monkey.y;
coconuts.push(newCoconut);
game.addChild(newCoconut);
}
for (var i = coconuts.length - 1; i >= 0; i--) {
if (coconuts[i].intersects(parasol)) {
score += 1;
scoreTxt.setText(score);
coconuts[i].destroy();
coconuts.splice(i, 1);
} else if (coconuts[i].y > 2732) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};