User prompt
Make the arrow a little bit lower than the finger to see it
User prompt
Remove the line and only keep the arrow
User prompt
Somehow make the line point forward
User prompt
Only check if shots less or equal to 0 on reset to let you use your last shot
User prompt
Only check if shots = 0 on reset to let you use your last shot
User prompt
Add 180 to the rotation
User prompt
Make it point forward
User prompt
Make the line direction flipped
User prompt
It still points backwards fix direction
User prompt
The line is pointing backwards it should point forward
User prompt
The line is pointing backwards
User prompt
Instead of trajectory dots add a line that stretches from ball to finger on aim and an arrow at the finger
User prompt
Add a shots counter which decreases on each shot (starts at 10) and if you lose all shots game over
User prompt
Make the coins have a sin up-down floating animation ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the coins not spin
User prompt
Add a coin collect sound
User prompt
Add coins that give 3 score when you throw the ball at them, the coins move to other places when reset ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make 10 dots between the ball and the finger with each being the same distance to each other
User prompt
Make the dots not GUI based so it can be normal
User prompt
They still move in random directions and disappear fix that
User prompt
Make the dots don’t break the game
User prompt
The hoop, the net and the backboard should all move when resetting after scoring, also keep track of did you score so the hoop net and backboard only move when you both resetted and scoref ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the dots appear in front of everything
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Basketball = Container.expand(function () { var self = Container.call(this); // Visual components var ball = self.attachAsset('basketball', { anchorX: 0.5, anchorY: 0.5 }); var lines = self.attachAsset('basketballLines', { anchorX: 0.5, anchorY: 0.5, alpha: 0.3 }); // Physics properties self.velocityX = 0; self.velocityY = 0; self.gravity = 0.5; self.bounce = 0.7; self.isMoving = false; self.hasScored = false; self.hasThroughNet = false; // Initialize last positions for collision detection self.lastX = 0; self.lastY = 0; self.update = function () { if (self.isMoving) { // Store last position self.lastX = self.x; self.lastY = self.y; // Apply physics self.velocityY += self.gravity; self.x += self.velocityX; self.y += self.velocityY; // Rotate ball based on movement ball.rotation += self.velocityX * 0.02; // Check boundaries if (self.x < 40 || self.x > 2008) { self.velocityX *= -self.bounce; self.x = self.x < 40 ? 40 : 2008; } if (self.y < 40) { self.y = 40; self.velocityY *= -self.bounce; } if (self.y > 2692) { self.y = 2692; self.velocityY *= -self.bounce; self.velocityX *= 0.9; // Friction if (Math.abs(self.velocityY) < 2) { self.isMoving = false; self.velocityX = 0; self.velocityY = 0; } } } }; self.shoot = function (powerX, powerY) { self.velocityX = powerX; self.velocityY = powerY; self.isMoving = true; self.hasScored = false; self.hasThroughNet = false; LK.getSound('shoot').play(); }; self.reset = function () { self.x = 1024; self.y = 2400; self.velocityX = 0; self.velocityY = 0; self.isMoving = false; self.hasScored = false; self.hasThroughNet = false; ball.rotation = 0; }; return self; }); var Hoop = Container.expand(function () { var self = Container.call(this); // Backboard var backboard = self.attachAsset('backboard', { anchorX: 0.5, anchorY: 0.5, x: 100, y: 0 }); // Hoop rim var rim = self.attachAsset('hoop', { anchorX: 0.5, anchorY: 0.5, y: 50 }); // Net var net = self.attachAsset('net', { anchorX: 0.5, anchorY: 0, y: 70, alpha: 0.6 }); // Scoring zone (invisible) self.scoringZone = { x: -90, y: 45, width: 180, height: 30 }; self.checkScore = function (ball) { // Define scoring zone boundaries var zoneLeft = self.x + self.scoringZone.x; var zoneRight = self.x + self.scoringZone.x + self.scoringZone.width; var zoneTop = self.y + self.scoringZone.y; var zoneBottom = self.y + self.scoringZone.y + self.scoringZone.height; // Check if ball is currently in zone var ballInZone = ball.x >= zoneLeft && ball.x <= zoneRight && ball.y >= zoneTop && ball.y <= zoneBottom; // Check if ball's trajectory crossed through the scoring zone from above var crossedFromAbove = false; if (ball.lastY < zoneTop && ball.y >= zoneTop && ball.velocityY > 0) { // Calculate where the ball was when it crossed the top of the zone var timeToZone = (zoneTop - ball.lastY) / (ball.y - ball.lastY); var crossX = ball.lastX + (ball.x - ball.lastX) * timeToZone; // Check if the crossing point is within the horizontal bounds if (crossX >= zoneLeft && crossX <= zoneRight) { crossedFromAbove = true; } } // Score if ball crossed from above or is in zone moving downward if ((ballInZone || crossedFromAbove) && ball.velocityY > 0 && !ball.hasScored) { ball.hasThroughNet = true; ball.hasScored = true; // Make ball bounce out of the net ball.velocityY = -Math.abs(ball.velocityY) * 0.3; // Reverse and reduce Y velocity ball.velocityX *= 0.7; // Reduce X velocity slightly // Animate net tween(net, { scaleY: 1.2 }, { duration: 200, onFinish: function onFinish() { tween(net, { scaleY: 1 }, { duration: 200 }); } }); LK.getSound('score').play(); return true; } return false; }; return self; }); /**** * Initialize Game ****/ // Game variables var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ //Minimalistic tween library for animations // Sounds // Trajectory line // Hoop assets // Basketball assets // Game variables var basketball = null; var hoop = null; var isDragging = false; var dragStartX = 0; var dragStartY = 0; var trajectoryDots = []; var score = 0; var scoreTxt = null; var hasJustScored = false; // Add single background var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 })); // Initialize game elements basketball = game.addChild(new Basketball()); basketball.reset(); hoop = game.addChild(new Hoop()); hoop.x = 1024; hoop.y = 800; // Score display scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Trajectory preview dots for (var i = 0; i < 10; i++) { var dot = LK.getAsset('trajectoryDot', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); trajectoryDots.push(dot); game.addChild(dot); } function updateTrajectory(startX, startY, endX, endY) { var deltaX = endX - startX; var deltaY = endY - startY; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); var powerMultiplier = Math.min(distance / 100, 1) * 28.8; var powerX = deltaX * powerMultiplier; var powerY = deltaY * powerMultiplier; // Show exactly 10 dots with equal spacing between ball and finger var numDots = 10; for (var i = 0; i < trajectoryDots.length; i++) { if (!trajectoryDots[i]) continue; // Skip if dot doesn't exist if (i < numDots) { // Calculate position along the trajectory for each of the 10 dots var t = (i + 1) * 0.8; // Time step to spread dots evenly var x = startX + powerX * t; var y = startY + powerY * t + 0.5 * 0.5 * t * t; // Use correct gravity (0.5 matches Basketball class) // Use game coordinates directly trajectoryDots[i].x = x; trajectoryDots[i].y = y; trajectoryDots[i].alpha = isDragging ? Math.max(0, 1 - i * 0.1) : 0; } else { // Hide dots beyond the first 10 trajectoryDots[i].alpha = 0; } } } function hideTrajectory() { for (var i = 0; i < trajectoryDots.length; i++) { if (trajectoryDots[i]) { trajectoryDots[i].alpha = 0; } } } // Game input handling game.down = function (x, y, obj) { if (!basketball.isMoving) { // Check if touch is near basketball var dx = x - basketball.x; var dy = y - basketball.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 100) { isDragging = true; dragStartX = x; dragStartY = y; } } }; game.move = function (x, y, obj) { if (isDragging) { updateTrajectory(basketball.x, basketball.y, x, y); } }; game.up = function (x, y, obj) { if (isDragging) { isDragging = false; hideTrajectory(); // Calculate shooting power based on drag distance var deltaX = x - dragStartX; var deltaY = y - dragStartY; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); var powerMultiplier = Math.min(distance / 100, 1) * 28.8; var powerX = deltaX * powerMultiplier; var powerY = deltaY * powerMultiplier; // Limit power var maxPower = 90; var power = Math.sqrt(powerX * powerX + powerY * powerY); if (power > maxPower) { powerX = powerX / power * maxPower; powerY = powerY / power * maxPower; } basketball.shoot(powerX, powerY); } }; // Main game loop game.update = function () { // Check for scoring if (basketball.isMoving && hoop.checkScore(basketball)) { score += 5; scoreTxt.setText('Score: ' + score); LK.setScore(score); hasJustScored = true; } // Reset ball if it goes off screen or stops moving if (!basketball.isMoving && (basketball.y > 2500 || basketball.x < -100 || basketball.x > 2148)) { LK.setTimeout(function () { basketball.reset(); // Teleport hoop, net, and backboard to a new random position when ball resets after scoring if (hasJustScored) { var newX = 300 + Math.random() * 1448; // Random X between 300 and 1748 var newY = 600 + Math.random() * 400; // Random Y between 600 and 1000 hoop.x = newX; hoop.y = newY; hasJustScored = false; // Reset the flag } }, 1000); } // Update trajectory preview if (isDragging) { // Trajectory is updated in move handler } };
===================================================================
--- original.js
+++ change.js
@@ -203,9 +203,9 @@
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Trajectory preview dots
-for (var i = 0; i < 15; i++) {
+for (var i = 0; i < 10; i++) {
var dot = LK.getAsset('trajectoryDot', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
@@ -219,17 +219,25 @@
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
var powerMultiplier = Math.min(distance / 100, 1) * 28.8;
var powerX = deltaX * powerMultiplier;
var powerY = deltaY * powerMultiplier;
+ // Show exactly 10 dots with equal spacing between ball and finger
+ var numDots = 10;
for (var i = 0; i < trajectoryDots.length; i++) {
if (!trajectoryDots[i]) continue; // Skip if dot doesn't exist
- var t = i * 0.5; // Smaller time step for better accuracy
- var x = startX + powerX * t;
- var y = startY + powerY * t + 0.5 * 0.5 * t * t; // Use correct gravity (0.5 matches Basketball class)
- // Use game coordinates directly
- trajectoryDots[i].x = x;
- trajectoryDots[i].y = y;
- trajectoryDots[i].alpha = isDragging ? Math.max(0, 1 - i * 0.07) : 0;
+ if (i < numDots) {
+ // Calculate position along the trajectory for each of the 10 dots
+ var t = (i + 1) * 0.8; // Time step to spread dots evenly
+ var x = startX + powerX * t;
+ var y = startY + powerY * t + 0.5 * 0.5 * t * t; // Use correct gravity (0.5 matches Basketball class)
+ // Use game coordinates directly
+ trajectoryDots[i].x = x;
+ trajectoryDots[i].y = y;
+ trajectoryDots[i].alpha = isDragging ? Math.max(0, 1 - i * 0.1) : 0;
+ } else {
+ // Hide dots beyond the first 10
+ trajectoryDots[i].alpha = 0;
+ }
}
}
function hideTrajectory() {
for (var i = 0; i < trajectoryDots.length; i++) {
Basketball 2d 2d facing the front of the camera In-Game asset. 2d. High contrast.
Silver coin. In-Game asset. 2d. High contrast. No shadows
Basketball net. Just the net not the hoop side view 2d 2d side view just the not the hoop or backboard In-Game asset. 2d. High contrast. No shadows
Black arrow pointing up. In-Game asset. 2d. High contrast. No shadows