User prompt
Please fix the bug: 'ReferenceError: tween is not defined' in or related to this line: 'tween(LK.getGameOverScreen(), {' Line Number: 158 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make the game end when you get to -57 points and the screen says GAME OVER! fading in and says click to start again and when you get up too 89,234,584 points the screen says YOU WIN! fading in and also says click to play again ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
can you add a scoreboard on this please
Initial prompt
Black Hole
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the Black Hole (Player)
var BlackHole = Container.expand(function () {
var self = Container.call(this);
var blackHoleGraphics = self.attachAsset('blackHole', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = 120; // 6x5 size
self.height = 100;
self.update = function () {
// Update logic for the black hole
};
});
// Class for Stars
var Star = Container.expand(function (color, points) {
var self = Container.call(this);
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5,
tint: color
});
self.points = points;
self.speed = 2;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var blackHole = game.addChild(new BlackHole());
blackHole.x = 2048 / 2;
blackHole.y = 2732 - 150;
var stars = [];
var starColors = [{
color: 0xFFFF00,
points: 12
},
// Yellow
{
color: 0x0000FF,
points: 40
},
// Blue
{
color: 0x00FF00,
points: 100
},
// Green
{
color: 0xFFA500,
points: 84
},
// Orange
{
color: 0xFFFFFF,
points: 68
},
// White
{
color: 0xC2B280,
points: 96
},
// Sand
{
color: 0xA020F0,
points: -23
},
// Purple
{
color: 0x40E0D0,
points: -12
},
// Turquoise
{
color: 0xFF0000,
points: -39
} // Red
];
function spawnStar() {
var randomIndex = Math.floor(Math.random() * starColors.length);
var starData = starColors[randomIndex];
var newStar = new Star(starData.color, starData.points);
newStar.x = Math.random() * 2048;
newStar.y = 0;
stars.push(newStar);
game.addChild(newStar);
}
game.down = function (x, y, obj) {
// Start the game by spawning stars
spawnStar();
};
// Create a new Text2 object for the score display
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
// Add the score text to the GUI overlay at the top center of the screen
LK.gui.top.addChild(scoreTxt);
game.update = function () {
// Update black hole position based on touch
game.move = function (x, y, obj) {
blackHole.x = x;
blackHole.y = y;
};
// Update stars
for (var i = stars.length - 1; i >= 0; i--) {
var star = stars[i];
star.update();
if (blackHole.intersects(star)) {
LK.setScore(LK.getScore() + star.points);
// Update the score display
scoreTxt.setText(LK.getScore());
star.destroy();
stars.splice(i, 1);
}
}
// Spawn a new star every 60 frames
if (LK.ticks % 60 === 0) {
spawnStar();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,129 +1,138 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the Black Hole (Player)
var BlackHole = Container.expand(function () {
- var self = Container.call(this);
- var blackHoleGraphics = self.attachAsset('blackHole', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.width = 120; // 6x5 size
- self.height = 100;
- self.update = function () {
- // Update logic for the black hole
- };
+ var self = Container.call(this);
+ var blackHoleGraphics = self.attachAsset('blackHole', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = 120; // 6x5 size
+ self.height = 100;
+ self.update = function () {
+ // Update logic for the black hole
+ };
});
// Class for Stars
var Star = Container.expand(function (color, points) {
- var self = Container.call(this);
- var starGraphics = self.attachAsset('star', {
- anchorX: 0.5,
- anchorY: 0.5,
- tint: color
- });
- self.points = points;
- self.speed = 2;
- self.update = function () {
- self.y += self.speed;
- if (self.y > 2732) {
- self.destroy();
- }
- };
+ var self = Container.call(this);
+ var starGraphics = self.attachAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ tint: color
+ });
+ self.points = points;
+ self.speed = 2;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var blackHole = game.addChild(new BlackHole());
blackHole.x = 2048 / 2;
blackHole.y = 2732 - 150;
var stars = [];
var starColors = [{
- color: 0xFFFF00,
- points: 12
+ color: 0xFFFF00,
+ points: 12
},
// Yellow
{
- color: 0x0000FF,
- points: 40
+ color: 0x0000FF,
+ points: 40
},
// Blue
{
- color: 0x00FF00,
- points: 100
+ color: 0x00FF00,
+ points: 100
},
// Green
{
- color: 0xFFA500,
- points: 84
+ color: 0xFFA500,
+ points: 84
},
// Orange
{
- color: 0xFFFFFF,
- points: 68
+ color: 0xFFFFFF,
+ points: 68
},
// White
{
- color: 0xC2B280,
- points: 96
+ color: 0xC2B280,
+ points: 96
},
// Sand
{
- color: 0xA020F0,
- points: -23
+ color: 0xA020F0,
+ points: -23
},
// Purple
{
- color: 0x40E0D0,
- points: -12
+ color: 0x40E0D0,
+ points: -12
},
// Turquoise
{
- color: 0xFF0000,
- points: -39
+ color: 0xFF0000,
+ points: -39
} // Red
];
function spawnStar() {
- var randomIndex = Math.floor(Math.random() * starColors.length);
- var starData = starColors[randomIndex];
- var newStar = new Star(starData.color, starData.points);
- newStar.x = Math.random() * 2048;
- newStar.y = 0;
- stars.push(newStar);
- game.addChild(newStar);
+ var randomIndex = Math.floor(Math.random() * starColors.length);
+ var starData = starColors[randomIndex];
+ var newStar = new Star(starData.color, starData.points);
+ newStar.x = Math.random() * 2048;
+ newStar.y = 0;
+ stars.push(newStar);
+ game.addChild(newStar);
}
game.down = function (x, y, obj) {
- // Start the game by spawning stars
- spawnStar();
+ // Start the game by spawning stars
+ spawnStar();
};
+// Create a new Text2 object for the score display
+var scoreTxt = new Text2('0', {
+ size: 150,
+ fill: 0xFFFFFF
+});
+// Add the score text to the GUI overlay at the top center of the screen
+LK.gui.top.addChild(scoreTxt);
game.update = function () {
- // Update black hole position based on touch
- game.move = function (x, y, obj) {
- blackHole.x = x;
- blackHole.y = y;
- };
- // Update stars
- for (var i = stars.length - 1; i >= 0; i--) {
- var star = stars[i];
- star.update();
- if (blackHole.intersects(star)) {
- LK.setScore(LK.getScore() + star.points);
- star.destroy();
- stars.splice(i, 1);
- }
- }
- // Spawn a new star every 60 frames
- if (LK.ticks % 60 === 0) {
- spawnStar();
- }
+ // Update black hole position based on touch
+ game.move = function (x, y, obj) {
+ blackHole.x = x;
+ blackHole.y = y;
+ };
+ // Update stars
+ for (var i = stars.length - 1; i >= 0; i--) {
+ var star = stars[i];
+ star.update();
+ if (blackHole.intersects(star)) {
+ LK.setScore(LK.getScore() + star.points);
+ // Update the score display
+ scoreTxt.setText(LK.getScore());
+ star.destroy();
+ stars.splice(i, 1);
+ }
+ }
+ // Spawn a new star every 60 frames
+ if (LK.ticks % 60 === 0) {
+ spawnStar();
+ }
};
\ No newline at end of file