/**** * Classes ****/ var HomingProjectile = Container.expand(function (target) { var self = Container.call(this); var projectileGraphic = self.createAsset('projectile', 'Homing Projectile', 0.5, 0.5); projectileGraphic.scale.set(0.5); self.speed = backgroundRed ? 10 : 5; self.target = target; self.move = function () { var directionX = self.target.x - self.x; var directionY = self.target.y - self.y; var magnitude = Math.sqrt(directionX * directionX + directionY * directionY); var homingFactor = 0.5; self.x += directionX / magnitude * self.speed * homingFactor; self.y += directionY / magnitude * self.speed * homingFactor; }; }); var SnakeSegment = Container.expand(function () { var self = Container.call(this); var segmentGraphic = self.createAsset('snakeSegment', 'Snake Segment', 0.5, 0.5); self.move = function (x, y) { self.x = x; self.y = y; }; }); var Food = Container.expand(function () { var self = Container.call(this); var foodGraphic = self.createAsset('food', 'Food', 0.5, 0.5); self.projectiles = []; self.shoot = function (targetX, targetY) { var projectileCount = backgroundRed ? 50 : 1; for (var i = 0; i < projectileCount; i++) { var projectile = new HomingProjectile(snake[0]); projectile.x = self.x; projectile.y = self.y; self.projectiles.push(projectile); game.addChild(projectile); LK.setTimeout(function (projectile) { return function () { projectile.destroy(); var index = self.projectiles.indexOf(projectile); if (index > -1) { self.projectiles.splice(index, 1); } }; }(projectile), backgroundRed ? 2000 : 3500); } }; self.place = function (x, y) { self.x = x; self.y = y; }; self.moveProjectiles = function () { for (var i = self.projectiles.length - 1; i >= 0; i--) { self.projectiles[i].move(); if (self.projectiles[i].x < 0 || self.projectiles[i].x > 2048 || self.projectiles[i].y < 0 || self.projectiles[i].y > 2732) { self.projectiles[i].destroy(); self.projectiles.splice(i, 1); } } }; }); var Projectile = Container.expand(function () { var self = Container.call(this); var projectileGraphic = self.createAsset('projectile', 'Lethal Projectile', 0.5, 0.5); projectileGraphic.scale.set(0.5); self.speed = 4; self.direction = { x: 0, y: 1 }; self.move = function () { self.x += self.direction.x * self.speed; self.y += self.direction.y * self.speed; }; self.setDirection = function (x, y) { self.direction.x = x; self.direction.y = y; }; }); var WallSpike = Container.expand(function () { var self = Container.call(this); var spikeGraphic = self.createAsset('wallSpike', 'Wall Spike', 0.5, 0.5); self.move = function (x, y) { self.x = x; self.y = y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1F7A1F //Change background color to green for pool table }); /**** * Game Code ****/ var snake = []; var food; var direction = { x: 0, y: 0 }; var spikes = []; var spikeTimer = 0; var spikeInterval = 5000; // 5 seconds var backgroundRed = false; var nextDirection = { x: 0, y: 0 }; var gridSize = 64; var score = 0; var scoreTxt; var isGameOver = false; function initGame() { // Initialize the snake in the center of the screen var initialX = 2048 / 2; var initialY = 2732 / 2; var snakeHead = new SnakeSegment(); snakeHead.move(initialX, initialY); snake.push(snakeHead); game.addChild(snakeHead); // Initialize the food at a random position placeFood(); // Initialize score display scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Set initial direction direction = { x: gridSize, y: 0 }; } function placeFood() { var foodX = Math.floor(Math.random() * ((2048 - gridSize * 2) / gridSize)) * gridSize + gridSize * 1.5; var foodY = Math.floor(Math.random() * ((2732 - gridSize * 2) / gridSize)) * gridSize + gridSize * 1.5; if (!food) { food = new Food(); game.addChild(food); } food.place(foodX, foodY); } function updateScore() { score += 1; scoreTxt.setText(score.toString()); } function gameOver() { isGameOver = true; LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } function handleInput(obj) { var touchPos = obj.event.getLocalPosition(game); var head = snake[0]; var deltaX = touchPos.x - head.x; var deltaY = touchPos.y - head.y; var magnitude = Math.sqrt(deltaX * deltaX + deltaY * deltaY); nextDirection = { x: deltaX / magnitude * gridSize, y: deltaY / magnitude * gridSize }; } game.on('down', handleInput); LK.on('tick', function () { if (isGameOver) { return; } // Update direction direction = nextDirection; // Move snake var newX = snake[0].x + direction.x * 0.2; var newY = snake[0].y + direction.y * 0.2; // Check for collisions with walls if (newX < 0 || newX > 2048 || newY < 0 || newY > 2732) { gameOver(); return; } // Check for collisions with self for (var i = 1; i < snake.length; i++) { if (snake[i].x === newX && snake[i].y === newY) { gameOver(); return; } } // Check for food collision if (snake[0].intersects(food)) { var tail = snake[snake.length - 1]; var newSegment1 = new SnakeSegment(); var newSegment2 = new SnakeSegment(); var newSegmentX1 = tail.x - direction.x; var newSegmentY1 = tail.y - direction.y; var newSegmentX2 = newSegmentX1 - direction.x; var newSegmentY2 = newSegmentY1 - direction.y; newSegment1.move(newSegmentX1, newSegmentY1); newSegment2.move(newSegmentX2, newSegmentY2); snake.push(newSegment1); snake.push(newSegment2); game.addChild(newSegment1); game.addChild(newSegment2); updateScore(); placeFood(); } // Move snake segments for (var i = snake.length - 1; i > 0; i--) { snake[i].move(snake[i - 1].x, snake[i - 1].y); } // Move head last snake[0].move(newX, newY); // Food shoots projectiles randomly if (Math.random() < 0.005) { // 0.5% chance each tick food.shoot(snake[0].x, snake[0].y); } // Move projectiles food.moveProjectiles(); // Check for collisions with projectiles for (var i = 0; i < food.projectiles.length; i++) { if (snake[0].intersects(food.projectiles[i])) { gameOver(); return; } } }); LK.on('tick', function () { if (isGameOver) { return; } spikeTimer += 1000 / 60; // Increment timer based on 60FPS tick if (spikeTimer >= spikeInterval) { spikeTimer = 0; // Reset timer backgroundRed = !backgroundRed; // Toggle background state if (backgroundRed) { game.setBackgroundColor(0xff0000); // Set background to red // Create spikes around the entire wall perimeter var spikeSize = 128; // Increasing each spike to 128x128 var spikeSpacing = 3 * spikeSize; // Triple the space between spikes to accommodate larger size for (var x = 0; x < 2048; x += spikeSpacing) { var spikeTop = new WallSpike(); spikeTop.move(x, 0); spikes.push(spikeTop); game.addChild(spikeTop); var spikeBottom = new WallSpike(); spikeBottom.move(x, 2732 - spikeSize); spikes.push(spikeBottom); game.addChild(spikeBottom); } for (var y = spikeSpacing; y < 2732 - spikeSpacing; y += spikeSpacing) { var spikeLeft = new WallSpike(); spikeLeft.move(0, y); spikes.push(spikeLeft); game.addChild(spikeLeft); var spikeRight = new WallSpike(); spikeRight.move(2048 - spikeSize, y); spikes.push(spikeRight); game.addChild(spikeRight); } } else { game.setBackgroundColor(0x1F7A1F); // Set background to green // Remove spikes while (spikes.length > 0) { var spikeToRemove = spikes.pop(); spikeToRemove.destroy(); } } } // Check for collisions with spikes for (var i = 0; i < spikes.length; i++) { if (snake[0].intersects(spikes[i])) { gameOver(); return; } } // Existing game tick logic... }); // Start the game initGame();
/****
* Classes
****/
var HomingProjectile = Container.expand(function (target) {
var self = Container.call(this);
var projectileGraphic = self.createAsset('projectile', 'Homing Projectile', 0.5, 0.5);
projectileGraphic.scale.set(0.5);
self.speed = backgroundRed ? 10 : 5;
self.target = target;
self.move = function () {
var directionX = self.target.x - self.x;
var directionY = self.target.y - self.y;
var magnitude = Math.sqrt(directionX * directionX + directionY * directionY);
var homingFactor = 0.5;
self.x += directionX / magnitude * self.speed * homingFactor;
self.y += directionY / magnitude * self.speed * homingFactor;
};
});
var SnakeSegment = Container.expand(function () {
var self = Container.call(this);
var segmentGraphic = self.createAsset('snakeSegment', 'Snake Segment', 0.5, 0.5);
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
var Food = Container.expand(function () {
var self = Container.call(this);
var foodGraphic = self.createAsset('food', 'Food', 0.5, 0.5);
self.projectiles = [];
self.shoot = function (targetX, targetY) {
var projectileCount = backgroundRed ? 50 : 1;
for (var i = 0; i < projectileCount; i++) {
var projectile = new HomingProjectile(snake[0]);
projectile.x = self.x;
projectile.y = self.y;
self.projectiles.push(projectile);
game.addChild(projectile);
LK.setTimeout(function (projectile) {
return function () {
projectile.destroy();
var index = self.projectiles.indexOf(projectile);
if (index > -1) {
self.projectiles.splice(index, 1);
}
};
}(projectile), backgroundRed ? 2000 : 3500);
}
};
self.place = function (x, y) {
self.x = x;
self.y = y;
};
self.moveProjectiles = function () {
for (var i = self.projectiles.length - 1; i >= 0; i--) {
self.projectiles[i].move();
if (self.projectiles[i].x < 0 || self.projectiles[i].x > 2048 || self.projectiles[i].y < 0 || self.projectiles[i].y > 2732) {
self.projectiles[i].destroy();
self.projectiles.splice(i, 1);
}
}
};
});
var Projectile = Container.expand(function () {
var self = Container.call(this);
var projectileGraphic = self.createAsset('projectile', 'Lethal Projectile', 0.5, 0.5);
projectileGraphic.scale.set(0.5);
self.speed = 4;
self.direction = {
x: 0,
y: 1
};
self.move = function () {
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
};
self.setDirection = function (x, y) {
self.direction.x = x;
self.direction.y = y;
};
});
var WallSpike = Container.expand(function () {
var self = Container.call(this);
var spikeGraphic = self.createAsset('wallSpike', 'Wall Spike', 0.5, 0.5);
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1F7A1F //Change background color to green for pool table
});
/****
* Game Code
****/
var snake = [];
var food;
var direction = {
x: 0,
y: 0
};
var spikes = [];
var spikeTimer = 0;
var spikeInterval = 5000; // 5 seconds
var backgroundRed = false;
var nextDirection = {
x: 0,
y: 0
};
var gridSize = 64;
var score = 0;
var scoreTxt;
var isGameOver = false;
function initGame() {
// Initialize the snake in the center of the screen
var initialX = 2048 / 2;
var initialY = 2732 / 2;
var snakeHead = new SnakeSegment();
snakeHead.move(initialX, initialY);
snake.push(snakeHead);
game.addChild(snakeHead);
// Initialize the food at a random position
placeFood();
// Initialize score display
scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Set initial direction
direction = {
x: gridSize,
y: 0
};
}
function placeFood() {
var foodX = Math.floor(Math.random() * ((2048 - gridSize * 2) / gridSize)) * gridSize + gridSize * 1.5;
var foodY = Math.floor(Math.random() * ((2732 - gridSize * 2) / gridSize)) * gridSize + gridSize * 1.5;
if (!food) {
food = new Food();
game.addChild(food);
}
food.place(foodX, foodY);
}
function updateScore() {
score += 1;
scoreTxt.setText(score.toString());
}
function gameOver() {
isGameOver = true;
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
function handleInput(obj) {
var touchPos = obj.event.getLocalPosition(game);
var head = snake[0];
var deltaX = touchPos.x - head.x;
var deltaY = touchPos.y - head.y;
var magnitude = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
nextDirection = {
x: deltaX / magnitude * gridSize,
y: deltaY / magnitude * gridSize
};
}
game.on('down', handleInput);
LK.on('tick', function () {
if (isGameOver) {
return;
}
// Update direction
direction = nextDirection;
// Move snake
var newX = snake[0].x + direction.x * 0.2;
var newY = snake[0].y + direction.y * 0.2;
// Check for collisions with walls
if (newX < 0 || newX > 2048 || newY < 0 || newY > 2732) {
gameOver();
return;
}
// Check for collisions with self
for (var i = 1; i < snake.length; i++) {
if (snake[i].x === newX && snake[i].y === newY) {
gameOver();
return;
}
}
// Check for food collision
if (snake[0].intersects(food)) {
var tail = snake[snake.length - 1];
var newSegment1 = new SnakeSegment();
var newSegment2 = new SnakeSegment();
var newSegmentX1 = tail.x - direction.x;
var newSegmentY1 = tail.y - direction.y;
var newSegmentX2 = newSegmentX1 - direction.x;
var newSegmentY2 = newSegmentY1 - direction.y;
newSegment1.move(newSegmentX1, newSegmentY1);
newSegment2.move(newSegmentX2, newSegmentY2);
snake.push(newSegment1);
snake.push(newSegment2);
game.addChild(newSegment1);
game.addChild(newSegment2);
updateScore();
placeFood();
}
// Move snake segments
for (var i = snake.length - 1; i > 0; i--) {
snake[i].move(snake[i - 1].x, snake[i - 1].y);
}
// Move head last
snake[0].move(newX, newY);
// Food shoots projectiles randomly
if (Math.random() < 0.005) {
// 0.5% chance each tick
food.shoot(snake[0].x, snake[0].y);
}
// Move projectiles
food.moveProjectiles();
// Check for collisions with projectiles
for (var i = 0; i < food.projectiles.length; i++) {
if (snake[0].intersects(food.projectiles[i])) {
gameOver();
return;
}
}
});
LK.on('tick', function () {
if (isGameOver) {
return;
}
spikeTimer += 1000 / 60; // Increment timer based on 60FPS tick
if (spikeTimer >= spikeInterval) {
spikeTimer = 0; // Reset timer
backgroundRed = !backgroundRed; // Toggle background state
if (backgroundRed) {
game.setBackgroundColor(0xff0000); // Set background to red
// Create spikes around the entire wall perimeter
var spikeSize = 128; // Increasing each spike to 128x128
var spikeSpacing = 3 * spikeSize; // Triple the space between spikes to accommodate larger size
for (var x = 0; x < 2048; x += spikeSpacing) {
var spikeTop = new WallSpike();
spikeTop.move(x, 0);
spikes.push(spikeTop);
game.addChild(spikeTop);
var spikeBottom = new WallSpike();
spikeBottom.move(x, 2732 - spikeSize);
spikes.push(spikeBottom);
game.addChild(spikeBottom);
}
for (var y = spikeSpacing; y < 2732 - spikeSpacing; y += spikeSpacing) {
var spikeLeft = new WallSpike();
spikeLeft.move(0, y);
spikes.push(spikeLeft);
game.addChild(spikeLeft);
var spikeRight = new WallSpike();
spikeRight.move(2048 - spikeSize, y);
spikes.push(spikeRight);
game.addChild(spikeRight);
}
} else {
game.setBackgroundColor(0x1F7A1F); // Set background to green
// Remove spikes
while (spikes.length > 0) {
var spikeToRemove = spikes.pop();
spikeToRemove.destroy();
}
}
}
// Check for collisions with spikes
for (var i = 0; i < spikes.length; i++) {
if (snake[0].intersects(spikes[i])) {
gameOver();
return;
}
}
// Existing game tick logic...
});
// Start the game
initGame();
a wooden brown chair. In-Game asset. Blank background. High contrast.
a blue apple with a gun. In-Game asset. Blank background. High contrast.
the 8 balls from pool. In-Game asset. Blank background. High contrast.
a table with a gun. In-Game asset. Blank background. High contrast.
a roundsaw. In-Game asset. Blank background. High contrast.