User prompt
kaleciye top değidiği zaman gol sayılıyor bu olmasın kale çizgisi beyaz olarak belirlensin
User prompt
kale sahanın dışında olsun kaleci topa vurulduktan sonra hareket etsin
User prompt
karakter topa dokununca top direk kaleye gidiyor topa dokunuş açısına ve hızına göre top kaleye gitsin kalecide rastgele bir şekilde hareket etsin
Code edit (1 edits merged)
Please save this source code
User prompt
Pocket Soccer Strike
Initial prompt
Başkan bana 2d futbol oyunu yap
/**** * 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.friction = 0.98; self.bounceReduction = 0.7; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; // Apply friction self.velocityX *= self.friction; self.velocityY *= self.friction; // Bounce off field boundaries if (self.x <= 50 || self.x >= 1998) { self.velocityX *= -self.bounceReduction; self.x = Math.max(50, Math.min(1998, self.x)); } if (self.y <= 300 || self.y >= 1650) { self.velocityY *= -self.bounceReduction; self.y = Math.max(300, Math.min(1650, self.y)); } }; return self; }); var Goalkeeper = Container.expand(function () { var self = Container.call(this); var keeperGraphics = self.attachAsset('goalkeeper', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 4; self.targetX = 1024; self.update = function () { // Only move if goalkeeper is active (ball has been kicked) if (goalkeeperActive) { // Random movement every 30 ticks (0.5 seconds) if (LK.ticks % 30 === 0) { self.targetX = 874 + Math.random() * 300; // Random position within goal area } var diffX = self.targetX - self.x; if (Math.abs(diffX) > 5) { self.x += diffX > 0 ? self.speed : -self.speed; } // Keep goalkeeper within goal area self.x = Math.max(874, Math.min(1174, self.x)); } }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2E7D32 }); /**** * Game Code ****/ // Game field var field = game.addChild(LK.getAsset('field', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 975 })); // Goal var goal = game.addChild(LK.getAsset('goal', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 200 })); // Goal line (white line marking the goal) var goalLine = game.addChild(LK.getAsset('goalLine', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 300 })); // Player var player = game.addChild(new Player()); player.x = 1024; player.y = 1400; // Ball var ball = game.addChild(new Ball()); ball.x = 1024; ball.y = 1000; // Goalkeeper var goalkeeper = game.addChild(new Goalkeeper()); goalkeeper.x = 1024; goalkeeper.y = 250; // Game variables var gameTime = 60; var gameStarted = false; var dragNode = null; var lastBallDistance = 0; var lastPlayerX = 0; var lastPlayerY = 0; var playerVelocityX = 0; var playerVelocityY = 0; var goalkeeperActive = false; // UI Elements var scoreText = new Text2('0', { size: 80, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); var timerText = new Text2('60', { size: 60, fill: 0xFFFFFF }); timerText.anchor.set(1, 0); LK.gui.topRight.addChild(timerText); // Game timer var gameTimer = LK.setInterval(function () { if (gameStarted && gameTime > 0) { gameTime--; timerText.setText(gameTime.toString()); if (gameTime <= 0) { LK.showGameOver(); } } }, 1000); // Input handling game.down = function (x, y, obj) { if (!gameStarted) { gameStarted = true; } dragNode = player; }; game.move = function (x, y, obj) { if (dragNode && gameStarted) { // Track player velocity for kick calculation playerVelocityX = x - dragNode.x; playerVelocityY = y - dragNode.y; dragNode.x = Math.max(50, Math.min(1998, x)); dragNode.y = Math.max(600, Math.min(1650, y)); } }; game.up = function (x, y, obj) { dragNode = null; }; // Game update loop game.update = function () { if (!gameStarted || gameTime <= 0) return; // Check player-ball collision for kicking var playerBallDistance = Math.sqrt(Math.pow(player.x - ball.x, 2) + Math.pow(player.y - ball.y, 2)); if (playerBallDistance < 60 && lastBallDistance >= 60) { // Calculate kick direction based on player movement and ball position var ballDirection = Math.atan2(ball.y - player.y, ball.x - player.x); // Base kick power on player velocity magnitude var velocityMagnitude = Math.sqrt(playerVelocityX * playerVelocityX + playerVelocityY * playerVelocityY); var kickPower = Math.max(8, Math.min(20, velocityMagnitude * 2)); // Power between 8-20 // If player has significant velocity, use movement direction, otherwise use ball direction var kickAngle; if (velocityMagnitude > 2) { kickAngle = Math.atan2(playerVelocityY, playerVelocityX); } else { kickAngle = ballDirection; } ball.velocityX = Math.cos(kickAngle) * kickPower; ball.velocityY = Math.sin(kickAngle) * kickPower; goalkeeperActive = true; // Activate goalkeeper movement LK.getSound('kick').play(); } lastBallDistance = playerBallDistance; // Increase goalkeeper speed based on score goalkeeper.speed = 4 + LK.getScore() * 0.5; // Check goalkeeper collision (save) var keeperBallDistance = Math.sqrt(Math.pow(goalkeeper.x - ball.x, 2) + Math.pow(goalkeeper.y - ball.y, 2)); if (keeperBallDistance < 50 && ball.y <= 350) { // Goalkeeper save LK.getSound('save').play(); ball.velocityX *= -0.5; ball.velocityY *= -0.5; } // Check goal scoring (ball crosses goal line) if (ball.x >= 874 && ball.x <= 1174 && ball.y <= 300) { // Goal scored! LK.setScore(LK.getScore() + 1); scoreText.setText(LK.getScore().toString()); LK.getSound('goal').play(); // Flash effect LK.effects.flashScreen(0x00FF00, 500); // Reset ball position ball.x = 1024; ball.y = 1000; ball.velocityX = 0; ball.velocityY = 0; } // Check if ball goes behind goal line but outside goal if (ball.y <= 100) { ball.y = 100; ball.velocityY *= -0.7; } };
===================================================================
--- original.js
+++ change.js
@@ -92,8 +92,15 @@
anchorY: 0.5,
x: 1024,
y: 200
}));
+// Goal line (white line marking the goal)
+var goalLine = game.addChild(LK.getAsset('goalLine', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: 300
+}));
// Player
var player = game.addChild(new Player());
player.x = 1024;
player.y = 1400;
@@ -182,31 +189,30 @@
}
lastBallDistance = playerBallDistance;
// Increase goalkeeper speed based on score
goalkeeper.speed = 4 + LK.getScore() * 0.5;
- // Check goal scoring
- if (ball.x >= 874 && ball.x <= 1174 && ball.y <= 300 && ball.y >= 100) {
- // Check if goalkeeper blocks the ball
- var keeperBallDistance = Math.sqrt(Math.pow(goalkeeper.x - ball.x, 2) + Math.pow(goalkeeper.y - ball.y, 2));
- if (keeperBallDistance > 50) {
- // Goal scored!
- LK.setScore(LK.getScore() + 1);
- scoreText.setText(LK.getScore().toString());
- LK.getSound('goal').play();
- // Flash effect
- LK.effects.flashScreen(0x00FF00, 500);
- // Reset ball position
- ball.x = 1024;
- ball.y = 1000;
- ball.velocityX = 0;
- ball.velocityY = 0;
- } else {
- // Goalkeeper save
- LK.getSound('save').play();
- ball.velocityX *= -0.5;
- ball.velocityY *= -0.5;
- }
+ // Check goalkeeper collision (save)
+ var keeperBallDistance = Math.sqrt(Math.pow(goalkeeper.x - ball.x, 2) + Math.pow(goalkeeper.y - ball.y, 2));
+ if (keeperBallDistance < 50 && ball.y <= 350) {
+ // Goalkeeper save
+ LK.getSound('save').play();
+ ball.velocityX *= -0.5;
+ ball.velocityY *= -0.5;
}
+ // Check goal scoring (ball crosses goal line)
+ if (ball.x >= 874 && ball.x <= 1174 && ball.y <= 300) {
+ // Goal scored!
+ LK.setScore(LK.getScore() + 1);
+ scoreText.setText(LK.getScore().toString());
+ LK.getSound('goal').play();
+ // Flash effect
+ LK.effects.flashScreen(0x00FF00, 500);
+ // Reset ball position
+ ball.x = 1024;
+ ball.y = 1000;
+ ball.velocityX = 0;
+ ball.velocityY = 0;
+ }
// Check if ball goes behind goal line but outside goal
if (ball.y <= 100) {
ball.y = 100;
ball.velocityY *= -0.7;