/**** * Classes ****/ // Ball class for shots from AI opponents var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 0; self.speedY = 0; self.move = function () { self.x += self.speedX; self.y += self.speedY; }; self.setSpeed = function (speedX, speedY) { self.speedX = speedX; self.speedY = speedY; }; }); // Assets will be automatically created based on usage in the code. // Defender class var Defender = Container.expand(function () { var self = Container.call(this); var defenderGraphics = self.attachAsset('defender', { anchorX: 0.5, anchorY: 0.5 }); self.move = function (x, y) { self.x = x; self.y = y; }; }); // Life class for the player's lives var Life = Container.expand(function () { var self = Container.call(this); var lifeGraphics = self.attachAsset('life', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize lives function initLives() { for (var i = 0; i < 3; i++) { var life = game.addChild(new Life()); life.x = 25 + i * 60; // Position 25 pixels from the left and 60 pixels apart life.y = 25; // Position 25 pixels from the top lives.push(life); } } // Global variables var defender; var balls = []; var gameAreaWidth = 2048; var gameAreaHeight = 2732; var scoreCounter; var lives = []; // Initialize defender function initDefender() { defender = game.addChild(new Defender()); defender.x = gameAreaWidth / 2; defender.y = gameAreaHeight - 200; // Position defender towards the bottom } // Initialize balls function initBalls() { var ball = game.addChild(new Ball()); ball.x = Math.random() * gameAreaWidth; ball.y = 0; // Start from the top var speedX = (Math.random() - 0.5) * 20; var speedY = Math.random() * 10 + 4; ball.setSpeed(speedX, speedY); balls.push(ball); } // Move defender based on touch game.on('move', function (obj) { var pos = obj.event.getLocalPosition(game); defender.move(pos.x, defender.y); }); // Ball movement and collision detection LK.on('tick', function () { balls.forEach(function (ball, index) { ball.move(); ball.rotation += 0.1; // Bounce off the left and right sides of the screen if (ball.x < 0 || ball.x > gameAreaWidth) { ball.speedX *= -1; } // Remove ball if it goes off screen if (ball.y > gameAreaHeight) { ball.destroy(); balls.splice(index, 1); // Decrease lives var life = lives.pop(); life.destroy(); // End game if all lives are lost if (lives.length == 0) { LK.showGameOver(); } } // Check collision with defender if (ball.intersects(defender)) { ball.destroy(); balls.splice(index, 1); // Handle collision (e.g., game over, score update) // Add 2 score to the score counter when a basketball is defended LK.setScore(LK.getScore() + 2); scoreCounter.setText(LK.getScore()); // Increase the life amount by 1 every time a player gets 10 score, with a maximum of 3 lives if (LK.getScore() % 10 == 0 && lives.length < 3) { var life = game.addChild(new Life()); life.x = 25 + lives.length * 60; // Position 25 pixels from the left and 60 pixels apart life.y = 25; // Position 25 pixels from the top lives.push(life); } } }); // Add new ball every few seconds if (LK.ticks % Math.floor(180 / (1 + 0.1 * Math.floor(LK.getScore() / 10))) == 0) { // Every 3 seconds initBalls(); } }); // Initialize game elements function initGame() { var background = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: gameAreaWidth / 2, y: gameAreaHeight / 2 })); initDefender(); initBalls(); initScoreCounter(); initLives(); } initGame(); // Initialize score counter function initScoreCounter() { scoreCounter = new Text2('0', { size: 150, fill: "#ffffff", stroke: "#000000", strokeThickness: 10 }); scoreCounter.anchor.set(0.5, 0); LK.gui.top.addChild(scoreCounter); }
/****
* Classes
****/
// Ball class for shots from AI opponents
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
};
self.setSpeed = function (speedX, speedY) {
self.speedX = speedX;
self.speedY = speedY;
};
});
// Assets will be automatically created based on usage in the code.
// Defender class
var Defender = Container.expand(function () {
var self = Container.call(this);
var defenderGraphics = self.attachAsset('defender', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
// Life class for the player's lives
var Life = Container.expand(function () {
var self = Container.call(this);
var lifeGraphics = self.attachAsset('life', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize lives
function initLives() {
for (var i = 0; i < 3; i++) {
var life = game.addChild(new Life());
life.x = 25 + i * 60; // Position 25 pixels from the left and 60 pixels apart
life.y = 25; // Position 25 pixels from the top
lives.push(life);
}
}
// Global variables
var defender;
var balls = [];
var gameAreaWidth = 2048;
var gameAreaHeight = 2732;
var scoreCounter;
var lives = [];
// Initialize defender
function initDefender() {
defender = game.addChild(new Defender());
defender.x = gameAreaWidth / 2;
defender.y = gameAreaHeight - 200; // Position defender towards the bottom
}
// Initialize balls
function initBalls() {
var ball = game.addChild(new Ball());
ball.x = Math.random() * gameAreaWidth;
ball.y = 0; // Start from the top
var speedX = (Math.random() - 0.5) * 20;
var speedY = Math.random() * 10 + 4;
ball.setSpeed(speedX, speedY);
balls.push(ball);
}
// Move defender based on touch
game.on('move', function (obj) {
var pos = obj.event.getLocalPosition(game);
defender.move(pos.x, defender.y);
});
// Ball movement and collision detection
LK.on('tick', function () {
balls.forEach(function (ball, index) {
ball.move();
ball.rotation += 0.1;
// Bounce off the left and right sides of the screen
if (ball.x < 0 || ball.x > gameAreaWidth) {
ball.speedX *= -1;
}
// Remove ball if it goes off screen
if (ball.y > gameAreaHeight) {
ball.destroy();
balls.splice(index, 1);
// Decrease lives
var life = lives.pop();
life.destroy();
// End game if all lives are lost
if (lives.length == 0) {
LK.showGameOver();
}
}
// Check collision with defender
if (ball.intersects(defender)) {
ball.destroy();
balls.splice(index, 1);
// Handle collision (e.g., game over, score update)
// Add 2 score to the score counter when a basketball is defended
LK.setScore(LK.getScore() + 2);
scoreCounter.setText(LK.getScore());
// Increase the life amount by 1 every time a player gets 10 score, with a maximum of 3 lives
if (LK.getScore() % 10 == 0 && lives.length < 3) {
var life = game.addChild(new Life());
life.x = 25 + lives.length * 60; // Position 25 pixels from the left and 60 pixels apart
life.y = 25; // Position 25 pixels from the top
lives.push(life);
}
}
});
// Add new ball every few seconds
if (LK.ticks % Math.floor(180 / (1 + 0.1 * Math.floor(LK.getScore() / 10))) == 0) {
// Every 3 seconds
initBalls();
}
});
// Initialize game elements
function initGame() {
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: gameAreaWidth / 2,
y: gameAreaHeight / 2
}));
initDefender();
initBalls();
initScoreCounter();
initLives();
}
initGame();
// Initialize score counter
function initScoreCounter() {
scoreCounter = new Text2('0', {
size: 150,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 10
});
scoreCounter.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreCounter);
}
Singular basketball. 8-bit art style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Tall, bulky, black male holding hands up trying to defend a basketball shot. Basketball player is wearing red shorts with a red jersey. The basketball is not present in the image. 8-bit art style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Basketball court facing to the benches. No players are present. Colors are show.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.