Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: isGamePaused is not defined' in or related to this line: 'if (!isGamePaused) {' Line Number: 440
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'x')' in or related to this line: 'currentBackground.x = 2048 / 2;' Line Number: 398
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: round is not defined' in or related to this line: 'var currentBackground = LK.getAsset('background' + round, {' Line Number: 431
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: displayRoundText is not defined' in or related to this line: 'displayRoundText(gameRound);' Line Number: 454
Code edit (2 edits merged)
Please save this source code
User prompt
add handswithgloves asset to screen
Code edit (1 edits merged)
Please save this source code
User prompt
only increase score if entire ball goes through basket
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: game.addchild is not a function' in or related to this line: 'game.addchild(self.leftElement);' Line Number: 219
Code edit (1 edits merged)
Please save this source code
Code edit (23 edits merged)
Please save this source code
User prompt
make the roundText opaque
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
remove the little ball at the top left of the screen
User prompt
if ball intersects with defender reset multiplier
User prompt
if ball intersects with defender remove multiplier
Code edit (1 edits merged)
Please save this source code
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
self.hasScored = false;
self.hasBounced = false;
self.throwSpeed = 0;
var ballGraphics = LK.getAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(ballGraphics);
self.speed = {
x: 0,
y: 0
};
self.hasThrown = false;
self.move = function () {
self.speed.y += 3.2;
self.x += self.speed.x;
if (self.x < self.width / 2) {
self.x = self.width / 2;
} else if (self.x > 2048 - self.width / 2) {
self.x = 2048 - self.width / 2;
}
self.y += self.speed.y;
if (self.y < self.height / 2) {
self.y = self.height / 2;
self.speed.y *= -0.5;
}
self.rotation += self.speed.x * 0.01;
if (self.hasThrown) {
var targetScale = 0.8;
self.scale.x += (targetScale - self.scale.x) * 0.05;
self.scale.y += (targetScale - self.scale.y) * 0.05;
}
if (self.hasScored) {
self.alpha -= 0.15;
} else {
self.alpha += 0.15;
if (self.alpha > 1) {
self.alpha = 1;
}
}
};
self.bounceOffPoint = function (x, y, elasticity) {
var dx = self.x - x;
var dy = self.y - y;
var angle = Math.atan2(dy, dx);
var speed = Math.sqrt(self.speed.x * self.speed.x + self.speed.y * self.speed.y);
self.speed.x = Math.cos(angle) * speed * elasticity;
self.speed.y = Math.sin(angle) * speed * elasticity;
};
self.angleTo = function (x, y) {
var dx = self.x - x;
var dy = self.y - y;
return Math.atan2(dy, dx);
};
self.distanceTo = function (x, y) {
var dx = self.x - x;
var dy = self.y - y;
return Math.sqrt(dx * dx + dy * dy);
};
self.moveToDistance = function (x, y, distance) {
var angle = self.angleTo(x, y);
self.x = x + Math.cos(angle) * (distance * 1.05);
self.y = y + Math.sin(angle) * (distance * 1.05);
};
});
var Defender = Container.expand(function () {
var self = Container.call(this);
var defenderGraphics = self.attachAsset('defender', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = 1600;
self.targetY = 833;
self.targetCorner = 0;
self.distanceFromTarget = function () {
self.distanceX = self.targetX - self.x;
self.distanceY = self.targetY - self.y;
};
self.pickNewTarget = function () {
// Gradually move defender within 200 pixel radius of 'hoopRimSeparate' asset
self.targetCorner = (self.targetCorner + 1) % 4;
self.targetX = hoopRim.x - 550 + (self.targetCorner + 1) % 4 % 3 * 3 % 5 % 2 * 1100;
self.targetY = hoopRim.y - 550 + (self.targetCorner + 0) % 4 % 3 * 3 % 5 % 2 * 833;
self.distanceFromTarget();
};
self.move = function () {
self.x += self.distanceX * 0.01;
self.y += self.distanceY * 0.01;
};
});
var ExplosionParticle = Container.expand(function () {
var self = Container.call(this);
self.interactive = false;
var shapes = ['dust', 'dust', 'dust'];
var shapeIndex = Math.floor(Math.random() * shapes.length);
var explosionGraphics = self.attachAsset(shapes[shapeIndex], {
anchorX: 0.5,
anchorY: 0.5
});
explosionGraphics.blendMode = 1;
self.lifeSpan = 30 + Math.random() * 20; // Random lifespan between 30 to 50 ticks
self.speed = {
x: (Math.random() - 0.5) * 10,
y: (Math.random() - 0.5) * 10
};
self.scale.set(Math.random() * 0.5 + 0.5); // Random scale between 0.5 to 1
//self.rotation = Math.random() * Math.PI * 2;
self.move = function () {
self.x += self.speed.x;
self.y += self.speed.y;
self.lifeSpan--;
if (self.lifeSpan <= 0) {
self.destroy();
}
};
});
var Flower = Container.expand(function () {
var self = Container.call(this);
self.interactive = false;
var flowerTypes = ['leftElement', 'rightElement', 'ballShadow']; // Reuse existing shapes for flowers
var flowerIndex = Math.floor(Math.random() * flowerTypes.length);
var flowerGraphics = self.attachAsset(flowerTypes[flowerIndex], {
anchorX: 0.5,
anchorY: 0.5
});
flowerGraphics.scaleX = flowerGraphics.scaleY = Math.random() * 0.5 + 0.5; // Random scale for variety
self.speed = {
x: (Math.random() - 0.5) * 2,
y: Math.random() * 5 + 2 // Falling speed
};
self.move = function () {
self.x += self.speed.x;
self.y += self.speed.y;
if (self.y > 2732 + 100) {
// Remove flower when it goes off screen
self.destroy();
}
};
});
var Hoop = Container.expand(function () {
var self = Container.call(this);
self.setScore = function (score) {
self.scoreLabel.setText(score.toString());
};
self.moveTo = function (newX, newY, hoopRim) {
var dx = (newX - self.x) / 60;
var dy = (newY - self.y) / 60;
var steps = 0;
var interval = LK.setInterval(function () {
self.x += dx;
self.y += dy;
hoopRim.x = self.x;
hoopRim.y = self.y + self.children[1].y - 250;
steps++;
if (steps >= 60) {
LK.clearInterval(interval);
}
});
};
var backboardGraphics = LK.getAsset('backboard', {
anchorX: 0.5,
anchorY: 0.5
});
backboardGraphics.y -= 250;
self.addChild(backboardGraphics);
self.hoopRimGraphics = LK.getAsset('hoopRim', {
anchorX: 0.5,
anchorY: 0.5
});
self.hoopRimGraphics.y = backboardGraphics.height / 2 - 550 + 20 + 120 + 150 + 100;
self.hoopRimGraphics.alpha = 0;
self.addChild(self.hoopRimGraphics);
self.leftElement = LK.getAsset('leftElement', {
anchorX: 0.5,
anchorY: 0.5
});
self.leftElement.x = self.hoopRimGraphics.x - self.hoopRimGraphics.width / 2 + self.leftElement.width / 2 - 50;
self.leftElement.y = self.hoopRimGraphics.y - 250;
self.leftElement.alpha = 0;
self.addChild(self.leftElement);
self.rightElement = LK.getAsset('rightElement', {
anchorX: 0.5,
anchorY: 0.5
});
self.rightElement.x = self.hoopRimGraphics.x + self.hoopRimGraphics.width / 2 - self.rightElement.width / 2 + 50;
self.rightElement.y = self.hoopRimGraphics.y - 250;
self.rightElement.alpha = 0;
self.addChild(self.rightElement);
self.hoopOutlineGraphics = LK.getAsset('hoopOutline', {
anchorX: 1,
anchorY: 0.5
});
self.hoopOutlineGraphics.y = self.hoopRimGraphics.y - 230;
self.hoopOutlineGraphics.alpha = 1;
self.hoopOutlineGraphics.tint = 0xbb502e;
self.hoopOutlineGraphics.rotation = Math.PI / 2;
self.addChild(self.hoopOutlineGraphics);
self.multiplierLabel = new Text2('', {
size: 200,
fill: '#8d4529',
font: 'Impact'
});
self.multiplierLabel.anchor.set(.5, 1);
self.multiplierLabel.x = self.hoopRimGraphics.x;
self.multiplierLabel.y = self.hoopRimGraphics.y - 250 - 50 + 30;
self.addChild(self.multiplierLabel);
self.scoreLabel = new Text2('0', {
size: 270,
fill: '#4b190c',
font: 'Impact'
});
self.scoreLabel.anchor.set(.5, .5);
self.scoreLabel.x = self.hoopRimGraphics.x;
self.scoreLabel.y = self.hoopRimGraphics.y - 250 - 20 - 420;
self.addChild(self.scoreLabel);
});
var HoopRim = Container.expand(function () {
var self = Container.call(this);
var hoopRimGraphics = LK.getAsset('hoopRimSeparate', {
anchorX: 0.5,
anchorY: 0.5
});
self.addChild(hoopRimGraphics);
});
var Particle = Container.expand(function () {
var self = Container.call(this);
self.interactive = false;
var particleGraphics = self.attachAsset('rainbowParticle', {
anchorX: 0.5,
anchorY: 0.5
});
particleGraphics.blendMode = 1;
self.lifeSpan = 60;
self.speed = {
x: (Math.random() - 0.5) * 2,
y: (Math.random() - 0.5) * 2
};
self.scale.set(Math.random() * 0.6 + 0.2);
self.rotation = Math.random() * Math.PI * 2;
self.move = function () {
self.x += self.speed.x;
self.y += self.speed.y;
self.alpha -= 0.03;
if (self.alpha <= 0) {
self.destroy();
}
};
});
var PowerBall = Container.expand(function () {
var self = Container.call(this);
var powerBallGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.scale.set(0.5); // Smaller size for the power ball
self.interactive = true; // Make the power ball interactive
self.powerLevel = 0; // Initialize power level at 0
self.maxPower = 10; // Maximum power level
self.updatePower = function (delta) {
self.powerLevel += delta;
if (self.powerLevel > self.maxPower) {
self.powerLevel = self.maxPower;
} else if (self.powerLevel < 0) {
self.powerLevel = 0;
}
// Update the visual representation of power level here if needed
};
self.on('down', function () {
// Increase power level when the power ball is pressed
self.updatePower(1);
});
});
var handsWithGloves = Container.expand(function () {
var self = Container.call(this);
var handsWithGlovesGraphics = self.attachAsset('handsWithGloves', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = 1600;
self.targetY = 833;
self.targetCorner = 0;
self.distanceFromTarget = function () {
self.distanceX = self.targetX - self.x;
self.distanceY = self.targetY - self.y;
};
self.pickNewTarget = function () {
// Gradually move defender within 200 pixel radius of 'hoopRimSeparate' asset
self.targetCorner = (self.targetCorner + 1) % 4;
self.targetX = hoopRim.x - 550 + (self.targetCorner + 1) % 4 % 3 * 3 % 5 % 2 * 1100;
self.targetY = hoopRim.y - 550 + (self.targetCorner + 0) % 4 % 3 * 3 % 5 % 2 * 833;
self.distanceFromTarget();
};
self.move = function () {
self.x += self.distanceX * 0.01;
self.y += self.distanceY * 0.01;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var handsWithGloves = LK.getAsset('handswithgloves', {
anchorX: 0.5,
anchorY: 0.5
});
handsWithGloves.x = 2048 / 2;
handsWithGloves.y = 2732 - handsWithGloves.height / 2;
game.addChild(handsWithGloves);
var currentPowerBar = 1;
// Cycle through power bar assets
var cyclePowerBars = function cyclePowerBars() {
var powerBarAsset = 'powerBar' + currentPowerBar;
var powerBar = LK.getAsset(powerBarAsset, {
anchorX: 0.5,
anchorY: 0.5
});
powerBar.x = 2048 - powerBar.width / 2; // Position in bottom right corner
powerBar.y = 2732 - powerBar.height / 2;
game.addChild(powerBar);
currentPowerBar = currentPowerBar % 9 + 1;
LK.setTimeout(function () {
game.removeChild(powerBar);
}, 500);
ball.throwSpeed = 1 + currentPowerBar / 4;
};
var longestStreak = 0;
var currentStreak = 0;
var mouseDownTime = 0;
var screenClicks = 0;
var powerBar1Displayed = false;
var powerBar1 = LK.getAsset('powerBar1', {
anchorX: 0.5,
anchorY: 0.5
});
powerBar1.x = 2048 - powerBar1.width / 2;
powerBar1.y = 2732 - powerBar1.height / 2;
var powerBar2Displayed = false;
var powerBar2 = LK.getAsset('powerBar2', {
anchorX: 0.5,
anchorY: 0.5
});
var powerBar3Displayed = false;
var powerBar4Displayed = false;
var gameRound = 1;
var currentBackground;
var timerTxt = new Text2('100', {
size: 150,
fill: "#ffffff"
});
timerTxt.anchor.set(0, 0);
timerTxt.x = 50;
timerTxt.y = 50;
var gameTime = 100;
var score = 0;
var scoreMultiplier = 1;
var hoop = game.addChild(new Hoop());
var defender = game.addChild(new Defender());
defender.x = 2048 / 2;
defender.y = 2732 / 2 - 500; // Position above the hoop
defender.distanceFromTarget();
var ballShadow = LK.getAsset('ballShadow', {
anchorX: 0.5,
anchorY: 0.5
});
ballShadow.alpha = 0.5;
// ***
// This function resets/updates the assets at each round
var newRoundFunc = function newRoundFunc(round) {
// background
game.removeChild(currentBackground);
currentBackground = LK.getAsset('background' + round, {
anchorX: 0.5,
anchorY: 0.5
});
currentBackground.x = 2048 / 2;
currentBackground.y = 2732 / 2 + 150;
currentBackground.alpha = 0.7;
game.addChild(currentBackground);
// Round text
var roundText = new Text2('ROUND ' + round, {
size: 200,
fill: "#ffffff",
alpha: 1
});
roundText.anchor.set(0.5, 0.5); // Center the text
roundText.x = 2048 / 2; // Center horizontally
roundText.y = 500; // Center vertically
game.addChild(roundText);
// Remove roundtext after 3 seconds
LK.setTimeout(function () {
game.removeChild(roundText);
}, 3000);
// Timer text
LK.gui.topLeft.addChild(timerTxt);
// add b-ball assets in correct order
game.addChild(hoop);
game.addChild(defender);
game.addChild(ballShadow);
};
// Start newround
newRoundFunc(gameRound);
// updates the clock or something
var isGamePaused = false;
var timerInterval = LK.setInterval(function () {
if (!isGamePaused) {
gameTime--;
if (gameTime <= 0) {
LK.clearInterval(timerInterval);
LK.showGameOver();
return;
}
timerTxt.setText(gameTime.toString());
}
}, 1000);
var ball = game.addChild(new Ball());
var hoopRim = game.addChild(new HoopRim());
ball.hitElement = '';
hoop.x = 2048 / 2;
hoop.y = 2732 / 2;
hoopRim.x = hoop.x;
hoopRim.y = hoop.y + hoop.children[1].y - 250;
ball.x = 2048 / 2;
ball.on('down', function (obj) {
if (!ball.hasThrown) {
mouseDownTime = Date.now();
powerBar1Displayed = false;
var event = obj.event;
dragStart = event.getLocalPosition(game);
}
});
ball.on('up', function (obj) {
mouseDownTime = 0;
});
var dragStart = null;
game.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
if (dragStart !== null && ball.distanceTo(pos.x, pos.y) > 400) {
game.fireBall(obj);
}
});
game.fireBall = function (obj) {
if (dragStart !== null) {
var event = obj.event;
var pos = event.getLocalPosition(game);
var dx = pos.x - dragStart.x;
var dy = pos.y - dragStart.y;
var angle = Math.atan2(dy, dx);
ball.speed.x = -ball.throwSpeed * Math.cos(angle) * 30;
ball.speed.y = -ball.throwSpeed * Math.sin(angle) * 30;
ball.hasThrown = true;
ball.hitElement = '';
game.removeChild(ball);
game.addChild(ball);
dragStart = null;
}
};
game.on('up', function (obj) {
if (dragStart !== null) {
var event = obj.event;
var pos = event.getLocalPosition(game);
var distance = Math.sqrt(Math.pow(pos.x - dragStart.x, 2) + Math.pow(pos.y - dragStart.y, 2));
if (distance > 150) {
game.fireBall(obj);
}
}
dragStart = null;
});
var floorY = 2632 + 900 * (ball.scale.y - 1);
ball.y = floorY - ball.height;
powerBarIncrease = 0;
// ***
// MAIN GAME LOOP
LK.on('tick', function () {
if (Math.abs(defender.x - defender.targetX) <= 5 && Math.abs(defender.y - defender.targetY) <= 5) {
defender.pickNewTarget();
defender.distanceFromTarget();
defender.move();
} else {
defender.move();
}
if (ball.hasThrown) {
// Create a fire particle only when there is a multiplier
if (scoreMultiplier == 2) {
var particle = new Particle();
particle.alpha = 0.8;
// Set fire particle color to yellow for x2 multiplier
particle.tint = 0xFFFF00; // Yellow color
var angle = Math.random() * Math.PI * 2;
var radius = ball.width * 0.5 * Math.sqrt(Math.random());
particle.x = ball.x + Math.cos(angle) * radius;
particle.y = ball.y + Math.sin(angle) * radius;
game.addChild(particle);
} else if (scoreMultiplier >= 3) {
var particle = new Particle();
particle.alpha = 0.8;
// Set fire particle color to red and increase size for x3 or higher multiplier
particle.tint = 0xFF0000; // Red color
particle.scale.set(1.5); // Increase size
var angle = Math.random() * Math.PI * 2;
var radius = ball.width * 0.75 * Math.sqrt(Math.random()); // Increase radius for bigger particles
particle.x = ball.x + Math.cos(angle) * radius;
particle.y = ball.y + Math.sin(angle) * radius;
game.addChild(particle);
}
}
powerBarIncrease += 1;
if (powerBarIncrease % 10 == 0) {
if (mouseDownTime > 0) {
cyclePowerBars();
} else {
powerBarIncrease = 0;
currentPowerBar = 1;
}
}
if (scoreMultiplier > 1 && !ball.hasThrown) {
for (var i = 0; i < 2; i++) {
var particle = new Particle();
particle.alpha = ball.alpha;
var angle = Math.random() * Math.PI * 2;
var radius = ball.width * 0.5 * Math.sqrt(Math.random());
particle.x = ball.x + Math.cos(angle) * radius;
particle.y = ball.y + Math.sin(angle) * radius;
game.addChild(particle);
}
}
game.children.forEach(function (child) {
if (child instanceof Particle) {
child.move();
}
});
var floorY = 2632 + 900 * (ball.scale.y - 1);
ball.move();
if (ball.speed.y > 0) {
game.removeChild(hoopRim);
game.addChild(hoopRim);
if (ball.distanceTo(hoop.x + hoop.leftElement.x, hoop.y + hoop.leftElement.y) < ball.width / 2 + hoop.leftElement.width / 2) {
ball.moveToDistance(hoop.x + hoop.leftElement.x, hoop.y + hoop.leftElement.y, ball.width / 2 + hoop.leftElement.width / 2 + 1);
ball.bounceOffPoint(hoop.x + hoop.leftElement.x, hoop.y + hoop.leftElement.y, 0.5);
ball.hitElement = 'left';
}
if (ball.distanceTo(hoop.x + hoop.rightElement.x, hoop.y + hoop.rightElement.y) < ball.width / 2 + hoop.rightElement.width / 2) {
ball.moveToDistance(hoop.x + hoop.rightElement.x, hoop.y + hoop.rightElement.y, ball.width / 2 + hoop.rightElement.width / 2 + 1);
ball.bounceOffPoint(hoop.x + hoop.rightElement.x, hoop.y + hoop.rightElement.y, 0.5);
ball.hitElement = 'right';
}
}
ballShadow.x = ball.x;
ballShadow.y = 1800 + ball.height / 2 + 500 * ball.scale.x;
var scale = (1 - 2 * (ball.y - 2732 + ball.height) / 2732) * ball.scale.x;
ballShadow.scale.set(scale);
ballShadow.alpha = (1 - scale + 1) / 2 * ball.alpha;
// Removed code that makes ball go in opposite direction if it intersects with hands
// Check for intersection with defender and make ball disappear for 1 second
// Check if ball lands on the platform or the floor and hasn't scored yet
if (ball.y + ball.height > floorY && ball.speed.y > 0) {
ball.y = floorY - ball.height;
ball.speed.y *= -0.75;
ballShadow.x = ball.x;
ballShadow.visible = true;
if (ball.hasThrown && !ball.hasScored) {
ball.hasBounced = true;
ball.x = 2048 / 2;
currentStreak = 0;
ball.y = floorY - ball.height;
ball.speed.x = 0;
ball.speed.y = 0;
ball.hasThrown = false;
ball.hasBounced = false;
ball.scale.x = 1;
ball.scale.y = 1;
ball.alpha = 1;
scoreMultiplier = 1;
hoop.multiplierLabel.setText('');
hoop.x += 5;
if (hoop.x > 2048 - hoop.width / 2) {
hoop.x = hoop.width / 2;
}
hoopRim.x = hoop.x;
} else if (ball.hasScored) {
ball.x = 2048 / 2;
ball.y = floorY - ball.height;
ball.speed.x = 0;
ball.speed.y = 0;
ball.hasThrown = false;
ball.hasScored = false;
ball.hasBounced = false;
ball.scale.x = 1;
ball.scale.y = 1;
if (ball.hitElement === '') {
if (scoreMultiplier < 3) {
scoreMultiplier++;
}
} else {
scoreMultiplier = 1;
}
if (scoreMultiplier > 1) {
hoop.multiplierLabel.setText('x' + scoreMultiplier);
} else {
hoop.multiplierLabel.setText('');
}
ball.hitElement = '';
hoop.moveTo(Math.random() * 1000 + 500, Math.random() * 1000 + 900, hoopRim);
}
} else if (ball.hasThrown && ball.intersects(hoop.hoopRimGraphics) && ball.speed.y > 0 && !ball.hasScored && !ball.hasBounced && ball.x > hoop.x + hoop.leftElement.x && ball.x < hoop.x + hoop.rightElement.x && ball.y < hoop.y + 150) {
ball.hasScored = true;
score += scoreMultiplier * 2;
currentStreak += 1;
if (currentStreak > longestStreak) {
longestStreak = currentStreak;
}
// Generate flowers falling from the sky
for (var i = 0; i < 10; i++) {
// Generate 10 flowers
var flower = new Flower();
flower.x = Math.random() * 2048; // Random x position across the screen width
flower.y = -100; // Start just above the screen
game.addChild(flower);
}
if (hoop.x > 2048 - hoop.width / 2) {
hoop.x = hoop.width / 2;
}
hoopRim.x = hoop.x;
if (score >= 3) {
score = 0; // Reset score to 0
gameTime = 100; // Reset timer to 100
timerTxt.setText(gameTime.toString()); // Update timer display
hoop.scoreLabel.setText(score.toString());
hoop.setScore(score);
gameRound = gameRound + 1;
newRoundFunc(gameRound);
} else {
hoop.scoreLabel.setText(score.toString());
hoop.setScore(score);
}
}
if (ball.intersects(defender) && !ball.hasScored && ball.hasThrown) {
scoreMultiplier = 1; // Reset multiplier
var dust = new ExplosionParticle();
dust.x = defender.x + (Math.random() - 0.5) * defender.width;
dust.y = defender.y + (Math.random() - 0.5) * defender.height;
game.addChild(dust);
LK.setTimeout(function () {
game.removeChild(dust);
}, 500);
hoop.multiplierLabel.setText('');
// Display miniball assets while ball is invisible
// Display 8 miniballs while the main ball is invisible
/*var miniballPositions = [];
if (defender.x > 2048 / 2) {
// Defender is on the right side
for (var i = 0; i < 5; i++) {
miniballPositions.push({
x: 2048 / 2 + 2048 / 10 * i,
// Spread across the right half of the screen
y: ball.y - 50
});
}
} else {
// Defender is on the left side
for (var i = 0; i < 5; i++) {
miniballPositions.push({
x: 2048 / 10 * i,
// Spread across the left half of the screen
y: ball.y - 50
});
}
}*/
// Reset ball
ball.x = 2048 / 2;
ball.y = floorY - ball.height - 50;
ball.speed.x = 0;
ball.speed.y = 0;
ball.hasThrown = false;
ball.visible = true; // Ensure ball is visible after reset
}
}); ===================================================================
--- original.js
+++ change.js
@@ -354,10 +354,28 @@
var powerBar3Displayed = false;
var powerBar4Displayed = false;
var gameRound = 1;
var currentBackground;
-var timerTxt;
+var timerTxt = new Text2('100', {
+ size: 150,
+ fill: "#ffffff"
+});
+timerTxt.anchor.set(0, 0);
+timerTxt.x = 50;
+timerTxt.y = 50;
var gameTime = 100;
+var score = 0;
+var scoreMultiplier = 1;
+var hoop = game.addChild(new Hoop());
+var defender = game.addChild(new Defender());
+defender.x = 2048 / 2;
+defender.y = 2732 / 2 - 500; // Position above the hoop
+defender.distanceFromTarget();
+var ballShadow = LK.getAsset('ballShadow', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+ballShadow.alpha = 0.5;
// ***
// This function resets/updates the assets at each round
var newRoundFunc = function newRoundFunc(round) {
// background
@@ -384,36 +402,30 @@
LK.setTimeout(function () {
game.removeChild(roundText);
}, 3000);
// Timer text
- LK.gui.topLeft.removeChild(timerTxt);
- timerTxt = new Text2('100', {
- size: 150,
- fill: "#ffffff"
- });
- timerTxt.anchor.set(0, 0);
- timerTxt.x = 50;
- timerTxt.y = 50;
LK.gui.topLeft.addChild(timerTxt);
+ // add b-ball assets in correct order
+ game.addChild(hoop);
+ game.addChild(defender);
+ game.addChild(ballShadow);
};
+// Start newround
newRoundFunc(gameRound);
-var hoop = game.addChild(new Hoop());
-var defender = game.addChild(new Defender());
-defender.x = 2048 / 2;
-defender.y = 2732 / 2 - 500; // Position above the hoop
-defender.distanceFromTarget();
-var score = 0;
-var scoreMultiplier = 1;
-var ballShadow = LK.getAsset('ballShadow', {
- anchorX: 0.5,
- anchorY: 0.5
-});
-ballShadow.alpha = 0.5;
-game.addChild(ballShadow);
+// updates the clock or something
+var isGamePaused = false;
+var timerInterval = LK.setInterval(function () {
+ if (!isGamePaused) {
+ gameTime--;
+ if (gameTime <= 0) {
+ LK.clearInterval(timerInterval);
+ LK.showGameOver();
+ return;
+ }
+ timerTxt.setText(gameTime.toString());
+ }
+}, 1000);
var ball = game.addChild(new Ball());
-var powerBall = game.addChild(new PowerBall());
-powerBall.x = ball.x + ball.width / 2 + powerBall.width / 2 + 20; // Position powerball to the right of the ball
-powerBall.y = ball.y; // Align horizontally with the ball
var hoopRim = game.addChild(new HoopRim());
ball.hitElement = '';
hoop.x = 2048 / 2;
hoop.y = 2732 / 2;
@@ -445,10 +457,10 @@
var pos = event.getLocalPosition(game);
var dx = pos.x - dragStart.x;
var dy = pos.y - dragStart.y;
var angle = Math.atan2(dy, dx);
- ball.speed.x = -ball.throwSpeed * Math.cos(angle) * 30 * (0.9 + powerBall.powerLevel / 10) / 3 * 1.5;
- ball.speed.y = -ball.throwSpeed * Math.sin(angle) * 30 * (0.9 + powerBall.powerLevel / 10) * 1.5;
+ ball.speed.x = -ball.throwSpeed * Math.cos(angle) * 30;
+ ball.speed.y = -ball.throwSpeed * Math.sin(angle) * 30;
ball.hasThrown = true;
ball.hitElement = '';
game.removeChild(ball);
game.addChild(ball);
Basketball, cartoon style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
4:3 Simple rectangle white outline. Black background
Paris. Paris basketball backgroung. Eiffel Tower. Eurosport logo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
rainbow sparkle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
two white palms facing forward no background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. HD Color
POV basketball court in forest. Full screen. Background. High detail
basketball barn background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
basketball dungeon background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
heaven background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pow effect. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
left hand. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Wide Single Orange metal bar lying down Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast. —ar 2:1
https://kagi.com/proxy/basketball_backboard.png?c=iNrrnnUOe99nVfDGJsYBLujiaX2Hu-zxBFRkvLEyXdRnJ8cU3RjcAYbR-o12E923qVNGy1CEGrQG87ogCD3yUarJdZYt5R03mmEMb7Jrh-8%3D blank backboard Single Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.