/**** * Classes ****/ var Heart = Container.expand(function () { var self = Container.call(this); var heartGraphics = self.attachAsset('heart', { anchorX: 0.5, anchorY: 0.5 }); }); var Knife = Container.expand(function () { var self = Container.call(this); self.angleTo = function (other) { var dx = other.x - self.x; var dy = other.y - self.y; return Math.atan2(dy, dx); }; var knifeGraphics = self.attachAsset('knife', { anchorX: 0.5 }); self.speed = 30; self.stuck = false; self.falling = false; self.spinDirection = Math.random() < 0.5 ? -1 : 1; self._move_migrated = function () { if (!self.stuck && !self.falling) { self.y -= self.speed; } }; self.fall = function () { if (self.falling) { if (!self.fallInitiated) { knifeGraphics.anchor.x = .5; knifeGraphics.anchor.y = .5; self.x += knifeGraphics.width / 2; self.y += knifeGraphics.height / 2; self.fallInitiated = true; } self.y += self.speed; self.rotation += self.spinDirection * 0.1; } }; self.hit = function (knives) { for (var i = 0; i < knives.length; i++) { if (knives[i] !== self && knives[i].stuck) { var angleDiff = Math.abs(knives[i].hitAngle % (2 * Math.PI) - self.hitAngle % (2 * Math.PI)); if (angleDiff < Math.PI / 24) { return true; } } } return false; }; }); var Target = Container.expand(function () { var self = Container.call(this); var targetGraphics = self.attachAsset('target', { anchorX: 0.5, anchorY: 0.5 }); self.rotationSpeed = 0.01; self.rotation = 4 * Math.PI; self.pointSections = [10, 20, 30, 50, 100]; // Different point values for different zones self.rotate = function () { self.rotation += self.rotationSpeed; }; self.hit = function () { LK.effects.flashObject(self, 0x00ff00, 500); }; self.getPointsAtAngle = function (angle) { // Normalize angle between 0 and 2*PI var normalizedAngle = Math.abs(angle % (2 * Math.PI)); // Divide target into 5 equal sections var sectionSize = 2 * Math.PI / self.pointSections.length; // Determine which section was hit var sectionIndex = Math.floor(normalizedAngle / sectionSize); // Return points for that section return self.pointSections[sectionIndex]; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2e6343 }); /**** * Game Code ****/ var background = game.attachAsset('background', {}); background.width = 2048; background.height = 2732; var knives = []; var targets = []; var score = 0; var lives = [new Heart(), new Heart(), new Heart()]; var scoreTxt = new Text2(score.toString(), { size: 150, fill: 0xFFFFFF, font: "Impact", dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 4, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreTxt.anchor.set(.5, 0); LK.gui.top.addChild(scoreTxt); for (var i = 0; i < lives.length; i++) { lives[i].x = 2048 - (i + 1) * 130 - 15; lives[i].y = 100 + 15; game.addChild(lives[i]); } var knife = game.addChild(new Knife()); knife.x = 2048 / 2; knife.y = 2732 - 200; var target = game.addChild(new Target()); target.x = 2048 / 2; target.y = 2732 / 2; // Add score labels to the target var pointLabels = []; for (var i = 0; i < target.pointSections.length; i++) { var label = new Text2(target.pointSections[i].toString(), { size: 80, fill: 0xFFFFFF, font: "Impact", dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 4, dropShadowDistance: 3 }); label.anchor.set(0.5, 0.5); // Position the labels evenly around the target var angle = i * 2 * Math.PI / target.pointSections.length; var radius = target.width * 0.35; // Position labels within the target label.x = target.x + Math.cos(angle) * radius; label.y = target.y + Math.sin(angle) * radius; pointLabels.push(label); game.addChild(label); } game.on('down', function (x, y, obj) { var newKnife = new Knife(); newKnife.x = knife.x; newKnife.y = knife.y; knives.push(newKnife); game.addChild(newKnife); }); LK.on('tick', function () { target.rotate(); // Update point labels to stay aligned with the target rotation for (var i = 0; i < pointLabels.length; i++) { var angle = i * 2 * Math.PI / target.pointSections.length + target.rotation; var radius = target.width * 0.35; pointLabels[i].x = target.x + Math.cos(angle) * radius; pointLabels[i].y = target.y + Math.sin(angle) * radius; // Keep the text orientation normal pointLabels[i].rotation = angle + Math.PI / 2; } for (var i = 0; i < knives.length; i++) { knives[i]._move_migrated(); knives[i].fall(); } for (var i = 0; i < knives.length; i++) { if (Math.abs(knives[i].y - target.y) <= target.height / 2 && !knives[i].stuck) { knives[i].stuck = true; knives[i].hitAngle = target.rotation - Math.PI / 2; if (knives[i].hit(knives)) { knives[i].falling = true; var lostLife = lives.pop(); lostLife.destroy(); LK.setScore(score); scoreTxt.setText(score.toString()); if (lives.length > 0) { LK.effects.flashScreen(0xff0000, 500); } } else { target.hit(); // Get points based on the section hit var pointsEarned = target.getPointsAtAngle(knives[i].hitAngle); score += pointsEarned; target.rotationSpeed += 0.005 / 3; LK.setScore(score); scoreTxt.setText(score.toString()); // Show points earned as floating text var pointsText = new Text2("+" + pointsEarned, { size: 100, fill: 0xFFFF00, font: "Impact" }); pointsText.anchor.set(0.5, 0.5); pointsText.x = knives[i].x; pointsText.y = knives[i].y - 100; game.addChild(pointsText); // Animate and remove the points text var startY = pointsText.y; var fadeInterval = LK.setInterval(function () { pointsText.y -= 3; pointsText.alpha -= 0.05; if (pointsText.alpha <= 0) { LK.clearInterval(fadeInterval); pointsText.destroy(); } }, 50); } } if (knives[i].stuck && !knives[i].falling) { knives[i].rotation = target.rotation - knives[i].hitAngle - Math.PI / 2; knives[i].x = target.x + Math.cos(target.rotation - knives[i].hitAngle) * target.width / 2; knives[i].y = target.y + Math.sin(target.rotation - knives[i].hitAngle) * target.height / 2; } } for (var i = knives.length - 1; i >= 0; i--) { if (knives[i].y < -50) { knives[i].destroy(); knives.splice(i, 1); } if (lives.length === 0) { LK.showGameOver(); } } });
/****
* Classes
****/
var Heart = Container.expand(function () {
var self = Container.call(this);
var heartGraphics = self.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
});
var Knife = Container.expand(function () {
var self = Container.call(this);
self.angleTo = function (other) {
var dx = other.x - self.x;
var dy = other.y - self.y;
return Math.atan2(dy, dx);
};
var knifeGraphics = self.attachAsset('knife', {
anchorX: 0.5
});
self.speed = 30;
self.stuck = false;
self.falling = false;
self.spinDirection = Math.random() < 0.5 ? -1 : 1;
self._move_migrated = function () {
if (!self.stuck && !self.falling) {
self.y -= self.speed;
}
};
self.fall = function () {
if (self.falling) {
if (!self.fallInitiated) {
knifeGraphics.anchor.x = .5;
knifeGraphics.anchor.y = .5;
self.x += knifeGraphics.width / 2;
self.y += knifeGraphics.height / 2;
self.fallInitiated = true;
}
self.y += self.speed;
self.rotation += self.spinDirection * 0.1;
}
};
self.hit = function (knives) {
for (var i = 0; i < knives.length; i++) {
if (knives[i] !== self && knives[i].stuck) {
var angleDiff = Math.abs(knives[i].hitAngle % (2 * Math.PI) - self.hitAngle % (2 * Math.PI));
if (angleDiff < Math.PI / 24) {
return true;
}
}
}
return false;
};
});
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
self.rotationSpeed = 0.01;
self.rotation = 4 * Math.PI;
self.pointSections = [10, 20, 30, 50, 100]; // Different point values for different zones
self.rotate = function () {
self.rotation += self.rotationSpeed;
};
self.hit = function () {
LK.effects.flashObject(self, 0x00ff00, 500);
};
self.getPointsAtAngle = function (angle) {
// Normalize angle between 0 and 2*PI
var normalizedAngle = Math.abs(angle % (2 * Math.PI));
// Divide target into 5 equal sections
var sectionSize = 2 * Math.PI / self.pointSections.length;
// Determine which section was hit
var sectionIndex = Math.floor(normalizedAngle / sectionSize);
// Return points for that section
return self.pointSections[sectionIndex];
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2e6343
});
/****
* Game Code
****/
var background = game.attachAsset('background', {});
background.width = 2048;
background.height = 2732;
var knives = [];
var targets = [];
var score = 0;
var lives = [new Heart(), new Heart(), new Heart()];
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: 0xFFFFFF,
font: "Impact",
dropShadow: true,
dropShadowColor: 0x000000,
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreTxt.anchor.set(.5, 0);
LK.gui.top.addChild(scoreTxt);
for (var i = 0; i < lives.length; i++) {
lives[i].x = 2048 - (i + 1) * 130 - 15;
lives[i].y = 100 + 15;
game.addChild(lives[i]);
}
var knife = game.addChild(new Knife());
knife.x = 2048 / 2;
knife.y = 2732 - 200;
var target = game.addChild(new Target());
target.x = 2048 / 2;
target.y = 2732 / 2;
// Add score labels to the target
var pointLabels = [];
for (var i = 0; i < target.pointSections.length; i++) {
var label = new Text2(target.pointSections[i].toString(), {
size: 80,
fill: 0xFFFFFF,
font: "Impact",
dropShadow: true,
dropShadowColor: 0x000000,
dropShadowBlur: 4,
dropShadowDistance: 3
});
label.anchor.set(0.5, 0.5);
// Position the labels evenly around the target
var angle = i * 2 * Math.PI / target.pointSections.length;
var radius = target.width * 0.35; // Position labels within the target
label.x = target.x + Math.cos(angle) * radius;
label.y = target.y + Math.sin(angle) * radius;
pointLabels.push(label);
game.addChild(label);
}
game.on('down', function (x, y, obj) {
var newKnife = new Knife();
newKnife.x = knife.x;
newKnife.y = knife.y;
knives.push(newKnife);
game.addChild(newKnife);
});
LK.on('tick', function () {
target.rotate();
// Update point labels to stay aligned with the target rotation
for (var i = 0; i < pointLabels.length; i++) {
var angle = i * 2 * Math.PI / target.pointSections.length + target.rotation;
var radius = target.width * 0.35;
pointLabels[i].x = target.x + Math.cos(angle) * radius;
pointLabels[i].y = target.y + Math.sin(angle) * radius;
// Keep the text orientation normal
pointLabels[i].rotation = angle + Math.PI / 2;
}
for (var i = 0; i < knives.length; i++) {
knives[i]._move_migrated();
knives[i].fall();
}
for (var i = 0; i < knives.length; i++) {
if (Math.abs(knives[i].y - target.y) <= target.height / 2 && !knives[i].stuck) {
knives[i].stuck = true;
knives[i].hitAngle = target.rotation - Math.PI / 2;
if (knives[i].hit(knives)) {
knives[i].falling = true;
var lostLife = lives.pop();
lostLife.destroy();
LK.setScore(score);
scoreTxt.setText(score.toString());
if (lives.length > 0) {
LK.effects.flashScreen(0xff0000, 500);
}
} else {
target.hit();
// Get points based on the section hit
var pointsEarned = target.getPointsAtAngle(knives[i].hitAngle);
score += pointsEarned;
target.rotationSpeed += 0.005 / 3;
LK.setScore(score);
scoreTxt.setText(score.toString());
// Show points earned as floating text
var pointsText = new Text2("+" + pointsEarned, {
size: 100,
fill: 0xFFFF00,
font: "Impact"
});
pointsText.anchor.set(0.5, 0.5);
pointsText.x = knives[i].x;
pointsText.y = knives[i].y - 100;
game.addChild(pointsText);
// Animate and remove the points text
var startY = pointsText.y;
var fadeInterval = LK.setInterval(function () {
pointsText.y -= 3;
pointsText.alpha -= 0.05;
if (pointsText.alpha <= 0) {
LK.clearInterval(fadeInterval);
pointsText.destroy();
}
}, 50);
}
}
if (knives[i].stuck && !knives[i].falling) {
knives[i].rotation = target.rotation - knives[i].hitAngle - Math.PI / 2;
knives[i].x = target.x + Math.cos(target.rotation - knives[i].hitAngle) * target.width / 2;
knives[i].y = target.y + Math.sin(target.rotation - knives[i].hitAngle) * target.height / 2;
}
}
for (var i = knives.length - 1; i >= 0; i--) {
if (knives[i].y < -50) {
knives[i].destroy();
knives.splice(i, 1);
}
if (lives.length === 0) {
LK.showGameOver();
}
}
});
Cartoon flat dart board. Single Game Texture. In-Game asset. 2d. White background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
artoon knife pointing up. Symmetrical. Vertical. 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