Code edit (1 edits merged)
Please save this source code
User prompt
topScoreTxt yazı rengini sarı yap
Code edit (6 edits merged)
Please save this source code
User prompt
Sol alt köşeye bir yaz ekle "Top Score : MrSabri 65"
Code edit (2 edits merged)
Please save this source code
User prompt
when game over write a final score so goalCount
Code edit (5 edits merged)
Please save this source code
User prompt
Oyun bitince gol sayısı gözüksün
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Can't find variable: Goalkeeper' in or related to this line: 'var goalkeeper = game.addChild(new Goalkeeper());' Line Number: 104
User prompt
Please fix the bug: 'Can't find variable: Ball' in or related to this line: 'var ball = game.addChild(new Ball());' Line Number: 67
Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: currentInGoal' in or related to this line: 'ballLastInGoal = currentInGoal;' Line Number: 316
User prompt
eğer top netHitbox ile çarpışırsa gol olur
User prompt
add hitbox for net
Code edit (1 edits merged)
Please save this source code
Code edit (11 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Can't find variable: goalPostLeftX' in or related to this line: 'self.minX = goalPostLeftX; // kale direğinin sol kenarı' Line Number: 96
Code edit (1 edits merged)
Please save this source code
User prompt
Reduce the net's hitbox
User prompt
netin hitboxunu küçült
User prompt
Top direkt aim yönünde gitsin
User prompt
Topun hitboxunu azalt
User prompt
Increase hotbox of ball
/**** * 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.5; self.friction = 0.97; self.shoot = function (targetX, targetY) { var deltaX = targetX - self.x; var deltaY = targetY - self.y; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); self.velocityX = deltaX / distance * 30; self.velocityY = deltaY / distance * 30; self.isMoving = true; }; self.reset = function () { self.x = 1024; self.y = 1700; self.velocityX = 0; self.velocityY = 0; self.isMoving = false; }; self.update = function () { if (self.isMoving) { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; self.velocityX *= self.friction; self.velocityY *= self.friction; if (Math.abs(self.velocityX) < 0.5 && Math.abs(self.velocityY) < 0.5) { self.isMoving = false; } } }; self.intersects = function (other) { var ballWidth = ballGraphics.width; var ballHeight = ballGraphics.height; var hotboxShrinkX = ballWidth * 0.15; var hotboxShrinkY = ballHeight * 0.15; var ballLeft = self.x - ballWidth / 2 + hotboxShrinkX; var ballRight = self.x + ballWidth / 2 - hotboxShrinkX; var ballTop = self.y - ballHeight / 2 + hotboxShrinkY; var ballBottom = self.y + ballHeight / 2 - hotboxShrinkY; var otherLeft = other.x; var otherRight = other.x + (other.width || other.getAsset && other.getAsset({}, {}).width || 0); var otherTop = other.y; var otherBottom = other.y + (other.height || other.getAsset && other.getAsset({}, {}).height || 0); if (typeof other.anchorX === "number" && typeof other.anchorY === "number" && other.width && other.height) { otherLeft = other.x - other.width * other.anchorX; otherRight = other.x + other.width * (1 - other.anchorX); otherTop = other.y - other.height * other.anchorY; otherBottom = other.y + other.height * (1 - other.anchorY); } return !(ballLeft > otherRight || ballRight < otherLeft || ballTop > otherBottom || ballBottom < otherTop); }; return self; }); var Goalkeeper = Container.expand(function () { var self = Container.call(this); var keeperGraphics = self.attachAsset('goalkeeper', { anchorX: 0.5, anchorY: 1.0 }); self.direction = 1; self.speed = 5; self.minX = 710; self.maxX = 1340; self.reactDistance = 700; self.update = function () { self.x += self.direction * self.speed; if (self.x <= self.minX) { self.x = self.minX; self.direction = 1; } else if (self.x >= self.maxX) { self.x = self.maxX; self.direction = -1; } if (ball.isMoving && ball.y < self.y + self.reactDistance) { if (ball.x < self.x - 20) { self.direction = -1; self.speed = 5; } else if (ball.x > self.x + 20) { self.direction = 1; self.speed = 5; } } else { self.speed = 3 + Math.floor(goalCount / 1); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228b22 }); /**** * Game Code ****/ var goalCount = 0; LK.playMusic('MatchMusic'); var goalWidth = 800; var goalHeight = 400; var goalX = 1024 - goalWidth / 2; var goalY = 500; var goalPostLeftX = goalX; var goalPostRightX = goalX + goalWidth; var background = game.addChild(LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366, scaleX: 2.048, scaleY: 2.732 })); var net = game.addChild(LK.getAsset('net', { x: goalX + 20, y: goalY + 20, alpha: 0.3 })); var leftPost = game.addChild(LK.getAsset('goalpost', { x: goalX, y: goalY, anchorX: 0.5, anchorY: 0 })); var rightPost = game.addChild(LK.getAsset('goalpost', { x: goalX + goalWidth, y: goalY, anchorX: 0.5, anchorY: 0 })); var crossbar = game.addChild(LK.getAsset('crossbar', { x: goalX, y: goalY, anchorX: 0, anchorY: 0.5 })); var ball = game.addChild(new Ball()); ball.reset(); var goalkeeper = game.addChild(new Goalkeeper()); goalkeeper.x = 1024; goalkeeper.y = goalY + goalHeight + 30; var aimLine = game.addChild(LK.getAsset('aimLine', { anchorX: 0.5, anchorY: 0, alpha: 0 })); var isAiming = false; var shotCount = 0; var scoreTxt = new Text2('Goals: 0', { size: 90, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 1.5); LK.gui.bottom.addChild(scoreTxt); var instructionTxt = new Text2('Tap and drag to aim, release to shoot!', { size: 80, fill: 0xFFFFFF }); instructionTxt.anchor.set(0.5, 1.5); instructionTxt.x = 1024; instructionTxt.y = 2400; game.addChild(instructionTxt); function updateScore() { scoreTxt.setText('Goals: ' + goalCount); console.log('Score updated: Goals = ' + goalCount); // Debugging } function resetForNextShot() { LK.setTimeout(function () { ball.reset(); isAiming = false; aimLine.alpha = 0; }, 500); } function checkGoal() { if (ball.intersects(net)) { // Kaleci kurtarış alanını daralttık var keeperSaveZone = { x: goalkeeper.x - 80, // Daha dar alan y: goalkeeper.y - 140, width: 160, // Daha dar alan height: 140 }; var ballInSaveZone = ball.x > keeperSaveZone.x && ball.x < keeperSaveZone.x + keeperSaveZone.width && ball.y > keeperSaveZone.y && ball.y < keeperSaveZone.y + keeperSaveZone.height; if (!ballInSaveZone) { goalCount++; console.log('Goal scored! goalCount: ' + goalCount); // Debugging goalkeeper.speed += 1; LK.effects.flashScreen(0x00ff00, 500); updateScore(); resetForNextShot(); return true; } else { console.log('Goalkeeper saved! goalCount: ' + goalCount); // Debugging goalkeeper.speed += 2; LK.effects.flashScreen(0xff0000, 500); LK.stopMusic(); LK.showGameOver('Final Score: ' + goalCount); // Oyun burada bitiyor return true; } } var inGoalArea = ball.x > goalX - 50 && ball.x < goalX + goalWidth + 50 && ball.y > goalY - 50 && ball.y < goalY + goalHeight + 50; if (inGoalArea && !ball.intersects(net) && ball.isMoving) { console.log('Ball in goal area but no goal. goalCount: ' + goalCount); // Debugging resetForNextShot(); return true; } return false; } game.down = function (x, y, obj) { if (!ball.isMoving) { isAiming = true; aimLine.x = ball.x; aimLine.y = ball.y; aimLine.alpha = 0.8; var deltaX = x - ball.x; var deltaY = y - ball.y; var angle = Math.atan2(deltaY, deltaX); aimLine.rotation = angle - Math.PI / 2; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); aimLine.height = Math.min(distance * 0.5, 200); } }; game.move = function (x, y, obj) { if (isAiming) { var deltaX = x - ball.x; var deltaY = y - ball.y; var angle = Math.atan2(deltaY, deltaX); aimLine.rotation = angle - Math.PI / 2; var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); aimLine.height = Math.min(distance * 0.5, 200); } }; game.up = function (x, y, obj) { if (isAiming && !ball.isMoving) { shotCount++; ball.shoot(x, y); isAiming = false; aimLine.alpha = 0; if (shotCount === 1) { instructionTxt.alpha = 0; } } }; var ballLastY = ball.y; var ballLastInGoal = false; game.update = function () { // Önce top ve kaleci güncellemelerini yap ball.update(); goalkeeper.update(); // Gol kontrolü var currentInGoal = ball.x > goalX && ball.x < goalX + goalWidth && ball.y > goalY && ball.y < goalY + goalHeight; if (!ballLastInGoal && currentInGoal && ball.isMoving) { checkGoal(); } // Oyun sonu koşulları if (ball.y < -100 || ball.x < 0 || ball.x > 2048) { console.log('Game Over triggered. Final goalCount: ' + goalCount); // Debugging LK.stopMusic(); LK.showGameOver('Final Score: ' + goalCount); } ballLastY = ball.y; ballLastInGoal = currentInGoal; };
===================================================================
--- original.js
+++ change.js
@@ -20,10 +20,10 @@
self.shoot = function (targetX, targetY) {
var deltaX = targetX - self.x;
var deltaY = targetY - self.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
- self.velocityX = deltaX / distance * 30; // Increase speed for direct aim
- self.velocityY = deltaY / distance * 30; // Increase speed for direct aim
+ self.velocityX = deltaX / distance * 30;
+ self.velocityY = deltaY / distance * 30;
self.isMoving = true;
};
self.reset = function () {
self.x = 1024;
@@ -43,33 +43,27 @@
self.isMoving = false;
}
}
};
- // Override intersects to reduce the hotbox of the ball
self.intersects = function (other) {
- // Get bounds of this ball
var ballWidth = ballGraphics.width;
var ballHeight = ballGraphics.height;
- // Reduce hotbox by 30% in each direction
var hotboxShrinkX = ballWidth * 0.15;
var hotboxShrinkY = ballHeight * 0.15;
var ballLeft = self.x - ballWidth / 2 + hotboxShrinkX;
var ballRight = self.x + ballWidth / 2 - hotboxShrinkX;
var ballTop = self.y - ballHeight / 2 + hotboxShrinkY;
var ballBottom = self.y + ballHeight / 2 - hotboxShrinkY;
- // Get bounds of the other object
var otherLeft = other.x;
var otherRight = other.x + (other.width || other.getAsset && other.getAsset({}, {}).width || 0);
var otherTop = other.y;
var otherBottom = other.y + (other.height || other.getAsset && other.getAsset({}, {}).height || 0);
- // If other has anchor, adjust accordingly
if (typeof other.anchorX === "number" && typeof other.anchorY === "number" && other.width && other.height) {
otherLeft = other.x - other.width * other.anchorX;
otherRight = other.x + other.width * (1 - other.anchorX);
otherTop = other.y - other.height * other.anchorY;
otherBottom = other.y + other.height * (1 - other.anchorY);
}
- // AABB collision
return !(ballLeft > otherRight || ballRight < otherLeft || ballTop > otherBottom || ballBottom < otherTop);
};
return self;
});
@@ -80,10 +74,10 @@
anchorY: 1.0
});
self.direction = 1;
self.speed = 5;
- self.minX = 710; // kale direğinin sol kenarı
- self.maxX = 1340; // kale direğinin sağ kenarı
+ self.minX = 710;
+ self.maxX = 1340;
self.reactDistance = 700;
self.update = function () {
self.x += self.direction * self.speed;
if (self.x <= self.minX) {
@@ -119,14 +113,14 @@
* Game Code
****/
var goalCount = 0;
LK.playMusic('MatchMusic');
-var goalWidth = 800; // Increased width
-var goalHeight = 400; // Increased height
-var goalX = 1024 - goalWidth / 2; // Centered horizontally
-var goalY = 500; // Moved further down the screen
-var goalPostLeftX = goalX; // Left post X position
-var goalPostRightX = goalX + goalWidth; // Right post X position
+var goalWidth = 800;
+var goalHeight = 400;
+var goalX = 1024 - goalWidth / 2;
+var goalY = 500;
+var goalPostLeftX = goalX;
+var goalPostRightX = goalX + goalWidth;
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
@@ -160,9 +154,9 @@
var ball = game.addChild(new Ball());
ball.reset();
var goalkeeper = game.addChild(new Goalkeeper());
goalkeeper.x = 1024;
-goalkeeper.y = goalY + goalHeight + 30; // Moved even closer to the net
+goalkeeper.y = goalY + goalHeight + 30;
var aimLine = game.addChild(LK.getAsset('aimLine', {
anchorX: 0.5,
anchorY: 0,
alpha: 0
@@ -172,10 +166,10 @@
var scoreTxt = new Text2('Goals: 0', {
size: 90,
fill: 0xFFFFFF
});
-scoreTxt.anchor.set(0.5, 1.5); // Anchor to a position slightly higher than before
-LK.gui.bottom.addChild(scoreTxt); // Add score text to the bottom of the screen
+scoreTxt.anchor.set(0.5, 1.5);
+LK.gui.bottom.addChild(scoreTxt);
var instructionTxt = new Text2('Tap and drag to aim, release to shoot!', {
size: 80,
fill: 0xFFFFFF
});
@@ -184,49 +178,49 @@
instructionTxt.y = 2400;
game.addChild(instructionTxt);
function updateScore() {
scoreTxt.setText('Goals: ' + goalCount);
+ console.log('Score updated: Goals = ' + goalCount); // Debugging
}
function resetForNextShot() {
LK.setTimeout(function () {
ball.reset();
isAiming = false;
aimLine.alpha = 0;
- ball.reset();
- isAiming = false;
- aimLine.alpha = 0;
}, 500);
}
function checkGoal() {
if (ball.intersects(net)) {
- // Check for goalkeeper collision with reduced side hitbox
+ // Kaleci kurtarış alanını daralttık
var keeperSaveZone = {
- x: goalkeeper.x - 110,
- // Increased from 100 to 110 for wider side coverage
- y: goalkeeper.y - 160,
- // Reduced height zone
- width: 220,
- // Increased from 200 to 220 for wider side hitbox
- height: 160 // Reduced from ~212 to 160
+ x: goalkeeper.x - 80,
+ // Daha dar alan
+ y: goalkeeper.y - 140,
+ width: 160,
+ // Daha dar alan
+ height: 140
};
var ballInSaveZone = ball.x > keeperSaveZone.x && ball.x < keeperSaveZone.x + keeperSaveZone.width && ball.y > keeperSaveZone.y && ball.y < keeperSaveZone.y + keeperSaveZone.height;
if (!ballInSaveZone) {
goalCount++;
- goalkeeper.speed += 1; // Increase goalkeeper speed after a goal is scored
- LK.effects.flashScreen(0x00ff00, 500); // Trigger green light effect
+ console.log('Goal scored! goalCount: ' + goalCount); // Debugging
+ goalkeeper.speed += 1;
+ LK.effects.flashScreen(0x00ff00, 500);
+ updateScore();
+ resetForNextShot();
+ return true;
} else {
- goalkeeper.speed += 2; // Increase goalkeeper speed after conceding a goal
- LK.effects.flashScreen(0xff0000, 500); // Trigger red light effect
+ console.log('Goalkeeper saved! goalCount: ' + goalCount); // Debugging
+ goalkeeper.speed += 2;
+ LK.effects.flashScreen(0xff0000, 500);
LK.stopMusic();
- LK.showGameOver('Final Score: ' + goalCount);
+ LK.showGameOver('Final Score: ' + goalCount); // Oyun burada bitiyor
+ return true;
}
- updateScore();
- resetForNextShot();
- return true;
}
- // Check if ball is in goal area but doesn't touch net (save scenario)
var inGoalArea = ball.x > goalX - 50 && ball.x < goalX + goalWidth + 50 && ball.y > goalY - 50 && ball.y < goalY + goalHeight + 50;
if (inGoalArea && !ball.intersects(net) && ball.isMoving) {
+ console.log('Ball in goal area but no goal. goalCount: ' + goalCount); // Debugging
resetForNextShot();
return true;
}
return false;
@@ -268,19 +262,21 @@
};
var ballLastY = ball.y;
var ballLastInGoal = false;
game.update = function () {
+ // Önce top ve kaleci güncellemelerini yap
+ ball.update();
+ goalkeeper.update();
+ // Gol kontrolü
var currentInGoal = ball.x > goalX && ball.x < goalX + goalWidth && ball.y > goalY && ball.y < goalY + goalHeight;
if (!ballLastInGoal && currentInGoal && ball.isMoving) {
checkGoal();
}
- if (ball.y < -100) {
+ // Oyun sonu koşulları
+ if (ball.y < -100 || ball.x < 0 || ball.x > 2048) {
+ console.log('Game Over triggered. Final goalCount: ' + goalCount); // Debugging
LK.stopMusic();
- LK.showGameOver('Final Score: ' + goalCount); // End the game and show goal count
+ LK.showGameOver('Final Score: ' + goalCount);
}
- if (ball.x < 0 || ball.x > 2048) {
- LK.stopMusic();
- LK.showGameOver('Final Score: ' + goalCount); // End the game and show goal count
- }
ballLastY = ball.y;
ballLastInGoal = currentInGoal;
};
\ No newline at end of file