/****
* Classes
****/
// Assets will be automatically created and loaded during gameplay
// Basketball class
var Basketball = Container.expand(function () {
var self = Container.call(this);
var basketballGraphics = self.attachAsset('basketball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -20;
self.initialSpeedX = 0;
self.initialSpeedY = 0;
self.hasCollided = false;
self.scoreMultiplier = 2;
self.update = function () {
// Apply gravity
self.speedY += 0.5; // Adjust gravity strength as needed
// Apply friction
self.speedX *= 0.99; // Adjust friction strength as needed
self.speedY *= 0.99; // Adjust friction strength as needed
self.x += self.speedX;
self.y += self.speedY;
// Remove basketball if its speed is less than 5% of its initial speed
if (Math.abs(self.speedX) < Math.abs(self.initialSpeedX * 0.05) && Math.abs(self.speedY) < Math.abs(self.initialSpeedY * 0.05)) {
self.destroy();
basketballs.splice(basketballs.indexOf(self), 1);
// Move the hoop to a random position in the upper half of the screen smoothly
var targetX = Math.random() * (2048 - hoop.width) + hoop.width / 2;
var targetY = Math.random() * (2732 / 2 - hoop.height) + hoop.height / 2;
var moveSpeed = 10; // Adjust speed as needed
isHoopMoving = true;
var moveInterval = LK.setInterval(function () {
var dx = targetX - hoop.x;
var dy = targetY - hoop.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < moveSpeed) {
hoop.x = targetX;
hoop.y = targetY;
LK.clearInterval(moveInterval);
isHoopMoving = false;
} else {
hoop.x += dx / distance * moveSpeed;
hoop.y += dy / distance * moveSpeed;
}
}, 16); // Approximately 60 FPS
}
// Check for collision with screen edges and bounce
if (self.x <= 0 || self.x >= 2048) {
self.speedX *= -0.8; // Reverse horizontal direction with energy loss
self.x = Math.max(0, Math.min(self.x, 2048)); // Prevent sticking to the edge
self.scoreMultiplier *= 2; // Double the score multiplier
LK.getSound('collision').play(); // Play collision sound
// Generate an image at the collision point showing the score multiplier
var multiplierImageId = 'X' + self.scoreMultiplier;
var multiplierImage = LK.getAsset(multiplierImageId, {
anchorX: 0.5,
anchorY: 0.5,
x: Math.max(200, Math.min(self.x, 2048 - 200)),
y: Math.max(200, Math.min(self.y, 2732 - 200))
});
game.addChild(multiplierImage);
LK.setTimeout(function () {
multiplierImage.destroy();
}, 2000);
}
if (self.y <= 0 || self.y >= 2732) {
self.speedY *= -0.8; // Reverse vertical direction with energy loss
self.y = Math.max(0, Math.min(self.y, 2732)); // Prevent sticking to the edge
self.scoreMultiplier *= 2; // Double the score multiplier
LK.getSound('collision').play(); // Play collision sound
// Generate an image at the collision point showing the score multiplier
var multiplierImageId = 'X' + self.scoreMultiplier;
var multiplierImage = LK.getAsset(multiplierImageId, {
anchorX: 0.5,
anchorY: 0.5,
x: Math.max(200, Math.min(self.x, 2048 - 200)),
y: Math.max(200, Math.min(self.y, 2732 - 200))
});
game.addChild(multiplierImage);
LK.setTimeout(function () {
multiplierImage.destroy();
}, 2000);
}
};
});
// Hoop class
var Hoop = Container.expand(function () {
var self = Container.call(this);
var hoopGraphics = self.attachAsset('hoop', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Hoop movement logic if needed
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Player movement logic if needed
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ff0000"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Add countdown timer text
var countdownTxt = new Text2('60', {
size: 100,
fill: "#ffffff"
});
countdownTxt.anchor.set(1, 0); // Anchor to the top-right corner
LK.gui.topRight.addChild(countdownTxt);
var player = game.addChild(new Player());
// Set a timer to end the game after one minute (60000 milliseconds)
LK.setTimeout(function () {
LK.showGameOver();
}, 60000);
player.x = 2048 / 2;
player.y = 2732 - 200;
var hoop = game.addChild(new Hoop());
var isHoopMoving = false;
Basketball.hoop = hoop;
hoop.x = Math.max(hoop.width / 2, Math.min(2048 - hoop.width / 2, 2048 / 2));
hoop.y = Math.max(hoop.height / 2, Math.min(2732 / 2 - hoop.height / 2, 2732 / 4));
var basketballs = [];
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
}
game.down = function (x, y, obj) {
// Create a new basketball and shoot it towards the clicked position
if (basketballs.length === 0 && !isHoopMoving) {
var newBasketball = new Basketball();
newBasketball.x = player.x;
newBasketball.y = player.y;
newBasketball.speedX = (x - player.x) / 8; // Adjust speed for a faster shot
newBasketball.speedY = (y - player.y) / 8; // Adjust speed for a faster shot
newBasketball.initialSpeedX = newBasketball.speedX;
newBasketball.initialSpeedY = newBasketball.speedY;
basketballs.push(newBasketball);
game.addChild(newBasketball);
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
game.update = function () {
// Update countdown timer
if (LK.ticks % 60 == 0) {
var remainingTime = Math.max(0, 60 - Math.floor(LK.ticks / 60));
countdownTxt.setText(remainingTime.toString() + "s");
if (remainingTime <= 3) {
countdownTxt.fill = "#ff0000"; // Change to red
countdownTxt.style.fontWeight = "bold"; // Emphasize
countdownTxt.style.fontSize = 120; // Increase font size for emphasis
} else if (remainingTime <= 10) {
countdownTxt.fill = "#ffff00"; // Change to yellow
countdownTxt.style.fontWeight = "normal"; // Default emphasis
countdownTxt.style.fontSize = 100; // Default font size
} else {
countdownTxt.fill = "#ffffff"; // Default to white
if (countdownTxt.style) {
countdownTxt.style.fontWeight = "normal"; // Default emphasis
countdownTxt.style.fontSize = 100; // Default font size
}
}
}
for (var i = basketballs.length - 1; i >= 0; i--) {
if (basketballs[i].intersects(hoop) && !basketballs[i].hasCollided) {
basketballs[i].hasCollided = true;
score += basketballs[i].scoreMultiplier;
LK.setScore(score);
scoreTxt.setText(score);
}
if (basketballs[i] && basketballs[i].y < -50) {
basketballs[i].speedY *= -0.8; // Reverse vertical direction with energy loss
basketballs[i].y = Math.max(0, Math.min(basketballs[i].y, 2732)); // Prevent sticking to the edge
}
}
if (LK.ticks % 60 == 0) {
var newBasketball = new Basketball();
newBasketball.x = player.x;
newBasketball.y = player.y;
basketballs.push(newBasketball);
game.addChild(newBasketball);
}
};
一个篮球筐,正视,只有篮筐没有下面的杆. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
篮球,2D. 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.
篮球场,写实风格,视角是站在篮球场中心看向其中一个篮筐,在体育馆内. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆炸,里面有X2的字样. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆炸,里面有X4的字样. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆炸,里面有X8的字样. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆炸,里面有X16的字样,和前面几个图片样式一样. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆炸,里面有“X32”的字样,暖色调. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆炸,里面有“X64”的字样,暖色调. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆炸,里面有“X128”的字样,暖色调. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆炸,里面有“X256”的字样,暖色调. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆炸,里面有“X512”的字样,暖色调. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
爆炸,里面有“X1024”的字样,暖色调. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.