/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Slash = Container.expand(function () { var self = Container.call(this); self.graphic = self.attachAsset('slash', { anchorX: 0.5, anchorY: 0.5 }); self.points = []; self.active = false; self.lifetime = 0; self.start = function (x, y) { self.points = [{ x: x, y: y }]; self.active = true; self.lifetime = 10; self.x = x; self.y = y; self.rotation = 0; self.alpha = 1; self.visible = true; }; self.addPoint = function (x, y) { if (!self.active) { return; } self.points.push({ x: x, y: y }); if (self.points.length > 1) { var lastPoint = self.points[self.points.length - 2]; var newPoint = { x: x, y: y }; // Calculate direction for rotation var dx = newPoint.x - lastPoint.x; var dy = newPoint.y - lastPoint.y; // Position at midpoint self.x = (lastPoint.x + newPoint.x) / 2; self.y = (lastPoint.y + newPoint.y) / 2; // Calculate rotation self.rotation = Math.atan2(dy, dx); // Set length based on distance var distance = Math.sqrt(dx * dx + dy * dy); self.scale.x = distance / 50; // 50 is the base width of the slash shape } }; self.end = function () { self.active = false; }; self.update = function () { if (!self.active && self.visible) { self.lifetime--; self.alpha -= 0.1; if (self.lifetime <= 0 || self.alpha <= 0) { self.visible = false; } } }; return self; }); var Target = Container.expand(function (type) { var self = Container.call(this); self.type = type || 'normal'; self.slashed = false; self.speed = 0; self.directionX = 0; self.directionY = 0; self.rotationSpeed = 0; var assetId; if (self.type === 'normal') { assetId = 'normalTarget'; } else if (self.type === 'special') { assetId = 'specialTarget'; } else if (self.type === 'danger') { assetId = 'dangerTarget'; } self.graphic = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.setup = function (options) { self.speed = options.speed || 10; self.directionX = options.directionX || 0; self.directionY = options.directionY || 0; self.rotationSpeed = (Math.random() - 0.5) * 0.1; self.x = options.startX; self.y = options.startY; return self; }; self.slice = function () { if (self.slashed) { return false; } self.slashed = true; if (self.type === 'normal') { LK.getSound('slashSound').play(); LK.effects.flashObject(self, 0xffffff, 200); return 10; } else if (self.type === 'special') { LK.getSound('specialSound').play(); LK.effects.flashObject(self, 0xffffff, 300); return 25; } else if (self.type === 'danger') { LK.getSound('dangerSound').play(); LK.effects.flashObject(self, 0xff0000, 300); return -1; // Signal game over } return 0; }; self.update = function () { if (self.slashed) { self.alpha -= 0.05; self.scale.x *= 0.95; self.scale.y *= 0.95; if (self.alpha <= 0) { self.destroy(); } return; } self.x += self.directionX * self.speed; self.y += self.directionY * self.speed; self.rotation += self.rotationSpeed; // Check for collision with other targets if this is a danger target if (self.type === 'danger' && !self.slashed) { for (var i = 0; i < targets.length; i++) { var otherTarget = targets[i]; // Skip if checking against itself or already slashed targets if (otherTarget === self || otherTarget.slashed || otherTarget.type === 'danger') { continue; } // Simple distance-based collision detection var dx = self.x - otherTarget.x; var dy = self.y - otherTarget.y; var distance = Math.sqrt(dx * dx + dy * dy); // If targets are close enough (considering their size), trigger a collision if (distance < (self.graphic.width / 2 + otherTarget.graphic.width / 2) * 0.8) { // Trigger the other target's slice method otherTarget.slice(); } } } // Check if it's off-screen if (self.x < -200 || self.x > 2248 || self.y < -200 || self.y > 2932) { self.destroy(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x003366 }); /**** * Game Code ****/ // Game variables var targets = []; var slash = null; var score = 0; var isSlashing = false; var difficulty = 1; var targetFrequency = 50; // How often targets spawn (lower = more frequent) var lastSlashPoint = { x: 0, y: 0 }; var highScore = storage.highScore || 0; // Set up background var background = LK.getAsset('background', { anchorX: 0, anchorY: 0 }); game.addChild(background); // Create slash effect slash = game.addChild(new Slash()); slash.visible = false; // Set up UI elements var scoreTxt = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var highScoreTxt = new Text2('Best: ' + highScore, { size: 70, fill: 0xCCCCCC }); highScoreTxt.anchor.set(0.5, 0); highScoreTxt.y = 110; LK.gui.top.addChild(highScoreTxt); // Game event handlers game.down = function (x, y, obj) { isSlashing = true; lastSlashPoint.x = x; lastSlashPoint.y = y; slash.start(x, y); }; game.move = function (x, y, obj) { if (!isSlashing) { return; } // Only register movement if it's a significant distance var dx = x - lastSlashPoint.x; var dy = y - lastSlashPoint.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 20) { lastSlashPoint.x = x; lastSlashPoint.y = y; slash.addPoint(x, y); // Check for collisions with targets for (var i = targets.length - 1; i >= 0; i--) { var target = targets[i]; if (!target.slashed) { // Line segment collision detection with target var lineStart = slash.points[slash.points.length - 2]; var lineEnd = { x: x, y: y }; // Simple distance-based collision for this demo var midX = (lineStart.x + lineEnd.x) / 2; var midY = (lineStart.y + lineEnd.y) / 2; var targetDx = target.x - midX; var targetDy = target.y - midY; var targetDist = Math.sqrt(targetDx * targetDx + targetDy * targetDy); if (targetDist < target.graphic.width / 2) { var points = target.slice(); if (points === -1) { // Game over if (score > highScore) { highScore = score; storage.highScore = highScore; highScoreTxt.setText("Best: " + highScore); } LK.effects.flashScreen(0xff0000, 500); // Save current music state before stopping storage.musicMuted = false; LK.stopMusic(); // Stop music before game over LK.showGameOver(); return; } score += points; scoreTxt.setText("Score: " + score); LK.setScore(score); } } } } }; game.up = function (x, y, obj) { isSlashing = false; slash.end(); }; // Spawn a new target function spawnTarget() { var startX, startY, endX, endY; var side = Math.floor(Math.random() * 4); // 0: top, 1: right, 2: bottom, 3: left // Determine spawn position (off-screen) switch (side) { case 0: // Top startX = Math.random() * 2048; startY = -100; endX = Math.random() * 2048; endY = 2832; break; case 1: // Right startX = 2148; startY = Math.random() * 2732; endX = -100; endY = Math.random() * 2732; break; case 2: // Bottom startX = Math.random() * 2048; startY = 2832; endX = Math.random() * 2048; endY = -100; break; case 3: // Left startX = -100; startY = Math.random() * 2732; endX = 2148; endY = Math.random() * 2732; break; } // Calculate direction var dx = endX - startX; var dy = endY - startY; var dist = Math.sqrt(dx * dx + dy * dy); var dirX = dx / dist; var dirY = dy / dist; // Determine target type var targetType; var rand = Math.random(); if (rand < 0.1) { targetType = 'danger'; } else if (rand < 0.3) { targetType = 'special'; } else { targetType = 'normal'; } // Create and setup target var target = new Target(targetType); // Make danger targets move significantly faster var speedMultiplier = targetType === 'danger' ? 3 : 1; target.setup({ startX: startX, startY: startY, directionX: dirX, directionY: dirY, speed: (5 + Math.random() * 5 * difficulty) * speedMultiplier }); targets.push(target); game.addChild(target); } // Initialize the game function initGame() { // Stop any currently playing music first LK.stopMusic(); // Check if music was saved as muted in storage var musicMuted = storage.musicMuted === true; // Play the game music with a fade-in effect if not muted if (!musicMuted) { LK.playMusic('gameMusic', { fade: { start: 0, end: 0.7, duration: 1000 } }); } // Reset game variables targets = []; score = 0; difficulty = 1; isSlashing = false; // Update UI scoreTxt.setText("Score: 0"); highScoreTxt.setText("Best: " + highScore); LK.setScore(0); } // Main game update function game.update = function () { // Update all targets for (var i = targets.length - 1; i >= 0; i--) { var target = targets[i]; // If target is being destroyed, remove from array if (!target.parent) { targets.splice(i, 1); continue; } } // Update slash effect slash.update(); // Spawn new targets based on game tick and difficulty if (LK.ticks % Math.max(10, Math.floor(targetFrequency / difficulty)) === 0) { spawnTarget(); } // Increase difficulty over time if (LK.ticks % 300 === 0) { difficulty += 0.1; } }; // Initialize the game initGame(); // Make sure music is properly initialized on first load if (storage.musicMuted === undefined) { storage.musicMuted = false; } // Check if we need to restart music (after a reset) if (!storage.musicMuted) { LK.playMusic('gameMusic', { fade: { start: 0, end: 0.7, duration: 1000 } }); }
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Slash = Container.expand(function () {
var self = Container.call(this);
self.graphic = self.attachAsset('slash', {
anchorX: 0.5,
anchorY: 0.5
});
self.points = [];
self.active = false;
self.lifetime = 0;
self.start = function (x, y) {
self.points = [{
x: x,
y: y
}];
self.active = true;
self.lifetime = 10;
self.x = x;
self.y = y;
self.rotation = 0;
self.alpha = 1;
self.visible = true;
};
self.addPoint = function (x, y) {
if (!self.active) {
return;
}
self.points.push({
x: x,
y: y
});
if (self.points.length > 1) {
var lastPoint = self.points[self.points.length - 2];
var newPoint = {
x: x,
y: y
};
// Calculate direction for rotation
var dx = newPoint.x - lastPoint.x;
var dy = newPoint.y - lastPoint.y;
// Position at midpoint
self.x = (lastPoint.x + newPoint.x) / 2;
self.y = (lastPoint.y + newPoint.y) / 2;
// Calculate rotation
self.rotation = Math.atan2(dy, dx);
// Set length based on distance
var distance = Math.sqrt(dx * dx + dy * dy);
self.scale.x = distance / 50; // 50 is the base width of the slash shape
}
};
self.end = function () {
self.active = false;
};
self.update = function () {
if (!self.active && self.visible) {
self.lifetime--;
self.alpha -= 0.1;
if (self.lifetime <= 0 || self.alpha <= 0) {
self.visible = false;
}
}
};
return self;
});
var Target = Container.expand(function (type) {
var self = Container.call(this);
self.type = type || 'normal';
self.slashed = false;
self.speed = 0;
self.directionX = 0;
self.directionY = 0;
self.rotationSpeed = 0;
var assetId;
if (self.type === 'normal') {
assetId = 'normalTarget';
} else if (self.type === 'special') {
assetId = 'specialTarget';
} else if (self.type === 'danger') {
assetId = 'dangerTarget';
}
self.graphic = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.setup = function (options) {
self.speed = options.speed || 10;
self.directionX = options.directionX || 0;
self.directionY = options.directionY || 0;
self.rotationSpeed = (Math.random() - 0.5) * 0.1;
self.x = options.startX;
self.y = options.startY;
return self;
};
self.slice = function () {
if (self.slashed) {
return false;
}
self.slashed = true;
if (self.type === 'normal') {
LK.getSound('slashSound').play();
LK.effects.flashObject(self, 0xffffff, 200);
return 10;
} else if (self.type === 'special') {
LK.getSound('specialSound').play();
LK.effects.flashObject(self, 0xffffff, 300);
return 25;
} else if (self.type === 'danger') {
LK.getSound('dangerSound').play();
LK.effects.flashObject(self, 0xff0000, 300);
return -1; // Signal game over
}
return 0;
};
self.update = function () {
if (self.slashed) {
self.alpha -= 0.05;
self.scale.x *= 0.95;
self.scale.y *= 0.95;
if (self.alpha <= 0) {
self.destroy();
}
return;
}
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
self.rotation += self.rotationSpeed;
// Check for collision with other targets if this is a danger target
if (self.type === 'danger' && !self.slashed) {
for (var i = 0; i < targets.length; i++) {
var otherTarget = targets[i];
// Skip if checking against itself or already slashed targets
if (otherTarget === self || otherTarget.slashed || otherTarget.type === 'danger') {
continue;
}
// Simple distance-based collision detection
var dx = self.x - otherTarget.x;
var dy = self.y - otherTarget.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// If targets are close enough (considering their size), trigger a collision
if (distance < (self.graphic.width / 2 + otherTarget.graphic.width / 2) * 0.8) {
// Trigger the other target's slice method
otherTarget.slice();
}
}
}
// Check if it's off-screen
if (self.x < -200 || self.x > 2248 || self.y < -200 || self.y > 2932) {
self.destroy();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x003366
});
/****
* Game Code
****/
// Game variables
var targets = [];
var slash = null;
var score = 0;
var isSlashing = false;
var difficulty = 1;
var targetFrequency = 50; // How often targets spawn (lower = more frequent)
var lastSlashPoint = {
x: 0,
y: 0
};
var highScore = storage.highScore || 0;
// Set up background
var background = LK.getAsset('background', {
anchorX: 0,
anchorY: 0
});
game.addChild(background);
// Create slash effect
slash = game.addChild(new Slash());
slash.visible = false;
// Set up UI elements
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var highScoreTxt = new Text2('Best: ' + highScore, {
size: 70,
fill: 0xCCCCCC
});
highScoreTxt.anchor.set(0.5, 0);
highScoreTxt.y = 110;
LK.gui.top.addChild(highScoreTxt);
// Game event handlers
game.down = function (x, y, obj) {
isSlashing = true;
lastSlashPoint.x = x;
lastSlashPoint.y = y;
slash.start(x, y);
};
game.move = function (x, y, obj) {
if (!isSlashing) {
return;
}
// Only register movement if it's a significant distance
var dx = x - lastSlashPoint.x;
var dy = y - lastSlashPoint.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 20) {
lastSlashPoint.x = x;
lastSlashPoint.y = y;
slash.addPoint(x, y);
// Check for collisions with targets
for (var i = targets.length - 1; i >= 0; i--) {
var target = targets[i];
if (!target.slashed) {
// Line segment collision detection with target
var lineStart = slash.points[slash.points.length - 2];
var lineEnd = {
x: x,
y: y
};
// Simple distance-based collision for this demo
var midX = (lineStart.x + lineEnd.x) / 2;
var midY = (lineStart.y + lineEnd.y) / 2;
var targetDx = target.x - midX;
var targetDy = target.y - midY;
var targetDist = Math.sqrt(targetDx * targetDx + targetDy * targetDy);
if (targetDist < target.graphic.width / 2) {
var points = target.slice();
if (points === -1) {
// Game over
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
highScoreTxt.setText("Best: " + highScore);
}
LK.effects.flashScreen(0xff0000, 500);
// Save current music state before stopping
storage.musicMuted = false;
LK.stopMusic(); // Stop music before game over
LK.showGameOver();
return;
}
score += points;
scoreTxt.setText("Score: " + score);
LK.setScore(score);
}
}
}
}
};
game.up = function (x, y, obj) {
isSlashing = false;
slash.end();
};
// Spawn a new target
function spawnTarget() {
var startX, startY, endX, endY;
var side = Math.floor(Math.random() * 4); // 0: top, 1: right, 2: bottom, 3: left
// Determine spawn position (off-screen)
switch (side) {
case 0:
// Top
startX = Math.random() * 2048;
startY = -100;
endX = Math.random() * 2048;
endY = 2832;
break;
case 1:
// Right
startX = 2148;
startY = Math.random() * 2732;
endX = -100;
endY = Math.random() * 2732;
break;
case 2:
// Bottom
startX = Math.random() * 2048;
startY = 2832;
endX = Math.random() * 2048;
endY = -100;
break;
case 3:
// Left
startX = -100;
startY = Math.random() * 2732;
endX = 2148;
endY = Math.random() * 2732;
break;
}
// Calculate direction
var dx = endX - startX;
var dy = endY - startY;
var dist = Math.sqrt(dx * dx + dy * dy);
var dirX = dx / dist;
var dirY = dy / dist;
// Determine target type
var targetType;
var rand = Math.random();
if (rand < 0.1) {
targetType = 'danger';
} else if (rand < 0.3) {
targetType = 'special';
} else {
targetType = 'normal';
}
// Create and setup target
var target = new Target(targetType);
// Make danger targets move significantly faster
var speedMultiplier = targetType === 'danger' ? 3 : 1;
target.setup({
startX: startX,
startY: startY,
directionX: dirX,
directionY: dirY,
speed: (5 + Math.random() * 5 * difficulty) * speedMultiplier
});
targets.push(target);
game.addChild(target);
}
// Initialize the game
function initGame() {
// Stop any currently playing music first
LK.stopMusic();
// Check if music was saved as muted in storage
var musicMuted = storage.musicMuted === true;
// Play the game music with a fade-in effect if not muted
if (!musicMuted) {
LK.playMusic('gameMusic', {
fade: {
start: 0,
end: 0.7,
duration: 1000
}
});
}
// Reset game variables
targets = [];
score = 0;
difficulty = 1;
isSlashing = false;
// Update UI
scoreTxt.setText("Score: 0");
highScoreTxt.setText("Best: " + highScore);
LK.setScore(0);
}
// Main game update function
game.update = function () {
// Update all targets
for (var i = targets.length - 1; i >= 0; i--) {
var target = targets[i];
// If target is being destroyed, remove from array
if (!target.parent) {
targets.splice(i, 1);
continue;
}
}
// Update slash effect
slash.update();
// Spawn new targets based on game tick and difficulty
if (LK.ticks % Math.max(10, Math.floor(targetFrequency / difficulty)) === 0) {
spawnTarget();
}
// Increase difficulty over time
if (LK.ticks % 300 === 0) {
difficulty += 0.1;
}
};
// Initialize the game
initGame();
// Make sure music is properly initialized on first load
if (storage.musicMuted === undefined) {
storage.musicMuted = false;
}
// Check if we need to restart music (after a reset)
if (!storage.musicMuted) {
LK.playMusic('gameMusic', {
fade: {
start: 0,
end: 0.7,
duration: 1000
}
});
}
corona virus. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
cancer entity piece on body. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
white blood cell. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows