Code edit (3 edits merged)
Please save this source code
User prompt
add x and y coordinated to the messageTxt so I can position it on the screen, that are numerical values not a percentage of the screen size
Code edit (13 edits merged)
Please save this source code
User prompt
add x and y coordinated to the messageTxt so I can position it on the screen
User prompt
now add a new UI element on the screen placed at the bottom of the board. this is a white text aligned to the middle of the screen and says "Balance is the path.". This will display other text messages in the future, chosen from a list I will provide soon
Code edit (1 edits merged)
Please save this source code
User prompt
nice, the text is now animated, but the increased font size seems to not be perfectly centered to the original size. the increase anchor should be to the center of the text
User prompt
when the score UI increments, i want you to add an animation on the score UI text, so that it bumps up whenever it increases. so when it increasesby 1 point, increase the font size by 25% for 100 miliseconds then revert back to it's original font size
User prompt
Fix Bug: 'TypeError: Cannot read properties of undefined (reading 'visible')' in this line: 'if (obstacles[i] instanceof Coin_Blue && hero.children[1].visible || obstacles[i] instanceof Coin_Yellow && hero.children[2].visible) {' Line Number: 163
User prompt
remove the original hero from the screen since we're not using it anymore
Code edit (1 edits merged)
Please save this source code
User prompt
make the score ui size smaller
User prompt
add a black glow to the score UI text and make it 10 px thick
Code edit (1 edits merged)
Please save this source code
User prompt
move the score UI 100 pixels higehr
User prompt
move the score UI lower, so it's exactly in the center of the screen
User prompt
add a background centered to the screen that stretches across theentire screen
Code edit (2 edits merged)
Please save this source code
User prompt
the coins shuold have acceleration. they start at the current speed but should accelerate over time
Code edit (4 edits merged)
Please save this source code
User prompt
you're decreasing the spawn frequency of the coins by 1 milisecond for every generated coin. now I need you to add a limit to that number, so once the obstacleTimer reaches 50 miliseconds, it stops and it can't go any lower than that
User prompt
increase the spawn frequency after a new coin is generated. reduce it by 1 milisecond per coin. thus if right now the game spawns a new coins every 1200 miliseconds, after the first generated coins, the next one appears after 1199 miliseconds, and so on
Code edit (1 edits merged)
Please save this source code
User prompt
now, after everyspawned coin, regardless of it's color, decrease the obstaclesTimer by 1 milisecond
User prompt
change the spawn frequency from 1 second to 2
/****
* Classes
****/
// Define the Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.createAsset('hero', 'Hero character', 0.5, 0.5);
var heroBlue = self.createAsset('heroBlue', 'Hero character blue', 0.5, 0.5);
var heroYellow = self.createAsset('heroYellow', 'Hero character yellow', 0.5, 0.5);
heroBlue.visible = true;
heroYellow.visible = false;
// Toggle hero color
self.toggleColor = function () {
heroBlue.visible = !heroBlue.visible;
heroYellow.visible = !heroYellow.visible;
};
self.speedY = 0;
// Hero is static in the center of the screen
self.update = function () {};
});
// Define the Coin_Blue class
var Coin_Blue = Container.expand(function (x, y) {
var self = Container.call(this);
var coinGraphics = self.createAsset('coinBlue', 'Blue Coin', 0.5, 0.5);
self.x = x;
self.y = y;
// Move the coin
self.move = function () {
var dx = game.width / 2 - self.x;
var dy = game.height / 2 - self.y;
var angle = Math.atan2(dy, dx);
self.x += Math.cos(angle) * 5;
self.y += Math.sin(angle) * 5;
};
// Check if the coin is off-screen
self.isOffScreen = function () {
return self.x < -coinGraphics.width;
};
});
// Define the Coin_Yellow class
var Coin_Yellow = Container.expand(function (x, y) {
var self = Container.call(this);
var coinGraphics = self.createAsset('coinYellow', 'Yellow Coin', 0.5, 0.5);
self.x = x;
self.y = y;
// Move the coin
self.move = function () {
var dx = game.width / 2 - self.x;
var dy = game.height / 2 - self.y;
var angle = Math.atan2(dy, dx);
self.x += Math.cos(angle) * 5;
self.y += Math.sin(angle) * 5;
};
// Check if the coin is off-screen
self.isOffScreen = function () {
return self.x < -coinGraphics.width;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize important asset arrays and game variables
var hero;
var obstacles = [];
var colors = [0xFF0000, 0x00FF00, 0x0000FF]; // Red, Green, Blue
var score = 0;
var scoreTxt;
var obstacleTimer = 0;
var gameOver = false;
// Create the hero and set initial color to blue
hero = game.addChild(new Hero());
hero.x = game.width / 2;
hero.y = game.height / 2;
// Create the score text
scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Handle the tap event to toggle the hero's color
game.on('down', function (obj) {
if (!gameOver) {
hero.toggleColor();
}
});
// Game tick event
LK.on('tick', function () {
if (!gameOver) {
// Update the hero
hero.update();
var spawnPoints = [{
x: 0,
y: 0
}, {
x: game.width,
y: 0
}, {
x: 0,
y: game.height
}, {
x: game.width,
y: game.height
}];
// Add a new coin every 60 frames (1 second)
obstacleTimer++;
if (obstacleTimer === 120) {
obstacleTimer = 0;
// If all spawn points have been used, replenish them
if (spawnPoints.length === 0) {
spawnPoints = [{
x: 0,
y: 0
}, {
x: game.width,
y: 0
}, {
x: 0,
y: game.height
}, {
x: game.width,
y: game.height
}];
}
// Select a random spawn point and remove it from the array
var spawnIndex = Math.floor(Math.random() * spawnPoints.length);
var spawnPoint = spawnPoints[spawnIndex];
spawnPoints.splice(spawnIndex, 1);
// Generate a random coin type
var coinType = Math.random() < 0.5 ? Coin_Blue : Coin_Yellow;
// Spawn the coin at the selected spawn point
var coin = new coinType(spawnPoint.x, spawnPoint.y);
obstacles.push(coin);
game.addChild(coin);
}
// Update coins
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].move();
// Check for collision
if (hero.intersects(obstacles[i])) {
if (obstacles[i] instanceof Coin_Blue && hero.children[1].visible || obstacles[i] instanceof Coin_Yellow && hero.children[2].visible) {
// Increment score when correct coin is collected
score++;
scoreTxt.setText(score.toString());
obstacles[i].destroy();
obstacles.splice(i, 1);
} else {
gameOver = true;
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Remove off-screen coins
if (obstacles[i] && obstacles[i].isOffScreen()) {
obstacles[i].destroy();
obstacles.splice(i, 1);
}
}
}
});
minimalist meditation background. no elements. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. High contrast. No shadows.
black 8-ball biliard ball. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white round ball with black edges. has a black infinity logo inprinted on it. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
round black circle. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white circle with a thin black paintbrushed outline. minimalist. pixelated. 8 bit.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.