var Footballer = Container.expand(function () { var self = Container.call(this); var footballerGraphics = self.createAsset('footballer', 'Player Footballer', .5, 1); footballerGraphics.scale.set(2); self.move = function (position) { self.x = position.x; }; }); var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.createAsset('ball', 'Juggling Ball', .5, .5); self.speedY = -5; self.speedModifier = 0; self.move = function () { self.x += self.speedX; self.y += self.speedY; self.speedY += 0.98 + LK.ticks / 50000; if (self.y >= 2732 - self.height / 2) { self.y = 2732 - self.height / 2; self.speedY = -60; } if (self.x <= 0) { self.x = 0; self.speedX *= -1; } if (self.x >= 2048 - self.width) { self.x = 2048 - self.width; self.speedX *= -1; } if (self.y < 0) { self.speedY *= -0.5; } }; self.bounce = function (speedX, speedY) { self.speedX = speedX; var difficultyMultiplier = 1 + Math.floor(score / 5) * 0.1; self.speedY = (speedY * (5.4 + difficultyMultiplier) + LK.ticks / 1800) * (1 + LK.ticks / 50000); }; }); var Game = Container.expand(function () { var self = Container.call(this); var ball = self.addChild(new Ball()); ball.x = 2048 / 2; ball.y = 2732 / 2; var footballer = self.addChild(new Footballer()); footballer.x = 2048 / 2; footballer.y = 2732 - footballer.height / 2; stage.on('move', function (obj) { var event = obj.event; var pos = event.getLocalPosition(self); footballer.move(pos); }); var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(.5, 0); LK.gui.topCenter.addChild(scoreTxt); var isGameOver = false; ball.on('down', function (obj) { var kickStrengthX = 0; var kickStrengthY = -20; ball.bounce(kickStrengthX, kickStrengthY); score++; scoreTxt.setText(score); }); LK.on('tick', function () { ball.move(); if (ball.intersects(footballer) && ball.speedY > 0) { var relativeIntersectX = ball.x + ball.width / 2 - (footballer.x + footballer.width / 2); var normalizedRelativeIntersectionX = 2 * relativeIntersectX / footballer.width; var bounceAngle = normalizedRelativeIntersectionX * Math.PI / 4; ball.speedY = -60 * Math.cos(bounceAngle); ball.speedX = 60 * Math.sin(bounceAngle); score++; scoreTxt.setText(score); } if (ball.y >= 2732 - ball.height / 2) { isGameOver = true; } if (isGameOver) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); });
var Footballer = Container.expand(function () {
var self = Container.call(this);
var footballerGraphics = self.createAsset('footballer', 'Player Footballer', .5, 1);
footballerGraphics.scale.set(2);
self.move = function (position) {
self.x = position.x;
};
});
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.createAsset('ball', 'Juggling Ball', .5, .5);
self.speedY = -5;
self.speedModifier = 0;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
self.speedY += 0.98 + LK.ticks / 50000;
if (self.y >= 2732 - self.height / 2) {
self.y = 2732 - self.height / 2;
self.speedY = -60;
}
if (self.x <= 0) {
self.x = 0;
self.speedX *= -1;
}
if (self.x >= 2048 - self.width) {
self.x = 2048 - self.width;
self.speedX *= -1;
}
if (self.y < 0) {
self.speedY *= -0.5;
}
};
self.bounce = function (speedX, speedY) {
self.speedX = speedX;
var difficultyMultiplier = 1 + Math.floor(score / 5) * 0.1;
self.speedY = (speedY * (5.4 + difficultyMultiplier) + LK.ticks / 1800) * (1 + LK.ticks / 50000);
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var ball = self.addChild(new Ball());
ball.x = 2048 / 2;
ball.y = 2732 / 2;
var footballer = self.addChild(new Footballer());
footballer.x = 2048 / 2;
footballer.y = 2732 - footballer.height / 2;
stage.on('move', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(self);
footballer.move(pos);
});
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(.5, 0);
LK.gui.topCenter.addChild(scoreTxt);
var isGameOver = false;
ball.on('down', function (obj) {
var kickStrengthX = 0;
var kickStrengthY = -20;
ball.bounce(kickStrengthX, kickStrengthY);
score++;
scoreTxt.setText(score);
});
LK.on('tick', function () {
ball.move();
if (ball.intersects(footballer) && ball.speedY > 0) {
var relativeIntersectX = ball.x + ball.width / 2 - (footballer.x + footballer.width / 2);
var normalizedRelativeIntersectionX = 2 * relativeIntersectX / footballer.width;
var bounceAngle = normalizedRelativeIntersectionX * Math.PI / 4;
ball.speedY = -60 * Math.cos(bounceAngle);
ball.speedX = 60 * Math.sin(bounceAngle);
score++;
scoreTxt.setText(score);
}
if (ball.y >= 2732 - ball.height / 2) {
isGameOver = true;
}
if (isGameOver) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
});