User prompt
her strike yapıldığında ortadaki engel biraz daha uzasın ve penguenin hızını biraz daha düşür, penguenin ateşe çarpıp yandığı yere başka bir ses eklemek istiyorum
User prompt
penguen yanarken başka bir resim olsun
User prompt
penguen ortada çıkan engele değdiğinde yansın
User prompt
penguen çok hızlı fırlıyor biraz yavaşlatalım
User prompt
eğer ortadaki engele 3 kere çarparsa penguen yanarak ölsün ve yandığı zamanki resmini değiştirebileyim
User prompt
ortada çıkan engel çizgisinin resmini değiştiremiyorum
User prompt
ortadaki çizginin arkasına ışınlanıyor , o şekilde olmasını istemiyorum çizginin bir duvar gibi olduğunu düşün aynı çerçevede olduğu gibi görev görsün ona vurursa penguen geriye seksin ve pengueni biraz yavaşlat çok hızlı gidiyor
User prompt
strike yaptıktan sonra çıkan engel hala geçirgen , o çizgi geçirgen olmasın aynı duvar gibi ona vurulduğunda geri sekilsin
User prompt
ekranın ortasında çıkan engel geçilmez olsun yani duvar gibi ona dokununca penguen seksin
User prompt
penguen mouse ile itme hızımıza göre hızını alsın her seferinde aynı hızda gitmesin örneğin yavaş fırlatırsak yavaş hızlı fırlatırsak hızlı gitsin
User prompt
penguenin hızı biraz yavaşlasın ve engel yatay olarak karşımıza çıksın
User prompt
labutlara sadece önden vurunca yıkılması ister arkadan ister sağdan ister soldan nereden vurursan vur gerçek fizik kurallarına uygun olarak yıkılsınlar , her levelde labutların arasının açılması mekaniğini iptal et yen bir mekanik ekliyoruz her strike yapışta ekranın ortasında ya sağdan ya da soldan bir engel çıksın ve bu engelin olmadığı boş alandan pengueni atıp labutları yıkabilelim ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
eğer penguen duvardan sekerek labutlara gelirse de labutları yıkabilsin
User prompt
eğer strike yapamazsa labutlar sıfırdan dizilmesin kaldığı yerden devam etsin
User prompt
penguenin hızını biraz arttır bu sefer hiç gitmiyor
User prompt
penguenin sürtünme hızı daha biraz daha yavaşlasın gerçek bir buzun üzerinde kayıyomuş hissiyatı versin, oyuncu her strike yaptığında labutlar etrafa daha fazla açılsın ve vurması zorlaşsın 2 kere strike yapamazsa game over olsun ve oyun tekrar başlasın
User prompt
labutların arasını biraz daha aç ve penguen çarpar çarpmaz hepsi yıkılmasın gerçek fizik kurallarına uygun yıkılsınlar , duvardan çarptırarak atarsan daha fazla puan versin
User prompt
When the penguin hits the wall, calculate the reflection vector based on a 90-degree bounce logic and apply reduced velocity. The penguin should continue moving in that new direction.
User prompt
The light blue area should also act like a wall, and when the penguin hits it, it should bounce off.
User prompt
Make the entire frame of the game act like a wall, so that when the penguin hits it, it bounces off.
User prompt
The edges should be walls, but when the penguin hits them, its speed should decrease, and it should continue moving at a perfect 90-degree angle.
User prompt
Only the front pins should fall over, and there should be a mechanic where the pins disappear by colliding with each other. If the penguin goes straight, it should knock all the pins over.
User prompt
When the penguin is released, at the maximum speed, it should definitely reach the pins. However, if it is thrown more slowly, it shouldn't reach the pins.
User prompt
The penguin should move a bit faster, and the arrow should be removed. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
The arrow should start from where the penguin is being held, and the farther I pull the penguin, the farther it should be launched.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var AimArrow = Container.expand(function () { var self = Container.call(this); // Create arrow components var arrowLine = self.attachAsset('aimLine', { anchorX: 0.5, anchorY: 1.0, width: 10, height: 150 }); // Set initial visibility self.visible = false; // Update arrow position and rotation based on angle self.updateArrow = function (startX, startY, angle) { self.x = startX; self.y = startY; self.rotation = angle; self.visible = true; }; self.hide = function () { self.visible = false; }; return self; }); var BowlingPin = Container.expand(function () { var self = Container.call(this); var pinGraphics = self.attachAsset('bowlingPin', { anchorX: 0.5, anchorY: 0.5 }); self.isKnockedDown = false; self.velocityX = 0; self.velocityY = 0; self.friction = 0.95; self.lastX = 0; self.lastY = 0; self.row = 0; // Store which row this pin belongs to self.mass = 1 + Math.random() * 0.2; // Slight mass variation for more realistic physics self.collisionEnergy = 0; // Track collision energy for better pin-to-pin interactions self.rotationVelocity = 0; // Track rotation velocity separately self.knockDown = function () { if (!self.isKnockedDown) { self.isKnockedDown = true; // Calculate direction based on the impact var directionX = Math.random() - 0.5; var directionY = Math.random() * 0.3 + 0.7; // Mostly forward, slight randomness // More realistic physics - calculate velocity based on position, mass, etc. self.velocityX = directionX * (5 + Math.random() * 3); self.velocityY = directionY * (5 + Math.random() * 3); self.rotationVelocity = (Math.random() - 0.5) * 0.2; // Add collision energy for pin-to-pin interactions self.collisionEnergy = 10; LK.getSound('pinHit').play(); return true; } return false; }; self.applyImpact = function (impactX, impactY, energy) { // Apply an impact force from another object (pin or penguin) // Direction based on impact position var dirX = self.x - impactX; var dirY = self.y - impactY; // Normalize var length = Math.sqrt(dirX * dirX + dirY * dirY); if (length > 0) { dirX /= length; dirY /= length; } // Apply velocity based on energy and direction var forceScale = energy / self.mass; self.velocityX += dirX * forceScale; self.velocityY += dirY * forceScale; // Add some rotation based on impact offset var rotationImpact = (Math.random() - 0.5) * 0.1 * forceScale; self.rotationVelocity += rotationImpact; // Mark as knocked down if (!self.isKnockedDown) { self.isKnockedDown = true; self.collisionEnergy = energy * 0.8; // Transfer most of the energy LK.getSound('pinHit').play(); return true; } return false; }; self.update = function () { // Store last position for collision detection self.lastX = self.x; self.lastY = self.y; if (self.isKnockedDown) { // Apply velocity self.x += self.velocityX; self.y += self.velocityY; // Apply friction self.velocityX *= self.friction; self.velocityY *= self.friction; // Apply rotation pinGraphics.rotation += self.rotationVelocity; self.rotationVelocity *= 0.98; // Dampen rotation // Gradually reduce collision energy self.collisionEnergy *= 0.95; // More realistic falling behavior with physics-based motion // Pins slow down more when they're almost stopped if (Math.abs(self.velocityX) < 0.5 && Math.abs(self.velocityY) < 0.5) { self.velocityX *= 0.9; self.velocityY *= 0.9; } // Slower fade out for more realistic pin falling if (Math.abs(self.velocityX) < 0.1 && Math.abs(self.velocityY) < 0.1) { pinGraphics.alpha *= 0.99; // Slower fade when stopped } else { pinGraphics.alpha *= 0.995; // Normal fade when moving } // Remove from game when almost invisible if (pinGraphics.alpha < 0.1) { self.visible = false; } } }; self.reset = function () { self.isKnockedDown = false; self.velocityX = 0; self.velocityY = 0; self.rotationVelocity = 0; self.collisionEnergy = 0; pinGraphics.rotation = 0; pinGraphics.alpha = 1; self.visible = true; }; return self; }); var Penguin = Container.expand(function () { var self = Container.call(this); var penguinGraphics = self.attachAsset('penguin', { anchorX: 0.5, anchorY: 0.5 }); // Physics properties self.velocityX = 0; self.velocityY = 0; self.friction = 0.98; // Increased value for faster sliding self.active = false; self.hasCollided = false; self.pullDistance = 0; // Store the pull distance for power calculation self.launch = function (angle, power) { // Scale speed so that only at max power (MAX_POWER) will it reach the pins // Lower power values will result in the penguin not reaching the pins var speedMultiplier = power / MAX_POWER; // Normalize based on max power var baseSpeed = 25; // Minimum speed needed to move var reachPinsSpeed = 40; // Speed needed to reach pins var maxSpeed = baseSpeed + (reachPinsSpeed - baseSpeed) * speedMultiplier; self.velocityX = Math.cos(angle) * maxSpeed; self.velocityY = Math.sin(angle) * maxSpeed; // Special case for throwing straight - make sure it reaches pins at max power if (Math.abs(Math.cos(angle)) < 0.2 && Math.sin(angle) < -0.8 && speedMultiplier > 0.9) { // Adjust vertical speed to ensure it reaches the pins self.velocityY = -reachPinsSpeed; } self.active = true; self.hasCollided = false; LK.getSound('slide').play(); }; self.update = function () { if (!self.active) return; // Apply velocity self.x += self.velocityX; self.y += self.velocityY; // Apply friction // Ice physics - lower friction when moving fast, gradually increases as slowing down var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY); var dynamicFriction = speed > 10 ? 0.995 : 0.98; // More slippery at high speeds (more realistic ice physics) self.velocityX *= dynamicFriction; self.velocityY *= dynamicFriction; // More realistic penguin rotation while sliding var rotationFactor = speed > 5 ? 0.005 : 0.01; // Less rotation at high speeds penguinGraphics.rotation += self.velocityX * rotationFactor; // Stop if velocity is very small if (Math.abs(self.velocityX) < 0.1 && Math.abs(self.velocityY) < 0.1) { self.active = false; self.velocityX = 0; self.velocityY = 0; penguinGraphics.rotation = 0; // Reset rotation when stopped } // Frame boundary checks with proper reflection vectors // Left boundary if (self.x < 0) { self.x = 0; // Calculate reflection vector for a 90-degree bounce with reduced speed var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY) * 0.8; self.velocityX = -self.velocityX * 0.8; // Reverse X direction with reduced speed // If X velocity is very small, set to zero for perfect 90-degree bounce if (Math.abs(self.velocityX) < 0.5) { self.velocityX = 0; // Perfect 90 degrees means no horizontal movement self.velocityY = self.velocityY > 0 ? speed : -speed; // Maintain vertical direction } // Award wall bounce bonus if active and hasn't collided yet if (self.active && !self.hasCollided) { self.wallBounceCount = self.wallBounceCount || 0; self.wallBounceCount++; } } // Right boundary else if (self.x > 2048) { self.x = 2048; // Calculate reflection vector for a 90-degree bounce with reduced speed var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY) * 0.8; self.velocityX = -self.velocityX * 0.8; // Reverse X direction with reduced speed // If X velocity is very small, set to zero for perfect 90-degree bounce if (Math.abs(self.velocityX) < 0.5) { self.velocityX = 0; // Perfect 90 degrees means no horizontal movement self.velocityY = self.velocityY > 0 ? speed : -speed; // Maintain vertical direction } } // Top boundary if (self.y < 0) { self.y = 0; // Calculate reflection vector for a 90-degree bounce with reduced speed var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY) * 0.8; self.velocityY = -self.velocityY * 0.8; // Reverse Y direction with reduced speed // If Y velocity is very small, set to zero for perfect 90-degree bounce if (Math.abs(self.velocityY) < 0.5) { self.velocityY = 0; // Perfect 90 degrees means no vertical movement self.velocityX = self.velocityX > 0 ? speed : -speed; // Maintain horizontal direction } } // Bottom boundary if (self.y > 2732) { self.y = 2732; // Calculate reflection vector for a 90-degree bounce with reduced speed var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY) * 0.8; self.velocityY = -self.velocityY * 0.8; // Reverse Y direction with reduced speed // If Y velocity is very small, set to zero for perfect 90-degree bounce if (Math.abs(self.velocityY) < 0.5) { self.velocityY = 0; // Perfect 90 degrees means no vertical movement self.velocityX = self.velocityX > 0 ? speed : -speed; // Maintain horizontal direction } } // Bowling lane boundary checks (light blue area) // Calculate bowling lane boundaries var laneLeftBoundary = bowlingLane.x - bowlingLane.width / 2; var laneRightBoundary = bowlingLane.x + bowlingLane.width / 2; var laneTopBoundary = bowlingLane.y; var laneBottomBoundary = bowlingLane.y + bowlingLane.height; // Check if penguin is outside the lane but not outside the game boundaries // Left lane boundary if (self.x < laneLeftBoundary && self.x > 0) { self.x = laneLeftBoundary; // Calculate reflection vector for a 90-degree bounce with reduced speed var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY) * 0.8; self.velocityX = -self.velocityX * 0.8; // Reverse X direction with reduced speed // If X velocity is very small, set to zero for perfect 90-degree bounce if (Math.abs(self.velocityX) < 0.5) { self.velocityX = 0; self.velocityY = self.velocityY > 0 ? speed : -speed; } } // Right lane boundary else if (self.x > laneRightBoundary && self.x < 2048) { self.x = laneRightBoundary; // Calculate reflection vector for a 90-degree bounce with reduced speed var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY) * 0.8; self.velocityX = -self.velocityX * 0.8; // Reverse X direction with reduced speed // If X velocity is very small, set to zero for perfect 90-degree bounce if (Math.abs(self.velocityX) < 0.5) { self.velocityX = 0; self.velocityY = self.velocityY > 0 ? speed : -speed; } } // Top lane boundary if (self.y < laneTopBoundary && self.y > 0) { self.y = laneTopBoundary; // Calculate reflection vector for a 90-degree bounce with reduced speed var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY) * 0.8; self.velocityY = -self.velocityY * 0.8; // Reverse Y direction with reduced speed // If Y velocity is very small, set to zero for perfect 90-degree bounce if (Math.abs(self.velocityY) < 0.5) { self.velocityY = 0; self.velocityX = self.velocityX > 0 ? speed : -speed; } } // Bottom lane boundary if (self.y > laneBottomBoundary && self.y < 2732) { self.y = laneBottomBoundary; // Calculate reflection vector for a 90-degree bounce with reduced speed var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY) * 0.8; self.velocityY = -self.velocityY * 0.8; // Reverse Y direction with reduced speed // If Y velocity is very small, set to zero for perfect 90-degree bounce if (Math.abs(self.velocityY) < 0.5) { self.velocityY = 0; self.velocityX = self.velocityX > 0 ? speed : -speed; } } }; self.reset = function () { self.x = launchArea.x; self.y = launchArea.y - 250; // Move penguin further up the lane self.velocityX = 0; self.velocityY = 0; self.active = false; self.hasCollided = false; self.pullDistance = 0; // Reset pull distance self.wallBounceCount = 0; // Reset wall bounce counter penguinGraphics.rotation = 0; }; return self; }); var PowerMeter = Container.expand(function () { var self = Container.call(this); var meterBG = self.attachAsset('powerMeterBG', { anchorX: 0.5, anchorY: 0.5 }); var meter = self.attachAsset('powerMeter', { anchorX: 0.5, anchorY: 1.0, height: 0 // Start with no power }); var maxPower = 300; self.power = 0; self.increasing = true; self.update = function () { if (self.visible) { if (self.increasing) { self.power += 5; if (self.power >= maxPower) { self.power = maxPower; self.increasing = false; } } else { self.power -= 5; if (self.power <= 0) { self.power = 0; self.increasing = true; } } // Update meter height based on power meter.height = self.power; meter.y = meterBG.y + meterBG.height / 2 - meter.height / 2; } }; self.getPowerRatio = function () { return self.power / maxPower; }; self.reset = function () { self.power = 0; self.increasing = true; meter.height = 0; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xC7E6F7 }); /**** * Game Code ****/ // Game constants var MAX_POWER = 20; var PIN_ROWS = 4; var FRAMES = 10; var PINS_PER_FRAME = 10; // Game state variables var currentFrame = 1; var pinsKnockedDown = 0; var totalScore = 0; var aiming = false; var powering = false; var gameState = "aiming"; // States: aiming, powering, sliding, scoring, gameover var aimAngle = -Math.PI / 2; // Start aiming straight up var consecutiveFailedStrikes = 0; // Track consecutive failures to get a strike var strikeInLastFrame = false; // Track if the player got a strike in the last frame var obstacle = null; // Reference to obstacle object // Create background var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0 })); // Create bowling lane var bowlingLane = game.addChild(LK.getAsset('bowlingLane', { anchorX: 0.5, anchorY: 0, x: 2048 / 2, y: 100 })); // Create launch area var launchArea = game.addChild(LK.getAsset('launchArea', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2400 })); // Create the aiming line var aimLine = game.addChild(LK.getAsset('aimLine', { anchorX: 0.5, anchorY: 1.0, x: launchArea.x, y: launchArea.y, visible: false })); // Arrow removed as requested // Create the power meter var powerMeter = game.addChild(new PowerMeter()); powerMeter.x = 1900; powerMeter.y = 1400; powerMeter.visible = false; // Create the penguin var penguin = game.addChild(new Penguin()); penguin.x = launchArea.x; penguin.y = launchArea.y - 250; // Move penguin further up the lane // Create bowling pins var pins = []; setupPins(); // Create UI elements var frameText = new Text2('Frame: 1/10', { size: 70, fill: 0x000000 }); frameText.anchor.set(0.5, 0); // Position frame text under the penguin's position frameText.y = penguin.y + 150; LK.gui.center.addChild(frameText); var scoreText = new Text2('Score: 0', { size: 70, fill: 0x000000 }); scoreText.anchor.set(0.5, 0); scoreText.y = 80; LK.gui.top.addChild(scoreText); var instructionText = new Text2('Tap and drag to pull penguin back, release to launch', { size: 50, fill: 0x000000 }); instructionText.anchor.set(0.5, 0); instructionText.y = 180; LK.gui.top.addChild(instructionText); // Helper functions function setupPins() { // Clear any existing pins for (var i = 0; i < pins.length; i++) { pins[i].destroy(); } pins = []; // Create pin layout in traditional bowling triangle formation // Ensure pins are exactly centered on the lane var startX = 2048 / 2; // Center of screen var startY = 400; // Position from top var pinSpacingX = 120; // Fixed horizontal spacing regardless of strikes var pinSpacingY = 120; // Fixed vertical spacing regardless of strikes // Standard bowling pin layout (4-3-2-1 triangle) // First row (back) - 4 pins for (var i = 0; i < 4; i++) { var pin = new BowlingPin(); pin.x = startX + (i - 1.5) * pinSpacingX; // Perfectly centered pin.y = startY; pin.row = 1; // Back row pin.lastX = pin.x; pin.lastY = pin.y; pins.push(pin); game.addChild(pin); } // Second row - 3 pins for (var i = 0; i < 3; i++) { var pin = new BowlingPin(); pin.x = startX + (i - 1) * pinSpacingX; // Centered relative to first row pin.y = startY + pinSpacingY; pin.row = 2; // Second row pin.lastX = pin.x; pin.lastY = pin.y; pins.push(pin); game.addChild(pin); } // Third row - 2 pins for (var i = 0; i < 2; i++) { var pin = new BowlingPin(); pin.x = startX + (i - 0.5) * pinSpacingX; // Centered relative to second row pin.y = startY + 2 * pinSpacingY; pin.row = 3; // Third row pin.lastX = pin.x; pin.lastY = pin.y; pins.push(pin); game.addChild(pin); } // Fourth row (front) - 1 pin var pin = new BowlingPin(); pin.x = startX; // Center pin pin.y = startY + 3 * pinSpacingY; pin.row = 4; // Front row pin.lastX = pin.x; pin.lastY = pin.y; pins.push(pin); game.addChild(pin); pinsKnockedDown = 0; // Remove any existing obstacle if (typeof obstacle !== 'undefined' && obstacle) { obstacle.destroy(); obstacle = null; } // Add obstacle after strike if (currentFrame > 1 && strikeInLastFrame) { // Create obstacle based on a random position (left or right) var obstaclePosition = Math.random() < 0.5 ? "left" : "right"; obstacle = game.addChild(LK.getAsset('aimLine', { anchorX: 0.5, anchorY: 0.5, width: 50, height: 500, x: obstaclePosition === "left" ? startX - 200 : startX + 200, y: 1200, tint: 0x333333 })); // Display instruction about the obstacle instructionText.setText("Obstacle added! Find a way around it to hit the pins!"); } } function updateAimLine() { aimLine.rotation = aimAngle; // Ensure the aim line points from the penguin position aimLine.x = launchArea.x; aimLine.y = launchArea.y; } function launchPenguin() { // Calculate power based on the pull distance var powerRatio = Math.min(penguin.pullDistance / 300, 1); // Normalize based on max drag distance var power = powerRatio * MAX_POWER; // Launch penguin from current position toward the launch area var launchAngle = aimAngle + Math.PI; // Reverse the angle to launch toward the pins penguin.launch(launchAngle, power); gameState = "sliding"; powerMeter.visible = false; // Update instruction text based on power and difficulty var difficultyMsg = pinSpacingMultiplier > 1.0 ? " - Difficulty: " + Math.round((pinSpacingMultiplier - 1) * 100) + "%" : ""; if (powerRatio >= 0.9) { instructionText.setText("Full power! Watch the penguin slide!" + difficultyMsg); } else { instructionText.setText("Watch the penguin slide! (Power: " + Math.round(powerRatio * 100) + "%)" + difficultyMsg); } } function checkCollisions() { if (!penguin.active || penguin.hasCollided) return; var newKnockdowns = 0; // Calculate penguin velocity magnitude for physics-based knockdown var penguinSpeed = Math.sqrt(penguin.velocityX * penguin.velocityX + penguin.velocityY * penguin.velocityY); var penguinDirection = Math.atan2(penguin.velocityY, penguin.velocityX); // Check penguin collision with ANY pin based on realistic physics for (var i = 0; i < pins.length; i++) { var pin = pins[i]; if (!pin.isKnockedDown && penguin.intersects(pin)) { // Calculate direction of impact from penguin to pin var impactAngle = Math.atan2(pin.y - penguin.y, pin.x - penguin.x); // Calculate angle difference to determine if hitting from front, side, etc. var angleDiff = Math.abs((impactAngle - penguinDirection + Math.PI) % (2 * Math.PI) - Math.PI); // More realistic physics: energy transfer based on angle of impact and penguin speed var energyTransfer = penguinSpeed * (1 - angleDiff / Math.PI); // Knock down pin with physics impact if (pin.applyImpact(penguin.x, penguin.y, energyTransfer)) { newKnockdowns++; pinsKnockedDown++; // Update score totalScore += 1; updateScoreDisplay(); } } } // Now check for pin-to-pin collisions between ALL pins with realistic physics for (var i = 0; i < pins.length; i++) { var pin1 = pins[i]; if (pin1.isKnockedDown && pin1.collisionEnergy > 1) { // This pin is moving with enough energy to cause collisions for (var j = 0; j < pins.length; j++) { var pin2 = pins[j]; if (i !== j && pin1.intersects(pin2)) { // Calculate impact dynamics var impactDirection = Math.atan2(pin2.y - pin1.y, pin2.x - pin1.x); var impactSpeed = Math.sqrt(pin1.velocityX * pin1.velocityX + pin1.velocityY * pin1.velocityY); // If pin2 is not knocked down, apply impact if (!pin2.isKnockedDown) { if (pin2.applyImpact(pin1.x, pin1.y, pin1.collisionEnergy * 0.7)) { pinsKnockedDown++; totalScore += 1; updateScoreDisplay(); } } // Both pins are moving - apply realistic collision physics else { // Calculate new velocities based on conservation of momentum var velocity1 = Math.sqrt(pin1.velocityX * pin1.velocityX + pin1.velocityY * pin1.velocityY); var velocity2 = Math.sqrt(pin2.velocityX * pin2.velocityX + pin2.velocityY * pin2.velocityY); if (velocity1 > 0.5 || velocity2 > 0.5) { // Simple elastic collision - exchange some momentum var tempVX = pin1.velocityX * 0.5; var tempVY = pin1.velocityY * 0.5; pin1.velocityX = pin1.velocityX * 0.5 + pin2.velocityX * 0.5; pin1.velocityY = pin1.velocityY * 0.5 + pin2.velocityY * 0.5; pin2.velocityX = tempVX * 0.5 + pin2.velocityX * 0.5; pin2.velocityY = tempVY * 0.5 + pin2.velocityY * 0.5; // Add some random scatter for realism pin1.velocityX += (Math.random() - 0.5) * 0.5; pin1.velocityY += (Math.random() - 0.5) * 0.5; pin2.velocityX += (Math.random() - 0.5) * 0.5; pin2.velocityY += (Math.random() - 0.5) * 0.5; // Update rotation velocities pin1.rotationVelocity += (Math.random() - 0.5) * 0.1; pin2.rotationVelocity += (Math.random() - 0.5) * 0.1; } } } } } } // Handle collision with obstacle if present if (typeof obstacle !== 'undefined' && obstacle && penguin.intersects(obstacle)) { // Detect which side of the obstacle we hit var hitFromLeft = penguin.x < obstacle.x; // Realistic bounce physics if (hitFromLeft) { penguin.x = obstacle.x - obstacle.width / 2 - penguin.width / 2; penguin.velocityX = -Math.abs(penguin.velocityX) * 0.8; } else { penguin.x = obstacle.x + obstacle.width / 2 + penguin.width / 2; penguin.velocityX = Math.abs(penguin.velocityX) * 0.8; } // Add slight vertical component for realism penguin.velocityY += (Math.random() - 0.5) * 2; } if (newKnockdowns > 0) { penguin.hasCollided = true; // Play strike sound if all pins are knocked down if (pinsKnockedDown === PINS_PER_FRAME) { LK.getSound('strike').play(); LK.effects.flashScreen(0xFFFFFF, 500); instructionText.setText("STRIKE!"); } } } function updateScoreDisplay() { scoreText.setText("Score: " + totalScore); // Update high score if needed if (totalScore > storage.highScore) { storage.highScore = totalScore; } } function nextFrame() { // Check if player got a strike var isStrike = pinsKnockedDown === PINS_PER_FRAME; // Store if we had a strike in the last frame to use in setupPins strikeInLastFrame = isStrike; // Update consecutive fails counter if (isStrike) { consecutiveFailedStrikes = 0; instructionText.setText("STRIKE! Next frame will have an obstacle!"); } else { consecutiveFailedStrikes++; // Check for game over condition (2 consecutive failed strikes) if (consecutiveFailedStrikes >= 2) { gameState = "gameover"; instructionText.setText("Game Over! 2 consecutive misses! Final Score: " + totalScore); // Show game over screen after a brief delay LK.setTimeout(function () { LK.showGameOver(); }, 2000); return; } } currentFrame++; if (currentFrame > FRAMES) { // Game over gameState = "gameover"; instructionText.setText("Game Over! Final Score: " + totalScore); // Show game over screen after a brief delay LK.setTimeout(function () { LK.showGameOver(); }, 2000); } else { // Setup for next frame frameText.setText("Frame: " + currentFrame + "/10"); // Reset pins regardless of strike setupPins(); penguin.reset(); gameState = "aiming"; // Update instruction based on presence of obstacle if (typeof obstacle !== 'undefined' && obstacle) { instructionText.setText("Tap and drag backward to aim, find a path around the obstacle!"); } else { instructionText.setText("Tap and drag backward to aim, release to launch"); } } } function checkGameStateTransition() { if (gameState === "sliding") { // Check if penguin has stopped if (!penguin.active) { // Add wall bounce bonus if any if (penguin.wallBounceCount && penguin.wallBounceCount > 0) { var bounceBonus = penguin.wallBounceCount * 2; totalScore += bounceBonus; instructionText.setText("Nice trick shot! +" + bounceBonus + " bonus points!"); updateScoreDisplay(); } // Wait a bit for pins to settle and then move to next frame LK.setTimeout(function () { nextFrame(); }, 2000); gameState = "scoring"; } } } // Event handlers game.down = function (x, y, obj) { if (gameState === "aiming") { aiming = true; aimLine.visible = false; // Store original penguin position penguin.originalX = penguin.x; penguin.originalY = penguin.y; } }; game.move = function (x, y, obj) { if (aiming) { // Calculate aim angle from penguin to opposite of pull direction var dx = launchArea.x - x; var dy = launchArea.y - y; // Calculate the distance of the pull for power var distance = Math.sqrt(dx * dx + dy * dy); // Limit the maximum drag distance var maxDrag = 300; distance = Math.min(distance, maxDrag); // Calculate the angle aimAngle = Math.atan2(dy, dx); // Move the penguin to the drag position penguin.x = launchArea.x - Math.cos(aimAngle) * distance; penguin.y = launchArea.y - Math.sin(aimAngle) * distance; // Store the pull distance for calculating power later penguin.pullDistance = distance; } }; game.up = function (x, y, obj) { if (aiming) { aiming = false; // Only launch if penguin was actually pulled back if (penguin.pullDistance > 10) { // Launch immediately after release launchPenguin(); } else { // Reset penguin position if not pulled back enough penguin.x = penguin.originalX; penguin.y = penguin.originalY; } } }; // Game update loop game.update = function () { if (gameState === "sliding") { penguin.update(); // Update pin physics for (var i = 0; i < pins.length; i++) { pins[i].update(); } checkCollisions(); // Check for pin-to-pin collisions even after penguin has finished moving if (penguin.hasCollided) { for (var i = 0; i < pins.length; i++) { var pin1 = pins[i]; if (pin1.isKnockedDown && pin1.visible && (Math.abs(pin1.velocityX) > 0.5 || Math.abs(pin1.velocityY) > 0.5)) { for (var j = 0; j < pins.length; j++) { var pin2 = pins[j]; if (i !== j && !pin2.isKnockedDown && pin2.visible && pin1.intersects(pin2)) { if (pin2.knockDown()) { pinsKnockedDown++; totalScore++; updateScoreDisplay(); } } } } } } checkGameStateTransition(); } }; // Initialize variables and start the game consecutiveFailedStrikes = 0; pinSpacingMultiplier = 1.0; // Show initial instructions instructionText.setText("Tap and drag backward to aim, release to launch. 2 misses = Game Over!"); // Start background music LK.playMusic('gameMusic'); ;
===================================================================
--- original.js
+++ change.js
@@ -44,23 +44,55 @@
self.friction = 0.95;
self.lastX = 0;
self.lastY = 0;
self.row = 0; // Store which row this pin belongs to
+ self.mass = 1 + Math.random() * 0.2; // Slight mass variation for more realistic physics
+ self.collisionEnergy = 0; // Track collision energy for better pin-to-pin interactions
+ self.rotationVelocity = 0; // Track rotation velocity separately
self.knockDown = function () {
if (!self.isKnockedDown) {
self.isKnockedDown = true;
- // More realistic physical response based on pin position and row
- // Front pins fall backward, back pins fall forward
- var directionModifier = self.row < 3 ? 1 : -1;
- // Add horizontal randomness
- self.velocityX = (Math.random() - 0.5) * 8;
- // Add vertical velocity based on row position
- self.velocityY = directionModifier * (Math.random() * 3 + 2);
+ // Calculate direction based on the impact
+ var directionX = Math.random() - 0.5;
+ var directionY = Math.random() * 0.3 + 0.7; // Mostly forward, slight randomness
+ // More realistic physics - calculate velocity based on position, mass, etc.
+ self.velocityX = directionX * (5 + Math.random() * 3);
+ self.velocityY = directionY * (5 + Math.random() * 3);
+ self.rotationVelocity = (Math.random() - 0.5) * 0.2;
+ // Add collision energy for pin-to-pin interactions
+ self.collisionEnergy = 10;
LK.getSound('pinHit').play();
return true;
}
return false;
};
+ self.applyImpact = function (impactX, impactY, energy) {
+ // Apply an impact force from another object (pin or penguin)
+ // Direction based on impact position
+ var dirX = self.x - impactX;
+ var dirY = self.y - impactY;
+ // Normalize
+ var length = Math.sqrt(dirX * dirX + dirY * dirY);
+ if (length > 0) {
+ dirX /= length;
+ dirY /= length;
+ }
+ // Apply velocity based on energy and direction
+ var forceScale = energy / self.mass;
+ self.velocityX += dirX * forceScale;
+ self.velocityY += dirY * forceScale;
+ // Add some rotation based on impact offset
+ var rotationImpact = (Math.random() - 0.5) * 0.1 * forceScale;
+ self.rotationVelocity += rotationImpact;
+ // Mark as knocked down
+ if (!self.isKnockedDown) {
+ self.isKnockedDown = true;
+ self.collisionEnergy = energy * 0.8; // Transfer most of the energy
+ LK.getSound('pinHit').play();
+ return true;
+ }
+ return false;
+ };
self.update = function () {
// Store last position for collision detection
self.lastX = self.x;
self.lastY = self.y;
@@ -70,13 +102,25 @@
self.y += self.velocityY;
// Apply friction
self.velocityX *= self.friction;
self.velocityY *= self.friction;
- // More realistic falling behavior - pins rotate more when moving faster
- var rotationSpeed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY) * 0.03;
- pinGraphics.rotation += Math.min(rotationSpeed, 0.15);
+ // Apply rotation
+ pinGraphics.rotation += self.rotationVelocity;
+ self.rotationVelocity *= 0.98; // Dampen rotation
+ // Gradually reduce collision energy
+ self.collisionEnergy *= 0.95;
+ // More realistic falling behavior with physics-based motion
+ // Pins slow down more when they're almost stopped
+ if (Math.abs(self.velocityX) < 0.5 && Math.abs(self.velocityY) < 0.5) {
+ self.velocityX *= 0.9;
+ self.velocityY *= 0.9;
+ }
// Slower fade out for more realistic pin falling
- pinGraphics.alpha *= 0.985;
+ if (Math.abs(self.velocityX) < 0.1 && Math.abs(self.velocityY) < 0.1) {
+ pinGraphics.alpha *= 0.99; // Slower fade when stopped
+ } else {
+ pinGraphics.alpha *= 0.995; // Normal fade when moving
+ }
// Remove from game when almost invisible
if (pinGraphics.alpha < 0.1) {
self.visible = false;
}
@@ -85,8 +129,10 @@
self.reset = function () {
self.isKnockedDown = false;
self.velocityX = 0;
self.velocityY = 0;
+ self.rotationVelocity = 0;
+ self.collisionEnergy = 0;
pinGraphics.rotation = 0;
pinGraphics.alpha = 1;
self.visible = true;
};
@@ -128,17 +174,22 @@
// Apply velocity
self.x += self.velocityX;
self.y += self.velocityY;
// Apply friction
- self.velocityX *= self.friction;
- self.velocityY *= self.friction;
- // Slight rotation effect for realism
- penguinGraphics.rotation += self.velocityX * 0.01;
+ // Ice physics - lower friction when moving fast, gradually increases as slowing down
+ var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY);
+ var dynamicFriction = speed > 10 ? 0.995 : 0.98; // More slippery at high speeds (more realistic ice physics)
+ self.velocityX *= dynamicFriction;
+ self.velocityY *= dynamicFriction;
+ // More realistic penguin rotation while sliding
+ var rotationFactor = speed > 5 ? 0.005 : 0.01; // Less rotation at high speeds
+ penguinGraphics.rotation += self.velocityX * rotationFactor;
// Stop if velocity is very small
if (Math.abs(self.velocityX) < 0.1 && Math.abs(self.velocityY) < 0.1) {
self.active = false;
self.velocityX = 0;
self.velocityY = 0;
+ penguinGraphics.rotation = 0; // Reset rotation when stopped
}
// Frame boundary checks with proper reflection vectors
// Left boundary
if (self.x < 0) {
@@ -330,9 +381,10 @@
var powering = false;
var gameState = "aiming"; // States: aiming, powering, sliding, scoring, gameover
var aimAngle = -Math.PI / 2; // Start aiming straight up
var consecutiveFailedStrikes = 0; // Track consecutive failures to get a strike
-var pinSpacingMultiplier = 1.0; // Controls pin spacing based on strikes
+var strikeInLastFrame = false; // Track if the player got a strike in the last frame
+var obstacle = null; // Reference to obstacle object
// Create background
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
@@ -405,10 +457,10 @@
// Create pin layout in traditional bowling triangle formation
// Ensure pins are exactly centered on the lane
var startX = 2048 / 2; // Center of screen
var startY = 400; // Position from top
- var pinSpacingX = 120 * pinSpacingMultiplier; // Increased horizontal spacing based on multiplier
- var pinSpacingY = 120 * pinSpacingMultiplier; // Increased vertical spacing based on multiplier
+ var pinSpacingX = 120; // Fixed horizontal spacing regardless of strikes
+ var pinSpacingY = 120; // Fixed vertical spacing regardless of strikes
// Standard bowling pin layout (4-3-2-1 triangle)
// First row (back) - 4 pins
for (var i = 0; i < 4; i++) {
var pin = new BowlingPin();
@@ -451,8 +503,29 @@
pin.lastY = pin.y;
pins.push(pin);
game.addChild(pin);
pinsKnockedDown = 0;
+ // Remove any existing obstacle
+ if (typeof obstacle !== 'undefined' && obstacle) {
+ obstacle.destroy();
+ obstacle = null;
+ }
+ // Add obstacle after strike
+ if (currentFrame > 1 && strikeInLastFrame) {
+ // Create obstacle based on a random position (left or right)
+ var obstaclePosition = Math.random() < 0.5 ? "left" : "right";
+ obstacle = game.addChild(LK.getAsset('aimLine', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ width: 50,
+ height: 500,
+ x: obstaclePosition === "left" ? startX - 200 : startX + 200,
+ y: 1200,
+ tint: 0x333333
+ }));
+ // Display instruction about the obstacle
+ instructionText.setText("Obstacle added! Find a way around it to hit the pins!");
+ }
}
function updateAimLine() {
aimLine.rotation = aimAngle;
// Ensure the aim line points from the penguin position
@@ -478,46 +551,92 @@
}
function checkCollisions() {
if (!penguin.active || penguin.hasCollided) return;
var newKnockdowns = 0;
- // First, check penguin collision with front pins only
+ // Calculate penguin velocity magnitude for physics-based knockdown
+ var penguinSpeed = Math.sqrt(penguin.velocityX * penguin.velocityX + penguin.velocityY * penguin.velocityY);
+ var penguinDirection = Math.atan2(penguin.velocityY, penguin.velocityX);
+ // Check penguin collision with ANY pin based on realistic physics
for (var i = 0; i < pins.length; i++) {
var pin = pins[i];
- // Calculate penguin velocity magnitude for physics-based knockdown
- var penguinSpeed = Math.sqrt(penguin.velocityX * penguin.velocityX + penguin.velocityY * penguin.velocityY);
- var isPenguinGoingStraight = Math.abs(penguin.velocityX) < 3 && penguin.velocityY < 0;
- // Check if penguin has hit a wall
- var hasHitWall = penguin.wallBounceCount && penguin.wallBounceCount > 0;
- // Allow any pin to be knocked down if penguin has bounced off a wall
- // Otherwise, use the original logic for direct throws
- var isTargetablePin = hasHitWall || pin.row === 4 || isPenguinGoingStraight && penguinSpeed > 25 && pin.row === 3 || isPenguinGoingStraight && penguinSpeed > 35;
- if (!pin.isKnockedDown && isTargetablePin && penguin.intersects(pin)) {
- if (pin.knockDown()) {
+ if (!pin.isKnockedDown && penguin.intersects(pin)) {
+ // Calculate direction of impact from penguin to pin
+ var impactAngle = Math.atan2(pin.y - penguin.y, pin.x - penguin.x);
+ // Calculate angle difference to determine if hitting from front, side, etc.
+ var angleDiff = Math.abs((impactAngle - penguinDirection + Math.PI) % (2 * Math.PI) - Math.PI);
+ // More realistic physics: energy transfer based on angle of impact and penguin speed
+ var energyTransfer = penguinSpeed * (1 - angleDiff / Math.PI);
+ // Knock down pin with physics impact
+ if (pin.applyImpact(penguin.x, penguin.y, energyTransfer)) {
newKnockdowns++;
pinsKnockedDown++;
// Update score
totalScore += 1;
updateScoreDisplay();
}
}
}
- // Now check for pin-to-pin collisions between ALL pins
+ // Now check for pin-to-pin collisions between ALL pins with realistic physics
for (var i = 0; i < pins.length; i++) {
- var pin = pins[i];
- if (pin.isKnockedDown && (Math.abs(pin.velocityX) > 0.5 || Math.abs(pin.velocityY) > 0.5)) {
- // This pin is moving and can cause collisions
+ var pin1 = pins[i];
+ if (pin1.isKnockedDown && pin1.collisionEnergy > 1) {
+ // This pin is moving with enough energy to cause collisions
for (var j = 0; j < pins.length; j++) {
- if (i !== j && !pins[j].isKnockedDown && pin.intersects(pins[j])) {
- // This pin collided with another pin
- if (pins[j].knockDown()) {
- pinsKnockedDown++;
- totalScore += 1;
- updateScoreDisplay();
+ var pin2 = pins[j];
+ if (i !== j && pin1.intersects(pin2)) {
+ // Calculate impact dynamics
+ var impactDirection = Math.atan2(pin2.y - pin1.y, pin2.x - pin1.x);
+ var impactSpeed = Math.sqrt(pin1.velocityX * pin1.velocityX + pin1.velocityY * pin1.velocityY);
+ // If pin2 is not knocked down, apply impact
+ if (!pin2.isKnockedDown) {
+ if (pin2.applyImpact(pin1.x, pin1.y, pin1.collisionEnergy * 0.7)) {
+ pinsKnockedDown++;
+ totalScore += 1;
+ updateScoreDisplay();
+ }
}
+ // Both pins are moving - apply realistic collision physics
+ else {
+ // Calculate new velocities based on conservation of momentum
+ var velocity1 = Math.sqrt(pin1.velocityX * pin1.velocityX + pin1.velocityY * pin1.velocityY);
+ var velocity2 = Math.sqrt(pin2.velocityX * pin2.velocityX + pin2.velocityY * pin2.velocityY);
+ if (velocity1 > 0.5 || velocity2 > 0.5) {
+ // Simple elastic collision - exchange some momentum
+ var tempVX = pin1.velocityX * 0.5;
+ var tempVY = pin1.velocityY * 0.5;
+ pin1.velocityX = pin1.velocityX * 0.5 + pin2.velocityX * 0.5;
+ pin1.velocityY = pin1.velocityY * 0.5 + pin2.velocityY * 0.5;
+ pin2.velocityX = tempVX * 0.5 + pin2.velocityX * 0.5;
+ pin2.velocityY = tempVY * 0.5 + pin2.velocityY * 0.5;
+ // Add some random scatter for realism
+ pin1.velocityX += (Math.random() - 0.5) * 0.5;
+ pin1.velocityY += (Math.random() - 0.5) * 0.5;
+ pin2.velocityX += (Math.random() - 0.5) * 0.5;
+ pin2.velocityY += (Math.random() - 0.5) * 0.5;
+ // Update rotation velocities
+ pin1.rotationVelocity += (Math.random() - 0.5) * 0.1;
+ pin2.rotationVelocity += (Math.random() - 0.5) * 0.1;
+ }
+ }
}
}
}
}
+ // Handle collision with obstacle if present
+ if (typeof obstacle !== 'undefined' && obstacle && penguin.intersects(obstacle)) {
+ // Detect which side of the obstacle we hit
+ var hitFromLeft = penguin.x < obstacle.x;
+ // Realistic bounce physics
+ if (hitFromLeft) {
+ penguin.x = obstacle.x - obstacle.width / 2 - penguin.width / 2;
+ penguin.velocityX = -Math.abs(penguin.velocityX) * 0.8;
+ } else {
+ penguin.x = obstacle.x + obstacle.width / 2 + penguin.width / 2;
+ penguin.velocityX = Math.abs(penguin.velocityX) * 0.8;
+ }
+ // Add slight vertical component for realism
+ penguin.velocityY += (Math.random() - 0.5) * 2;
+ }
if (newKnockdowns > 0) {
penguin.hasCollided = true;
// Play strike sound if all pins are knocked down
if (pinsKnockedDown === PINS_PER_FRAME) {
@@ -536,16 +655,14 @@
}
function nextFrame() {
// Check if player got a strike
var isStrike = pinsKnockedDown === PINS_PER_FRAME;
- // Update consecutive fails counter and spacing multiplier
+ // Store if we had a strike in the last frame to use in setupPins
+ strikeInLastFrame = isStrike;
+ // Update consecutive fails counter
if (isStrike) {
consecutiveFailedStrikes = 0;
- // Increase pin spacing for added difficulty after a strike
- pinSpacingMultiplier += 0.15;
- // Cap the multiplier to prevent pins from going off-screen
- pinSpacingMultiplier = Math.min(pinSpacingMultiplier, 2.0);
- instructionText.setText("Pins are spreading out! Next throw will be more challenging!");
+ instructionText.setText("STRIKE! Next frame will have an obstacle!");
} else {
consecutiveFailedStrikes++;
// Check for game over condition (2 consecutive failed strikes)
if (consecutiveFailedStrikes >= 2) {
@@ -569,15 +686,18 @@
}, 2000);
} else {
// Setup for next frame
frameText.setText("Frame: " + currentFrame + "/10");
- // Only reset pins if player got a strike, otherwise continue with current pins
- if (isStrike) {
- setupPins();
- }
+ // Reset pins regardless of strike
+ setupPins();
penguin.reset();
gameState = "aiming";
- instructionText.setText("Tap and drag backward to aim, release to launch");
+ // Update instruction based on presence of obstacle
+ if (typeof obstacle !== 'undefined' && obstacle) {
+ instructionText.setText("Tap and drag backward to aim, find a path around the obstacle!");
+ } else {
+ instructionText.setText("Tap and drag backward to aim, release to launch");
+ }
}
}
function checkGameStateTransition() {
if (gameState === "sliding") {
A cartoon-style penguin lying flat on its belly, facing forward with its body stretched out. In-Game asset. 2d. High contrast. No shadows
Bowling pin. In-Game asset. 2d. High contrast. No shadows
iglo. In-Game asset. 2d. High contrast. No shadows
Icy surface. In-Game asset. 2d. High contrast. No shadows
Snow gently falling from the sky in a peaceful winter scene. The snowflakes are soft and light, creating a calm atmosphere. The snow is falling in large, delicate flakes, covering the icy surface and creating a serene, magical ambiance.". In-Game asset. 2d. High contrast. No shadows
horizontal fire. In-Game asset. 2d. High contrast. No shadows
pişmiş tavuk. In-Game asset. 2d. High contrast. No shadows