User prompt
kazanan oyuncusu ismi #0b3ee3 hex renk kodunu kulansın
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: LK.effects.fireworks is not a function' in or related to this line: 'LK.effects.fireworks(winnerTxt.x, winnerTxt.y, {' Line Number: 352
User prompt
kazanan yazısı çıktığı zaman havai fişek efekti ekle
User prompt
frame 10/10 Olduğunda en yüksek score yapan oyuncunun ismi ekranda yazsın
User prompt
oyun sonunu kaldır
User prompt
game over yazısı yerine en yüksek puanı alan oyuncusunun ismi yazsın
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'fill')' in or related to this line: 'playerTxt.style.fill = "#FF2222";' Line Number: 288
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'fill')' in or related to this line: 'playerTxt.style.fill = 0xFF2222;' Line Number: 288
User prompt
Player 2 yazısını mavi yap
User prompt
son değişikliği geri al
User prompt
Tüm player1 yazılarını kırmızı yap
User prompt
Player 1 yazısını kırmızı yap
Code edit (1 edits merged)
Please save this source code
User prompt
oyunu 2 kişilik yapalım
User prompt
pinler sadece frame sayısı 3-6-9-1 de yeniden oluşturulsun
User prompt
bowling ball ın hareket hızını yavaşlat
User prompt
vurulan pinler 2. frame için yeniden konumlandırılmasın 3 turda bir yeniden konumlandırılsın
User prompt
1 turda yıkılan pinler 2. turda frame de yeniden oluşturulmasın pin sadece 3 frame de bir yeniden oluşturulsun
User prompt
topun gidiş hızını daha gerçekçi yap
User prompt
oyunun bakış açısını değiştir
Code edit (1 edits merged)
Please save this source code
User prompt
Bowling Strike Master
Initial prompt
bowling oyunu yapalım
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Bowling Ball class var BowlingBall = Container.expand(function () { var self = Container.call(this); var shadow = self.attachAsset('shadow', { anchorX: 0.5, anchorY: 0.5, y: 80 }); shadow.alpha = 0.25; var ballAsset = self.attachAsset('bowlingBall', { anchorX: 0.5, anchorY: 0.5 }); self.radius = ballAsset.width / 2; self.vx = 0; self.vy = 0; self.isRolling = false; self.update = function () { if (self.isRolling) { self.x += self.vx; self.y += self.vy; // Friction self.vx *= 0.995; self.vy *= 0.995; // Ball rotation for effect ballAsset.rotation += 0.15 * (self.vx + self.vy); // Stop if slow if (Math.abs(self.vx) < 1 && Math.abs(self.vy) < 1) { self.isRolling = false; self.vx = 0; self.vy = 0; } } }; self.reset = function (x, y) { self.x = x; self.y = y; self.vx = 0; self.vy = 0; self.isRolling = false; ballAsset.rotation = 0; }; return self; }); // Pin class var Pin = Container.expand(function () { var self = Container.call(this); var pinAsset = self.attachAsset('pin', { anchorX: 0.5, anchorY: 1 }); self.isStanding = true; self.knockDown = function () { if (!self.isStanding) return; self.isStanding = false; // Animate pin falling tween(self, { rotation: Math.PI / 2, y: self.y + 60 }, { duration: 400, easing: tween.cubicOut }); // Fade out after a short delay tween(self, { alpha: 0 }, { duration: 300, delay: 400, onFinish: function onFinish() { self.visible = false; } }); }; self.reset = function () { self.isStanding = true; self.rotation = 0; self.alpha = 1; self.visible = true; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 }); /**** * Game Code ****/ // Sound for ball roll // Shadow for ball // Lane // Pin // Bowling Ball // Lane setup var lane = LK.getAsset('lane', { anchorX: 0.5, anchorY: 0, x: 2048 / 2, y: 300 }); game.addChild(lane); // Pin setup var pins = []; var pinRows = 4; // 4 rows: 1,2,3,4 = 10 pins var pinSpacingX = 110; var pinSpacingY = 120; var laneTopY = lane.y + 180; var laneCenterX = lane.x; var pinStartY = lane.y + 320; var pinStartX = lane.x; var pinLayout = [[0], [-1, 1], [-2, 0, 2], [-3, -1, 1, 3]]; for (var row = 0; row < pinRows; row++) { for (var col = 0; col < pinLayout[row].length; col++) { var pin = new Pin(); pin.x = laneCenterX + pinLayout[row][col] * pinSpacingX; pin.y = pinStartY + row * pinSpacingY; pins.push(pin); game.addChild(pin); } } // Ball setup var ballStartX = lane.x; var ballStartY = lane.y + lane.height - 180; var ball = new BowlingBall(); ball.reset(ballStartX, ballStartY); game.addChild(ball); // Game state var throwsPerFrame = 2; var currentThrow = 1; var frame = 1; var maxFrames = 10; var pinsDownThisFrame = 0; var totalScore = 0; var isAiming = false; var aimStart = null; var aimEnd = null; var isBallRolling = false; var gameOver = false; // GUI var scoreTxt = new Text2('Score: 0', { size: 90, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var frameTxt = new Text2('Frame: 1/10', { size: 60, fill: "#fff" }); frameTxt.anchor.set(0.5, 0); LK.gui.top.addChild(frameTxt); frameTxt.y = 110; var throwTxt = new Text2('Throw: 1/2', { size: 60, fill: "#fff" }); throwTxt.anchor.set(0.5, 0); LK.gui.top.addChild(throwTxt); throwTxt.y = 180; // Helper: reset pins function resetPins() { for (var i = 0; i < pins.length; i++) { pins[i].reset(); } } // Helper: count standing pins function countStandingPins() { var count = 0; for (var i = 0; i < pins.length; i++) { if (pins[i].isStanding) count++; } return count; } // Helper: get pin bounding box function getPinBounds(pin) { return { x: pin.x - 30, y: pin.y - 180, width: 60, height: 180 }; } // Helper: ball-pin collision function checkBallPinCollision(ball, pin) { if (!pin.isStanding) return false; var dx = ball.x - pin.x; var dy = ball.y - (pin.y - 90); var dist = Math.sqrt(dx * dx + dy * dy); if (dist < ball.radius + 50) { return true; } return false; } // Helper: knock down pins hit by ball function handleBallPinCollisions() { var hit = false; for (var i = 0; i < pins.length; i++) { if (checkBallPinCollision(ball, pins[i])) { pins[i].knockDown(); hit = true; } } if (hit) { LK.getSound('hit').play(); } } // Helper: check if all pins are down function allPinsDown() { for (var i = 0; i < pins.length; i++) { if (pins[i].isStanding) return false; } return true; } // Helper: update GUI function updateGUI() { scoreTxt.setText('Score: ' + totalScore); frameTxt.setText('Frame: ' + frame + '/' + maxFrames); throwTxt.setText('Throw: ' + currentThrow + '/' + throwsPerFrame); } // Helper: next throw or frame function nextThrowOrFrame() { var pinsDown = 10 - countStandingPins(); pinsDownThisFrame += pinsDown; totalScore += pinsDown; LK.setScore(totalScore); updateGUI(); if (allPinsDown()) { // Strike or spare LK.getSound('strike').play(); LK.effects.flashObject(scoreTxt, 0xffd700, 800); // Next frame frame++; if (frame > maxFrames) { LK.showGameOver(); gameOver = true; return; } resetPins(); pinsDownThisFrame = 0; currentThrow = 1; } else if (currentThrow < throwsPerFrame) { // Next throw in same frame currentThrow++; } else { // End of frame frame++; if (frame > maxFrames) { LK.showGameOver(); gameOver = true; return; } resetPins(); pinsDownThisFrame = 0; currentThrow = 1; } // Reset ball ball.reset(ballStartX, ballStartY); isBallRolling = false; isAiming = false; aimStart = null; aimEnd = null; updateGUI(); } // Touch/drag controls var dragStart = null; var dragEnd = null; var dragActive = false; function isOnBall(x, y) { var dx = x - ball.x; var dy = y - ball.y; return dx * dx + dy * dy < ball.radius * ball.radius * 1.2; } game.down = function (x, y, obj) { if (gameOver) return; if (isBallRolling) return; // Only allow drag if touch is on ball and ball is at start if (isOnBall(x, y) && !isBallRolling) { dragStart = { x: x, y: y }; dragActive = true; isAiming = true; } }; game.move = function (x, y, obj) { if (gameOver) return; if (!dragActive) return; // Show aiming line (not implemented visually) dragEnd = { x: x, y: y }; }; game.up = function (x, y, obj) { if (gameOver) return; if (!dragActive) return; dragActive = false; isAiming = false; dragEnd = { x: x, y: y }; // Calculate swipe vector var dx = dragEnd.x - dragStart.x; var dy = dragEnd.y - dragStart.y; // Only allow upward swipes if (dy > -40) return; // Set ball velocity based on swipe var speed = Math.min(Math.sqrt(dx * dx + dy * dy), 1200); var norm = Math.sqrt(dx * dx + dy * dy); if (norm === 0) return; ball.vx = dx / norm * (speed / 18); ball.vy = dy / norm * (speed / 12); ball.isRolling = true; isBallRolling = true; LK.getSound('roll').play(); }; // Game update loop game.update = function () { if (gameOver) return; ball.update(); // Ball stays in lane var laneLeft = lane.x - lane.width / 2 + ball.radius; var laneRight = lane.x + lane.width / 2 - ball.radius; if (ball.x < laneLeft) { ball.x = laneLeft; ball.vx *= -0.5; } if (ball.x > laneRight) { ball.x = laneRight; ball.vx *= -0.5; } // Ball reaches pins if (ball.isRolling) { handleBallPinCollisions(); // Ball out of lane (top) if (ball.y < lane.y + 100) { ball.isRolling = false; isBallRolling = false; LK.setTimeout(nextThrowOrFrame, 700); } // Ball stops moving if (!ball.isRolling) { LK.setTimeout(nextThrowOrFrame, 700); } } }; // Initial GUI update updateGUI();
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,363 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// Bowling Ball class
+var BowlingBall = Container.expand(function () {
+ var self = Container.call(this);
+ var shadow = self.attachAsset('shadow', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ y: 80
+ });
+ shadow.alpha = 0.25;
+ var ballAsset = self.attachAsset('bowlingBall', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.radius = ballAsset.width / 2;
+ self.vx = 0;
+ self.vy = 0;
+ self.isRolling = false;
+ self.update = function () {
+ if (self.isRolling) {
+ self.x += self.vx;
+ self.y += self.vy;
+ // Friction
+ self.vx *= 0.995;
+ self.vy *= 0.995;
+ // Ball rotation for effect
+ ballAsset.rotation += 0.15 * (self.vx + self.vy);
+ // Stop if slow
+ if (Math.abs(self.vx) < 1 && Math.abs(self.vy) < 1) {
+ self.isRolling = false;
+ self.vx = 0;
+ self.vy = 0;
+ }
+ }
+ };
+ self.reset = function (x, y) {
+ self.x = x;
+ self.y = y;
+ self.vx = 0;
+ self.vy = 0;
+ self.isRolling = false;
+ ballAsset.rotation = 0;
+ };
+ return self;
+});
+// Pin class
+var Pin = Container.expand(function () {
+ var self = Container.call(this);
+ var pinAsset = self.attachAsset('pin', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.isStanding = true;
+ self.knockDown = function () {
+ if (!self.isStanding) return;
+ self.isStanding = false;
+ // Animate pin falling
+ tween(self, {
+ rotation: Math.PI / 2,
+ y: self.y + 60
+ }, {
+ duration: 400,
+ easing: tween.cubicOut
+ });
+ // Fade out after a short delay
+ tween(self, {
+ alpha: 0
+ }, {
+ duration: 300,
+ delay: 400,
+ onFinish: function onFinish() {
+ self.visible = false;
+ }
+ });
+ };
+ self.reset = function () {
+ self.isStanding = true;
+ self.rotation = 0;
+ self.alpha = 1;
+ self.visible = true;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x222222
+});
+
+/****
+* Game Code
+****/
+// Sound for ball roll
+// Shadow for ball
+// Lane
+// Pin
+// Bowling Ball
+// Lane setup
+var lane = LK.getAsset('lane', {
+ anchorX: 0.5,
+ anchorY: 0,
+ x: 2048 / 2,
+ y: 300
+});
+game.addChild(lane);
+// Pin setup
+var pins = [];
+var pinRows = 4; // 4 rows: 1,2,3,4 = 10 pins
+var pinSpacingX = 110;
+var pinSpacingY = 120;
+var laneTopY = lane.y + 180;
+var laneCenterX = lane.x;
+var pinStartY = lane.y + 320;
+var pinStartX = lane.x;
+var pinLayout = [[0], [-1, 1], [-2, 0, 2], [-3, -1, 1, 3]];
+for (var row = 0; row < pinRows; row++) {
+ for (var col = 0; col < pinLayout[row].length; col++) {
+ var pin = new Pin();
+ pin.x = laneCenterX + pinLayout[row][col] * pinSpacingX;
+ pin.y = pinStartY + row * pinSpacingY;
+ pins.push(pin);
+ game.addChild(pin);
+ }
+}
+// Ball setup
+var ballStartX = lane.x;
+var ballStartY = lane.y + lane.height - 180;
+var ball = new BowlingBall();
+ball.reset(ballStartX, ballStartY);
+game.addChild(ball);
+// Game state
+var throwsPerFrame = 2;
+var currentThrow = 1;
+var frame = 1;
+var maxFrames = 10;
+var pinsDownThisFrame = 0;
+var totalScore = 0;
+var isAiming = false;
+var aimStart = null;
+var aimEnd = null;
+var isBallRolling = false;
+var gameOver = false;
+// GUI
+var scoreTxt = new Text2('Score: 0', {
+ size: 90,
+ fill: "#fff"
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var frameTxt = new Text2('Frame: 1/10', {
+ size: 60,
+ fill: "#fff"
+});
+frameTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(frameTxt);
+frameTxt.y = 110;
+var throwTxt = new Text2('Throw: 1/2', {
+ size: 60,
+ fill: "#fff"
+});
+throwTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(throwTxt);
+throwTxt.y = 180;
+// Helper: reset pins
+function resetPins() {
+ for (var i = 0; i < pins.length; i++) {
+ pins[i].reset();
+ }
+}
+// Helper: count standing pins
+function countStandingPins() {
+ var count = 0;
+ for (var i = 0; i < pins.length; i++) {
+ if (pins[i].isStanding) count++;
+ }
+ return count;
+}
+// Helper: get pin bounding box
+function getPinBounds(pin) {
+ return {
+ x: pin.x - 30,
+ y: pin.y - 180,
+ width: 60,
+ height: 180
+ };
+}
+// Helper: ball-pin collision
+function checkBallPinCollision(ball, pin) {
+ if (!pin.isStanding) return false;
+ var dx = ball.x - pin.x;
+ var dy = ball.y - (pin.y - 90);
+ var dist = Math.sqrt(dx * dx + dy * dy);
+ if (dist < ball.radius + 50) {
+ return true;
+ }
+ return false;
+}
+// Helper: knock down pins hit by ball
+function handleBallPinCollisions() {
+ var hit = false;
+ for (var i = 0; i < pins.length; i++) {
+ if (checkBallPinCollision(ball, pins[i])) {
+ pins[i].knockDown();
+ hit = true;
+ }
+ }
+ if (hit) {
+ LK.getSound('hit').play();
+ }
+}
+// Helper: check if all pins are down
+function allPinsDown() {
+ for (var i = 0; i < pins.length; i++) {
+ if (pins[i].isStanding) return false;
+ }
+ return true;
+}
+// Helper: update GUI
+function updateGUI() {
+ scoreTxt.setText('Score: ' + totalScore);
+ frameTxt.setText('Frame: ' + frame + '/' + maxFrames);
+ throwTxt.setText('Throw: ' + currentThrow + '/' + throwsPerFrame);
+}
+// Helper: next throw or frame
+function nextThrowOrFrame() {
+ var pinsDown = 10 - countStandingPins();
+ pinsDownThisFrame += pinsDown;
+ totalScore += pinsDown;
+ LK.setScore(totalScore);
+ updateGUI();
+ if (allPinsDown()) {
+ // Strike or spare
+ LK.getSound('strike').play();
+ LK.effects.flashObject(scoreTxt, 0xffd700, 800);
+ // Next frame
+ frame++;
+ if (frame > maxFrames) {
+ LK.showGameOver();
+ gameOver = true;
+ return;
+ }
+ resetPins();
+ pinsDownThisFrame = 0;
+ currentThrow = 1;
+ } else if (currentThrow < throwsPerFrame) {
+ // Next throw in same frame
+ currentThrow++;
+ } else {
+ // End of frame
+ frame++;
+ if (frame > maxFrames) {
+ LK.showGameOver();
+ gameOver = true;
+ return;
+ }
+ resetPins();
+ pinsDownThisFrame = 0;
+ currentThrow = 1;
+ }
+ // Reset ball
+ ball.reset(ballStartX, ballStartY);
+ isBallRolling = false;
+ isAiming = false;
+ aimStart = null;
+ aimEnd = null;
+ updateGUI();
+}
+// Touch/drag controls
+var dragStart = null;
+var dragEnd = null;
+var dragActive = false;
+function isOnBall(x, y) {
+ var dx = x - ball.x;
+ var dy = y - ball.y;
+ return dx * dx + dy * dy < ball.radius * ball.radius * 1.2;
+}
+game.down = function (x, y, obj) {
+ if (gameOver) return;
+ if (isBallRolling) return;
+ // Only allow drag if touch is on ball and ball is at start
+ if (isOnBall(x, y) && !isBallRolling) {
+ dragStart = {
+ x: x,
+ y: y
+ };
+ dragActive = true;
+ isAiming = true;
+ }
+};
+game.move = function (x, y, obj) {
+ if (gameOver) return;
+ if (!dragActive) return;
+ // Show aiming line (not implemented visually)
+ dragEnd = {
+ x: x,
+ y: y
+ };
+};
+game.up = function (x, y, obj) {
+ if (gameOver) return;
+ if (!dragActive) return;
+ dragActive = false;
+ isAiming = false;
+ dragEnd = {
+ x: x,
+ y: y
+ };
+ // Calculate swipe vector
+ var dx = dragEnd.x - dragStart.x;
+ var dy = dragEnd.y - dragStart.y;
+ // Only allow upward swipes
+ if (dy > -40) return;
+ // Set ball velocity based on swipe
+ var speed = Math.min(Math.sqrt(dx * dx + dy * dy), 1200);
+ var norm = Math.sqrt(dx * dx + dy * dy);
+ if (norm === 0) return;
+ ball.vx = dx / norm * (speed / 18);
+ ball.vy = dy / norm * (speed / 12);
+ ball.isRolling = true;
+ isBallRolling = true;
+ LK.getSound('roll').play();
+};
+// Game update loop
+game.update = function () {
+ if (gameOver) return;
+ ball.update();
+ // Ball stays in lane
+ var laneLeft = lane.x - lane.width / 2 + ball.radius;
+ var laneRight = lane.x + lane.width / 2 - ball.radius;
+ if (ball.x < laneLeft) {
+ ball.x = laneLeft;
+ ball.vx *= -0.5;
+ }
+ if (ball.x > laneRight) {
+ ball.x = laneRight;
+ ball.vx *= -0.5;
+ }
+ // Ball reaches pins
+ if (ball.isRolling) {
+ handleBallPinCollisions();
+ // Ball out of lane (top)
+ if (ball.y < lane.y + 100) {
+ ball.isRolling = false;
+ isBallRolling = false;
+ LK.setTimeout(nextThrowOrFrame, 700);
+ }
+ // Ball stops moving
+ if (!ball.isRolling) {
+ LK.setTimeout(nextThrowOrFrame, 700);
+ }
+ }
+};
+// Initial GUI update
+updateGUI();
\ No newline at end of file