/****
* 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 = 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.rotate = function () {
self.rotation += self.rotationSpeed;
};
self.hit = function () {
LK.effects.flashObject(self, 0x00ff00, 500);
};
});
/****
* 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: "#ffffff",
font: "Impact",
dropShadow: true,
dropShadowColor: "#000000",
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.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;
game.on('down', function (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();
for (var i = 0; i < knives.length; i++) {
knives[i].move();
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();
target.rotationSpeed += 0.005 / 3;
score += 1;
LK.setScore(score);
scoreTxt.setText(score.toString());
}
}
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.
Cartoon knife pointing up. Symmetrical. Vertical. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single cartoon extra life heart. No drop shadows. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.