User prompt
create a "heart" asset that is used to display the amount of lives left instead of a number at the top left corner
User prompt
instead of a number put the amount of lifes left as a corresponding number of heart assets in the top left corner
User prompt
make it so you have three lifes, meaning that if you get hit by an enemy you don't lose instantly but much rather lose a life, if all lives are gone, the game is over
User prompt
make it so that at the start of the game there is only one enemy that spawns
User prompt
make it so the amount of enemies increased with each time all balls are collected and the game is reset. Use the function that keeps track of the amount of times the game is reset for that. It starts with one enemy and is capped at five in wave five. After wave five no more enemies are added
User prompt
make it even bigger
User prompt
make it 100% opacity
User prompt
display the immunity asset at the top of the screen over anything else, make it a bit bigger and move it down 100 pixels
User prompt
make it so the immunity is also active for two seconds when the game starts
User prompt
make it so the basket has a two-second immunity and cannot be hit by enemies after a reset. Add an immunity asset with an aspect ration of 2:1 that is displayed at the top of the screen when the player is immune to damage
User prompt
make it so there is a minium distance between balls and boost pads of 1/10 of the screen size
User prompt
balls can no longer spawn directly next to a boost pad
User prompt
nake it so a maximum of three boost pads can spawn with every game reset, including the game start
User prompt
add a function that keeps track how many times all the balls where collected and the game elements were reset. Display the amount of resets in the wave counter on the top right
User prompt
when all balls are collected and the game elements are reset, add +1 to the wave counter
User prompt
the wave function broke, now after all the balls are collected no new wave with new obstacles balls and so on is initialized. fix this issue
User prompt
wave one should start with only one enemy, fix it
User prompt
make it so the amount of enemies increased with each wave. It starts with one enemy and is capped at five in wave five. After wave five no more enemies are added
User prompt
boost pads and enemys still spawn way too close to the basket at the start of the game, fix that
User prompt
a wave ends and a new one starts when all the balls are collected. So if the first wave of balls is collected, wave two begins. Asjust the wave score accordingly
User prompt
display which wave of balls you're currently on right below the "Score" tab
User prompt
make it so that when every ball that is initialized on the start of the game is collected, all the obstacles, boost pads as well as the position of the enemies are reset and a new wave of balls to collect spawns
User prompt
make it so no enemies or obstacles and no boostpads can spawn in a square radius of 1/3 of the screen size around where the basket is initialized at the beginning of the game
User prompt
it's not displayed. Make it so it's showned riught below the "Game over"
User prompt
make it so the score is displayed on the game over screen
/****
* Classes
****/
// Ball class
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self["throw"] = function () {
// Throw logic for the ball
};
self.spawn = function () {
self.x = Math.random() * 2048;
self.y = Math.random() * 2732;
};
});
// Assets will be automatically created based on usage in the code.
// Basket class
var Basket = Container.expand(function () {
var self = Container.call(this);
var basketGraphics = self.attachAsset('basket', {
anchorX: 0.5,
anchorY: 0.5
});
self.drawArrow = function (pos) {
// Calculate the distance and direction of the drag
var dx = pos.x - self.x;
var dy = pos.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var direction = Math.atan2(dy, dx);
// Remove the previous arrow if it exists
if (self.arrow) {
self.arrow.destroy();
}
// Create a new arrow asset
self.arrow = LK.getAsset('arrow', {
anchorX: 0.0,
// Anchor at the start of the arrow
anchorY: 0.5,
// Center vertically
x: self.x,
y: self.y,
scaleX: Math.min(Math.max(distance / 100, 1), 0.3 * Math.sqrt(2048 * 2048 + 2732 * 2732) / 100),
// Stretch the arrow in the direction of the cursor, but ensure it's at least 1 to allow it to extend outside the screen and not more than 40% of the screen size
scaleY: 1,
rotation: direction
});
// Correctly align the basket's opening with the arrow direction without additional rotation
basketGraphics.rotation = direction;
// Add the arrow to the game
game.addChild(self.arrow);
};
self.move = function () {
// Move the basket
self.x += self.vx;
self.y += self.vy;
// Apply friction
self.vx *= 0.99;
self.vy *= 0.99;
// Check for collision with the edges of the screen and bounce off
if (self.x < 0) {
self.vx = Math.abs(self.vx);
// Correctly adjust the basket's rotation to align with the new direction of movement, ensuring the opening follows the path
basketGraphics.rotation = Math.atan2(self.vy, self.vx);
} else if (self.x > 2048) {
self.vx = -Math.abs(self.vx);
basketGraphics.rotation = Math.atan2(self.vy, self.vx);
}
if (self.y < 0) {
self.vy = Math.abs(self.vy);
// Adjust the basket's rotation to follow the path of reflection, ensuring the opening is correctly aligned
basketGraphics.rotation = Math.atan2(self.vy, self.vx) + Math.PI / 2;
} else if (self.y > 2732) {
self.vy = -Math.abs(self.vy);
basketGraphics.rotation = Math.atan2(self.vy, self.vx) + Math.PI / 2;
}
// Check for collision with obstacles and boostpads, bounce off obstacles, and reflect with increased speed on boostpads
for (var i = 0; i < obstacles.length; i++) {
if (self.intersects(obstacles[i])) {
// Calculate the angle of reflection
var dx = self.x - obstacles[i].x;
var dy = self.y - obstacles[i].y;
var angle = Math.atan2(dy, dx);
// Reflect the velocity
self.vx = Math.cos(angle) * Math.sqrt(self.vx * self.vx + self.vy * self.vy);
self.vy = Math.sin(angle) * Math.sqrt(self.vx * self.vx + self.vy * self.vy);
// Adjust the basket's rotation to follow the path of reflection, ensuring the opening faces the correct direction
basketGraphics.rotation = Math.atan2(self.vy, self.vx);
}
}
for (var j = 0; j < boostpads.length; j++) {
if (self.intersects(boostpads[j])) {
// Calculate the angle of reflection
var dxPad = self.x - boostpads[j].x;
var dyPad = self.y - boostpads[j].y;
var anglePad = Math.atan2(dyPad, dxPad);
// Reflect the velocity and increase speed
self.vx = Math.cos(anglePad) * 1.6 * Math.sqrt(self.vx * self.vx + self.vy * self.vy);
self.vy = Math.sin(anglePad) * 1.6 * Math.sqrt(self.vx * self.vx + self.vy * self.vy);
// Adjust the basket's rotation to follow the path of reflection with increased speed, ensuring the opening faces the correct direction
basketGraphics.rotation = Math.atan2(self.vy, self.vx);
// Mark the basket as having been boosted for double scoring
self.boosted = true;
}
}
};
self.shoot = function (pos) {
// Calculate the distance and direction of the drag
var dx = self.x - pos.x;
var dy = self.y - pos.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var direction = Math.atan2(dy, dx);
// Set the velocity of the basket to go 50% further than the cursor's end location
self.vx = -Math.cos(direction) * distance * 1.5 / 100;
self.vy = -Math.sin(direction) * distance * 1.5 / 100;
};
self.isBallHitByOpening = function (ball) {
// Calculate the angle between the basket's direction and the ball
if (ball) {
var dx = ball.x - self.x;
var dy = ball.y - self.y;
}
var angle = Math.atan2(dy, dx);
// Check if the ball is within the opening angle of the basket
return Math.abs(angle - basketGraphics.rotation) < Math.PI / 4;
};
});
// Boostpad class
var Boostpad = Container.expand(function () {
var self = Container.call(this);
var boostpadGraphics = self.attachAsset('boostPad', {
anchorX: 0.5,
anchorY: 0.5
});
self.positionBoostpad = function () {
// Positioning logic for the boostpad, similar to obstacle
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFF0000 // Red color to differentiate enemies
});
self.moveTowardsBasket = function (basket) {
var dx = basket.x - self.x;
var dy = basket.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
this.speed = this.speed || 2; // Initialize speed if not set
var speed = this.speed; // Use the enemy's current speed
self.x += dx / distance * speed;
self.y += dy / distance * speed;
};
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.positionObstacle = function () {
// Positioning logic for the obstacle
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xADD8E6 // Init game with light blue background
});
/****
* Game Code
****/
// Add the background to the game
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0,
alpha: 0.5
}));
background.width = 2048;
background.height = 2732;
// Create a text element to display enemy speed percentage
var enemySpeedTxt = new Text2('Enemy Speed: 100%', {
size: 50,
fill: "#ffffff"
});
enemySpeedTxt.anchor.set(0, 0); // Anchor to the top left corner
LK.gui.topLeft.addChild(enemySpeedTxt);
// Update the enemy speed display text in the game tick event
LK.on('tick', function () {
var speedPercentage = Math.min(speedIncreaseCount * 30, 100); // Calculate speed percentage, capped at 100%
enemySpeedTxt.setText('Enemy Speed: ' + speedPercentage + '%');
// Existing game tick code...
});
// Initialize game elements
var basket = game.addChild(new Basket());
basket.x = 1024; // Center horizontally
basket.y = 2732 - 2732 / 4; // Position 1/4 of the screen size away from the bottom
basket.visible = true; // Ensure the basket is always visible
var balls = [];
for (var i = 0; i < 10; i++) {
var ball = game.addChild(new Ball());
ball.spawn();
balls.push(ball);
}
var obstacles = [];
var boostpads = []; // Array to store boostpad instances
var enemies = []; // Array to store enemy instances
// Create obstacles, boostpads, and enemies at random positions
// Define safe zone around basket spawn point
var safeZone = {
x: basket.x - 400,
y: basket.y - 400,
width: 800,
height: 800
};
for (var i = 0; i < 5; i++) {
var enemy = game.addChild(new Enemy());
do {
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * (2732 - 400) + 200; // Avoid placing too close to the bottom
} while (enemy.intersects(safeZone)); // Ensure enemy does not spawn within safe zone
enemies.push(enemy);
}
for (var i = 0; i < 5; i++) {
var obstacle = game.addChild(new Obstacle());
do {
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * (2732 - 400) + 200; // Avoid placing too close to the bottom
} while (obstacle.intersects(safeZone)); // Ensure obstacle does not spawn within safe zone
obstacles.push(obstacle);
// Create and position boostpads
var boostpad = game.addChild(new Boostpad());
do {
boostpad.x = Math.random() * 2048;
boostpad.y = Math.random() * (2732 - 400) + 200; // Avoid placing too close to the bottom
} while (boostpad.intersects(safeZone)); // Ensure boostpad does not spawn within safe zone
boostpads.push(boostpad);
}
// Initialize enemy speed increase factor and timer
var enemySpeedIncreaseFactor = 1.3; // 30% speed increase
var enemySpeedIncreaseInterval = 5000; // Increase speed every 5 seconds
var speedIncreaseCount = 0; // Initialize speed increase count
LK.setInterval(function () {
if (speedIncreaseCount < 5) {
// Check if speed has been increased less than 5 times
enemies.forEach(function (enemy) {
enemy.speed *= enemySpeedIncreaseFactor;
});
speedIncreaseCount++; // Increment the speed increase count
}
}, enemySpeedIncreaseInterval);
// Function to spawn a new ball
function spawnBall() {
var ball = new Ball();
ball.x = 1024; // Start from the center horizontally
ball.y = 2732 - 150; // Start a little above the basket
balls.push(ball);
game.addChild(ball);
}
// Touch event to throw a ball
var initialPos;
game.on('down', function (obj) {
var event = obj.event;
initialPos = event.getLocalPosition(game);
basket.shoot(initialPos);
});
game.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
basket.drawArrow(pos);
});
// Game tick event
LK.on('tick', function () {
// Move enemies towards the basket and check for collision
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].moveTowardsBasket(basket);
if (enemies[j].intersects(basket) && basket.isBallHitByOpening(enemies[j])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver('Your score: ' + score);
}
}
// Update balls
for (var i = balls.length - 1; i >= 0; i--) {
balls[i]["throw"]();
basket.move();
// Check for collision with basket
if (balls[i].intersects(basket) && basket.isBallHitByOpening(balls[i])) {
balls[i].destroy();
balls.splice(i, 1);
// Increase the score and update the score counter
score++;
// Check if the basket was boosted and the ball was hit in the same shot
if (basket.boosted && basket.isBallHitByOpening(balls[i])) {
score++; // Additional score for boosted basket
// Display bonus asset for one second in the top left corner when a bonus is hit
var bonusAsset = LK.getAsset('bonus', {
x: 150,
// Move away from the corner
y: 150,
// Move away from the corner
anchorX: 0,
anchorY: 0,
scaleX: 3,
// Make it three times as big
scaleY: 3 // Make it three times as big
});
game.addChild(bonusAsset);
LK.setTimeout(function () {
bonusAsset.destroy();
}, 1000);
}
// Reset boosted state after checking for bonus
basket.boosted = false;
scoreTxt.setText('Score: ' + score);
}
// Remove balls that are off-screen or collide with obstacles
if (balls[i] && (balls[i].y < 0 || obstacles.some(function (obstacle) {
return balls[i].intersects(obstacle);
}))) {
balls[i].destroy();
balls.splice(i, 1);
}
}
});
// Initialize the first ball
spawnBall();
// Create a score counter
var score = 0;
var scoreTxt = new Text2('Score: 0', {
size: 50,
fill: "#ffffff"
});
scoreTxt.anchor.set(1, 0); // Anchor to the top right corner
LK.gui.topRight.addChild(scoreTxt);
in-game asset. 2d. basketball. blank background. minimalistic flat graphic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Game Texture. In-Game asset. 2d. Blank background. super simplistic arrow from left to right. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Game Texture. In-Game asset. 2d. flat graphic orange red. Basketball saying "bonus" white font. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Game Texture. In-Game asset. 2d. flat minimalistic graphic. Boost pad with a lightning icon on the top. Top view. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
in-game asset. 2d. monster head from top view. blank background. minimalistic flat graphic. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
in-game asset. 2d. shield graphic green. blank background. minimalistic flat graphic. Single Game Texture. In-Game asset. 2d. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
in-game asset. 2d. flat 2d graphic of a blueish rectangle that looks like the top of a crate. blank background. minimalistic flat graphic. Single Game Texture. In-Game asset. 2d. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
in-game asset. yellow lighting bolt. small black outline. blank background. minimalistic flat graphic. Single Game Texture. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
in-game asset. 2d. magnet graphic recentgular with text saying "Magnetism". blank background. minimalistic flat graphic. Single Game Texture. In-Game asset. High contrast. No shadows. red and blue. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.