var Blob = Container.expand(function () { var self = Container.call(this); var blobGraphics = self.createAsset('blob', 'Blob Graphics', 0.5, 0.5); self.speed = 5; self.vx = 0; self.vy = 0; self.move = function () { self.x = Math.max(0, Math.min(self.x + self.vx, 16384)); self.y = Math.max(0, Math.min(self.y + self.vy, 16384)); }; self.expand = function () {}; }); var Foe = Container.expand(function () { var self = Container.call(this); var foeGraphics = self.createAsset('foe', 'Foe Graphics', 0.5, 0.5); self.speed = 3; self.move = function () {}; }); var Game = Container.expand(function () { var self = Container.call(this); self.worldWidth = 16384; self.worldHeight = 16384; for (var i = 0; i < self.worldWidth / 2048; i++) { for (var j = 0; j < self.worldHeight / 2048; j++) { var tile = self.createAsset('background', 'Background', 0, 0); tile.x = i * 2048; tile.y = j * 2048; tile.width = 2048; tile.height = 2048; self.addChildAt(tile, 0); } } var blobs = []; var foes = []; var isGameOver = false; var dragNode = null; var playerBlob = self.addChild(new Blob()); playerBlob.x = self.worldWidth / 2; playerBlob.y = self.worldHeight / 2; playerBlob.width = 300; playerBlob.height = 300; blobs.push(playerBlob); for (var i = 0; i < 100; i++) { var foe = self.addChild(new Foe()); foe.x = Math.random() * self.worldWidth; foe.y = Math.random() * self.worldHeight; foes.push(foe); } var joystickBase = LK.gui.createAsset('joystickBase', 'Joystick Base', 0, 0); joystickBase.alpha = 0.5; var joystickStick = LK.gui.createAsset('joystickStick', 'Joystick Stick', 0.5, 0.5); joystickBase.visible = false; joystickStick.visible = false; var score = 0; var scoreTxt = new Text2(score.toString(), { size: 150, fill: '#ffffff' }); scoreTxt.anchor.set(.5, .5); LK.gui.center.addChild(scoreTxt); var minimap = LK.gui.createAsset('minimap', 'Minimap', 0, 0); minimap.width = 400; minimap.height = 400; minimap.x = 0; minimap.y = 0; LK.gui.topLeft.addChild(minimap); var playerDot = minimap.createAsset('playerDot', 'Player Dot', 0.5, 0.5); var foeDots = []; for (var i = 0; i < 100; i++) { var foeDot = minimap.createAsset('foeDot', 'Foe Dot', 0.5, 0.5); foeDots.push(foeDot); } stage.on('down', function (obj) { var event = obj.event; var pos = event.getLocalPosition(joystickBase.parent); joystickBase.x = pos.x - joystickBase.width / 2; joystickBase.y = pos.y - joystickBase.height / 2; joystickBase.visible = true; joystickDrag = true; }); stage.on('up', function (obj) { joystickBase.visible = false; }); var joystickDrag = false; joystickBase.on('down', function (obj) { var event = obj.event; var pos = event.getLocalPosition(joystickBase.parent); joystickStick.x = joystickBase.width / 2; joystickStick.y = -joystickStick.height / 2; joystickDrag = true; }); var initialJoystickPos = null; stage.on('down', function (obj) { var event = obj.event; initialJoystickPos = event.getLocalPosition(joystickBase.parent); joystickDrag = true; }); stage.on('move', function (obj) { if (joystickDrag) { var event = obj.event; var pos = event.getLocalPosition(joystickBase.parent); var dx = pos.x - initialJoystickPos.x; var dy = pos.y - initialJoystickPos.y; var distance = Math.sqrt(dx * dx + dy * dy); var angle = Math.atan2(dy, dx); playerBlob.vx = Math.cos(angle) * playerBlob.speed; playerBlob.vy = Math.sin(angle) * playerBlob.speed; joystickStick.x = joystickBase.x + joystickBase.width / 2 + Math.min(distance, joystickBase.width / 2) * Math.cos(angle); joystickStick.y = joystickBase.y + joystickBase.height / 2 + Math.min(distance, joystickBase.height / 2) * Math.sin(angle); joystickStick.visible = true; } }); stage.on('up', function (obj) { joystickDrag = false; playerBlob.vx = 0; playerBlob.vy = 0; joystickStick.visible = false; joystickStick.x = 0; joystickStick.y = 0; }); LK.on('tick', function () { for (var i = 0; i < blobs.length; i++) { blobs[i].move(); } for (var i = 0; i < foes.length; i++) { foes[i].move(); } for (var i = 0; i < blobs.length; i++) { for (var j = 0; j < foes.length; j++) { if (blobs[i].intersects(foes[j])) { blobs[i].expand(); foes[j].destroy(); foes.splice(j, 1); score += 1; scoreTxt.setText(score.toString()); } } } if (blobs.length == 0) { isGameOver = true; } if (isGameOver) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } self.x = -Math.min(Math.max(playerBlob.x, 2048 / 2), self.worldWidth - 2048 / 2) + 2048 / 2; self.y = -Math.min(Math.max(playerBlob.y, 2732 / 2), self.worldHeight - 2732 / 2) + 2732 / 2; playerDot.x = playerBlob.x / self.worldWidth * minimap.width; playerDot.y = playerBlob.y / self.worldHeight * minimap.height; for (var i = 0; i < foes.length; i++) { if (foeDots[i]) { foeDots[i].x = foes[i].x / self.worldWidth * minimap.width; foeDots[i].y = foes[i].y / self.worldHeight * minimap.height; } } }); });
var Blob = Container.expand(function () {
var self = Container.call(this);
var blobGraphics = self.createAsset('blob', 'Blob Graphics', 0.5, 0.5);
self.speed = 5;
self.vx = 0;
self.vy = 0;
self.move = function () {
self.x = Math.max(0, Math.min(self.x + self.vx, 16384));
self.y = Math.max(0, Math.min(self.y + self.vy, 16384));
};
self.expand = function () {};
});
var Foe = Container.expand(function () {
var self = Container.call(this);
var foeGraphics = self.createAsset('foe', 'Foe Graphics', 0.5, 0.5);
self.speed = 3;
self.move = function () {};
});
var Game = Container.expand(function () {
var self = Container.call(this);
self.worldWidth = 16384;
self.worldHeight = 16384;
for (var i = 0; i < self.worldWidth / 2048; i++) {
for (var j = 0; j < self.worldHeight / 2048; j++) {
var tile = self.createAsset('background', 'Background', 0, 0);
tile.x = i * 2048;
tile.y = j * 2048;
tile.width = 2048;
tile.height = 2048;
self.addChildAt(tile, 0);
}
}
var blobs = [];
var foes = [];
var isGameOver = false;
var dragNode = null;
var playerBlob = self.addChild(new Blob());
playerBlob.x = self.worldWidth / 2;
playerBlob.y = self.worldHeight / 2;
playerBlob.width = 300;
playerBlob.height = 300;
blobs.push(playerBlob);
for (var i = 0; i < 100; i++) {
var foe = self.addChild(new Foe());
foe.x = Math.random() * self.worldWidth;
foe.y = Math.random() * self.worldHeight;
foes.push(foe);
}
var joystickBase = LK.gui.createAsset('joystickBase', 'Joystick Base', 0, 0);
joystickBase.alpha = 0.5;
var joystickStick = LK.gui.createAsset('joystickStick', 'Joystick Stick', 0.5, 0.5);
joystickBase.visible = false;
joystickStick.visible = false;
var score = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: '#ffffff'
});
scoreTxt.anchor.set(.5, .5);
LK.gui.center.addChild(scoreTxt);
var minimap = LK.gui.createAsset('minimap', 'Minimap', 0, 0);
minimap.width = 400;
minimap.height = 400;
minimap.x = 0;
minimap.y = 0;
LK.gui.topLeft.addChild(minimap);
var playerDot = minimap.createAsset('playerDot', 'Player Dot', 0.5, 0.5);
var foeDots = [];
for (var i = 0; i < 100; i++) {
var foeDot = minimap.createAsset('foeDot', 'Foe Dot', 0.5, 0.5);
foeDots.push(foeDot);
}
stage.on('down', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(joystickBase.parent);
joystickBase.x = pos.x - joystickBase.width / 2;
joystickBase.y = pos.y - joystickBase.height / 2;
joystickBase.visible = true;
joystickDrag = true;
});
stage.on('up', function (obj) {
joystickBase.visible = false;
});
var joystickDrag = false;
joystickBase.on('down', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(joystickBase.parent);
joystickStick.x = joystickBase.width / 2;
joystickStick.y = -joystickStick.height / 2;
joystickDrag = true;
});
var initialJoystickPos = null;
stage.on('down', function (obj) {
var event = obj.event;
initialJoystickPos = event.getLocalPosition(joystickBase.parent);
joystickDrag = true;
});
stage.on('move', function (obj) {
if (joystickDrag) {
var event = obj.event;
var pos = event.getLocalPosition(joystickBase.parent);
var dx = pos.x - initialJoystickPos.x;
var dy = pos.y - initialJoystickPos.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var angle = Math.atan2(dy, dx);
playerBlob.vx = Math.cos(angle) * playerBlob.speed;
playerBlob.vy = Math.sin(angle) * playerBlob.speed;
joystickStick.x = joystickBase.x + joystickBase.width / 2 + Math.min(distance, joystickBase.width / 2) * Math.cos(angle);
joystickStick.y = joystickBase.y + joystickBase.height / 2 + Math.min(distance, joystickBase.height / 2) * Math.sin(angle);
joystickStick.visible = true;
}
});
stage.on('up', function (obj) {
joystickDrag = false;
playerBlob.vx = 0;
playerBlob.vy = 0;
joystickStick.visible = false;
joystickStick.x = 0;
joystickStick.y = 0;
});
LK.on('tick', function () {
for (var i = 0; i < blobs.length; i++) {
blobs[i].move();
}
for (var i = 0; i < foes.length; i++) {
foes[i].move();
}
for (var i = 0; i < blobs.length; i++) {
for (var j = 0; j < foes.length; j++) {
if (blobs[i].intersects(foes[j])) {
blobs[i].expand();
foes[j].destroy();
foes.splice(j, 1);
score += 1;
scoreTxt.setText(score.toString());
}
}
}
if (blobs.length == 0) {
isGameOver = true;
}
if (isGameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
self.x = -Math.min(Math.max(playerBlob.x, 2048 / 2), self.worldWidth - 2048 / 2) + 2048 / 2;
self.y = -Math.min(Math.max(playerBlob.y, 2732 / 2), self.worldHeight - 2732 / 2) + 2732 / 2;
playerDot.x = playerBlob.x / self.worldWidth * minimap.width;
playerDot.y = playerBlob.y / self.worldHeight * minimap.height;
for (var i = 0; i < foes.length; i++) {
if (foeDots[i]) {
foeDots[i].x = foes[i].x / self.worldWidth * minimap.width;
foeDots[i].y = foes[i].y / self.worldHeight * minimap.height;
}
}
});
});