/**** * 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.gravity = 0.3; self.isMoving = false; self.startX = 0; self.startY = 0; self.reset = function () { self.x = self.startX; self.y = self.startY; self.velocityX = 0; self.velocityY = 0; self.isMoving = false; ballGraphics.alpha = 1; }; self.shoot = function (powerX, powerY) { self.velocityX = powerX * 0.8; self.velocityY = powerY * 0.8; self.isMoving = true; LK.getSound('kick').play(); }; self.update = function () { if (self.isMoving) { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; // Ball physics - slow down over time self.velocityX *= 0.99; } }; return self; }); var Footballer = Container.expand(function () { var self = Container.call(this); var footballerGraphics = self.attachAsset('footballer', { anchorX: 0.5, anchorY: 1 }); self.isKicking = false; self.performKick = function () { if (self.isKicking) { return; } self.isKicking = true; // Kick animation - lean forward and back tween(footballerGraphics, { scaleX: 1.2, rotation: 0.2 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(footballerGraphics, { scaleX: 1.0, rotation: 0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { self.isKicking = false; } }); } }); }; self.celebrate = function () { // Play celebration shout sound LK.getSound('celebration').play(); // Choose random celebration type var celebrationType = Math.floor(Math.random() * 6); if (celebrationType === 0) { // Celebration 1: Spin around with scale change tween(footballerGraphics, { rotation: Math.PI * 4, scaleX: 1.5, scaleY: 1.5 }, { duration: 1200, easing: tween.easeInOut, onFinish: function onFinish() { tween(footballerGraphics, { rotation: 0, scaleX: 1.0, scaleY: 1.0 }, { duration: 300, easing: tween.easeOut }); } }); } else if (celebrationType === 1) { // Celebration 2: Jump up and down tween(footballerGraphics, { y: footballerGraphics.y - 100, scaleY: 1.3 }, { duration: 400, easing: tween.easeOut, onFinish: function onFinish() { tween(footballerGraphics, { y: footballerGraphics.y + 100, scaleY: 1.0 }, { duration: 400, easing: tween.bounceOut, onFinish: function onFinish() { // Second jump tween(footballerGraphics, { y: footballerGraphics.y - 80, scaleY: 1.2 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { tween(footballerGraphics, { y: footballerGraphics.y + 80, scaleY: 1.0 }, { duration: 300, easing: tween.bounceOut }); } }); } }); } }); } else if (celebrationType === 2) { // Celebration 3: Side to side dance var originalX = footballerGraphics.x; tween(footballerGraphics, { x: originalX + 50, rotation: 0.3, scaleX: 1.2 }, { duration: 200, easing: tween.easeInOut, onFinish: function onFinish() { tween(footballerGraphics, { x: originalX - 50, rotation: -0.3 }, { duration: 300, easing: tween.easeInOut, onFinish: function onFinish() { tween(footballerGraphics, { x: originalX + 30, rotation: 0.2 }, { duration: 200, easing: tween.easeInOut, onFinish: function onFinish() { tween(footballerGraphics, { x: originalX, rotation: 0, scaleX: 1.0 }, { duration: 300, easing: tween.easeOut }); } }); } }); } }); } else if (celebrationType === 3) { // Celebration 4: Pumping fists (scale animation) tween(footballerGraphics, { scaleX: 1.4, scaleY: 0.8, rotation: 0.1 }, { duration: 150, easing: tween.easeOut, onFinish: function onFinish() { tween(footballerGraphics, { scaleX: 0.8, scaleY: 1.4, rotation: -0.1 }, { duration: 150, easing: tween.easeOut, onFinish: function onFinish() { tween(footballerGraphics, { scaleX: 1.3, scaleY: 0.9, rotation: 0.05 }, { duration: 150, easing: tween.easeOut, onFinish: function onFinish() { tween(footballerGraphics, { scaleX: 1.0, scaleY: 1.0, rotation: 0 }, { duration: 200, easing: tween.easeOut }); } }); } }); } }); } else if (celebrationType === 4) { // Celebration 5: Backflip sequence tween(footballerGraphics, { rotation: Math.PI * 2, y: footballerGraphics.y - 150, scaleX: 1.3, scaleY: 1.3 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { tween(footballerGraphics, { rotation: 0, y: footballerGraphics.y + 150, scaleX: 1.0, scaleY: 1.0 }, { duration: 400, easing: tween.bounceOut }); } }); } else { // Celebration 6: Victory arms up with shake var originalY = footballerGraphics.y; tween(footballerGraphics, { scaleY: 1.4, y: originalY - 30, rotation: 0.2 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(footballerGraphics, { rotation: -0.2 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(footballerGraphics, { rotation: 0.15 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(footballerGraphics, { rotation: -0.15 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(footballerGraphics, { rotation: 0, scaleY: 1.0, y: originalY }, { duration: 300, easing: tween.easeOut }); } }); } }); } }); } }); } }; return self; }); var Goalkeeper = Container.expand(function () { var self = Container.call(this); var keeperGraphics = self.attachAsset('goalkeeper', { anchorX: 0.5, anchorY: 1 }); self.homeX = 0; self.homeY = 0; self.targetX = 0; self.speed = 3; self.reactionTime = 0; self.isReacting = false; self.setHome = function (x, y) { self.homeX = x; self.homeY = y; self.x = x; self.y = y; self.targetX = x; }; self.reactToBall = function (ballX, ballY) { if (!self.isReacting && self.reactionTime <= 0) { self.isReacting = true; self.reactionTime = 30; // Reaction delay // Predict where ball will be if (ballX < self.homeX - 50) { self.targetX = self.homeX - 150; } else if (ballX > self.homeX + 50) { self.targetX = self.homeX + 150; } } }; self.returnHome = function () { self.targetX = self.homeX; self.isReacting = false; self.reactionTime = 60; // Cooldown before next reaction }; self.update = function () { if (self.reactionTime > 0) { self.reactionTime--; } // Move towards target var dx = self.targetX - self.x; if (Math.abs(dx) > self.speed) { self.x += dx > 0 ? self.speed : -self.speed; } else { self.x = self.targetX; } }; return self; }); var HeartSymbol = Container.expand(function () { var self = Container.call(this); // Create heart shape using heart image var heartBase = self.attachAsset('heart', { anchorX: 0.5, anchorY: 0.5 }); self.setVisible = function (visible) { self.alpha = visible ? 1 : 0.3; }; return self; }); var TargetZone = Container.expand(function () { var self = Container.call(this); var zoneGraphics = self.attachAsset('targetZone', { anchorX: 0.5, anchorY: 0.5 }); zoneGraphics.alpha = 0.3; self.points = 1; self.isActive = false; self.activate = function () { self.isActive = true; zoneGraphics.alpha = 0.6; tween(zoneGraphics, { alpha: 0.3 }, { duration: 1000 }); }; self.setPoints = function (points) { self.points = points; if (points > 1) { zoneGraphics.tint = 0xffd700; // Gold for high value zones } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2E8B57 }); /**** * Game Code ****/ // Add stadium background var stadium = game.addChild(LK.getAsset('stadium', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); // Game dimensions and positioning var gameWidth = 2048; var gameHeight = 2732; var goalWidth = 600; var goalHeight = 400; var goalX = gameWidth / 2; var goalY = gameHeight * 0.3; // Game state var currentLevel = 1; var streak = 0; var isAiming = false; var isShooting = false; var shotsTaken = 0; var lives = 3; // Create goal structure var goalBackground = game.addChild(LK.getAsset('goalBackground', { anchorX: 0.5, anchorY: 0.5, x: goalX, y: goalY })); var leftPost = game.addChild(LK.getAsset('goalPost', { anchorX: 0.5, anchorY: 0.5, x: goalX - goalWidth / 2, y: goalY })); var rightPost = game.addChild(LK.getAsset('goalPost', { anchorX: 0.5, anchorY: 0.5, x: goalX + goalWidth / 2, y: goalY })); var crossbar = game.addChild(LK.getAsset('goalCrossbar', { anchorX: 0.5, anchorY: 0.5, x: goalX, y: goalY - goalHeight / 2 })); // Create ball var ball = game.addChild(new Ball()); ball.startX = gameWidth / 2; ball.startY = gameHeight * 0.8; ball.reset(); // Create footballer var footballer = game.addChild(new Footballer()); footballer.x = gameWidth / 2 - 80; footballer.y = gameHeight * 0.85; // Create goalkeeper var goalkeeper = game.addChild(new Goalkeeper()); goalkeeper.setHome(goalX, goalY + goalHeight / 2 - 20); // Create target zones var targetZones = []; var zonePositions = [{ x: goalX - 200, y: goalY - 100, points: 3 }, // Top left corner { x: goalX + 200, y: goalY - 100, points: 3 }, // Top right corner { x: goalX - 200, y: goalY + 100, points: 2 }, // Bottom left { x: goalX + 200, y: goalY + 100, points: 2 }, // Bottom right { x: goalX, y: goalY, points: 1 } // Center ]; for (var i = 0; i < zonePositions.length; i++) { var zone = game.addChild(new TargetZone()); zone.x = zonePositions[i].x; zone.y = zonePositions[i].y; zone.setPoints(zonePositions[i].points); targetZones.push(zone); } // Aim line for visualization var aimLine = game.addChild(LK.getAsset('aimLine', { anchorX: 0.5, anchorY: 0, alpha: 0 })); // UI Elements var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var shotsTxt = new Text2('Shots: 0', { size: 60, fill: 0xFFFFFF }); shotsTxt.anchor.set(1, 0); LK.gui.topRight.addChild(shotsTxt); var levelTxt = new Text2('Level: 1', { size: 60, fill: 0xFFFFFF }); levelTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(levelTxt); // Create heart symbols for lives var heartSymbols = []; for (var h = 0; h < 3; h++) { var heart = new HeartSymbol(); heart.x = 150 + h * 100; heart.y = gameHeight - 150; heart.setVisible(true); heartSymbols.push(heart); game.addChild(heart); } // Game variables var dragStartX = 0; var dragStartY = 0; var isDragging = false; function resetShot() { ball.reset(); goalkeeper.returnHome(); isShooting = false; isAiming = false; aimLine.alpha = 0; // Activate random target zone var randomZone = targetZones[Math.floor(Math.random() * targetZones.length)]; randomZone.activate(); } function checkGoal() { // Check if ball is in goal area if (ball.x > goalX - goalWidth / 2 && ball.x < goalX + goalWidth / 2 && ball.y > goalY - goalHeight / 2 && ball.y < goalY + goalHeight / 2) { // Check which target zone was hit for (var i = 0; i < targetZones.length; i++) { var zone = targetZones[i]; if (zone.isActive && ball.intersects(zone)) { LK.setScore(LK.getScore() + zone.points); scoreTxt.setText('Score: ' + LK.getScore()); streak++; LK.getSound('goal').play(); LK.effects.flashScreen(0x00ff00, 500); footballer.celebrate(); LK.setTimeout(function () { nextShot(); }, 1000); return true; } } // Goal but missed target zone LK.setScore(LK.getScore() + 1); scoreTxt.setText('Score: ' + LK.getScore()); streak++; LK.getSound('goal').play(); footballer.celebrate(); LK.setTimeout(function () { nextShot(); }, 1000); return true; } // Check if goalkeeper saved if (ball.intersects(goalkeeper)) { streak = 0; lives--; // Hide a heart symbol if (lives >= 0 && lives < heartSymbols.length) { heartSymbols[lives].setVisible(false); } LK.getSound('save').play(); LK.effects.flashObject(goalkeeper, 0x00ff00, 500); if (lives <= 0) { LK.setTimeout(function () { LK.showGameOver(); }, 1000); } else { LK.setTimeout(function () { nextShot(); }, 1000); } return true; } return false; } function nextShot() { shotsTaken++; shotsTxt.setText('Shots: ' + shotsTaken); if (LK.getScore() >= currentLevel * 15) { currentLevel++; levelTxt.setText('Level: ' + currentLevel); // Increase difficulty goalkeeper.speed = Math.min(goalkeeper.speed + 0.3, 5); } resetShot(); } // Touch/Mouse controls game.down = function (x, y, obj) { if (!isShooting && !isAiming) { isAiming = true; isDragging = true; dragStartX = x; dragStartY = y; aimLine.x = ball.x; aimLine.y = ball.y; aimLine.alpha = 0.7; } }; game.move = function (x, y, obj) { if (isDragging && isAiming) { var dx = x - dragStartX; var dy = y - dragStartY; var distance = Math.sqrt(dx * dx + dy * dy); var maxDistance = 300; if (distance > maxDistance) { dx = dx / distance * maxDistance; dy = dy / distance * maxDistance; } // Update aim line aimLine.rotation = Math.atan2(dy, dx) + Math.PI / 2; aimLine.height = Math.min(distance, maxDistance); } }; game.up = function (x, y, obj) { if (isDragging && isAiming) { isDragging = false; isAiming = false; isShooting = true; aimLine.alpha = 0; var dx = x - dragStartX; var dy = y - dragStartY; var distance = Math.sqrt(dx * dx + dy * dy); var power = Math.min(distance / 10, 20); // Move footballer to ball position before kicking tween(footballer, { x: ball.x - 50, y: ball.y + 30 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { // After footballer reaches ball, perform kick and shoot ball footballer.performKick(); ball.shoot(dx / 10, dy / 10); } }); goalkeeper.reactToBall(ball.x + dx, ball.y + dy); } }; // Game update loop game.update = function () { if (isShooting && ball.isMoving) { // Check if ball went out of bounds if (ball.y < goalY - goalHeight / 2 - 100 || ball.x < 0 || ball.x > gameWidth || ball.y > gameHeight) { ball.isMoving = false; isShooting = false; streak = 0; lives--; // Hide a heart symbol if (lives >= 0 && lives < heartSymbols.length) { heartSymbols[lives].setVisible(false); } if (lives <= 0) { LK.setTimeout(function () { LK.showGameOver(); }, 1000); } else { LK.setTimeout(function () { nextShot(); }, 500); } return; } // Check for goal or save if (checkGoal()) { ball.isMoving = false; isShooting = false; return; } } }; // Initialize first shot resetShot();
/****
* 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.gravity = 0.3;
self.isMoving = false;
self.startX = 0;
self.startY = 0;
self.reset = function () {
self.x = self.startX;
self.y = self.startY;
self.velocityX = 0;
self.velocityY = 0;
self.isMoving = false;
ballGraphics.alpha = 1;
};
self.shoot = function (powerX, powerY) {
self.velocityX = powerX * 0.8;
self.velocityY = powerY * 0.8;
self.isMoving = true;
LK.getSound('kick').play();
};
self.update = function () {
if (self.isMoving) {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += self.gravity;
// Ball physics - slow down over time
self.velocityX *= 0.99;
}
};
return self;
});
var Footballer = Container.expand(function () {
var self = Container.call(this);
var footballerGraphics = self.attachAsset('footballer', {
anchorX: 0.5,
anchorY: 1
});
self.isKicking = false;
self.performKick = function () {
if (self.isKicking) {
return;
}
self.isKicking = true;
// Kick animation - lean forward and back
tween(footballerGraphics, {
scaleX: 1.2,
rotation: 0.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
scaleX: 1.0,
rotation: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isKicking = false;
}
});
}
});
};
self.celebrate = function () {
// Play celebration shout sound
LK.getSound('celebration').play();
// Choose random celebration type
var celebrationType = Math.floor(Math.random() * 6);
if (celebrationType === 0) {
// Celebration 1: Spin around with scale change
tween(footballerGraphics, {
rotation: Math.PI * 4,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 1200,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
rotation: 0,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
}
});
} else if (celebrationType === 1) {
// Celebration 2: Jump up and down
tween(footballerGraphics, {
y: footballerGraphics.y - 100,
scaleY: 1.3
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
y: footballerGraphics.y + 100,
scaleY: 1.0
}, {
duration: 400,
easing: tween.bounceOut,
onFinish: function onFinish() {
// Second jump
tween(footballerGraphics, {
y: footballerGraphics.y - 80,
scaleY: 1.2
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
y: footballerGraphics.y + 80,
scaleY: 1.0
}, {
duration: 300,
easing: tween.bounceOut
});
}
});
}
});
}
});
} else if (celebrationType === 2) {
// Celebration 3: Side to side dance
var originalX = footballerGraphics.x;
tween(footballerGraphics, {
x: originalX + 50,
rotation: 0.3,
scaleX: 1.2
}, {
duration: 200,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
x: originalX - 50,
rotation: -0.3
}, {
duration: 300,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
x: originalX + 30,
rotation: 0.2
}, {
duration: 200,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
x: originalX,
rotation: 0,
scaleX: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
}
});
}
});
}
});
} else if (celebrationType === 3) {
// Celebration 4: Pumping fists (scale animation)
tween(footballerGraphics, {
scaleX: 1.4,
scaleY: 0.8,
rotation: 0.1
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
scaleX: 0.8,
scaleY: 1.4,
rotation: -0.1
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
scaleX: 1.3,
scaleY: 0.9,
rotation: 0.05
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
scaleX: 1.0,
scaleY: 1.0,
rotation: 0
}, {
duration: 200,
easing: tween.easeOut
});
}
});
}
});
}
});
} else if (celebrationType === 4) {
// Celebration 5: Backflip sequence
tween(footballerGraphics, {
rotation: Math.PI * 2,
y: footballerGraphics.y - 150,
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
rotation: 0,
y: footballerGraphics.y + 150,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 400,
easing: tween.bounceOut
});
}
});
} else {
// Celebration 6: Victory arms up with shake
var originalY = footballerGraphics.y;
tween(footballerGraphics, {
scaleY: 1.4,
y: originalY - 30,
rotation: 0.2
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
rotation: -0.2
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
rotation: 0.15
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
rotation: -0.15
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(footballerGraphics, {
rotation: 0,
scaleY: 1.0,
y: originalY
}, {
duration: 300,
easing: tween.easeOut
});
}
});
}
});
}
});
}
});
}
};
return self;
});
var Goalkeeper = Container.expand(function () {
var self = Container.call(this);
var keeperGraphics = self.attachAsset('goalkeeper', {
anchorX: 0.5,
anchorY: 1
});
self.homeX = 0;
self.homeY = 0;
self.targetX = 0;
self.speed = 3;
self.reactionTime = 0;
self.isReacting = false;
self.setHome = function (x, y) {
self.homeX = x;
self.homeY = y;
self.x = x;
self.y = y;
self.targetX = x;
};
self.reactToBall = function (ballX, ballY) {
if (!self.isReacting && self.reactionTime <= 0) {
self.isReacting = true;
self.reactionTime = 30; // Reaction delay
// Predict where ball will be
if (ballX < self.homeX - 50) {
self.targetX = self.homeX - 150;
} else if (ballX > self.homeX + 50) {
self.targetX = self.homeX + 150;
}
}
};
self.returnHome = function () {
self.targetX = self.homeX;
self.isReacting = false;
self.reactionTime = 60; // Cooldown before next reaction
};
self.update = function () {
if (self.reactionTime > 0) {
self.reactionTime--;
}
// Move towards target
var dx = self.targetX - self.x;
if (Math.abs(dx) > self.speed) {
self.x += dx > 0 ? self.speed : -self.speed;
} else {
self.x = self.targetX;
}
};
return self;
});
var HeartSymbol = Container.expand(function () {
var self = Container.call(this);
// Create heart shape using heart image
var heartBase = self.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
self.setVisible = function (visible) {
self.alpha = visible ? 1 : 0.3;
};
return self;
});
var TargetZone = Container.expand(function () {
var self = Container.call(this);
var zoneGraphics = self.attachAsset('targetZone', {
anchorX: 0.5,
anchorY: 0.5
});
zoneGraphics.alpha = 0.3;
self.points = 1;
self.isActive = false;
self.activate = function () {
self.isActive = true;
zoneGraphics.alpha = 0.6;
tween(zoneGraphics, {
alpha: 0.3
}, {
duration: 1000
});
};
self.setPoints = function (points) {
self.points = points;
if (points > 1) {
zoneGraphics.tint = 0xffd700; // Gold for high value zones
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2E8B57
});
/****
* Game Code
****/
// Add stadium background
var stadium = game.addChild(LK.getAsset('stadium', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Game dimensions and positioning
var gameWidth = 2048;
var gameHeight = 2732;
var goalWidth = 600;
var goalHeight = 400;
var goalX = gameWidth / 2;
var goalY = gameHeight * 0.3;
// Game state
var currentLevel = 1;
var streak = 0;
var isAiming = false;
var isShooting = false;
var shotsTaken = 0;
var lives = 3;
// Create goal structure
var goalBackground = game.addChild(LK.getAsset('goalBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: goalX,
y: goalY
}));
var leftPost = game.addChild(LK.getAsset('goalPost', {
anchorX: 0.5,
anchorY: 0.5,
x: goalX - goalWidth / 2,
y: goalY
}));
var rightPost = game.addChild(LK.getAsset('goalPost', {
anchorX: 0.5,
anchorY: 0.5,
x: goalX + goalWidth / 2,
y: goalY
}));
var crossbar = game.addChild(LK.getAsset('goalCrossbar', {
anchorX: 0.5,
anchorY: 0.5,
x: goalX,
y: goalY - goalHeight / 2
}));
// Create ball
var ball = game.addChild(new Ball());
ball.startX = gameWidth / 2;
ball.startY = gameHeight * 0.8;
ball.reset();
// Create footballer
var footballer = game.addChild(new Footballer());
footballer.x = gameWidth / 2 - 80;
footballer.y = gameHeight * 0.85;
// Create goalkeeper
var goalkeeper = game.addChild(new Goalkeeper());
goalkeeper.setHome(goalX, goalY + goalHeight / 2 - 20);
// Create target zones
var targetZones = [];
var zonePositions = [{
x: goalX - 200,
y: goalY - 100,
points: 3
},
// Top left corner
{
x: goalX + 200,
y: goalY - 100,
points: 3
},
// Top right corner
{
x: goalX - 200,
y: goalY + 100,
points: 2
},
// Bottom left
{
x: goalX + 200,
y: goalY + 100,
points: 2
},
// Bottom right
{
x: goalX,
y: goalY,
points: 1
} // Center
];
for (var i = 0; i < zonePositions.length; i++) {
var zone = game.addChild(new TargetZone());
zone.x = zonePositions[i].x;
zone.y = zonePositions[i].y;
zone.setPoints(zonePositions[i].points);
targetZones.push(zone);
}
// Aim line for visualization
var aimLine = game.addChild(LK.getAsset('aimLine', {
anchorX: 0.5,
anchorY: 0,
alpha: 0
}));
// UI Elements
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var shotsTxt = new Text2('Shots: 0', {
size: 60,
fill: 0xFFFFFF
});
shotsTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(shotsTxt);
var levelTxt = new Text2('Level: 1', {
size: 60,
fill: 0xFFFFFF
});
levelTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(levelTxt);
// Create heart symbols for lives
var heartSymbols = [];
for (var h = 0; h < 3; h++) {
var heart = new HeartSymbol();
heart.x = 150 + h * 100;
heart.y = gameHeight - 150;
heart.setVisible(true);
heartSymbols.push(heart);
game.addChild(heart);
}
// Game variables
var dragStartX = 0;
var dragStartY = 0;
var isDragging = false;
function resetShot() {
ball.reset();
goalkeeper.returnHome();
isShooting = false;
isAiming = false;
aimLine.alpha = 0;
// Activate random target zone
var randomZone = targetZones[Math.floor(Math.random() * targetZones.length)];
randomZone.activate();
}
function checkGoal() {
// Check if ball is in goal area
if (ball.x > goalX - goalWidth / 2 && ball.x < goalX + goalWidth / 2 && ball.y > goalY - goalHeight / 2 && ball.y < goalY + goalHeight / 2) {
// Check which target zone was hit
for (var i = 0; i < targetZones.length; i++) {
var zone = targetZones[i];
if (zone.isActive && ball.intersects(zone)) {
LK.setScore(LK.getScore() + zone.points);
scoreTxt.setText('Score: ' + LK.getScore());
streak++;
LK.getSound('goal').play();
LK.effects.flashScreen(0x00ff00, 500);
footballer.celebrate();
LK.setTimeout(function () {
nextShot();
}, 1000);
return true;
}
}
// Goal but missed target zone
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Score: ' + LK.getScore());
streak++;
LK.getSound('goal').play();
footballer.celebrate();
LK.setTimeout(function () {
nextShot();
}, 1000);
return true;
}
// Check if goalkeeper saved
if (ball.intersects(goalkeeper)) {
streak = 0;
lives--;
// Hide a heart symbol
if (lives >= 0 && lives < heartSymbols.length) {
heartSymbols[lives].setVisible(false);
}
LK.getSound('save').play();
LK.effects.flashObject(goalkeeper, 0x00ff00, 500);
if (lives <= 0) {
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
} else {
LK.setTimeout(function () {
nextShot();
}, 1000);
}
return true;
}
return false;
}
function nextShot() {
shotsTaken++;
shotsTxt.setText('Shots: ' + shotsTaken);
if (LK.getScore() >= currentLevel * 15) {
currentLevel++;
levelTxt.setText('Level: ' + currentLevel);
// Increase difficulty
goalkeeper.speed = Math.min(goalkeeper.speed + 0.3, 5);
}
resetShot();
}
// Touch/Mouse controls
game.down = function (x, y, obj) {
if (!isShooting && !isAiming) {
isAiming = true;
isDragging = true;
dragStartX = x;
dragStartY = y;
aimLine.x = ball.x;
aimLine.y = ball.y;
aimLine.alpha = 0.7;
}
};
game.move = function (x, y, obj) {
if (isDragging && isAiming) {
var dx = x - dragStartX;
var dy = y - dragStartY;
var distance = Math.sqrt(dx * dx + dy * dy);
var maxDistance = 300;
if (distance > maxDistance) {
dx = dx / distance * maxDistance;
dy = dy / distance * maxDistance;
}
// Update aim line
aimLine.rotation = Math.atan2(dy, dx) + Math.PI / 2;
aimLine.height = Math.min(distance, maxDistance);
}
};
game.up = function (x, y, obj) {
if (isDragging && isAiming) {
isDragging = false;
isAiming = false;
isShooting = true;
aimLine.alpha = 0;
var dx = x - dragStartX;
var dy = y - dragStartY;
var distance = Math.sqrt(dx * dx + dy * dy);
var power = Math.min(distance / 10, 20);
// Move footballer to ball position before kicking
tween(footballer, {
x: ball.x - 50,
y: ball.y + 30
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// After footballer reaches ball, perform kick and shoot ball
footballer.performKick();
ball.shoot(dx / 10, dy / 10);
}
});
goalkeeper.reactToBall(ball.x + dx, ball.y + dy);
}
};
// Game update loop
game.update = function () {
if (isShooting && ball.isMoving) {
// Check if ball went out of bounds
if (ball.y < goalY - goalHeight / 2 - 100 || ball.x < 0 || ball.x > gameWidth || ball.y > gameHeight) {
ball.isMoving = false;
isShooting = false;
streak = 0;
lives--;
// Hide a heart symbol
if (lives >= 0 && lives < heartSymbols.length) {
heartSymbols[lives].setVisible(false);
}
if (lives <= 0) {
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
} else {
LK.setTimeout(function () {
nextShot();
}, 500);
}
return;
}
// Check for goal or save
if (checkGoal()) {
ball.isMoving = false;
isShooting = false;
return;
}
}
};
// Initialize first shot
resetShot();
ball. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
courtuis. In-Game asset. High contrast. No shadows. goalkeeper . full body . facing forward
kalp. In-Game asset. 2d. High contrast. No shadows
full body ronnaldo. In-Game asset. 2d. High contrast. No shadows. top olmasın. turned away. no ball