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 () { 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: 375 })); // 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 = 400; // Game variables var gameTime = 60; var gameStarted = false; var dragNode = null; var lastBallDistance = 0; // 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) { 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) { // Kick the ball toward goal var kickPowerX = (goal.x - ball.x) / 100; var kickPowerY = (goal.y - ball.y) / 100; ball.velocityX = kickPowerX * 15; ball.velocityY = kickPowerY * 15; LK.getSound('kick').play(); } lastBallDistance = playerBallDistance; // Update goalkeeper AI to track ball if (ball.y < 800) { goalkeeper.targetX = ball.x; // 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 <= 475 && ball.y >= 275) { // 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 if ball goes behind goal line but outside goal if (ball.y <= 275) { ball.y = 275; ball.velocityY *= -0.7; } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,193 @@
-/****
+/****
+* 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 () {
+ 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: 0x000000
-});
\ No newline at end of file
+ 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: 375
+}));
+// 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 = 400;
+// Game variables
+var gameTime = 60;
+var gameStarted = false;
+var dragNode = null;
+var lastBallDistance = 0;
+// 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) {
+ 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) {
+ // Kick the ball toward goal
+ var kickPowerX = (goal.x - ball.x) / 100;
+ var kickPowerY = (goal.y - ball.y) / 100;
+ ball.velocityX = kickPowerX * 15;
+ ball.velocityY = kickPowerY * 15;
+ LK.getSound('kick').play();
+ }
+ lastBallDistance = playerBallDistance;
+ // Update goalkeeper AI to track ball
+ if (ball.y < 800) {
+ goalkeeper.targetX = ball.x;
+ // 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 <= 475 && ball.y >= 275) {
+ // 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 if ball goes behind goal line but outside goal
+ if (ball.y <= 275) {
+ ball.y = 275;
+ ball.velocityY *= -0.7;
+ }
+};
\ No newline at end of file