/**** * Classes ****/ var BloodSplatter = Container.expand(function () { var self = Container.call(this); var bloodSplatterGraphics = self.attachAsset('bloodSplatter', { anchorX: 0.5, anchorY: 0.5 }); bloodSplatterGraphics.rotation = Math.random() * 2 * Math.PI; self.despawn = function () { LK.setTimeout(function () { self.destroy(); }, 3000); }; self.despawn(); }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpGraphics = self.attachAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); self.activate = function () {}; }); var Rat = Container.expand(function () { var self = Container.call(this); var ratGraphics = self.attachAsset('rat', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 10 + 5; self._move_migrated = function () { self.y += self.speed; if (self.y >= 2732) { LK.showGameOver(); } }; }); var Shuriken = Container.expand(function () { var self = Container.call(this); var shurikenGraphics = self.attachAsset('shuriken', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 50; self.rotationSpeed = 0.1; self._move_migrated = function () { ; self.y -= self.speed; self.rotation += self.rotationSpeed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var background = game.attachAsset('wooden_floor', {}); background.width = 2048; background.height = 2732; background.isCollisionObject = false; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(.5, 0); LK.gui.top.addChild(scoreTxt); var shurikens = []; var rats = []; var powerUps = []; var isGameOver = false; var tickOffset = 0; var score = 0; var spawnRate = 1; function init() { spawnRats(); } function spawnRats() { var spawnRate = 1; var spawnTime = Math.random() * 2000 / spawnRate + 1000; LK.setTimeout(function () { var rat = new Rat(); rat.x = Math.random() * 2048; rat.y = 0; rats.push(rat); game.addChild(rat); spawnRats(); }, spawnTime); } function update() { for (var i = 0; i < rats.length; i++) { rats[i]._move_migrated(); } for (var i = 0; i < shurikens.length; i++) { shurikens[i]._move_migrated(); } checkCollision(); updateScore(); if (isGameOver) { gameOver(); } } function gameOver() {} function checkCollision() { for (var i = 0; i < shurikens.length; i++) { for (var j = 0; j < rats.length; j++) { if (shurikens[i].intersects(rats[j])) { game.removeChild(shurikens[i]); shurikens.splice(i, 1); game.removeChild(rats[j]); var bloodSplatter = new BloodSplatter(); bloodSplatter.x = rats[j].x; bloodSplatter.y = rats[j].y; game.addChild(bloodSplatter); bloodSplatter.despawn(); rats.splice(j, 1); score++; break; } } } } function updateScore() { scoreTxt.setText(score); if (score % 10 == 0 && score != 0) { spawnRate *= 2; } } var lastShotTime = 0; var shotLimit = 3; game.on('down', function (x, y, obj) { if (LK.ticks - lastShotTime >= 60 / shotLimit) { var shuriken = new Shuriken(); shuriken.x = game.toLocal(obj.global).x; shuriken.y = 2732; shurikens.push(shuriken); game.addChild(shuriken); lastShotTime = LK.ticks; } }); game.on('move', function (x, y, obj) {}); game.on('up', function (x, y, obj) {}); LK.on('tick', function () { update(); for (var i = 0; i < rats.length; i++) { rats[i]._move_migrated(); } for (var i = 0; i < shurikens.length; i++) { shurikens[i]._move_migrated(); } checkCollision(); updateScore(); if (isGameOver) { gameOver(); } }); init();
/****
* Classes
****/
var BloodSplatter = Container.expand(function () {
var self = Container.call(this);
var bloodSplatterGraphics = self.attachAsset('bloodSplatter', {
anchorX: 0.5,
anchorY: 0.5
});
bloodSplatterGraphics.rotation = Math.random() * 2 * Math.PI;
self.despawn = function () {
LK.setTimeout(function () {
self.destroy();
}, 3000);
};
self.despawn();
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.activate = function () {};
});
var Rat = Container.expand(function () {
var self = Container.call(this);
var ratGraphics = self.attachAsset('rat', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 10 + 5;
self._move_migrated = function () {
self.y += self.speed;
if (self.y >= 2732) {
LK.showGameOver();
}
};
});
var Shuriken = Container.expand(function () {
var self = Container.call(this);
var shurikenGraphics = self.attachAsset('shuriken', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 50;
self.rotationSpeed = 0.1;
self._move_migrated = function () {
;
self.y -= self.speed;
self.rotation += self.rotationSpeed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
var background = game.attachAsset('wooden_floor', {});
background.width = 2048;
background.height = 2732;
background.isCollisionObject = false;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(.5, 0);
LK.gui.top.addChild(scoreTxt);
var shurikens = [];
var rats = [];
var powerUps = [];
var isGameOver = false;
var tickOffset = 0;
var score = 0;
var spawnRate = 1;
function init() {
spawnRats();
}
function spawnRats() {
var spawnRate = 1;
var spawnTime = Math.random() * 2000 / spawnRate + 1000;
LK.setTimeout(function () {
var rat = new Rat();
rat.x = Math.random() * 2048;
rat.y = 0;
rats.push(rat);
game.addChild(rat);
spawnRats();
}, spawnTime);
}
function update() {
for (var i = 0; i < rats.length; i++) {
rats[i]._move_migrated();
}
for (var i = 0; i < shurikens.length; i++) {
shurikens[i]._move_migrated();
}
checkCollision();
updateScore();
if (isGameOver) {
gameOver();
}
}
function gameOver() {}
function checkCollision() {
for (var i = 0; i < shurikens.length; i++) {
for (var j = 0; j < rats.length; j++) {
if (shurikens[i].intersects(rats[j])) {
game.removeChild(shurikens[i]);
shurikens.splice(i, 1);
game.removeChild(rats[j]);
var bloodSplatter = new BloodSplatter();
bloodSplatter.x = rats[j].x;
bloodSplatter.y = rats[j].y;
game.addChild(bloodSplatter);
bloodSplatter.despawn();
rats.splice(j, 1);
score++;
break;
}
}
}
}
function updateScore() {
scoreTxt.setText(score);
if (score % 10 == 0 && score != 0) {
spawnRate *= 2;
}
}
var lastShotTime = 0;
var shotLimit = 3;
game.on('down', function (x, y, obj) {
if (LK.ticks - lastShotTime >= 60 / shotLimit) {
var shuriken = new Shuriken();
shuriken.x = game.toLocal(obj.global).x;
shuriken.y = 2732;
shurikens.push(shuriken);
game.addChild(shuriken);
lastShotTime = LK.ticks;
}
});
game.on('move', function (x, y, obj) {});
game.on('up', function (x, y, obj) {});
LK.on('tick', function () {
update();
for (var i = 0; i < rats.length; i++) {
rats[i]._move_migrated();
}
for (var i = 0; i < shurikens.length; i++) {
shurikens[i]._move_migrated();
}
checkCollision();
updateScore();
if (isGameOver) {
gameOver();
}
});
init();