/****
* Classes
****/
var Axe = Container.expand(function () {
var self = Container.call(this);
var axeGraphics = self.attachAsset('axe', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 20;
self._move_migrated = function () {
self.y -= self.speed;
self.rotation += 0.1;
};
});
var Target = Container.expand(function () {
var self = Container.call(this);
var targetGraphics = self.attachAsset('target', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.direction = 1;
self._move_migrated = function () {
self.x += self.speed * self.direction;
if (self.x <= 0 || self.x >= 2048) {
self.direction *= -1;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var background = game.attachAsset('green_grass_field', {});
background.width = 2048;
background.height = 2732;
var targets = [];
var axes = [];
var score = 0;
var kills = 0;
var targetSpeed = 5;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
font: "Impact",
dropShadow: true,
dropShadowColor: "#000000"
});
scoreTxt.anchor.set(.5, 0);
LK.gui.top.addChild(scoreTxt);
var spawnTargets = function spawnTargets() {
for (var i = 0; i < 3; i++) {
var target = game.addChild(new Target());
target.speed = targetSpeed;
target.x = Math.random() * 2048;
target.y = Math.random() * (2732 - target.height * 2);
targets.push(target);
}
};
LK.on('tick', function () {
if (targets.length == 0) {
spawnTargets();
}
});
var axe;
game.on('down', function (x, y, obj) {
var pos = game.toLocal(obj.global);
axe = game.addChild(new Axe());
axe.x = pos.x;
axe.y = 2732 - axe.height + 50;
axes.push(axe);
});
LK.on('tick', function () {
for (var i = 0; i < targets.length; i++) {
targets[i]._move_migrated();
}
for (var i = 0; i < axes.length; i++) {
axes[i]._move_migrated();
if (axes[i].y < -50) {
axes[i].destroy();
axes.splice(i, 1);
}
if (axes[i].y <= 0) {
LK.showGameOver();
}
}
for (var i = 0; i < axes.length; i++) {
for (var j = 0; j < targets.length; j++) {
if (axes[i].intersects(targets[j])) {
var distance = Math.sqrt(Math.pow(axes[i].x - targets[j].x, 2) + Math.pow(axes[i].y - targets[j].y, 2));
score += Math.max(0, 100 - distance) + 50;
scoreTxt.setText(score);
axes[i].destroy();
axes.splice(i, 1);
targets[j].destroy();
targets.splice(j, 1);
kills++;
if (kills % 3 == 0) {
targetSpeed += 1;
}
break;
}
}
}
}); ===================================================================
--- original.js
+++ change.js
@@ -74,9 +74,9 @@
game.on('down', function (x, y, obj) {
var pos = game.toLocal(obj.global);
axe = game.addChild(new Axe());
axe.x = pos.x;
- axe.y = 2732 - axe.height;
+ axe.y = 2732 - axe.height + 50;
axes.push(axe);
});
LK.on('tick', function () {
for (var i = 0; i < targets.length; i++) {