/**** * Classes ****/ // Coin class var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.timer = 180; // 3 seconds * 60 FPS self.move = function () { self.timer -= 1; if (self.timer <= 0) { self.destroy(); } }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Enemy update logic here }; }); // Assets will be automatically generated based on usage in the code. // Hero class var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: -1.5, rotation: 1.5 }); self.update = function () { // Hero update logic here }; }); // HurlBall class var HurlBall = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('hurlBall', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = { x: 0, y: 0 }; self.move = function () { self.x += self.velocity.x; self.y += self.velocity.y; }; }); // Particle class var Particle = Container.expand(function () { var self = Container.call(this); var particleGraphics = self.attachAsset('particle', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = { x: (Math.random() - 0.5) * 10, y: (Math.random() - 0.5) * 10 }; self.timer = 180; // 3 seconds * 60 FPS self.move = function () { self.x += self.velocity.x; self.y += self.velocity.y; self.timer -= 1; if (self.timer <= 0) { self.destroy(); currentParticles--; return; } // Destroy particle after it appears to prevent game lag self.destroy(); }; }); /**** * Initialize Game ****/ // Function to spawn particles var game = new LK.Game({ backgroundColor: 0x008080 // Init game with teal background }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); var hero; var enemies = []; var hurlBalls = []; var coins = []; var coinSpawnTimer = 0; var dragStart = null; var dragEnd = null; var counter = new Text2('0', { size: 150, fill: "#ffffff" }); // Initialize hero hero = game.addChild(new Hero()); hero.x = 1024; // Center horizontally hero.y = 2732 - 200; // Position from the bottom // Function to spawn enemies function spawnEnemy() { var enemy = new Enemy(); enemy.x = Math.random() * 2048; // Random position across the width enemy.y = 100; // Start from the top enemies.push(enemy); game.addChild(enemy); } // Function to handle drag start function handleDragStart(obj) { var pos = obj.event.getLocalPosition(game); dragStart = { x: pos.x, y: pos.y }; } // Function to handle drag end and launch HurlBall function handleDragEnd(obj) { if (!dragStart) { return; } var pos = obj.event.getLocalPosition(game); dragEnd = { x: pos.x, y: pos.y }; var hurlBall = new HurlBall(); hurlBall.x = hero.x; hurlBall.y = hero.y; var velocityX = (dragEnd.x - dragStart.x) * 0.1; var velocityY = (dragEnd.y - dragStart.y) * 0.1; hurlBall.velocity = { x: velocityX, y: velocityY }; hurlBalls.push(hurlBall); game.addChild(hurlBall); dragStart = null; dragEnd = null; } // Attach event listeners for dragging game.on('down', handleDragStart); game.on('up', handleDragEnd); // Game tick function LK.on('tick', function () { // Move HurlBalls hurlBalls.forEach(function (ball, index) { ball.move(); // Check for collision with enemies enemies.forEach(function (enemy, enemyIndex) { if (ball.intersects(enemy)) { spawnParticles(enemy.x, enemy.y, 10); enemy.destroy(); enemies.splice(enemyIndex, 1); ball.destroy(); hurlBalls.splice(index, 1); } }); // Check for collision with coins coins.forEach(function (coin, coinIndex) { if (ball.intersects(coin)) { coin.destroy(); coins.splice(coinIndex, 1); // Increment the counter when HurlBall touches a coin counter.setText((parseInt(counter.text) + 1).toString()); } }); // Check for collision with particles game.children.forEach(function (child) {}); }); // Spawn enemies and coins periodically if (LK.ticks % 120 === 0) { // Every 2 seconds spawnEnemy(); coinSpawnTimer += 1; if (coinSpawnTimer >= 2) { // Every 4 seconds var coin = new Coin(); coin.x = Math.random() * 2048; // Random position across the width coin.y = Math.random() * 2732; // Random position across the height coins.push(coin); game.addChild(coin); coinSpawnTimer = 0; } // Move particles game.children.forEach(function (child) { if (child instanceof Particle) { child.move(); } }); // Check if the number of coins has reached 6 if (coins.length >= 6) { // Show game over screen LK.showGameOver("Too many coins on screen. Game over!"); } } }); // Function to spawn particles var maxParticles = 100; // Maximum number of particles var currentParticles = 0; // Current number of particles function spawnParticles(x, y, count) { for (var i = 0; i < count; i++) { var particle = new Particle(); particle.x = x; particle.y = y; game.addChild(particle); currentParticles++; } } // Initialize the first enemy spawnEnemy(); // Add the right arrow to the middle right of the screen var rightArrow = LK.getAsset('rightArrow', { anchorX: 0.5, anchorY: 0.5, x: 2048 - 100, // Position from the right y: 2732 / 2 // Center vertically }); game.addChild(rightArrow); var human; rightArrow.on('down', function () { game.removeChildren(); enemies.forEach(function (enemy, index) { enemy.destroy(); enemies.splice(index, 1); }); hurlBalls.forEach(function (ball, index) { ball.destroy(); hurlBalls.splice(index, 1); }); game.children.forEach(function (child) { if (child instanceof Particle) { child.destroy(); } }); hero.destroy(); var background2 = game.addChild(LK.getAsset('background2', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); var shop = game.addChild(LK.getAsset('shop', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 2732 })); var comment = game.addChild(LK.getAsset('comment', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); var leftArrow = game.addChild(LK.getAsset('leftArrow', { anchorX: 0.5, anchorY: 0.5, x: 100, y: 2732 / 2 })); leftArrow.on('down', function () { LK.showGameOver("Returning to main game..."); }); }); LK.on('tick', function () {}); ; ;
/****
* Classes
****/
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.timer = 180; // 3 seconds * 60 FPS
self.move = function () {
self.timer -= 1;
if (self.timer <= 0) {
self.destroy();
}
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Enemy update logic here
};
});
// Assets will be automatically generated based on usage in the code.
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: -1.5,
rotation: 1.5
});
self.update = function () {
// Hero update logic here
};
});
// HurlBall class
var HurlBall = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('hurlBall', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = {
x: 0,
y: 0
};
self.move = function () {
self.x += self.velocity.x;
self.y += self.velocity.y;
};
});
// Particle class
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = {
x: (Math.random() - 0.5) * 10,
y: (Math.random() - 0.5) * 10
};
self.timer = 180; // 3 seconds * 60 FPS
self.move = function () {
self.x += self.velocity.x;
self.y += self.velocity.y;
self.timer -= 1;
if (self.timer <= 0) {
self.destroy();
currentParticles--;
return;
}
// Destroy particle after it appears to prevent game lag
self.destroy();
};
});
/****
* Initialize Game
****/
// Function to spawn particles
var game = new LK.Game({
backgroundColor: 0x008080 // Init game with teal background
});
/****
* Game Code
****/
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var hero;
var enemies = [];
var hurlBalls = [];
var coins = [];
var coinSpawnTimer = 0;
var dragStart = null;
var dragEnd = null;
var counter = new Text2('0', {
size: 150,
fill: "#ffffff"
});
// Initialize hero
hero = game.addChild(new Hero());
hero.x = 1024; // Center horizontally
hero.y = 2732 - 200; // Position from the bottom
// Function to spawn enemies
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = Math.random() * 2048; // Random position across the width
enemy.y = 100; // Start from the top
enemies.push(enemy);
game.addChild(enemy);
}
// Function to handle drag start
function handleDragStart(obj) {
var pos = obj.event.getLocalPosition(game);
dragStart = {
x: pos.x,
y: pos.y
};
}
// Function to handle drag end and launch HurlBall
function handleDragEnd(obj) {
if (!dragStart) {
return;
}
var pos = obj.event.getLocalPosition(game);
dragEnd = {
x: pos.x,
y: pos.y
};
var hurlBall = new HurlBall();
hurlBall.x = hero.x;
hurlBall.y = hero.y;
var velocityX = (dragEnd.x - dragStart.x) * 0.1;
var velocityY = (dragEnd.y - dragStart.y) * 0.1;
hurlBall.velocity = {
x: velocityX,
y: velocityY
};
hurlBalls.push(hurlBall);
game.addChild(hurlBall);
dragStart = null;
dragEnd = null;
}
// Attach event listeners for dragging
game.on('down', handleDragStart);
game.on('up', handleDragEnd);
// Game tick function
LK.on('tick', function () {
// Move HurlBalls
hurlBalls.forEach(function (ball, index) {
ball.move();
// Check for collision with enemies
enemies.forEach(function (enemy, enemyIndex) {
if (ball.intersects(enemy)) {
spawnParticles(enemy.x, enemy.y, 10);
enemy.destroy();
enemies.splice(enemyIndex, 1);
ball.destroy();
hurlBalls.splice(index, 1);
}
});
// Check for collision with coins
coins.forEach(function (coin, coinIndex) {
if (ball.intersects(coin)) {
coin.destroy();
coins.splice(coinIndex, 1);
// Increment the counter when HurlBall touches a coin
counter.setText((parseInt(counter.text) + 1).toString());
}
});
// Check for collision with particles
game.children.forEach(function (child) {});
});
// Spawn enemies and coins periodically
if (LK.ticks % 120 === 0) {
// Every 2 seconds
spawnEnemy();
coinSpawnTimer += 1;
if (coinSpawnTimer >= 2) {
// Every 4 seconds
var coin = new Coin();
coin.x = Math.random() * 2048; // Random position across the width
coin.y = Math.random() * 2732; // Random position across the height
coins.push(coin);
game.addChild(coin);
coinSpawnTimer = 0;
}
// Move particles
game.children.forEach(function (child) {
if (child instanceof Particle) {
child.move();
}
});
// Check if the number of coins has reached 6
if (coins.length >= 6) {
// Show game over screen
LK.showGameOver("Too many coins on screen. Game over!");
}
}
});
// Function to spawn particles
var maxParticles = 100; // Maximum number of particles
var currentParticles = 0; // Current number of particles
function spawnParticles(x, y, count) {
for (var i = 0; i < count; i++) {
var particle = new Particle();
particle.x = x;
particle.y = y;
game.addChild(particle);
currentParticles++;
}
}
// Initialize the first enemy
spawnEnemy();
// Add the right arrow to the middle right of the screen
var rightArrow = LK.getAsset('rightArrow', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 - 100,
// Position from the right
y: 2732 / 2 // Center vertically
});
game.addChild(rightArrow);
var human;
rightArrow.on('down', function () {
game.removeChildren();
enemies.forEach(function (enemy, index) {
enemy.destroy();
enemies.splice(index, 1);
});
hurlBalls.forEach(function (ball, index) {
ball.destroy();
hurlBalls.splice(index, 1);
});
game.children.forEach(function (child) {
if (child instanceof Particle) {
child.destroy();
}
});
hero.destroy();
var background2 = game.addChild(LK.getAsset('background2', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var shop = game.addChild(LK.getAsset('shop', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 2732
}));
var comment = game.addChild(LK.getAsset('comment', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var leftArrow = game.addChild(LK.getAsset('leftArrow', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: 2732 / 2
}));
leftArrow.on('down', function () {
LK.showGameOver("Returning to main game...");
});
});
LK.on('tick', function () {});
;
;
Right arrow icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Angry basketball hoop. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Top down view of a cannon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Kinda futuristic basketball court. Background
Duck in a jersey.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Forest. Background
Chat bubble that says "Ignore me and attend the game!". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Left arrow icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.