User prompt
Let the try to get the ball
User prompt
Add players 16
User prompt
I still cannot make the ball go to the goal
User prompt
Make the line more father so it can aim at the goal
User prompt
Make the drag more father
Code edit (1 edits merged)
Please save this source code
User prompt
Soccer Strike Master
Initial prompt
Make a super high quality soccer
/****
* 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.gravity = 0.3;
self.friction = 0.98;
self.shoot = function (targetX, targetY, power) {
var deltaX = targetX - self.x;
var deltaY = targetY - self.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
self.velocityX = deltaX / distance * power * 0.8;
self.velocityY = deltaY / distance * power * 0.8;
self.isMoving = true;
LK.getSound('kick').play();
};
self.update = function () {
if (self.isMoving) {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityX *= self.friction;
self.velocityY *= self.friction;
// Stop ball if moving too slowly
if (Math.abs(self.velocityX) < 0.5 && Math.abs(self.velocityY) < 0.5) {
self.velocityX = 0;
self.velocityY = 0;
self.isMoving = false;
}
}
};
return self;
});
var Goalkeeper = Container.expand(function () {
var self = Container.call(this);
var keeperGraphics = self.attachAsset('goalkeeper', {
anchorX: 0.5,
anchorY: 1
});
self.direction = 1;
self.speed = 2;
self.minX = 0;
self.maxX = 0;
self.setMovementRange = function (minX, maxX) {
self.minX = minX;
self.maxX = maxX;
};
self.update = function () {
self.x += self.speed * self.direction;
if (self.x <= self.minX || self.x >= self.maxX) {
self.direction *= -1;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state variables
var currentLevel = 1;
var gameState = 'aiming'; // 'aiming', 'shooting', 'scored', 'missed'
var isDragging = false;
var dragStartX = 0;
var dragStartY = 0;
// Create field
var field = game.addChild(LK.getAsset('field', {
anchorX: 0.5,
anchorY: 1,
x: 1024,
y: 2732
}));
// Goal posts
var leftPost = game.addChild(LK.getAsset('goalpost', {
anchorX: 0.5,
anchorY: 1,
x: 824,
y: 600
}));
var rightPost = game.addChild(LK.getAsset('goalpost', {
anchorX: 0.5,
anchorY: 1,
x: 1224,
y: 600
}));
var crossbar = game.addChild(LK.getAsset('crossbar', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 400
}));
// Create ball
var ball = game.addChild(new Ball());
ball.x = 1024;
ball.y = 2200;
// Create goalkeeper
var goalkeeper = game.addChild(new Goalkeeper());
goalkeeper.x = 1024;
var goalY = 580;
goalkeeper.y = goalY;
goalkeeper.setMovementRange(850, 1198);
// Aim line (initially hidden)
var aimLine = game.addChild(LK.getAsset('aimLine', {
anchorX: 0.5,
anchorY: 1,
alpha: 0
}));
// UI Elements
var scoreTxt = new Text2('Level: 1', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var instructionTxt = new Text2('Drag to aim, release to shoot!', {
size: 60,
fill: 0xFFFFFF
});
instructionTxt.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionTxt);
function resetLevel() {
ball.x = 1024;
ball.y = 2200;
ball.velocityX = 0;
ball.velocityY = 0;
ball.isMoving = false;
gameState = 'aiming';
aimLine.alpha = 0;
// Increase goalkeeper speed with level
goalkeeper.speed = 2 + (currentLevel - 1) * 0.5;
scoreTxt.setText('Level: ' + currentLevel);
}
function checkGoal() {
// Check if ball is in goal area
if (ball.x > 824 && ball.x < 1224 && ball.y < 600 && ball.y > 400) {
// Check if goalkeeper didn't save it
var distanceToKeeper = Math.abs(ball.x - goalkeeper.x);
if (distanceToKeeper > 50) {
// Goal scored!
gameState = 'scored';
LK.getSound('goal').play();
LK.setScore(LK.getScore() + currentLevel * 10);
// Flash screen green
LK.effects.flashScreen(0x00ff00, 1000);
// Advance to next level after delay
LK.setTimeout(function () {
currentLevel++;
resetLevel();
}, 1500);
return true;
} else {
// Goalkeeper saved it
gameState = 'missed';
LK.getSound('save').play();
LK.effects.flashScreen(0xff0000, 500);
LK.setTimeout(function () {
resetLevel();
}, 1000);
return true;
}
}
return false;
}
function checkMiss() {
// Ball went off screen or stopped without scoring
if (ball.y < 300 || ball.x < 0 || ball.x > 2048 || !ball.isMoving && gameState === 'shooting') {
gameState = 'missed';
LK.setTimeout(function () {
resetLevel();
}, 1000);
return true;
}
return false;
}
// Touch/Mouse handlers
game.down = function (x, y, obj) {
if (gameState === 'aiming' && !ball.isMoving) {
isDragging = true;
dragStartX = x;
dragStartY = y;
aimLine.alpha = 0.7;
}
};
game.move = function (x, y, obj) {
if (isDragging && gameState === 'aiming') {
var deltaX = x - ball.x;
var deltaY = y - ball.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
// Update aim line position and rotation
aimLine.x = ball.x;
aimLine.y = ball.y;
aimLine.rotation = Math.atan2(deltaY, deltaX) + Math.PI / 2;
// Scale aim line based on power - increased sensitivity
var power = Math.min(distance / 1.5, 80);
aimLine.scaleY = power / 8;
}
};
game.up = function (x, y, obj) {
if (isDragging && gameState === 'aiming') {
isDragging = false;
aimLine.alpha = 0;
var deltaX = x - ball.x;
var deltaY = y - ball.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
var power = Math.min(distance / 1.5, 80);
if (power > 3) {
ball.shoot(x, y, power);
gameState = 'shooting';
}
}
};
// Main game loop
game.update = function () {
// Update goalkeeper movement
if (gameState !== 'scored') {
goalkeeper.update();
}
// Update ball physics
ball.update();
// Check for goal or miss
if (gameState === 'shooting') {
if (!checkGoal()) {
checkMiss();
}
}
// Win condition - reaching level 10
if (currentLevel > 10) {
LK.showYouWin();
}
};
// Initialize first level
resetLevel(); ===================================================================
--- original.js
+++ change.js
@@ -20,10 +20,10 @@
self.shoot = function (targetX, targetY, power) {
var deltaX = targetX - self.x;
var deltaY = targetY - self.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
- self.velocityX = deltaX / distance * power * 0.2;
- self.velocityY = deltaY / distance * power * 0.2;
+ self.velocityX = deltaX / distance * power * 0.8;
+ self.velocityY = deltaY / distance * power * 0.8;
self.isMoving = true;
LK.getSound('kick').play();
};
self.update = function () {
@@ -208,10 +208,10 @@
aimLine.x = ball.x;
aimLine.y = ball.y;
aimLine.rotation = Math.atan2(deltaY, deltaX) + Math.PI / 2;
// Scale aim line based on power - increased sensitivity
- var power = Math.min(distance / 2, 50);
- aimLine.scaleY = power / 10;
+ var power = Math.min(distance / 1.5, 80);
+ aimLine.scaleY = power / 8;
}
};
game.up = function (x, y, obj) {
if (isDragging && gameState === 'aiming') {
@@ -219,10 +219,10 @@
aimLine.alpha = 0;
var deltaX = x - ball.x;
var deltaY = y - ball.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
- var power = Math.min(distance / 2, 50);
- if (power > 5) {
+ var power = Math.min(distance / 1.5, 80);
+ if (power > 3) {
ball.shoot(x, y, power);
gameState = 'shooting';
}
}