var Level10 = Container.expand(function () {
var self = Container.call(this);
});
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.createAsset('explosion', 'Explosion Graphics', 0.5, 0.5);
self.speed = {
x: (Math.random() * 10 - 5) / 6,
y: (Math.random() * 10 - 5) / 6
};
self.move = function () {
self.x += self.speed.x;
self.y += self.speed.y;
};
self.fadeOut = function () {
self.alpha -= 0.02;
if (self.alpha <= 0) {
self.destroy();
}
};
});
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.createAsset('particle', 'Particle Graphics', 0.5, 0.5);
self.scale.set(1);
self.fadeSpeed = 1 / 150;
self.scaleSpeed = 1 / 150;
self.update = function () {
self.alpha -= self.fadeSpeed;
self.scale.x -= self.scaleSpeed;
self.scale.y -= self.scaleSpeed;
if (self.alpha <= 0) {
self.destroy();
}
};
});
var Bonus = Container.expand(function () {
var self = Container.call(this);
var bonusGraphics = self.createAsset('bonus', 'Bonus Graphics', 0.5, 0.5);
self.rotationSpeed = -0.01;
self.fadeSpeed = 0.01;
self.rotate = function () {
self.rotation += self.rotationSpeed;
};
});
var Galaxy = Container.expand(function () {
var self = Container.call(this);
self.rotationSpeed = -0.00033333;
var galaxyGraphics = self.createAsset('galaxy', 'Galaxy Graphics', 0.5, 0.5);
galaxyGraphics.scale.set(12);
self.scaleFactor = 0.0001;
self.scaleDirection = 0.8;
});
var Sun = Container.expand(function () {
var self = Container.call(this);
var sunGraphics = self.createAsset('sun', 'Sun Graphics', 0.5, 0.5);
sunGraphics.scale.set(4);
});
var Dot = Container.expand(function () {
var self = Container.call(this);
var dotGraphics = self.createAsset('dot', 'Dot Graphics', 0.5, 0.5);
dotGraphics.scale.set(Math.random() * (0.5 - 0.3) + 0.3);
var colors = [0xFFFFFF, 0xADD8E6, 0xFFFFE0, 0xEDDEA4, 0xEDDEA4];
dotGraphics.tint = colors[Math.floor(Math.random() * colors.length)];
self.speed = {
x: (Math.random() * 10 - 5) / 6,
y: (Math.random() * 10 - 5) / 6
};
self.alpha = 0;
self.fadeIn = true;
self.fadeOut = false;
self.lifeTime = 0;
self.maxLifeTime = Math.floor(Math.random() * (1200 - 300 + 1)) + 300;
self.move = function () {
self.x += self.speed.x * 0.9;
self.y += self.speed.y * 0.9;
self.lifeTime++;
if (self.fadeIn) {
self.alpha += 0.01;
if (self.alpha >= 1) {
self.fadeIn = false;
}
} else if (self.fadeOut) {
self.alpha -= 0.01;
if (self.alpha <= 0) {
self.x = Math.random() * 2048;
self.y = Math.random() * 2732;
self.alpha = 0;
self.fadeIn = true;
self.fadeOut = false;
self.lifeTime = 0;
}
} else if (self.lifeTime >= self.maxLifeTime) {
self.fadeOut = true;
}
};
});
var PlayerPaddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.createAsset('paddle', 'Player Paddle Graphics', 0.5, 0.5);
paddleGraphics.tint = 0xffffff;
self.speed = 20;
self.move = function (direction) {
self.y += direction * self.speed;
};
});
var AIPaddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.createAsset('paddle', 'AI Paddle Graphics', 0.5, 0.5);
paddleGraphics.tint = 0xE63946;
self.speed = 20;
self.move = function (direction) {
self.y += direction * self.speed;
};
});
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.createAsset('ball', 'Ball Graphics', 0.5, 0.5);
self.speed = {
x: 10,
y: 10
};
self.rotationSpeed = 0.01;
self.rotationDirection = 1;
self.move = function () {
self.x += self.speed.x;
self.y += self.speed.y;
self.rotation += self.rotationSpeed * self.rotationDirection;
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var galaxy = self.addChild(new Galaxy());
galaxy.x = 2048 / 2;
galaxy.y = 2732 / 2;
var sun = self.addChild(new Sun());
sun.x = 2048 / 2;
sun.y = 130;
var playerPaddle = self.addChildAt(new PlayerPaddle(), self.children.length);
var aiPaddle = self.addChildAt(new AIPaddle(), self.children.length);
var ball = self.addChildAt(new Ball(), self.children.length);
var bonus;
function createBonus() {
bonus = self.addChildAt(new Bonus(), self.children.length);
bonus.x = (Math.random() * 0.2 + 0.4) * 2048;
bonus.y = (Math.random() * 0.2 + 0.4) * 2732;
bonus.scale.set(0.01);
var scaleInterval = LK.setInterval(function () {
bonus.scale.x += 0.03;
bonus.scale.y += 0.03;
if (bonus.scale.x >= 1) {
LK.clearInterval(scaleInterval);
}
}, 200 / 60);
bonus.on('down', function () {
var scaleDownInterval = LK.setInterval(function () {
bonus.scale.x -= 0.1;
bonus.scale.y -= 0.1;
if (bonus.scale.x <= 0) {
LK.clearInterval(scaleDownInterval);
bonus.alpha = 0;
score += 3;
bonus.destroy();
for (var j = 0; j < 8; j++) {
var explosion = new Explosion();
explosion.x = bonus.x;
explosion.y = bonus.y;
self.addChild(explosion);
}
var bonusDelay = Math.floor(Math.random() * (15000 - 7000 + 1)) + 7000;
LK.setTimeout(createBonus, bonusDelay);
}
}, 200 / 60);
});
}
var bonusDelay = Math.floor(Math.random() * (15000 - 7000 + 1)) + 7000;
LK.setTimeout(createBonus, bonusDelay);
var paddles = [playerPaddle, aiPaddle];
var score = 0;
playerPaddle.x = 100;
playerPaddle.y = 2732 / 2;
aiPaddle.x = 2048 - 100;
aiPaddle.y = 2732 / 2;
ball.x = 2048 / 2;
ball.y = 2732 / 2;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
font: "Franklin Gothic Demi"
});
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
var dots = [];
for (var i = 0; i < 100; i++) {
var dot = new Dot();
dot.x = Math.random() * 2048;
dot.y = Math.random() * 2732;
dots.push(dot);
}
for (var i = 0; i < dots.length; i++) {
self.addChild(dots[i]);
}
var targetY = playerPaddle.y;
stage.on('down', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
targetY = pos.y;
});
stage.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
targetY = pos.y;
});
LK.on('tick', function () {
if (targetY < playerPaddle.y) {
playerPaddle.move(-1);
} else if (targetY > playerPaddle.y) {
playerPaddle.move(1);
}
});
LK.on('tick', function () {
ball.move();
if (LK.ticks % 6 == 0) {
var particle = new Particle();
particle.x = ball.x;
particle.y = ball.y;
self.addChild(particle);
}
if (bonus) {
bonus.rotate();
}
var direction = ball.y - aiPaddle.y;
direction = direction / Math.abs(direction);
aiPaddle.move(direction * 0.5);
for (var i = 0; i < paddles.length; i++) {
if (ball.intersects(paddles[i])) {
var hitPoint = ball.y - paddles[i].y;
var hitRatio = hitPoint / paddles[i].height;
ball.speed.y += hitRatio * 10;
if (ball.speed.x > 0 && ball.x < paddles[i].x || ball.speed.x < 0 && ball.x > paddles[i].x) {
ball.speed.x *= -1;
ball.rotationDirection *= -1;
for (var j = 0; j < 8; j++) {
var explosion = new Explosion();
explosion.x = paddles[i].x;
explosion.y = paddles[i].y;
self.addChild(explosion);
}
}
if (paddles[i] === playerPaddle) {
score++;
var randomColor = Math.floor(Math.random() * 16777215);
playerPaddle.children[0].tint = (randomColor & 0xF0F0F0) + ((0xFFFFFF & randomColor) >> 1);
if (bonus) {
bonus.scale.x *= 1.01;
bonus.scale.y *= 1.01;
bonus.rotationSpeed *= 1.01;
}
}
}
}
if (ball.y <= 0 || ball.y >= 2732) {
ball.speed.y *= -1;
}
if (ball.x <= 0) {
LK.showGameOver();
}
if (ball.x >= 2048) {
score++;
ball.x = 2048 / 2;
ball.y = 2732 / 2;
if (score >= 25) {
ball.speed.x = Math.random() < 0.5 ? -10 : 10;
} else {
ball.speed.x = 10;
}
ball.speed.y = Math.random() * 20 - 10;
}
scoreTxt.setText(score.toString());
if (score === 10) {
var level10Graphics = self.createAsset('level10', 'Level 10 Graphics', 0.5, 0.5);
level10Graphics.x = 2048 / 2;
level10Graphics.y = 2732 / 2;
self.addChild(level10Graphics);
var level10Time = 0;
LK.on('tick', function () {
level10Time += 1 / 60;
if (level10Time >= 1.5) {
level10Graphics.scale.x -= 0.1;
level10Graphics.scale.y -= 0.1;
level10Graphics.alpha -= 0.1;
if (level10Graphics.scale.x <= 0 || level10Graphics.alpha <= 0) {
level10Graphics.destroy();
}
}
});
}
for (var i = 0; i < dots.length; i++) {
dots[i].move();
}
for (var i = self.children.length - 1; i >= 0; i--) {
if (self.children[i] instanceof Particle) {
self.children[i].update();
}
if (self.children[i] instanceof Explosion) {
self.children[i].move();
self.children[i].fadeOut();
}
}
galaxy.rotation += galaxy.rotationSpeed;
galaxy.scale.x += galaxy.scaleFactor * galaxy.scaleDirection;
galaxy.scale.y += galaxy.scaleFactor * galaxy.scaleDirection;
if (galaxy.scale.x > 1.2 || galaxy.scale.x < 0.8) {
galaxy.scaleDirection *= -1;
}
});
});
var Level10 = Container.expand(function () {
var self = Container.call(this);
});
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.createAsset('explosion', 'Explosion Graphics', 0.5, 0.5);
self.speed = {
x: (Math.random() * 10 - 5) / 6,
y: (Math.random() * 10 - 5) / 6
};
self.move = function () {
self.x += self.speed.x;
self.y += self.speed.y;
};
self.fadeOut = function () {
self.alpha -= 0.02;
if (self.alpha <= 0) {
self.destroy();
}
};
});
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.createAsset('particle', 'Particle Graphics', 0.5, 0.5);
self.scale.set(1);
self.fadeSpeed = 1 / 150;
self.scaleSpeed = 1 / 150;
self.update = function () {
self.alpha -= self.fadeSpeed;
self.scale.x -= self.scaleSpeed;
self.scale.y -= self.scaleSpeed;
if (self.alpha <= 0) {
self.destroy();
}
};
});
var Bonus = Container.expand(function () {
var self = Container.call(this);
var bonusGraphics = self.createAsset('bonus', 'Bonus Graphics', 0.5, 0.5);
self.rotationSpeed = -0.01;
self.fadeSpeed = 0.01;
self.rotate = function () {
self.rotation += self.rotationSpeed;
};
});
var Galaxy = Container.expand(function () {
var self = Container.call(this);
self.rotationSpeed = -0.00033333;
var galaxyGraphics = self.createAsset('galaxy', 'Galaxy Graphics', 0.5, 0.5);
galaxyGraphics.scale.set(12);
self.scaleFactor = 0.0001;
self.scaleDirection = 0.8;
});
var Sun = Container.expand(function () {
var self = Container.call(this);
var sunGraphics = self.createAsset('sun', 'Sun Graphics', 0.5, 0.5);
sunGraphics.scale.set(4);
});
var Dot = Container.expand(function () {
var self = Container.call(this);
var dotGraphics = self.createAsset('dot', 'Dot Graphics', 0.5, 0.5);
dotGraphics.scale.set(Math.random() * (0.5 - 0.3) + 0.3);
var colors = [0xFFFFFF, 0xADD8E6, 0xFFFFE0, 0xEDDEA4, 0xEDDEA4];
dotGraphics.tint = colors[Math.floor(Math.random() * colors.length)];
self.speed = {
x: (Math.random() * 10 - 5) / 6,
y: (Math.random() * 10 - 5) / 6
};
self.alpha = 0;
self.fadeIn = true;
self.fadeOut = false;
self.lifeTime = 0;
self.maxLifeTime = Math.floor(Math.random() * (1200 - 300 + 1)) + 300;
self.move = function () {
self.x += self.speed.x * 0.9;
self.y += self.speed.y * 0.9;
self.lifeTime++;
if (self.fadeIn) {
self.alpha += 0.01;
if (self.alpha >= 1) {
self.fadeIn = false;
}
} else if (self.fadeOut) {
self.alpha -= 0.01;
if (self.alpha <= 0) {
self.x = Math.random() * 2048;
self.y = Math.random() * 2732;
self.alpha = 0;
self.fadeIn = true;
self.fadeOut = false;
self.lifeTime = 0;
}
} else if (self.lifeTime >= self.maxLifeTime) {
self.fadeOut = true;
}
};
});
var PlayerPaddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.createAsset('paddle', 'Player Paddle Graphics', 0.5, 0.5);
paddleGraphics.tint = 0xffffff;
self.speed = 20;
self.move = function (direction) {
self.y += direction * self.speed;
};
});
var AIPaddle = Container.expand(function () {
var self = Container.call(this);
var paddleGraphics = self.createAsset('paddle', 'AI Paddle Graphics', 0.5, 0.5);
paddleGraphics.tint = 0xE63946;
self.speed = 20;
self.move = function (direction) {
self.y += direction * self.speed;
};
});
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.createAsset('ball', 'Ball Graphics', 0.5, 0.5);
self.speed = {
x: 10,
y: 10
};
self.rotationSpeed = 0.01;
self.rotationDirection = 1;
self.move = function () {
self.x += self.speed.x;
self.y += self.speed.y;
self.rotation += self.rotationSpeed * self.rotationDirection;
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var galaxy = self.addChild(new Galaxy());
galaxy.x = 2048 / 2;
galaxy.y = 2732 / 2;
var sun = self.addChild(new Sun());
sun.x = 2048 / 2;
sun.y = 130;
var playerPaddle = self.addChildAt(new PlayerPaddle(), self.children.length);
var aiPaddle = self.addChildAt(new AIPaddle(), self.children.length);
var ball = self.addChildAt(new Ball(), self.children.length);
var bonus;
function createBonus() {
bonus = self.addChildAt(new Bonus(), self.children.length);
bonus.x = (Math.random() * 0.2 + 0.4) * 2048;
bonus.y = (Math.random() * 0.2 + 0.4) * 2732;
bonus.scale.set(0.01);
var scaleInterval = LK.setInterval(function () {
bonus.scale.x += 0.03;
bonus.scale.y += 0.03;
if (bonus.scale.x >= 1) {
LK.clearInterval(scaleInterval);
}
}, 200 / 60);
bonus.on('down', function () {
var scaleDownInterval = LK.setInterval(function () {
bonus.scale.x -= 0.1;
bonus.scale.y -= 0.1;
if (bonus.scale.x <= 0) {
LK.clearInterval(scaleDownInterval);
bonus.alpha = 0;
score += 3;
bonus.destroy();
for (var j = 0; j < 8; j++) {
var explosion = new Explosion();
explosion.x = bonus.x;
explosion.y = bonus.y;
self.addChild(explosion);
}
var bonusDelay = Math.floor(Math.random() * (15000 - 7000 + 1)) + 7000;
LK.setTimeout(createBonus, bonusDelay);
}
}, 200 / 60);
});
}
var bonusDelay = Math.floor(Math.random() * (15000 - 7000 + 1)) + 7000;
LK.setTimeout(createBonus, bonusDelay);
var paddles = [playerPaddle, aiPaddle];
var score = 0;
playerPaddle.x = 100;
playerPaddle.y = 2732 / 2;
aiPaddle.x = 2048 - 100;
aiPaddle.y = 2732 / 2;
ball.x = 2048 / 2;
ball.y = 2732 / 2;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff",
font: "Franklin Gothic Demi"
});
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
var dots = [];
for (var i = 0; i < 100; i++) {
var dot = new Dot();
dot.x = Math.random() * 2048;
dot.y = Math.random() * 2732;
dots.push(dot);
}
for (var i = 0; i < dots.length; i++) {
self.addChild(dots[i]);
}
var targetY = playerPaddle.y;
stage.on('down', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
targetY = pos.y;
});
stage.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
targetY = pos.y;
});
LK.on('tick', function () {
if (targetY < playerPaddle.y) {
playerPaddle.move(-1);
} else if (targetY > playerPaddle.y) {
playerPaddle.move(1);
}
});
LK.on('tick', function () {
ball.move();
if (LK.ticks % 6 == 0) {
var particle = new Particle();
particle.x = ball.x;
particle.y = ball.y;
self.addChild(particle);
}
if (bonus) {
bonus.rotate();
}
var direction = ball.y - aiPaddle.y;
direction = direction / Math.abs(direction);
aiPaddle.move(direction * 0.5);
for (var i = 0; i < paddles.length; i++) {
if (ball.intersects(paddles[i])) {
var hitPoint = ball.y - paddles[i].y;
var hitRatio = hitPoint / paddles[i].height;
ball.speed.y += hitRatio * 10;
if (ball.speed.x > 0 && ball.x < paddles[i].x || ball.speed.x < 0 && ball.x > paddles[i].x) {
ball.speed.x *= -1;
ball.rotationDirection *= -1;
for (var j = 0; j < 8; j++) {
var explosion = new Explosion();
explosion.x = paddles[i].x;
explosion.y = paddles[i].y;
self.addChild(explosion);
}
}
if (paddles[i] === playerPaddle) {
score++;
var randomColor = Math.floor(Math.random() * 16777215);
playerPaddle.children[0].tint = (randomColor & 0xF0F0F0) + ((0xFFFFFF & randomColor) >> 1);
if (bonus) {
bonus.scale.x *= 1.01;
bonus.scale.y *= 1.01;
bonus.rotationSpeed *= 1.01;
}
}
}
}
if (ball.y <= 0 || ball.y >= 2732) {
ball.speed.y *= -1;
}
if (ball.x <= 0) {
LK.showGameOver();
}
if (ball.x >= 2048) {
score++;
ball.x = 2048 / 2;
ball.y = 2732 / 2;
if (score >= 25) {
ball.speed.x = Math.random() < 0.5 ? -10 : 10;
} else {
ball.speed.x = 10;
}
ball.speed.y = Math.random() * 20 - 10;
}
scoreTxt.setText(score.toString());
if (score === 10) {
var level10Graphics = self.createAsset('level10', 'Level 10 Graphics', 0.5, 0.5);
level10Graphics.x = 2048 / 2;
level10Graphics.y = 2732 / 2;
self.addChild(level10Graphics);
var level10Time = 0;
LK.on('tick', function () {
level10Time += 1 / 60;
if (level10Time >= 1.5) {
level10Graphics.scale.x -= 0.1;
level10Graphics.scale.y -= 0.1;
level10Graphics.alpha -= 0.1;
if (level10Graphics.scale.x <= 0 || level10Graphics.alpha <= 0) {
level10Graphics.destroy();
}
}
});
}
for (var i = 0; i < dots.length; i++) {
dots[i].move();
}
for (var i = self.children.length - 1; i >= 0; i--) {
if (self.children[i] instanceof Particle) {
self.children[i].update();
}
if (self.children[i] instanceof Explosion) {
self.children[i].move();
self.children[i].fadeOut();
}
}
galaxy.rotation += galaxy.rotationSpeed;
galaxy.scale.x += galaxy.scaleFactor * galaxy.scaleDirection;
galaxy.scale.y += galaxy.scaleFactor * galaxy.scaleDirection;
if (galaxy.scale.x > 1.2 || galaxy.scale.x < 0.8) {
galaxy.scaleDirection *= -1;
}
});
});
2d earth Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white star, no background, pixelart Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Galaxy pixelart in black background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixelart of a tall and thin spaceship, no background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
sun pixelart Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white circle, no background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
3 yellow sparkles, pixelart, no background Single Game Texture. In-Game asset. 2d. High contrast. No shadows.
simple black circle no background Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Green microchip pixelart Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
number 10, golden color, pixelart Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.