/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Ball = Container.expand(function () { var self = Container.call(this); var ballGraphics = self.attachAsset('ball', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.isMoving = false; self.update = function () { if (self.isMoving) { self.x += self.velocityX; self.y += self.velocityY; // Apply gravity self.velocityY += 0.5; // Check if ball hits ground - stop completely, no bouncing if (self.y >= grassY - 30) { self.isMoving = false; self.velocityX = 0; self.velocityY = 0; self.y = grassY - 50; ballStopped(); } } }; self.kick = function (power, angle) { self.isMoving = true; var speed = power * 40; self.velocityX = Math.cos(angle) * speed; self.velocityY = Math.sin(angle) * speed; LK.getSound('kick').play(); }; return self; }); var Goalkeeper = Container.expand(function () { var self = Container.call(this); var keeperGraphics = self.attachAsset('goalkeeper', { anchorX: 0.5, anchorY: 1.0 }); self.direction = 1; self.speed = 2; self.minX = goalCenterX - 180; self.maxX = goalCenterX + 180; self.isDiving = false; self.update = function () { if (!self.isDiving) { self.x += self.direction * self.speed; if (self.x <= self.minX || self.x >= self.maxX) { self.direction *= -1; } } }; self.dive = function (ballX) { if (self.isDiving) { return; } self.isDiving = true; var targetX = ballX; // Clamp target to goal bounds if (targetX < self.minX) { targetX = self.minX; } if (targetX > self.maxX) { targetX = self.maxX; } tween(self, { x: targetX }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { LK.setTimeout(function () { self.isDiving = false; }, 1000); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228B22 }); /**** * Game Code ****/ // Game constants var goalCenterX = 1024; var goalCenterY = 400; var grassY = 2200; var penaltySpotX = 1024; var penaltySpotY = 800; // Game state var gameState = 'aiming'; // 'aiming', 'charging', 'kicked', 'result' var aimAngle = -Math.PI / 2; // Start aiming straight up var power = 0; var powerDirection = 1; var goals = 0; var misses = 0; var maxMisses = 3; // Create grass field var grass = game.addChild(LK.getAsset('grass', { anchorX: 0.5, anchorY: 1.0, x: 1024, y: grassY })); // Create goal posts var leftPost = game.addChild(LK.getAsset('goalpost', { anchorX: 0.5, anchorY: 1.0, x: goalCenterX - 200, y: goalCenterY + 200 })); var rightPost = game.addChild(LK.getAsset('goalpost', { anchorX: 0.5, anchorY: 1.0, x: goalCenterX + 200, y: goalCenterY + 200 })); var crossbar = game.addChild(LK.getAsset('crossbar', { anchorX: 0.5, anchorY: 0.5, x: goalCenterX, y: goalCenterY })); // Create penalty spot var penaltySpot = game.addChild(LK.getAsset('penaltySpot', { anchorX: 0.5, anchorY: 0.5, x: penaltySpotX, y: penaltySpotY })); // Create ball var ball = game.addChild(new Ball()); resetBallPosition(); // Create goalkeeper var goalkeeper = game.addChild(new Goalkeeper()); goalkeeper.x = goalCenterX; goalkeeper.y = goalCenterY + 200; // Create aim line (initially hidden) var aimLine = game.addChild(LK.getAsset('aimLine', { anchorX: 0.5, anchorY: 1.0, x: penaltySpotX, y: penaltySpotY, alpha: 0 })); // Create power bar (initially hidden) var powerBar = game.addChild(LK.getAsset('powerBar', { anchorX: 0.5, anchorY: 1.0, x: 200, y: 1000, alpha: 0, scaleY: 0 })); // UI Elements var scoreText = new Text2('Goals: 0', { size: 80, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); var missesText = new Text2('Misses: 0/3', { size: 60, fill: 0xFFFFFF }); missesText.anchor.set(1.0, 0); LK.gui.topRight.addChild(missesText); var instructionText = new Text2('Tap and hold to aim and charge power', { size: 50, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 1.0); LK.gui.bottom.addChild(instructionText); // Game functions function resetBallPosition() { ball.x = penaltySpotX; ball.y = penaltySpotY - 30; ball.isMoving = false; ball.velocityX = 0; ball.velocityY = 0; } function updateAimLine() { var lineLength = 150; var endX = ball.x + Math.cos(aimAngle) * lineLength; var endY = ball.y + Math.sin(aimAngle) * lineLength; aimLine.x = ball.x; aimLine.y = ball.y; aimLine.rotation = aimAngle + Math.PI / 2; } function updatePowerBar() { powerBar.scaleY = power; var colorValue = Math.floor(power * 255); powerBar.tint = colorValue << 16 | 255 - colorValue << 8; } function ballStopped() { // Check if goal was scored if (ball.x > goalCenterX - 200 && ball.x < goalCenterX + 200 && ball.y < goalCenterY + 200 && ball.y > goalCenterY - 50) { // Goal scored goals++; scoreText.setText('Goals: ' + goals); LK.setScore(goals); LK.getSound('goal').play(); // Flash screen green LK.effects.flashScreen(0x00ff00, 500); // Increase goalkeeper speed slightly goalkeeper.speed = Math.min(goalkeeper.speed + 0.2, 6); } else { // Missed misses++; missesText.setText('Misses: ' + misses + '/' + maxMisses); if (misses >= maxMisses) { LK.showGameOver(); return; } } // Reset for next shot LK.setTimeout(function () { resetBallPosition(); gameState = 'aiming'; instructionText.setText('Tap and hold to aim and charge power'); }, 1500); } function checkGoalkeeperSave() { if (ball.isMoving && ball.y < goalCenterY + 150 && ball.y > goalCenterY - 50) { var distanceToKeeper = Math.abs(ball.x - goalkeeper.x); if (distanceToKeeper < 60) { // Goalkeeper save ball.isMoving = false; ball.velocityX = 0; ball.velocityY = 0; LK.getSound('save').play(); // Flash screen red LK.effects.flashScreen(0xff0000, 500); ballStopped(); } } } // Touch/mouse input handling game.down = function (x, y, obj) { if (gameState === 'aiming') { gameState = 'charging'; power = 0; powerDirection = 1; // Show UI elements aimLine.alpha = 1; powerBar.alpha = 1; instructionText.setText('Release to kick!'); } }; game.move = function (x, y, obj) { if (gameState === 'charging') { // Update aim angle based on touch position relative to ball var dx = x - ball.x; var dy = y - ball.y; aimAngle = Math.atan2(dy, dx); // Limit aim angle to reasonable shooting range aimAngle = Math.max(aimAngle, -Math.PI * 0.8); aimAngle = Math.min(aimAngle, -Math.PI * 0.2); updateAimLine(); } }; game.up = function (x, y, obj) { if (gameState === 'charging') { gameState = 'kicked'; // Hide UI elements aimLine.alpha = 0; powerBar.alpha = 0; // Kick the ball ball.kick(power, aimAngle); // Make goalkeeper dive goalkeeper.dive(ball.x + Math.cos(aimAngle) * 200); instructionText.setText(''); } }; // Main game loop game.update = function () { if (gameState === 'charging') { // Update power power += powerDirection * 0.03; if (power >= 1) { power = 1; powerDirection = -1; } else if (power <= 0) { power = 0; powerDirection = 1; } updatePowerBar(); } if (gameState === 'kicked' && ball.isMoving) { checkGoalkeeperSave(); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Ball = Container.expand(function () {
var self = Container.call(this);
var ballGraphics = self.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.isMoving = false;
self.update = function () {
if (self.isMoving) {
self.x += self.velocityX;
self.y += self.velocityY;
// Apply gravity
self.velocityY += 0.5;
// Check if ball hits ground - stop completely, no bouncing
if (self.y >= grassY - 30) {
self.isMoving = false;
self.velocityX = 0;
self.velocityY = 0;
self.y = grassY - 50;
ballStopped();
}
}
};
self.kick = function (power, angle) {
self.isMoving = true;
var speed = power * 40;
self.velocityX = Math.cos(angle) * speed;
self.velocityY = Math.sin(angle) * speed;
LK.getSound('kick').play();
};
return self;
});
var Goalkeeper = Container.expand(function () {
var self = Container.call(this);
var keeperGraphics = self.attachAsset('goalkeeper', {
anchorX: 0.5,
anchorY: 1.0
});
self.direction = 1;
self.speed = 2;
self.minX = goalCenterX - 180;
self.maxX = goalCenterX + 180;
self.isDiving = false;
self.update = function () {
if (!self.isDiving) {
self.x += self.direction * self.speed;
if (self.x <= self.minX || self.x >= self.maxX) {
self.direction *= -1;
}
}
};
self.dive = function (ballX) {
if (self.isDiving) {
return;
}
self.isDiving = true;
var targetX = ballX;
// Clamp target to goal bounds
if (targetX < self.minX) {
targetX = self.minX;
}
if (targetX > self.maxX) {
targetX = self.maxX;
}
tween(self, {
x: targetX
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
LK.setTimeout(function () {
self.isDiving = false;
}, 1000);
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x228B22
});
/****
* Game Code
****/
// Game constants
var goalCenterX = 1024;
var goalCenterY = 400;
var grassY = 2200;
var penaltySpotX = 1024;
var penaltySpotY = 800;
// Game state
var gameState = 'aiming'; // 'aiming', 'charging', 'kicked', 'result'
var aimAngle = -Math.PI / 2; // Start aiming straight up
var power = 0;
var powerDirection = 1;
var goals = 0;
var misses = 0;
var maxMisses = 3;
// Create grass field
var grass = game.addChild(LK.getAsset('grass', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: grassY
}));
// Create goal posts
var leftPost = game.addChild(LK.getAsset('goalpost', {
anchorX: 0.5,
anchorY: 1.0,
x: goalCenterX - 200,
y: goalCenterY + 200
}));
var rightPost = game.addChild(LK.getAsset('goalpost', {
anchorX: 0.5,
anchorY: 1.0,
x: goalCenterX + 200,
y: goalCenterY + 200
}));
var crossbar = game.addChild(LK.getAsset('crossbar', {
anchorX: 0.5,
anchorY: 0.5,
x: goalCenterX,
y: goalCenterY
}));
// Create penalty spot
var penaltySpot = game.addChild(LK.getAsset('penaltySpot', {
anchorX: 0.5,
anchorY: 0.5,
x: penaltySpotX,
y: penaltySpotY
}));
// Create ball
var ball = game.addChild(new Ball());
resetBallPosition();
// Create goalkeeper
var goalkeeper = game.addChild(new Goalkeeper());
goalkeeper.x = goalCenterX;
goalkeeper.y = goalCenterY + 200;
// Create aim line (initially hidden)
var aimLine = game.addChild(LK.getAsset('aimLine', {
anchorX: 0.5,
anchorY: 1.0,
x: penaltySpotX,
y: penaltySpotY,
alpha: 0
}));
// Create power bar (initially hidden)
var powerBar = game.addChild(LK.getAsset('powerBar', {
anchorX: 0.5,
anchorY: 1.0,
x: 200,
y: 1000,
alpha: 0,
scaleY: 0
}));
// UI Elements
var scoreText = new Text2('Goals: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var missesText = new Text2('Misses: 0/3', {
size: 60,
fill: 0xFFFFFF
});
missesText.anchor.set(1.0, 0);
LK.gui.topRight.addChild(missesText);
var instructionText = new Text2('Tap and hold to aim and charge power', {
size: 50,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 1.0);
LK.gui.bottom.addChild(instructionText);
// Game functions
function resetBallPosition() {
ball.x = penaltySpotX;
ball.y = penaltySpotY - 30;
ball.isMoving = false;
ball.velocityX = 0;
ball.velocityY = 0;
}
function updateAimLine() {
var lineLength = 150;
var endX = ball.x + Math.cos(aimAngle) * lineLength;
var endY = ball.y + Math.sin(aimAngle) * lineLength;
aimLine.x = ball.x;
aimLine.y = ball.y;
aimLine.rotation = aimAngle + Math.PI / 2;
}
function updatePowerBar() {
powerBar.scaleY = power;
var colorValue = Math.floor(power * 255);
powerBar.tint = colorValue << 16 | 255 - colorValue << 8;
}
function ballStopped() {
// Check if goal was scored
if (ball.x > goalCenterX - 200 && ball.x < goalCenterX + 200 && ball.y < goalCenterY + 200 && ball.y > goalCenterY - 50) {
// Goal scored
goals++;
scoreText.setText('Goals: ' + goals);
LK.setScore(goals);
LK.getSound('goal').play();
// Flash screen green
LK.effects.flashScreen(0x00ff00, 500);
// Increase goalkeeper speed slightly
goalkeeper.speed = Math.min(goalkeeper.speed + 0.2, 6);
} else {
// Missed
misses++;
missesText.setText('Misses: ' + misses + '/' + maxMisses);
if (misses >= maxMisses) {
LK.showGameOver();
return;
}
}
// Reset for next shot
LK.setTimeout(function () {
resetBallPosition();
gameState = 'aiming';
instructionText.setText('Tap and hold to aim and charge power');
}, 1500);
}
function checkGoalkeeperSave() {
if (ball.isMoving && ball.y < goalCenterY + 150 && ball.y > goalCenterY - 50) {
var distanceToKeeper = Math.abs(ball.x - goalkeeper.x);
if (distanceToKeeper < 60) {
// Goalkeeper save
ball.isMoving = false;
ball.velocityX = 0;
ball.velocityY = 0;
LK.getSound('save').play();
// Flash screen red
LK.effects.flashScreen(0xff0000, 500);
ballStopped();
}
}
}
// Touch/mouse input handling
game.down = function (x, y, obj) {
if (gameState === 'aiming') {
gameState = 'charging';
power = 0;
powerDirection = 1;
// Show UI elements
aimLine.alpha = 1;
powerBar.alpha = 1;
instructionText.setText('Release to kick!');
}
};
game.move = function (x, y, obj) {
if (gameState === 'charging') {
// Update aim angle based on touch position relative to ball
var dx = x - ball.x;
var dy = y - ball.y;
aimAngle = Math.atan2(dy, dx);
// Limit aim angle to reasonable shooting range
aimAngle = Math.max(aimAngle, -Math.PI * 0.8);
aimAngle = Math.min(aimAngle, -Math.PI * 0.2);
updateAimLine();
}
};
game.up = function (x, y, obj) {
if (gameState === 'charging') {
gameState = 'kicked';
// Hide UI elements
aimLine.alpha = 0;
powerBar.alpha = 0;
// Kick the ball
ball.kick(power, aimAngle);
// Make goalkeeper dive
goalkeeper.dive(ball.x + Math.cos(aimAngle) * 200);
instructionText.setText('');
}
};
// Main game loop
game.update = function () {
if (gameState === 'charging') {
// Update power
power += powerDirection * 0.03;
if (power >= 1) {
power = 1;
powerDirection = -1;
} else if (power <= 0) {
power = 0;
powerDirection = 1;
}
updatePowerBar();
}
if (gameState === 'kicked' && ball.isMoving) {
checkGoalkeeperSave();
}
};
kalecinin elinde top olmasın penaltıda duran kaleci. In-Game asset. 2d. High contrast. No shadows
futbol topu. In-Game asset. 2d. High contrast. No shadows
futbol sahası, penaltı noktası, gerçek çim görseli. In-Game asset. 2d. High contrast. No shadows
yukarı gösteren ince çubuk gibi ok. In-Game asset. 2d. High contrast. No shadows