/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Ball class to represent the football var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = 0; self.speedY = 0; self.update = function () { self.x += self.speedX; self.y += self.speedY; // Dampen speed to simulate friction self.speedX *= 0.98; self.speedY *= 0.98; // Make the ball bounce when it hits the left or right edge of the screen if (self.x < 0 || self.x > 2048) { self.speedX *= -1; LK.getSound('vurma_sesi').play(); } }; }); // Goal class to represent the goal area var Goal = Container.expand(function () { var self = Container.call(this); var goalGraphics = self.attachAsset('goal', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var fieldLines = game.addChild(LK.getAsset('fieldLines', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); // Initialize game elements var field = game.addChild(LK.getAsset('field', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); // Initialize score var score = 0; // Initialize score text var scoreTxt = new Text2('Score: ' + score, { size: 50, fill: 0xFFFFFF }); LK.gui.center.addChild(scoreTxt); var ball = game.addChild(new Ball()); ball.x = 1024; // Center horizontally ball.y = 2000; // Position near the bottom var goalNorth = game.addChild(new Goal()); goalNorth.x = 1024; // Center horizontally goalNorth.y = 200; // Position near the top var goalSouth = game.addChild(new Goal()); goalSouth.x = 1024; // Center horizontally goalSouth.y = 2532; // Position near the bottom // Handle game interactions game.down = function (x, y, obj) { var localPos = game.toLocal(obj.global); var dx = localPos.x - ball.x; var dy = localPos.y - ball.y; var distance = Math.sqrt(dx * dx + dy * dy); // If the touch is close to the ball, kick it if (distance < 100) { ball.speedX = dx * 0.1; // Decrease the multiplier to make the ball move slower ball.speedY = dy * 0.1; // Decrease the multiplier to make the ball move slower } LK.getSound('vurma_sesi').play(); // Set the ball's speed to move in the direction of the mouse click ball.speedX = (localPos.x - ball.x) * 0.1; ball.speedY = (localPos.y - ball.y) * 0.1; }; // Update game state game.update = function () { ball.update(); // Check if the ball is in the goal if (ball.intersects(goalNorth) || ball.intersects(goalSouth)) { score += 1; scoreTxt.setText('Score: ' + score); // Reset ball position ball.x = 1024; ball.y = 2000; ball.speedX = 0; ball.speedY = 0; } // Check if the ball is off the screen if (ball.y < 0 || ball.y > 2732) { // Reset ball position ball.x = 1024; ball.y = 2000; ball.speedX = 0; ball.speedY = 0; } }; // Play the 'arkaplan' music asset in the background LK.playMusic('arkaplan');
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Ball class to represent the football
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
// Dampen speed to simulate friction
self.speedX *= 0.98;
self.speedY *= 0.98;
// Make the ball bounce when it hits the left or right edge of the screen
if (self.x < 0 || self.x > 2048) {
self.speedX *= -1;
LK.getSound('vurma_sesi').play();
}
};
});
// Goal class to represent the goal area
var Goal = Container.expand(function () {
var self = Container.call(this);
var goalGraphics = self.attachAsset('goal', {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var fieldLines = game.addChild(LK.getAsset('fieldLines', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Initialize game elements
var field = game.addChild(LK.getAsset('field', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Initialize score
var score = 0;
// Initialize score text
var scoreTxt = new Text2('Score: ' + score, {
size: 50,
fill: 0xFFFFFF
});
LK.gui.center.addChild(scoreTxt);
var ball = game.addChild(new Ball());
ball.x = 1024; // Center horizontally
ball.y = 2000; // Position near the bottom
var goalNorth = game.addChild(new Goal());
goalNorth.x = 1024; // Center horizontally
goalNorth.y = 200; // Position near the top
var goalSouth = game.addChild(new Goal());
goalSouth.x = 1024; // Center horizontally
goalSouth.y = 2532; // Position near the bottom
// Handle game interactions
game.down = function (x, y, obj) {
var localPos = game.toLocal(obj.global);
var dx = localPos.x - ball.x;
var dy = localPos.y - ball.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// If the touch is close to the ball, kick it
if (distance < 100) {
ball.speedX = dx * 0.1; // Decrease the multiplier to make the ball move slower
ball.speedY = dy * 0.1; // Decrease the multiplier to make the ball move slower
}
LK.getSound('vurma_sesi').play();
// Set the ball's speed to move in the direction of the mouse click
ball.speedX = (localPos.x - ball.x) * 0.1;
ball.speedY = (localPos.y - ball.y) * 0.1;
};
// Update game state
game.update = function () {
ball.update();
// Check if the ball is in the goal
if (ball.intersects(goalNorth) || ball.intersects(goalSouth)) {
score += 1;
scoreTxt.setText('Score: ' + score);
// Reset ball position
ball.x = 1024;
ball.y = 2000;
ball.speedX = 0;
ball.speedY = 0;
}
// Check if the ball is off the screen
if (ball.y < 0 || ball.y > 2732) {
// Reset ball position
ball.x = 1024;
ball.y = 2000;
ball.speedX = 0;
ball.speedY = 0;
}
};
// Play the 'arkaplan' music asset in the background
LK.playMusic('arkaplan');