/****
* Classes
****/
var Particle = Container.expand(function () {
var self = Container.call(this);
self.dx = (Math.random() * 2 - 1) * 2;
self.dy = (Math.random() * 2 - 1) * 2;
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
particleGraphics.blendMode = 1;
self.rotation = Math.random() * Math.PI * 2;
self.lifeSpan = 60;
self.tick = function () {
self.alpha -= 1 / self.lifeSpan;
self.scale.x -= 0.01;
self.scale.y -= 0.01;
self.x += self.dx;
self.y += self.dy;
if (self.alpha <= 0) {
self.destroy();
}
};
return self;
});
var ShotIndicator = Container.expand(function (maxShots) {
var self = Container.call(this);
self.maxShots = maxShots;
self.currentShots = maxShots;
self.indicators = [];
for (var i = 0; i < self.maxShots; i++) {
var indicator = self.attachAsset('shotIndicator', {
anchorY: 0.5
});
indicator.x = i * indicator.width;
self.indicators.push(indicator);
self.addChild(indicator);
}
self.updateIndicators = function () {
for (var i = 0; i < self.indicators.length; i++) {
self.indicators[i].alpha = i < self.currentShots ? 1 : 0.3;
}
};
self.useShot = function () {
if (self.currentShots > 0) {
self.currentShots--;
self.updateIndicators();
}
};
self.resetShots = function () {
self.currentShots = Math.min(self.currentShots + 2, self.maxShots);
self.updateIndicators();
};
self.updateIndicators();
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.tick = function () {
if (!self.initialized) {
self.rotationSpeed = -Math.PI / 60;
self.rotationTicks = 30;
self.initialized = true;
}
if (self.rotationTicks > 0) {
bulletGraphics.rotation -= self.rotationSpeed;
self.rotationTicks--;
}
self.speed += 0.2;
self.x += Math.cos(self.rotation) * self.speed;
self.y += Math.sin(self.rotation) * self.speed;
if (LK.ticks % 2 === 0) {
var particle = new Particle();
particle.x = self.x;
particle.y = self.y;
self.parent.addChildAt(particle, 1);
return particle;
}
return null;
};
});
var HexagonElement = Container.expand(function (delay) {
var self = Container.call(this);
self.fadeOut = function () {
var fadeOutInterval = LK.setInterval(function () {
self.alpha -= 0.05;
self.scale.x += 0.05;
self.scale.y += 0.05;
if (self.alpha <= 0) {
LK.clearInterval(fadeOutInterval);
self.destroy();
}
}, 10);
};
var backgroundElement = self.attachAsset('hexBackground', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundElement.alpha = 0;
backgroundElement.blendMode = 1;
backgroundElement.scale.x = 1;
backgroundElement.scale.y = 1;
var elementGraphics = self.attachAsset('element', {
anchorX: 0.5,
anchorY: 0.5
});
elementGraphics.alpha = 0;
elementGraphics.scale.x = 0;
elementGraphics.scale.y = 0;
self.fadeInDelay = delay * 5;
var directions = [{
x: 1,
y: 0
}, {
x: -1,
y: 0
}, {
x: 0.5,
y: Math.sqrt(3) / 2
}, {
x: -0.5,
y: Math.sqrt(3) / 2
}, {
x: 0.5,
y: -Math.sqrt(3) / 2
}, {
x: -0.5,
y: -Math.sqrt(3) / 2
}];
var chosenDirection = directions[Math.floor(Math.random() * directions.length)];
self.speed = 4;
self.tick = function () {
if (self.fadeInDelay > 0) {
self.fadeInDelay--;
} else {
if (elementGraphics.alpha < 1) {
elementGraphics.alpha += 0.05;
elementGraphics.scale.x += 0.05;
elementGraphics.scale.y += 0.05;
} else if (elementGraphics.alpha > 1) {
elementGraphics.alpha = 1;
}
if (backgroundElement.alpha < 1) {
backgroundElement.alpha += 0.1;
} else if (backgroundElement.alpha > 1) {
backgroundElement.alpha = 1;
}
}
self.x = (self.x + chosenDirection.x * self.speed + 2048) % 2048;
self.y = (self.y + chosenDirection.y * self.speed + 2732) % 2732;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2f2033
});
/****
* Game Code
****/
var backgroundElement = game.attachAsset('backgroundElement', {
anchorX: 0.5,
anchorY: 0.5
});
var targetScale = 1.8;
backgroundElement.x = 2048 / 2 - 45;
backgroundElement.y = 2732 / 2;
backgroundElement.scale.x = targetScale;
backgroundElement.scale.y = targetScale;
game.addChild(backgroundElement);
var score = 0;
var wave = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff",
weight: 500,
dropShadow: true,
dropShadowColor: '#000000',
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
game.updateScore = function (points) {
score += points;
LK.setScore(score);
scoreTxt.setText(score.toString());
};
game.updateScore(0);
var bullets = [];
var particles = [];
var elements = [];
var shotIndicator = new ShotIndicator(5);
shotIndicator.x = 2048 - shotIndicator.width * shotIndicator.maxShots - 20 - 30 - 10;
shotIndicator.y = 40 + 10 + 20;
LK.gui.topRight.addChild(shotIndicator);
game.shotIndicator = shotIndicator;
game.shotIndicator.resetShots();
function startNextLevel() {
bullets.forEach(function (bullet) {
bullet.destroy();
});
bullets = [];
elements.forEach(function (element) {
element.destroy();
});
elements = [];
game.shotIndicator.resetShots();
var hexagonsThisWave = Math.min(wave + 2, 8);
for (var i = 0; i < hexagonsThisWave; i++) {
var scaleModifier = Math.max(0.3, 1 - wave * 0.05);
var hexagonElement = new HexagonElement(i);
hexagonElement.x = Math.random() * 2048;
hexagonElement.y = Math.random() * 2732;
hexagonElement.scale.x = scaleModifier;
hexagonElement.scale.y = scaleModifier;
elements.push(hexagonElement);
game.addChild(hexagonElement);
}
}
game.startNextLevel = function () {
wave++;
targetScale = Math.max(1, targetScale - 0.05);
var waveText = new Text2('Wave ' + wave, {
size: 300,
fill: '#ffffff',
weight: 100,
align: 'center',
dropShadow: true,
dropShadowColor: '#000000',
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
waveText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(waveText);
LK.setTimeout(function () {
waveText.destroy();
}, 2000);
startNextLevel.call(this);
};
game.startNextLevel();
game.fireBulletsHexagon = function (position) {
var directions = [{
x: 1,
y: 0
}, {
x: -1,
y: 0
}, {
x: 0.5,
y: Math.sqrt(3) / 2
}, {
x: -0.5,
y: Math.sqrt(3) / 2
}, {
x: 0.5,
y: -Math.sqrt(3) / 2
}, {
x: -0.5,
y: -Math.sqrt(3) / 2
}];
directions.forEach(function (direction, index) {
var bullet = new Bullet();
bullet.x = position.x;
bullet.y = position.y;
bullet.rotation = Math.atan2(direction.y, direction.x);
bullets.push(bullet);
game.addChild(bullet);
});
};
game.on('down', function (obj) {
if (game.shotIndicator.currentShots <= 0) {
return;
}
game.shotIndicator.useShot();
var event = obj.event;
var pos = event.getLocalPosition(game);
game.fireBulletsHexagon(pos);
});
LK.on('tick', function () {
for (var i = bullets.length - 1; i >= 0; i--) {
var particle = bullets[i].tick();
if (particle) {
particles.push(particle);
}
for (var j = elements.length - 1; j >= 0; j--) {
var dx = bullets[i].x - elements[j].x;
var dy = bullets[i].y - elements[j].y;
var fixedIntersectionDistance = elements[j].width / 2;
if (Math.abs(dx) < fixedIntersectionDistance && Math.abs(dy) < fixedIntersectionDistance) {
var pos = {
x: elements[j].x,
y: elements[j].y
};
elements[j].fadeOut();
game.updateScore(1);
elements.splice(j, 1);
game.fireBulletsHexagon(pos);
break;
}
}
if (bullets[i].x < 0 || bullets[i].x > 2048 || bullets[i].y < 0 || bullets[i].y > 2732) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
for (var j = 0; j < elements.length; j++) {
elements[j].tick();
}
backgroundElement.scale.x += (targetScale - backgroundElement.scale.x) / 20;
backgroundElement.scale.y += (targetScale - backgroundElement.scale.y) / 20;
for (var k = particles.length - 1; k >= 0; k--) {
particles[k].tick();
if (particles[k].alpha <= 0) {
particles.splice(k, 1);
}
}
if (elements.length === 0 && bullets.length === 0) {
game.startNextLevel();
} else if (game.shotIndicator.currentShots <= 0 && bullets.length === 0) {
LK.effects.flashScreen(0xffffff, 300);
LK.showGameOver();
}
}); /****
* Classes
****/
var Particle = Container.expand(function () {
var self = Container.call(this);
self.dx = (Math.random() * 2 - 1) * 2;
self.dy = (Math.random() * 2 - 1) * 2;
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
particleGraphics.blendMode = 1;
self.rotation = Math.random() * Math.PI * 2;
self.lifeSpan = 60;
self.tick = function () {
self.alpha -= 1 / self.lifeSpan;
self.scale.x -= 0.01;
self.scale.y -= 0.01;
self.x += self.dx;
self.y += self.dy;
if (self.alpha <= 0) {
self.destroy();
}
};
return self;
});
var ShotIndicator = Container.expand(function (maxShots) {
var self = Container.call(this);
self.maxShots = maxShots;
self.currentShots = maxShots;
self.indicators = [];
for (var i = 0; i < self.maxShots; i++) {
var indicator = self.attachAsset('shotIndicator', {
anchorY: 0.5
});
indicator.x = i * indicator.width;
self.indicators.push(indicator);
self.addChild(indicator);
}
self.updateIndicators = function () {
for (var i = 0; i < self.indicators.length; i++) {
self.indicators[i].alpha = i < self.currentShots ? 1 : 0.3;
}
};
self.useShot = function () {
if (self.currentShots > 0) {
self.currentShots--;
self.updateIndicators();
}
};
self.resetShots = function () {
self.currentShots = Math.min(self.currentShots + 2, self.maxShots);
self.updateIndicators();
};
self.updateIndicators();
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.tick = function () {
if (!self.initialized) {
self.rotationSpeed = -Math.PI / 60;
self.rotationTicks = 30;
self.initialized = true;
}
if (self.rotationTicks > 0) {
bulletGraphics.rotation -= self.rotationSpeed;
self.rotationTicks--;
}
self.speed += 0.2;
self.x += Math.cos(self.rotation) * self.speed;
self.y += Math.sin(self.rotation) * self.speed;
if (LK.ticks % 2 === 0) {
var particle = new Particle();
particle.x = self.x;
particle.y = self.y;
self.parent.addChildAt(particle, 1);
return particle;
}
return null;
};
});
var HexagonElement = Container.expand(function (delay) {
var self = Container.call(this);
self.fadeOut = function () {
var fadeOutInterval = LK.setInterval(function () {
self.alpha -= 0.05;
self.scale.x += 0.05;
self.scale.y += 0.05;
if (self.alpha <= 0) {
LK.clearInterval(fadeOutInterval);
self.destroy();
}
}, 10);
};
var backgroundElement = self.attachAsset('hexBackground', {
anchorX: 0.5,
anchorY: 0.5
});
backgroundElement.alpha = 0;
backgroundElement.blendMode = 1;
backgroundElement.scale.x = 1;
backgroundElement.scale.y = 1;
var elementGraphics = self.attachAsset('element', {
anchorX: 0.5,
anchorY: 0.5
});
elementGraphics.alpha = 0;
elementGraphics.scale.x = 0;
elementGraphics.scale.y = 0;
self.fadeInDelay = delay * 5;
var directions = [{
x: 1,
y: 0
}, {
x: -1,
y: 0
}, {
x: 0.5,
y: Math.sqrt(3) / 2
}, {
x: -0.5,
y: Math.sqrt(3) / 2
}, {
x: 0.5,
y: -Math.sqrt(3) / 2
}, {
x: -0.5,
y: -Math.sqrt(3) / 2
}];
var chosenDirection = directions[Math.floor(Math.random() * directions.length)];
self.speed = 4;
self.tick = function () {
if (self.fadeInDelay > 0) {
self.fadeInDelay--;
} else {
if (elementGraphics.alpha < 1) {
elementGraphics.alpha += 0.05;
elementGraphics.scale.x += 0.05;
elementGraphics.scale.y += 0.05;
} else if (elementGraphics.alpha > 1) {
elementGraphics.alpha = 1;
}
if (backgroundElement.alpha < 1) {
backgroundElement.alpha += 0.1;
} else if (backgroundElement.alpha > 1) {
backgroundElement.alpha = 1;
}
}
self.x = (self.x + chosenDirection.x * self.speed + 2048) % 2048;
self.y = (self.y + chosenDirection.y * self.speed + 2732) % 2732;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2f2033
});
/****
* Game Code
****/
var backgroundElement = game.attachAsset('backgroundElement', {
anchorX: 0.5,
anchorY: 0.5
});
var targetScale = 1.8;
backgroundElement.x = 2048 / 2 - 45;
backgroundElement.y = 2732 / 2;
backgroundElement.scale.x = targetScale;
backgroundElement.scale.y = targetScale;
game.addChild(backgroundElement);
var score = 0;
var wave = 0;
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff",
weight: 500,
dropShadow: true,
dropShadowColor: '#000000',
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
game.updateScore = function (points) {
score += points;
LK.setScore(score);
scoreTxt.setText(score.toString());
};
game.updateScore(0);
var bullets = [];
var particles = [];
var elements = [];
var shotIndicator = new ShotIndicator(5);
shotIndicator.x = 2048 - shotIndicator.width * shotIndicator.maxShots - 20 - 30 - 10;
shotIndicator.y = 40 + 10 + 20;
LK.gui.topRight.addChild(shotIndicator);
game.shotIndicator = shotIndicator;
game.shotIndicator.resetShots();
function startNextLevel() {
bullets.forEach(function (bullet) {
bullet.destroy();
});
bullets = [];
elements.forEach(function (element) {
element.destroy();
});
elements = [];
game.shotIndicator.resetShots();
var hexagonsThisWave = Math.min(wave + 2, 8);
for (var i = 0; i < hexagonsThisWave; i++) {
var scaleModifier = Math.max(0.3, 1 - wave * 0.05);
var hexagonElement = new HexagonElement(i);
hexagonElement.x = Math.random() * 2048;
hexagonElement.y = Math.random() * 2732;
hexagonElement.scale.x = scaleModifier;
hexagonElement.scale.y = scaleModifier;
elements.push(hexagonElement);
game.addChild(hexagonElement);
}
}
game.startNextLevel = function () {
wave++;
targetScale = Math.max(1, targetScale - 0.05);
var waveText = new Text2('Wave ' + wave, {
size: 300,
fill: '#ffffff',
weight: 100,
align: 'center',
dropShadow: true,
dropShadowColor: '#000000',
dropShadowBlur: 4,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
waveText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(waveText);
LK.setTimeout(function () {
waveText.destroy();
}, 2000);
startNextLevel.call(this);
};
game.startNextLevel();
game.fireBulletsHexagon = function (position) {
var directions = [{
x: 1,
y: 0
}, {
x: -1,
y: 0
}, {
x: 0.5,
y: Math.sqrt(3) / 2
}, {
x: -0.5,
y: Math.sqrt(3) / 2
}, {
x: 0.5,
y: -Math.sqrt(3) / 2
}, {
x: -0.5,
y: -Math.sqrt(3) / 2
}];
directions.forEach(function (direction, index) {
var bullet = new Bullet();
bullet.x = position.x;
bullet.y = position.y;
bullet.rotation = Math.atan2(direction.y, direction.x);
bullets.push(bullet);
game.addChild(bullet);
});
};
game.on('down', function (obj) {
if (game.shotIndicator.currentShots <= 0) {
return;
}
game.shotIndicator.useShot();
var event = obj.event;
var pos = event.getLocalPosition(game);
game.fireBulletsHexagon(pos);
});
LK.on('tick', function () {
for (var i = bullets.length - 1; i >= 0; i--) {
var particle = bullets[i].tick();
if (particle) {
particles.push(particle);
}
for (var j = elements.length - 1; j >= 0; j--) {
var dx = bullets[i].x - elements[j].x;
var dy = bullets[i].y - elements[j].y;
var fixedIntersectionDistance = elements[j].width / 2;
if (Math.abs(dx) < fixedIntersectionDistance && Math.abs(dy) < fixedIntersectionDistance) {
var pos = {
x: elements[j].x,
y: elements[j].y
};
elements[j].fadeOut();
game.updateScore(1);
elements.splice(j, 1);
game.fireBulletsHexagon(pos);
break;
}
}
if (bullets[i].x < 0 || bullets[i].x > 2048 || bullets[i].y < 0 || bullets[i].y > 2732) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
for (var j = 0; j < elements.length; j++) {
elements[j].tick();
}
backgroundElement.scale.x += (targetScale - backgroundElement.scale.x) / 20;
backgroundElement.scale.y += (targetScale - backgroundElement.scale.y) / 20;
for (var k = particles.length - 1; k >= 0; k--) {
particles[k].tick();
if (particles[k].alpha <= 0) {
particles.splice(k, 1);
}
}
if (elements.length === 0 && bullets.length === 0) {
game.startNextLevel();
} else if (game.shotIndicator.currentShots <= 0 && bullets.length === 0) {
LK.effects.flashScreen(0xffffff, 300);
LK.showGameOver();
}
});
Hexagon target Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single White Hexagon, soft edges, simple, vector. Round corners. All white. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Amazing bright hexagon space background.
Triangle plasma bullet. Glowing. Pointing down. Dark outline. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
White triangle Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Single Bright light particle, white. Simple, vector. Triangle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.