User prompt
Karakteri alıp biz kontrol edebilelim kendi yarı sahımızada bir kale koy ve oyunun mantığını tamamen değiştirelim maç yapacağız ! ortaya bir top ta koy
Code edit (1 edits merged)
Please save this source code
User prompt
Blue Lock Soccer Shot
Initial prompt
Bir Blue Lock oyunu yapmanı istiyorum !
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Goal = Container.expand(function () { var self = Container.call(this); // Goal area var goalGraphics = self.attachAsset('goal', { anchorX: 0.5, anchorY: 0.5 }); goalGraphics.alpha = 0.3; // Left goalpost var leftPost = self.addChild(LK.getAsset('goalpost', { anchorX: 0.5, anchorY: 0.5 })); leftPost.x = -210; leftPost.y = 0; // Right goalpost var rightPost = self.addChild(LK.getAsset('goalpost', { anchorX: 0.5, anchorY: 0.5 })); rightPost.x = 210; rightPost.y = 0; return self; }); var Opponent = Container.expand(function () { var self = Container.call(this); var opponentGraphics = self.attachAsset('opponent', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.direction = 1; self.minX = 200; self.maxX = 1848; self.update = function () { self.x += self.speed * self.direction; if (self.x <= self.minX || self.x >= self.maxX) { self.direction *= -1; } }; 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 = 6; self.hasBall = false; return self; }); var SoccerBall = 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.active = true; self.update = function () { if (self.active) { self.x += self.velocityX; self.y += self.velocityY; self.velocityX *= self.friction; self.velocityY *= self.friction; // Keep ball in bounds if (self.x < 30) { self.x = 30; self.velocityX = Math.abs(self.velocityX); } if (self.x > 2018) { self.x = 2018; self.velocityX = -Math.abs(self.velocityX); } if (self.y < 30) { self.y = 30; self.velocityY = Math.abs(self.velocityY); } if (self.y > 2702) { self.y = 2702; self.velocityY = -Math.abs(self.velocityY); } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228B22 }); /**** * Game Code ****/ game.setBackgroundColor(0x228B22); // Game variables var opponents = []; var playerScore = 0; var opponentScore = 0; var dragNode = null; // UI Elements var scoreTxt = new Text2('Player: 0 - Opponent: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Game objects var player = game.addChild(new Player()); player.x = 1024; player.y = 2200; var ball = game.addChild(new SoccerBall()); ball.x = 1024; ball.y = 1366; // Player's goal (bottom) var playerGoal = game.addChild(new Goal()); playerGoal.x = 1024; playerGoal.y = 2600; // Opponent's goal (top) var opponentGoal = game.addChild(new Goal()); opponentGoal.x = 1024; opponentGoal.y = 300; // Create opponents for (var i = 0; i < 3; i++) { var opponent = game.addChild(new Opponent()); opponent.x = 400 + i * 400; opponent.y = 800 + i * 200; opponents.push(opponent); } // Ball kicking mechanics function kickBall(targetX, targetY) { var dx = targetX - ball.x; var dy = targetY - ball.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { var power = Math.min(distance / 100, 15); ball.velocityX = dx / distance * power; ball.velocityY = dy / distance * power; LK.getSound('kick').play(); } } // Touch controls for player movement and ball kicking game.down = function (x, y, obj) { var playerDistance = Math.sqrt((x - player.x) * (x - player.x) + (y - player.y) * (y - player.y)); var ballDistance = Math.sqrt((x - ball.x) * (x - ball.x) + (y - ball.y) * (y - ball.y)); if (playerDistance < ballDistance) { // Move player dragNode = player; } else { // Kick ball if player is close enough var playerToBall = Math.sqrt((player.x - ball.x) * (player.x - ball.x) + (player.y - ball.y) * (player.y - ball.y)); if (playerToBall < 120) { kickBall(x, y); } } }; game.move = function (x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } }; game.up = function (x, y, obj) { dragNode = null; }; // Goal scoring function function scoreGoal(isPlayer) { if (isPlayer) { playerScore++; } else { opponentScore++; } scoreTxt.setText('Player: ' + playerScore + ' - Opponent: ' + opponentScore); LK.getSound('goal').play(); // Reset ball position ball.x = 1024; ball.y = 1366; ball.velocityX = 0; ball.velocityY = 0; } // Game update loop game.update = function () { // Check player goal scoring (opponent scores) if (ball.y > playerGoal.y - 50 && ball.x > playerGoal.x - 200 && ball.x < playerGoal.x + 200) { scoreGoal(false); LK.effects.flashObject(playerGoal, 0xFF0000, 500); } // Check opponent goal scoring (player scores) if (ball.y < opponentGoal.y + 50 && ball.x > opponentGoal.x - 200 && ball.x < opponentGoal.x + 200) { scoreGoal(true); LK.effects.flashObject(opponentGoal, 0x00FF00, 500); } // Check win condition if (playerScore >= 5) { LK.showYouWin(); } if (opponentScore >= 5) { LK.showGameOver(); } // Simple AI for opponents to move toward ball for (var i = 0; i < opponents.length; i++) { var opponent = opponents[i]; var dx = ball.x - opponent.x; var dy = ball.y - opponent.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0 && distance < 300) { opponent.x += dx / distance * opponent.speed * 0.5; opponent.y += dy / distance * opponent.speed * 0.5; // Opponent kicks ball if close enough if (distance < 100) { ball.velocityX += dx / distance * 3; ball.velocityY += dy / distance * 3; } } } };
===================================================================
--- original.js
+++ change.js
@@ -5,26 +5,8 @@
/****
* Classes
****/
-var Defender = Container.expand(function () {
- var self = Container.call(this);
- var defenderGraphics = self.attachAsset('defender', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 3;
- self.direction = 1;
- self.minX = 200;
- self.maxX = 1848;
- self.update = function () {
- self.x += self.speed * self.direction;
- if (self.x <= self.minX || self.x >= self.maxX) {
- self.direction *= -1;
- }
- };
- return self;
-});
var Goal = Container.expand(function () {
var self = Container.call(this);
// Goal area
var goalGraphics = self.attachAsset('goal', {
@@ -47,31 +29,73 @@
rightPost.x = 210;
rightPost.y = 0;
return self;
});
-var SoccerBall = Container.expand(function () {
+var Opponent = Container.expand(function () {
var self = Container.call(this);
- var ballGraphics = self.attachAsset('ball', {
+ var opponentGraphics = self.attachAsset('opponent', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 8;
- self.active = true;
+ self.speed = 3;
+ self.direction = 1;
+ self.minX = 200;
+ self.maxX = 1848;
self.update = function () {
- if (self.active) {
- self.y -= self.speed;
+ self.x += self.speed * self.direction;
+ if (self.x <= self.minX || self.x >= self.maxX) {
+ self.direction *= -1;
}
};
return self;
});
-var Striker = Container.expand(function () {
+var Player = Container.expand(function () {
var self = Container.call(this);
- var strikerGraphics = self.attachAsset('striker', {
+ var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
+ self.speed = 6;
+ self.hasBall = false;
return self;
});
+var SoccerBall = 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.active = true;
+ self.update = function () {
+ if (self.active) {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityX *= self.friction;
+ self.velocityY *= self.friction;
+ // Keep ball in bounds
+ if (self.x < 30) {
+ self.x = 30;
+ self.velocityX = Math.abs(self.velocityX);
+ }
+ if (self.x > 2018) {
+ self.x = 2018;
+ self.velocityX = -Math.abs(self.velocityX);
+ }
+ if (self.y < 30) {
+ self.y = 30;
+ self.velocityY = Math.abs(self.velocityY);
+ }
+ if (self.y > 2702) {
+ self.y = 2702;
+ self.velocityY = -Math.abs(self.velocityY);
+ }
+ }
+ };
+ return self;
+});
/****
* Initialize Game
****/
@@ -83,152 +107,124 @@
* Game Code
****/
game.setBackgroundColor(0x228B22);
// Game variables
-var balls = [];
-var defenders = [];
-var ballsRemaining = 20;
-var level = 1;
-var defenderRows = 1;
+var opponents = [];
+var playerScore = 0;
+var opponentScore = 0;
+var dragNode = null;
// UI Elements
-var scoreTxt = new Text2('Score: 0', {
+var scoreTxt = new Text2('Player: 0 - Opponent: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
-var ballsTxt = new Text2('Balls: 20', {
- size: 60,
- fill: 0xFFFFFF
-});
-ballsTxt.anchor.set(1, 0);
-LK.gui.topRight.addChild(ballsTxt);
-var levelTxt = new Text2('Level: 1', {
- size: 60,
- fill: 0xFFFFFF
-});
-levelTxt.anchor.set(0, 0);
-LK.gui.topLeft.addChild(levelTxt);
// Game objects
-var striker = game.addChild(new Striker());
-striker.x = 1024;
-striker.y = 2500;
-var goal = game.addChild(new Goal());
-goal.x = 1024;
-goal.y = 300;
-// Initialize defenders
-function createDefenderRow(y, count, speed) {
- var spacing = 1600 / (count + 1);
- for (var i = 0; i < count; i++) {
- var defender = game.addChild(new Defender());
- defender.x = 224 + spacing * (i + 1);
- defender.y = y;
- defender.speed = speed;
- defenders.push(defender);
- }
+var player = game.addChild(new Player());
+player.x = 1024;
+player.y = 2200;
+var ball = game.addChild(new SoccerBall());
+ball.x = 1024;
+ball.y = 1366;
+// Player's goal (bottom)
+var playerGoal = game.addChild(new Goal());
+playerGoal.x = 1024;
+playerGoal.y = 2600;
+// Opponent's goal (top)
+var opponentGoal = game.addChild(new Goal());
+opponentGoal.x = 1024;
+opponentGoal.y = 300;
+// Create opponents
+for (var i = 0; i < 3; i++) {
+ var opponent = game.addChild(new Opponent());
+ opponent.x = 400 + i * 400;
+ opponent.y = 800 + i * 200;
+ opponents.push(opponent);
}
-function setupLevel() {
- // Clear existing defenders
- for (var i = defenders.length - 1; i >= 0; i--) {
- defenders[i].destroy();
+// Ball kicking mechanics
+function kickBall(targetX, targetY) {
+ var dx = targetX - ball.x;
+ var dy = targetY - ball.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 0) {
+ var power = Math.min(distance / 100, 15);
+ ball.velocityX = dx / distance * power;
+ ball.velocityY = dy / distance * power;
+ LK.getSound('kick').play();
}
- defenders = [];
- // Create new defender formation based on level
- if (level === 1) {
- createDefenderRow(1200, 2, 2);
- } else if (level === 2) {
- createDefenderRow(1200, 3, 2.5);
- } else if (level === 3) {
- createDefenderRow(1200, 3, 3);
- createDefenderRow(800, 2, 2.5);
- } else if (level === 4) {
- createDefenderRow(1200, 4, 3);
- createDefenderRow(800, 3, 2.5);
+}
+// Touch controls for player movement and ball kicking
+game.down = function (x, y, obj) {
+ var playerDistance = Math.sqrt((x - player.x) * (x - player.x) + (y - player.y) * (y - player.y));
+ var ballDistance = Math.sqrt((x - ball.x) * (x - ball.x) + (y - ball.y) * (y - ball.y));
+ if (playerDistance < ballDistance) {
+ // Move player
+ dragNode = player;
} else {
- // Progressive difficulty
- var rows = Math.min(3, Math.floor(level / 2));
- for (var r = 0; r < rows; r++) {
- var y = 1200 - r * 400;
- var count = Math.min(5, 2 + r + Math.floor(level / 3));
- var speed = 2 + level * 0.3 + r * 0.5;
- createDefenderRow(y, count, speed);
+ // Kick ball if player is close enough
+ var playerToBall = Math.sqrt((player.x - ball.x) * (player.x - ball.x) + (player.y - ball.y) * (player.y - ball.y));
+ if (playerToBall < 120) {
+ kickBall(x, y);
}
}
-}
-setupLevel();
-// Shooting mechanics
-function shootBall() {
- if (ballsRemaining <= 0) return;
- var ball = game.addChild(new SoccerBall());
- ball.x = striker.x;
- ball.y = striker.y - 50;
- balls.push(ball);
- ballsRemaining--;
- ballsTxt.setText('Balls: ' + ballsRemaining);
- LK.getSound('shoot').play();
-}
-// Touch controls
-game.down = function (x, y, obj) {
- shootBall();
};
-// Level progression
-function nextLevel() {
- level++;
- ballsRemaining = Math.max(15, 25 - level);
- levelTxt.setText('Level: ' + level);
- ballsTxt.setText('Balls: ' + ballsRemaining);
- setupLevel();
+game.move = function (x, y, obj) {
+ if (dragNode) {
+ dragNode.x = x;
+ dragNode.y = y;
+ }
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+// Goal scoring function
+function scoreGoal(isPlayer) {
+ if (isPlayer) {
+ playerScore++;
+ } else {
+ opponentScore++;
+ }
+ scoreTxt.setText('Player: ' + playerScore + ' - Opponent: ' + opponentScore);
+ LK.getSound('goal').play();
+ // Reset ball position
+ ball.x = 1024;
+ ball.y = 1366;
+ ball.velocityX = 0;
+ ball.velocityY = 0;
}
// Game update loop
game.update = function () {
- // Update balls
- for (var i = balls.length - 1; i >= 0; i--) {
- var ball = balls[i];
- if (!ball.active) continue;
- // Check if ball is off screen (top)
- if (ball.y < -50) {
- ball.destroy();
- balls.splice(i, 1);
- continue;
- }
- // Check collision with defenders
- var blocked = false;
- for (var j = 0; j < defenders.length; j++) {
- var defender = defenders[j];
- if (ball.intersects(defender)) {
- ball.active = false;
- ball.destroy();
- balls.splice(i, 1);
- blocked = true;
- LK.getSound('blocked').play();
- // Flash defender
- LK.effects.flashObject(defender, 0xFF0000, 300);
- break;
- }
- }
- if (blocked) continue;
- // Check goal scoring
- if (ball.y < goal.y + 50 && ball.x > goal.x - 200 && ball.x < goal.x + 200) {
- ball.active = false;
- ball.destroy();
- balls.splice(i, 1);
- // Score goal
- LK.setScore(LK.getScore() + 10);
- scoreTxt.setText('Score: ' + LK.getScore());
- LK.getSound('goal').play();
- // Flash goal
- LK.effects.flashObject(goal, 0xFFFF00, 500);
- // Check level completion (score milestone)
- if (LK.getScore() >= level * 50) {
- nextLevel();
- }
- }
+ // Check player goal scoring (opponent scores)
+ if (ball.y > playerGoal.y - 50 && ball.x > playerGoal.x - 200 && ball.x < playerGoal.x + 200) {
+ scoreGoal(false);
+ LK.effects.flashObject(playerGoal, 0xFF0000, 500);
}
- // Check game over condition
- if (ballsRemaining <= 0 && balls.length === 0) {
+ // Check opponent goal scoring (player scores)
+ if (ball.y < opponentGoal.y + 50 && ball.x > opponentGoal.x - 200 && ball.x < opponentGoal.x + 200) {
+ scoreGoal(true);
+ LK.effects.flashObject(opponentGoal, 0x00FF00, 500);
+ }
+ // Check win condition
+ if (playerScore >= 5) {
+ LK.showYouWin();
+ }
+ if (opponentScore >= 5) {
LK.showGameOver();
}
- // Auto-shoot for demonstration (remove this for manual control only)
- if (LK.ticks % 90 === 0 && ballsRemaining > 0) {
- shootBall();
+ // Simple AI for opponents to move toward ball
+ for (var i = 0; i < opponents.length; i++) {
+ var opponent = opponents[i];
+ var dx = ball.x - opponent.x;
+ var dy = ball.y - opponent.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 0 && distance < 300) {
+ opponent.x += dx / distance * opponent.speed * 0.5;
+ opponent.y += dy / distance * opponent.speed * 0.5;
+ // Opponent kicks ball if close enough
+ if (distance < 100) {
+ ball.velocityX += dx / distance * 3;
+ ball.velocityY += dy / distance * 3;
+ }
+ }
}
};
\ No newline at end of file