User prompt
Make the ball shoots 200 higher
User prompt
When landed in Green zone ball must go in ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Move backboard down 25
User prompt
Add a slight bit more power to shot
User prompt
Modify perfect shot logic to ensure basketball goes straight over the rim and into hoop when stopped in green zone ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
When shit allow ball to reach the middle of backboard before going I ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Allow ball to pass rim on the way up ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Prevent scoring when ball shoots under rim
User prompt
Ball must pass rim and fall into it ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
If shot bar lands on green make ball go straight through hoop with a swish ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Fix rim-rest animation structure to properly handle ball rolling into hoop ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Fix this please
User prompt
Make ball bigger
User prompt
Make basketball swish in for smooth gameplay ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Move backboard up 20
User prompt
Move backboard right 100
User prompt
Move backboard right 300
User prompt
Move backboard down 20
User prompt
Move backboard down 50
User prompt
Move hoop rim up 100 on backboard
User prompt
Make hoop rim bigger
User prompt
Make backboard bigger
User prompt
Remove ground
User prompt
Add background to game
User prompt
Make ball rotate vertically when shot ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Basketball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('basketball', { anchorX: 0.5, anchorY: 0.5 }); // Set z-index to render behind net and hoop ballGraphics.zIndex = -1; self.velocityX = 0; self.velocityY = 0; self.gravity = 0.5; self.bounceDecay = 0.7; self.hasScored = false; self.isActive = true; self.update = function () { if (!self.isActive) return; self.velocityY += self.gravity; self.x += self.velocityX; self.y += self.velocityY; // Check hoop collision if (hoop) { var hoopX = hoop.x; var hoopY = hoop.y - 350; // Adjust for hoop position within container var relativeX = self.x - hoopX; var relativeY = self.y - hoopY; // Check for scoring through hoop first (ball going through net area) if (Math.abs(relativeX) <= 60 && relativeY >= -10 && relativeY <= 50 && self.velocityY > 0 && !self.hasScored) { // Ball is going through hoop - animate net and score self.hasScored = true; self.isActive = false; // Set ball to render behind net and hoop ballGraphics.zIndex = -2; // Animate ball going through and down tween(self, { y: self.y + 100, x: hoopX + (Math.random() - 0.5) * 20 }, { duration: 500, easing: tween.easeIn }); // Animate net pulsate tween(hoop.net, { scaleX: 1.8, scaleY: 1.8 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(hoop.net, { scaleX: 1.5, scaleY: 1.5 }, { duration: 200, easing: tween.easeIn }); } }); // Score the basket currentStreak++; var points = 10 * currentStreak; if (self.isPerfectShot) { points *= 2; LK.effects.flashScreen(0xFFD700, 400); } LK.setScore(LK.getScore() + points); LK.getSound('swish').play(); scoreTxt.setText('Score: ' + LK.getScore()); streakTxt.setText('Streak: ' + currentStreak); LK.effects.flashObject(hoop, self.isPerfectShot ? 0xFFD700 : 0x00FF00, 300); return; } // Check if ball is hitting the hoop rim if (relativeX >= -125 && relativeX <= 125 && relativeY >= -25 && relativeY <= 25) { // Determine which side of the hoop was hit if (Math.abs(relativeX) > 90) { // Hit the sides of the rim self.velocityX = -self.velocityX * self.bounceDecay; if (relativeX < 0) { self.x = hoopX - 125; } else { self.x = hoopX + 125; } LK.getSound('bounce').play(); } else if (relativeY >= -25 && relativeY <= 0 && self.velocityY > 0) { // Hit the top of the rim (bouncing up) self.velocityY = -Math.abs(self.velocityY) * self.bounceDecay; self.y = hoopY - 25; self.velocityX *= 0.8; // Reduce horizontal velocity slightly LK.getSound('bounce').play(); } } // Check if ball is resting on the rim (low velocity and on top) if (Math.abs(relativeX) <= 90 && relativeY >= -30 && relativeY <= -20 && Math.abs(self.velocityY) < 2 && Math.abs(self.velocityX) < 3) { // Ball is resting on rim, make it roll into the hoop self.isActive = false; // Stop normal physics self.hasScored = true; // Mark as scored // Set ball to render behind net and hoop ballGraphics.zIndex = -2; // Animate rolling into hoop tween(self, { x: hoopX, y: hoopY + 40, rotation: self.rotation + Math.PI * 2 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { // Animate net pulsate tween(hoop.net, { scaleX: 1.8, scaleY: 1.8 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(hoop.net, { scaleX: 1.5, scaleY: 1.5 }, { duration: 200, easing: tween.easeIn }); } }); // Score the basket currentStreak++; var points = 10 * currentStreak; LK.setScore(LK.getScore() + points); // Play swish sound LK.getSound('swish').play(); // Update displays scoreTxt.setText('Score: ' + LK.getScore()); streakTxt.setText('Streak: ' + currentStreak); // Visual feedback LK.effects.flashObject(hoop, 0x00FF00, 300); } }); } } // Check ground collision if (self.y > 2632) { self.y = 2632; self.velocityY = -self.velocityY * self.bounceDecay; self.velocityX *= 0.9; LK.getSound('bounce').play(); if (Math.abs(self.velocityY) < 1) { self.isActive = false; } } // Remove if off screen if (self.x < -100 || self.x > 2148 || self.y > 2800) { self.isActive = false; } }; return self; }); var Hoop = Container.expand(function () { var self = Container.call(this); var backboard = self.attachAsset('backboard', { anchorX: 0.5, anchorY: 1 }); backboard.y = -20; var hoop = self.attachAsset('hoop', { anchorX: 0.5, anchorY: 0.5 }); hoop.y = -350; // Set z-index to render in front of basketball hoop.zIndex = 1; var net = self.attachAsset('net', { anchorX: 0.5, anchorY: 0, scaleX: 1.5, scaleY: 1.5 }); net.y = -325; net.alpha = 0.8; // Set z-index to render in front of basketball net.zIndex = 2; // Store net reference for animation access self.net = net; self.hoopBounds = { left: -90, right: 90, top: -20, bottom: 20 }; // Enable z-index sorting for proper rendering order self.sortableChildren = true; return self; }); var ShotBar = Container.expand(function () { var self = Container.call(this); // Background bar var bgBar = self.attachAsset('shotBarBg', { anchorX: 0.5, anchorY: 0.5 }); // Green zone var greenZone = self.attachAsset('shotBarGreen', { anchorX: 0.5, anchorY: 0.5 }); greenZone.x = 0; // Start at center, will move // Moving basketball indicator var indicator = self.attachAsset('basketball', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.6, scaleY: 0.6 }); self.isActive = false; self.isMoving = false; self.moveDirection = 1; // 1 for right, -1 for left self.moveSpeed = 8; self.maxDistance = 240; // Half of bar width minus indicator size self.perfectShot = false; self.startMoving = function () { self.isActive = true; self.isMoving = true; self.perfectShot = false; // Position green zone randomly greenZone.x = (Math.random() - 0.5) * 360; // Random position within bar // Reset indicator position indicator.x = -self.maxDistance; self.moveDirection = 1; self.visible = true; }; self.stopMoving = function () { self.isMoving = false; // Check if indicator is within green zone var greenLeft = greenZone.x - 60; var greenRight = greenZone.x + 60; self.perfectShot = indicator.x >= greenLeft && indicator.x <= greenRight; // Hide shot bar after a short delay var self_ref = self; LK.setTimeout(function () { self_ref.visible = false; self_ref.isActive = false; }, 200); return self.perfectShot; }; self.update = function () { if (!self.isMoving) return; // Move indicator back and forth indicator.x += self.moveSpeed * self.moveDirection; // Bounce off edges if (indicator.x >= self.maxDistance) { indicator.x = self.maxDistance; self.moveDirection = -1; } else if (indicator.x <= -self.maxDistance) { indicator.x = -self.maxDistance; self.moveDirection = 1; } }; self.visible = false; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var basketballs = []; var hoop = null; var ground = null; var scoreTxt = null; var streakTxt = null; var currentStreak = 0; var swipeStartX = 0; var swipeStartY = 0; var swipeStartTime = 0; var isSwipeStarted = false; var lastShotTime = 0; var musicNotes = ['note1', 'note2', 'note3', 'note4', 'note5']; var currentNoteIndex = 0; var shotBar = null; var isChargingShot = false; // Enable z-index sorting for proper rendering order game.sortableChildren = true; // Create ground ground = game.addChild(LK.getAsset('ground', { anchorX: 0, anchorY: 0 })); ground.y = 2632; // Create hoop hoop = game.addChild(new Hoop()); hoop.x = 624; hoop.y = 1300; // Create score display scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create streak display streakTxt = new Text2('Streak: 0', { size: 60, fill: 0xFFD700 }); streakTxt.anchor.set(0.5, 0); streakTxt.y = 100; LK.gui.top.addChild(streakTxt); // Create shot bar shotBar = game.addChild(new ShotBar()); shotBar.x = 624; shotBar.y = 2200; function createBasketball(startX, startY, velocityX, velocityY) { var ball = new Basketball(); ball.x = startX; ball.y = startY; ball.velocityX = velocityX; ball.velocityY = velocityY; ball.isPerfectShot = false; basketballs.push(ball); game.addChild(ball); return ball; } function checkBasketScore(ball) { // Scoring is now handled in Basketball class update method // This function is kept for compatibility but does nothing return; } game.down = function (x, y, obj) { if (LK.ticks - lastShotTime < 60) return; // Prevent rapid firing if (shotBar.isActive) { // Stop the shot bar and check for perfect shot var isPerfect = shotBar.stopMoving(); isChargingShot = false; // Calculate shooting parameters var startX = 624; var startY = 2500; var velocityX = 0; var velocityY = -15; // Base upward velocity if (isPerfect) { // Perfect shot - straight to hoop with precise trajectory var targetX = hoop.x; var targetY = hoop.y - 300; // Aim slightly above hoop center for perfect arc var deltaX = targetX - startX; var deltaY = targetY - startY; // Calculate perfect trajectory for swish var time = 45; // frames to reach target velocityX = deltaX / time; velocityY = deltaY / time - 0.5 * time * 0.5; // Account for gravity // Create perfect shot basketball var ball = createBasketball(startX, startY, velocityX, velocityY); ball.isPerfectShot = true; // Visual feedback for perfect shot LK.effects.flashScreen(0x00FF00, 200); // Add tween animation to ensure ball goes straight in tween(ball, { tint: 0xFFD700 }, { duration: 300, onFinish: function onFinish() { tween(ball, { tint: 0xFFFFFF }, { duration: 300 }); } }); // Add vertical rotation animation tween(ball, { rotation: ball.rotation + Math.PI * 4 }, { duration: 1500, easing: tween.easeOut }); } else { // Regular shot with some randomness velocityX = (Math.random() - 0.5) * 8; velocityY = -12 - Math.random() * 6; var ball = createBasketball(startX, startY, velocityX, velocityY); // Add vertical rotation animation for regular shot tween(ball, { rotation: ball.rotation + Math.PI * 3 }, { duration: 1200, easing: tween.easeOut }); } lastShotTime = LK.ticks; } else { // Start charging shot isChargingShot = true; shotBar.startMoving(); swipeStartX = x; swipeStartY = y; swipeStartTime = LK.ticks; } }; game.up = function (x, y, obj) { // Shot bar system handles shooting now, remove swipe-based shooting }; game.update = function () { // Update basketballs for (var i = basketballs.length - 1; i >= 0; i--) { var ball = basketballs[i]; if (!ball.isActive) { ball.destroy(); basketballs.splice(i, 1); continue; } // Check for scoring checkBasketScore(ball); // Check collision with other basketballs for (var j = i + 1; j < basketballs.length; j++) { var otherBall = basketballs[j]; if (!otherBall.isActive) continue; var dx = ball.x - otherBall.x; var dy = ball.y - otherBall.y; var distance = Math.sqrt(dx * dx + dy * dy); var minDistance = 120; // Combined radius of two basketballs if (distance < minDistance && distance > 0) { // Calculate collision normal var normalX = dx / distance; var normalY = dy / distance; // Separate balls to prevent overlap var overlap = minDistance - distance; var separationX = normalX * overlap * 0.5; var separationY = normalY * overlap * 0.5; ball.x += separationX; ball.y += separationY; otherBall.x -= separationX; otherBall.y -= separationY; // Calculate relative velocity var relativeVelX = ball.velocityX - otherBall.velocityX; var relativeVelY = ball.velocityY - otherBall.velocityY; // Calculate relative velocity along collision normal var relativeSpeed = relativeVelX * normalX + relativeVelY * normalY; // Only resolve if objects are moving towards each other if (relativeSpeed > 0) continue; // Calculate impulse scalar (assuming equal mass) var impulse = -2 * relativeSpeed / 2; var impulseX = impulse * normalX; var impulseY = impulse * normalY; // Apply impulse with bounce decay var bounceDecay = 0.8; ball.velocityX += impulseX * bounceDecay; ball.velocityY += impulseY * bounceDecay; otherBall.velocityX -= impulseX * bounceDecay; otherBall.velocityY -= impulseY * bounceDecay; // Play bounce sound LK.getSound('bounce').play(); } } } // Reset streak if no balls scored recently if (basketballs.length === 0 && LK.ticks - lastShotTime > 180) { if (currentStreak > 0) { currentStreak = 0; streakTxt.setText('Streak: 0'); currentNoteIndex = 0; // Reset musical progression } } // Check win condition if (LK.getScore() >= 500) { LK.showYouWin(); } }; // Start background music LK.playMusic('backgroundMusic');
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Basketball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('basketball', {
anchorX: 0.5,
anchorY: 0.5
});
// Set z-index to render behind net and hoop
ballGraphics.zIndex = -1;
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.5;
self.bounceDecay = 0.7;
self.hasScored = false;
self.isActive = true;
self.update = function () {
if (!self.isActive) return;
self.velocityY += self.gravity;
self.x += self.velocityX;
self.y += self.velocityY;
// Check hoop collision
if (hoop) {
var hoopX = hoop.x;
var hoopY = hoop.y - 350; // Adjust for hoop position within container
var relativeX = self.x - hoopX;
var relativeY = self.y - hoopY;
// Check for scoring through hoop first (ball going through net area)
if (Math.abs(relativeX) <= 60 && relativeY >= -10 && relativeY <= 50 && self.velocityY > 0 && !self.hasScored) {
// Ball is going through hoop - animate net and score
self.hasScored = true;
self.isActive = false;
// Set ball to render behind net and hoop
ballGraphics.zIndex = -2;
// Animate ball going through and down
tween(self, {
y: self.y + 100,
x: hoopX + (Math.random() - 0.5) * 20
}, {
duration: 500,
easing: tween.easeIn
});
// Animate net pulsate
tween(hoop.net, {
scaleX: 1.8,
scaleY: 1.8
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(hoop.net, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeIn
});
}
});
// Score the basket
currentStreak++;
var points = 10 * currentStreak;
if (self.isPerfectShot) {
points *= 2;
LK.effects.flashScreen(0xFFD700, 400);
}
LK.setScore(LK.getScore() + points);
LK.getSound('swish').play();
scoreTxt.setText('Score: ' + LK.getScore());
streakTxt.setText('Streak: ' + currentStreak);
LK.effects.flashObject(hoop, self.isPerfectShot ? 0xFFD700 : 0x00FF00, 300);
return;
}
// Check if ball is hitting the hoop rim
if (relativeX >= -125 && relativeX <= 125 && relativeY >= -25 && relativeY <= 25) {
// Determine which side of the hoop was hit
if (Math.abs(relativeX) > 90) {
// Hit the sides of the rim
self.velocityX = -self.velocityX * self.bounceDecay;
if (relativeX < 0) {
self.x = hoopX - 125;
} else {
self.x = hoopX + 125;
}
LK.getSound('bounce').play();
} else if (relativeY >= -25 && relativeY <= 0 && self.velocityY > 0) {
// Hit the top of the rim (bouncing up)
self.velocityY = -Math.abs(self.velocityY) * self.bounceDecay;
self.y = hoopY - 25;
self.velocityX *= 0.8; // Reduce horizontal velocity slightly
LK.getSound('bounce').play();
}
}
// Check if ball is resting on the rim (low velocity and on top)
if (Math.abs(relativeX) <= 90 && relativeY >= -30 && relativeY <= -20 && Math.abs(self.velocityY) < 2 && Math.abs(self.velocityX) < 3) {
// Ball is resting on rim, make it roll into the hoop
self.isActive = false; // Stop normal physics
self.hasScored = true; // Mark as scored
// Set ball to render behind net and hoop
ballGraphics.zIndex = -2;
// Animate rolling into hoop
tween(self, {
x: hoopX,
y: hoopY + 40,
rotation: self.rotation + Math.PI * 2
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Animate net pulsate
tween(hoop.net, {
scaleX: 1.8,
scaleY: 1.8
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(hoop.net, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
easing: tween.easeIn
});
}
});
// Score the basket
currentStreak++;
var points = 10 * currentStreak;
LK.setScore(LK.getScore() + points);
// Play swish sound
LK.getSound('swish').play();
// Update displays
scoreTxt.setText('Score: ' + LK.getScore());
streakTxt.setText('Streak: ' + currentStreak);
// Visual feedback
LK.effects.flashObject(hoop, 0x00FF00, 300);
}
});
}
}
// Check ground collision
if (self.y > 2632) {
self.y = 2632;
self.velocityY = -self.velocityY * self.bounceDecay;
self.velocityX *= 0.9;
LK.getSound('bounce').play();
if (Math.abs(self.velocityY) < 1) {
self.isActive = false;
}
}
// Remove if off screen
if (self.x < -100 || self.x > 2148 || self.y > 2800) {
self.isActive = false;
}
};
return self;
});
var Hoop = Container.expand(function () {
var self = Container.call(this);
var backboard = self.attachAsset('backboard', {
anchorX: 0.5,
anchorY: 1
});
backboard.y = -20;
var hoop = self.attachAsset('hoop', {
anchorX: 0.5,
anchorY: 0.5
});
hoop.y = -350;
// Set z-index to render in front of basketball
hoop.zIndex = 1;
var net = self.attachAsset('net', {
anchorX: 0.5,
anchorY: 0,
scaleX: 1.5,
scaleY: 1.5
});
net.y = -325;
net.alpha = 0.8;
// Set z-index to render in front of basketball
net.zIndex = 2;
// Store net reference for animation access
self.net = net;
self.hoopBounds = {
left: -90,
right: 90,
top: -20,
bottom: 20
};
// Enable z-index sorting for proper rendering order
self.sortableChildren = true;
return self;
});
var ShotBar = Container.expand(function () {
var self = Container.call(this);
// Background bar
var bgBar = self.attachAsset('shotBarBg', {
anchorX: 0.5,
anchorY: 0.5
});
// Green zone
var greenZone = self.attachAsset('shotBarGreen', {
anchorX: 0.5,
anchorY: 0.5
});
greenZone.x = 0; // Start at center, will move
// Moving basketball indicator
var indicator = self.attachAsset('basketball', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
self.isActive = false;
self.isMoving = false;
self.moveDirection = 1; // 1 for right, -1 for left
self.moveSpeed = 8;
self.maxDistance = 240; // Half of bar width minus indicator size
self.perfectShot = false;
self.startMoving = function () {
self.isActive = true;
self.isMoving = true;
self.perfectShot = false;
// Position green zone randomly
greenZone.x = (Math.random() - 0.5) * 360; // Random position within bar
// Reset indicator position
indicator.x = -self.maxDistance;
self.moveDirection = 1;
self.visible = true;
};
self.stopMoving = function () {
self.isMoving = false;
// Check if indicator is within green zone
var greenLeft = greenZone.x - 60;
var greenRight = greenZone.x + 60;
self.perfectShot = indicator.x >= greenLeft && indicator.x <= greenRight;
// Hide shot bar after a short delay
var self_ref = self;
LK.setTimeout(function () {
self_ref.visible = false;
self_ref.isActive = false;
}, 200);
return self.perfectShot;
};
self.update = function () {
if (!self.isMoving) return;
// Move indicator back and forth
indicator.x += self.moveSpeed * self.moveDirection;
// Bounce off edges
if (indicator.x >= self.maxDistance) {
indicator.x = self.maxDistance;
self.moveDirection = -1;
} else if (indicator.x <= -self.maxDistance) {
indicator.x = -self.maxDistance;
self.moveDirection = 1;
}
};
self.visible = false;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var basketballs = [];
var hoop = null;
var ground = null;
var scoreTxt = null;
var streakTxt = null;
var currentStreak = 0;
var swipeStartX = 0;
var swipeStartY = 0;
var swipeStartTime = 0;
var isSwipeStarted = false;
var lastShotTime = 0;
var musicNotes = ['note1', 'note2', 'note3', 'note4', 'note5'];
var currentNoteIndex = 0;
var shotBar = null;
var isChargingShot = false;
// Enable z-index sorting for proper rendering order
game.sortableChildren = true;
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
}));
ground.y = 2632;
// Create hoop
hoop = game.addChild(new Hoop());
hoop.x = 624;
hoop.y = 1300;
// Create score display
scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create streak display
streakTxt = new Text2('Streak: 0', {
size: 60,
fill: 0xFFD700
});
streakTxt.anchor.set(0.5, 0);
streakTxt.y = 100;
LK.gui.top.addChild(streakTxt);
// Create shot bar
shotBar = game.addChild(new ShotBar());
shotBar.x = 624;
shotBar.y = 2200;
function createBasketball(startX, startY, velocityX, velocityY) {
var ball = new Basketball();
ball.x = startX;
ball.y = startY;
ball.velocityX = velocityX;
ball.velocityY = velocityY;
ball.isPerfectShot = false;
basketballs.push(ball);
game.addChild(ball);
return ball;
}
function checkBasketScore(ball) {
// Scoring is now handled in Basketball class update method
// This function is kept for compatibility but does nothing
return;
}
game.down = function (x, y, obj) {
if (LK.ticks - lastShotTime < 60) return; // Prevent rapid firing
if (shotBar.isActive) {
// Stop the shot bar and check for perfect shot
var isPerfect = shotBar.stopMoving();
isChargingShot = false;
// Calculate shooting parameters
var startX = 624;
var startY = 2500;
var velocityX = 0;
var velocityY = -15; // Base upward velocity
if (isPerfect) {
// Perfect shot - straight to hoop with precise trajectory
var targetX = hoop.x;
var targetY = hoop.y - 300; // Aim slightly above hoop center for perfect arc
var deltaX = targetX - startX;
var deltaY = targetY - startY;
// Calculate perfect trajectory for swish
var time = 45; // frames to reach target
velocityX = deltaX / time;
velocityY = deltaY / time - 0.5 * time * 0.5; // Account for gravity
// Create perfect shot basketball
var ball = createBasketball(startX, startY, velocityX, velocityY);
ball.isPerfectShot = true;
// Visual feedback for perfect shot
LK.effects.flashScreen(0x00FF00, 200);
// Add tween animation to ensure ball goes straight in
tween(ball, {
tint: 0xFFD700
}, {
duration: 300,
onFinish: function onFinish() {
tween(ball, {
tint: 0xFFFFFF
}, {
duration: 300
});
}
});
// Add vertical rotation animation
tween(ball, {
rotation: ball.rotation + Math.PI * 4
}, {
duration: 1500,
easing: tween.easeOut
});
} else {
// Regular shot with some randomness
velocityX = (Math.random() - 0.5) * 8;
velocityY = -12 - Math.random() * 6;
var ball = createBasketball(startX, startY, velocityX, velocityY);
// Add vertical rotation animation for regular shot
tween(ball, {
rotation: ball.rotation + Math.PI * 3
}, {
duration: 1200,
easing: tween.easeOut
});
}
lastShotTime = LK.ticks;
} else {
// Start charging shot
isChargingShot = true;
shotBar.startMoving();
swipeStartX = x;
swipeStartY = y;
swipeStartTime = LK.ticks;
}
};
game.up = function (x, y, obj) {
// Shot bar system handles shooting now, remove swipe-based shooting
};
game.update = function () {
// Update basketballs
for (var i = basketballs.length - 1; i >= 0; i--) {
var ball = basketballs[i];
if (!ball.isActive) {
ball.destroy();
basketballs.splice(i, 1);
continue;
}
// Check for scoring
checkBasketScore(ball);
// Check collision with other basketballs
for (var j = i + 1; j < basketballs.length; j++) {
var otherBall = basketballs[j];
if (!otherBall.isActive) continue;
var dx = ball.x - otherBall.x;
var dy = ball.y - otherBall.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var minDistance = 120; // Combined radius of two basketballs
if (distance < minDistance && distance > 0) {
// Calculate collision normal
var normalX = dx / distance;
var normalY = dy / distance;
// Separate balls to prevent overlap
var overlap = minDistance - distance;
var separationX = normalX * overlap * 0.5;
var separationY = normalY * overlap * 0.5;
ball.x += separationX;
ball.y += separationY;
otherBall.x -= separationX;
otherBall.y -= separationY;
// Calculate relative velocity
var relativeVelX = ball.velocityX - otherBall.velocityX;
var relativeVelY = ball.velocityY - otherBall.velocityY;
// Calculate relative velocity along collision normal
var relativeSpeed = relativeVelX * normalX + relativeVelY * normalY;
// Only resolve if objects are moving towards each other
if (relativeSpeed > 0) continue;
// Calculate impulse scalar (assuming equal mass)
var impulse = -2 * relativeSpeed / 2;
var impulseX = impulse * normalX;
var impulseY = impulse * normalY;
// Apply impulse with bounce decay
var bounceDecay = 0.8;
ball.velocityX += impulseX * bounceDecay;
ball.velocityY += impulseY * bounceDecay;
otherBall.velocityX -= impulseX * bounceDecay;
otherBall.velocityY -= impulseY * bounceDecay;
// Play bounce sound
LK.getSound('bounce').play();
}
}
}
// Reset streak if no balls scored recently
if (basketballs.length === 0 && LK.ticks - lastShotTime > 180) {
if (currentStreak > 0) {
currentStreak = 0;
streakTxt.setText('Streak: 0');
currentNoteIndex = 0; // Reset musical progression
}
}
// Check win condition
if (LK.getScore() >= 500) {
LK.showYouWin();
}
};
// Start background music
LK.playMusic('backgroundMusic');
Make picture high definition
Remove everything but net
Remove basketball rings and backboards from picture
Shiny black rectangle frame. In-Game asset. 2d. High contrast. No shadows
Neon green basketball. In-Game asset. 2d. High contrast. No shadows
Change to black warriors uniform
Change to black warriors uniform
Padlock button that says *locked* Purchase for: $100. In-Game asset. 2d. High contrast. No shadows
Remove words "with basketball"
Number 1
Number 2
Number 3
Number 4
Number 5
Number 6
Number 7
Number 8
Make it say $HOP in big letters across the ball
Change it to say Rhythm
Make a shop backdrop with display shelves and framed areas to place items
Remove ball and put his hands down like he just caught a pass
Remove ball and fix hands
Record. In-Game asset. 2d. High contrast. No shadows
Make the net look like it's on fire