/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var FireParticle = Container.expand(function () { var self = Container.call(this); // Create particle graphics based on type var graphics; self.particleType = 'fire'; // default type self.setType = function (type) { if (self.graphics) { self.removeChild(self.graphics); } self.particleType = type; if (type === 'fire') { self.graphics = self.attachAsset('fireParticle', { anchorX: 0.5, anchorY: 0.5 }); self.graphics.blendMode = 1; } else if (type === 'core') { self.graphics = self.attachAsset('fireCore', { anchorX: 0.5, anchorY: 0.5 }); self.graphics.blendMode = 1; } else if (type === 'smoke') { self.graphics = self.attachAsset('smoke', { anchorX: 0.5, anchorY: 0.5 }); } }; // Initialize with default type self.setType('fire'); // Particle properties self.velocityX = 0; self.velocityY = 0; self.life = 1.0; self.maxLife = 1.0; self.update = function () { // Move particle self.x += self.velocityX; self.y += self.velocityY; // Reduce life - slower for smoke particles if (self.particleType === 'smoke') { self.life -= 0.0054; } else { self.life -= 0.0154; } // Update appearance based on life if (self.graphics) { self.graphics.alpha = Math.max(0, self.life / self.maxLife); if (self.particleType !== 'smoke') { self.graphics.scaleX = self.life; self.graphics.scaleY = self.life; } } // Add some randomness to movement - less for smoke if (self.particleType === 'smoke') { self.velocityX += (Math.random() - 0.5) * 0.1; self.velocityY += (Math.random() - 0.5) * 0.05; } else { self.velocityX += (Math.random() - 0.5) * 0.25; self.velocityY += (Math.random() - 0.5) * 0.15; } // Gravity effect for smoke if (self.particleType === 'smoke') { self.velocityY -= 0.02; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x51ff00 }); /**** * Game Code ****/ // Add background image fullscreen // Fire color assets that grow with wood placement var fireColorSize = 100; // Base size that will grow by 5 each wood placement var background = game.attachAsset('background1', { x: 0, y: 0, width: 2048, height: 2732 }); // Fire animation system var fireParticles = []; var fireBaseX = 1024; // Center of screen var fireBaseY = 1800; // Center of screen vertically var baseFireScale = 0.2; // Base scale factor for fire size (20x20) var fireScale = baseFireScale; // Current fire scale (will increase with burning wood) var burningWoodCount = 0; // Track number of burning wood pieces var lastWoodPlacedTime = LK.ticks; // Track when wood was last placed on fire var fireReductionTimer = 10 * 60; // 10 seconds at 60fps var gameStartTime = LK.ticks; // Track when game started var initialFireReductionStarted = true; // Track if initial reduction has started var fireGrowthTimer = null; // Timer for automatic fire growth var maxFireScale = 2.0; // Maximum fire scale (200x200 pixels) // Play fire sound repeatedly var fireSoundTimer = LK.setInterval(function () { LK.getSound('Firesound').play(); }, 2000); // Play every 2 seconds // Track wood placement count for incremental growth var woodPlacementCount = 0; // Function to update fire color asset sizes function updateFireColorSizes() { fireColorSize = Math.min(100 + woodPlacementCount * 5, 200); // Grow by 5 pixels per wood, max 200 // Reinitialize all fire color assets with new size } // Create fire particles continuously var fireTimer = LK.setInterval(function () { // Create main fire particles for (var i = 0; i < 16; i++) { var particle = new FireParticle(); // Use different fire color assets randomly var fireTypes = ['fireParticle', 'fireOrange', 'fireLightOrange', 'fireGold', 'fireBlue', 'fireGreen', 'fireMagenta', 'fireCyan', 'firePurple']; var randomFireType = fireTypes[Math.floor(Math.random() * fireTypes.length)]; if (particle.graphics) { particle.removeChild(particle.graphics); } particle.graphics = particle.attachAsset(randomFireType, { anchorX: 0.5, anchorY: 0.5 }); particle.graphics.blendMode = 1; particle.x = fireBaseX + (Math.random() - 0.5) * 2080 * fireScale; particle.y = fireBaseY + 300 + (Math.random() - 0.5) * 832 * fireScale; particle.velocityX = (Math.random() - 0.5) * 4; particle.velocityY = -Math.random() * 10 - 4; particle.life = 1.0; particle.maxLife = 1.0; // Scale animation - much bigger particles particle.graphics.scaleX = 2.0 + Math.random() * 2.0; particle.graphics.scaleY = 2.0 + Math.random() * 2.0; tween(particle.graphics, { scaleX: particle.graphics.scaleX * 3.0, scaleY: particle.graphics.scaleY * 3.0 }, { duration: 500 + Math.random() * 500, easing: tween.easeOut }); fireParticles.push(particle); game.addChild(particle); } // Create core fire particles (yellow/white) for (var j = 0; j < 10; j++) { var coreParticle = new FireParticle(); // Use core fire assets randomly var coreTypes = ['fireCore', 'fireYellowWhite', 'whiteParticle']; var randomCoreType = coreTypes[Math.floor(Math.random() * coreTypes.length)]; if (coreParticle.graphics) { coreParticle.removeChild(coreParticle.graphics); } coreParticle.graphics = coreParticle.attachAsset(randomCoreType, { anchorX: 0.5, anchorY: 0.5 }); coreParticle.graphics.blendMode = 1; coreParticle.x = fireBaseX + (Math.random() - 0.5) * 1300 * fireScale; coreParticle.y = fireBaseY + 300 + (Math.random() - 0.5) * 624 * fireScale; coreParticle.velocityX = (Math.random() - 0.5) * 3; coreParticle.velocityY = -Math.random() * 9 - 5; coreParticle.life = 1.0; coreParticle.maxLife = 1.0; // Much bigger core particles coreParticle.graphics.scaleX = 2.5; coreParticle.graphics.scaleY = 2.5; fireParticles.push(coreParticle); game.addChild(coreParticle); } // Create bright white hot center particles for (var k = 0; k < 6; k++) { var whiteParticle = new FireParticle(); if (whiteParticle.graphics) { whiteParticle.removeChild(whiteParticle.graphics); } whiteParticle.graphics = whiteParticle.attachAsset('whiteParticle', { anchorX: 0.5, anchorY: 0.5 }); whiteParticle.graphics.blendMode = 1; whiteParticle.x = fireBaseX + (Math.random() - 0.5) * 780 * fireScale; whiteParticle.y = fireBaseY + 300 + (Math.random() - 0.5) * 416 * fireScale; whiteParticle.velocityX = (Math.random() - 0.5) * 2; whiteParticle.velocityY = -Math.random() * 7.5 - 4; whiteParticle.life = 1.0; whiteParticle.maxLife = 1.0; // Intense white hot center particles whiteParticle.graphics.scaleX = 1.8; whiteParticle.graphics.scaleY = 1.8; // Add white glow effect with tween tween(whiteParticle.graphics, { scaleX: whiteParticle.graphics.scaleX * 2.5, scaleY: whiteParticle.graphics.scaleY * 2.5 }, { duration: 400 + Math.random() * 300, easing: tween.easeOut }); fireParticles.push(whiteParticle); game.addChild(whiteParticle); } // Create white base particles at the bottom of the fire for (var m = 0; m < 12; m++) { var whiteBaseParticle = new FireParticle(); if (whiteBaseParticle.graphics) { whiteBaseParticle.removeChild(whiteBaseParticle.graphics); } whiteBaseParticle.graphics = whiteBaseParticle.attachAsset('whiteParticle', { anchorX: 0.5, anchorY: 0.5 }); whiteBaseParticle.graphics.blendMode = 1; whiteBaseParticle.x = fireBaseX + (Math.random() - 0.5) * 1040 * fireScale; whiteBaseParticle.y = fireBaseY + 300 + 150 * fireScale + (Math.random() - 0.5) * 520 * fireScale; whiteBaseParticle.velocityX = (Math.random() - 0.5) * 1.5; whiteBaseParticle.velocityY = -Math.random() * 2.5 - 1; whiteBaseParticle.life = 1.0; whiteBaseParticle.maxLife = 1.0; // Base white particles same size as other fire particles whiteBaseParticle.graphics.scaleX = 2.0 + Math.random() * 1.0; whiteBaseParticle.graphics.scaleY = 2.0 + Math.random() * 1.0; // Add gentle scaling animation tween(whiteBaseParticle.graphics, { scaleX: whiteBaseParticle.graphics.scaleX * 2.0, scaleY: whiteBaseParticle.graphics.scaleY * 2.0 }, { duration: 600 + Math.random() * 400, easing: tween.easeOut }); fireParticles.push(whiteBaseParticle); game.addChild(whiteBaseParticle); // Move white base particles to back (behind fire) game.setChildIndex(whiteBaseParticle, 1); } // Create smoke particles (black/dark) - 10x more particles for (var s = 0; s < 10; s++) { var smokeParticle = new FireParticle(); // Use different smoke color assets randomly var smokeTypes = ['smoke', 'smokeGray', 'smokeLightGray', 'smokePurple', 'smokeTeal', 'smokeYellow']; var randomSmokeType = smokeTypes[Math.floor(Math.random() * smokeTypes.length)]; if (smokeParticle.graphics) { smokeParticle.removeChild(smokeParticle.graphics); } smokeParticle.graphics = smokeParticle.attachAsset(randomSmokeType, { anchorX: 0.5, anchorY: 0.5 }); smokeParticle.x = fireBaseX + (Math.random() - 0.5) * 1664 * fireScale; smokeParticle.y = fireBaseY + 300 - 300 * fireScale - Math.random() * 1040 * fireScale; smokeParticle.velocityX = (Math.random() - 0.5) * 3; smokeParticle.velocityY = -Math.random() * 3 - 1; smokeParticle.life = 3.9; smokeParticle.maxLife = 3.9; // Smoke particles start small (5-10px range) and grow slightly var startScale = 0.05 + Math.random() * 0.05; // 5-10px range from 100px base tween(smokeParticle.graphics, { scaleX: startScale * 2, scaleY: startScale * 2 }, { duration: 7800, easing: tween.easeOut }); smokeParticle.graphics.scaleX = startScale; smokeParticle.graphics.scaleY = startScale; fireParticles.push(smokeParticle); game.addChild(smokeParticle); // Move smoke particles to back (behind fire particles) game.setChildIndex(smokeParticle, 1); } }, 80); // Update fire system game.update = function () { // Count burning wood pieces and update fire scale burningWoodCount = 0; for (var w = 0; w < woodPieces.length; w++) { if (woodPieces[w].isBurning) { burningWoodCount++; } } // Start fire reduction only after no wood has been placed for a while AND fire has stopped growing var timeSinceLastWood = LK.ticks - lastWoodPlacedTime; var delayBeforeReduction = 5 * 60; // 5 seconds delay before starting reduction var fireFinishedGrowing = fireScale >= maxFireScale || fireGrowthTimer === null; if (!initialFireReductionStarted && timeSinceLastWood >= delayBeforeReduction && burningWoodCount === 0 && fireFinishedGrowing) { // Create a dummy object to tween the fireScale value var fireScaleObj = { value: fireScale }; // Begin fire reduction after delay using tween - first phase to 5x5 size var minSize = 5.0 / 100.0; // 5x5 pixels out of 100 pixel base asset tween(fireScaleObj, { value: minSize }, { duration: 8000, // 8 seconds to reach minimum size easing: tween.linear, onFinish: function onFinish() { // Start second phase: reduce from 5x5 to 0x0 tween(fireScaleObj, { value: 0 }, { duration: 2000, // 2 seconds to reach 0 easing: tween.linear, onFinish: function onFinish() { // Create dark overlay for screen fade var darkOverlay = LK.getAsset('smoke', { anchorX: 0, anchorY: 0, scaleX: 20.48, scaleY: 27.32, alpha: 0, x: 0, y: 0 }); darkOverlay.tint = 0x000000; game.addChild(darkOverlay); // Fade screen to black then show game over tween(darkOverlay, { alpha: 1 }, { duration: 1500, easing: tween.easeIn, onFinish: function onFinish() { LK.showGameOver(); } }); } }); } }); // Store reference to update fireScale each frame game.fireScaleObj = fireScaleObj; initialFireReductionStarted = true; } // Update fire scale from tween if active if (game.fireScaleObj) { fireScale = game.fireScaleObj.value; } // Add scale increase from burning wood var scaleIncrease = burningWoodCount * (30.0 / 100.0); // 30 pixels out of 100 pixel base asset fireScale = Math.max(0, fireScale + scaleIncrease); // Fire continues burning even at 400x400 pixels - no cleanup needed // Update and clean up particles for (var i = fireParticles.length - 1; i >= 0; i--) { var particle = fireParticles[i]; // Remove dead particles if (particle.life <= 0) { particle.destroy(); fireParticles.splice(i, 1); continue; } } // Update wood burning particles - wood now burns indefinitely for (var w = woodPieces.length - 1; w >= 0; w--) { var wood = woodPieces[w]; if (wood.isBurning) { // Clean up dead burn particles for (var b = wood.burnParticles.length - 1; b >= 0; b--) { var burnParticle = wood.burnParticles[b]; if (burnParticle.life <= 0) { wood.burnParticles.splice(b, 1); } } } } // Add flickering effect to the fire base if (LK.ticks % 10 === 0) { fireBaseX = 1024 + (Math.random() - 0.5) * 120 * fireScale; } }; // Array to track wood pieces var woodPieces = []; var draggedWood = null; // Track currently dragged wood var woodButton = game.attachAsset('woodButton', { x: 2048 - 100 - 100, y: 2732 - 100 - 50, // Adjusted Y to account for button height anchorX: 0.5, anchorY: 0.5 }); // Ensure wood button is visible on top of background game.setChildIndex(woodButton, game.children.length - 1); // Wood button click handler woodButton.down = function (x, y, obj) { // Create new wood piece at button position var newWood = game.attachAsset('Wood', { x: woodButton.x, y: woodButton.y, anchorX: 0.5, anchorY: 0.5 }); // Add wood piece properties newWood.isBurning = false; newWood.burnParticles = []; newWood.isDragging = true; // Mark as dragging woodPieces.push(newWood); // Ensure wood piece is visible on top of background game.setChildIndex(newWood, game.children.length - 1); // Set as active dragged wood draggedWood = newWood; }; // Game move handler for dragging wood game.move = function (x, y, obj) { if (draggedWood) { draggedWood.x = x; draggedWood.y = y; } }; // Game touch handler to start dragging existing wood pieces game.down = function (x, y, obj) { // Check if touch is on any existing wood piece for (var i = 0; i < woodPieces.length; i++) { var wood = woodPieces[i]; // Check if touch is within wood bounds var woodLeft = wood.x - wood.width / 2; var woodRight = wood.x + wood.width / 2; var woodTop = wood.y - wood.height / 2; var woodBottom = wood.y + wood.height / 2; if (x >= woodLeft && x <= woodRight && y >= woodTop && y <= woodBottom) { // Set this wood as the dragged piece draggedWood = wood; wood.isDragging = true; // Stop current burning if it was burning if (wood.isBurning && wood.fireTimer) { LK.clearInterval(wood.fireTimer); wood.fireTimer = null; // Clean up current burn particles for (var b = wood.burnParticles.length - 1; b >= 0; b--) { var burnParticle = wood.burnParticles[b]; burnParticle.destroy(); wood.burnParticles.splice(b, 1); } } // Reset burning state to allow re-placement wood.isBurning = false; wood.burnStartTime = null; break; } } }; // Game up handler to stop dragging and check for fire placement game.up = function (x, y, obj) { if (draggedWood) { // Check if wood is placed on fire area when released var fireDistance = Math.sqrt(Math.pow(draggedWood.x - fireBaseX, 2) + Math.pow(draggedWood.y - fireBaseY, 2)); if (fireDistance < 200 * fireScale) { // Always allow placement on fire, regardless of previous burning state draggedWood.isBurning = true; lastWoodPlacedTime = LK.ticks; // Update last wood placement time // Stop and reset the fire reduction system when wood is placed if (initialFireReductionStarted && game.fireScaleObj) { tween.stop(game.fireScaleObj, { value: true }); // Reset fire scale to a stable value while wood is burning game.fireScaleObj.value = Math.max(baseFireScale, game.fireScaleObj.value); // Reset the reduction system to allow it to restart after delay initialFireReductionStarted = false; game.fireScaleObj = null; } // Increment wood placement count for growing effect woodPlacementCount++; // Update fire color asset sizes by 5 pixels updateFireColorSizes(); // Calculate incremental growth - each wood placement grows more than the previous var baseGrowthAmount = 5.0 / 100.0; // Base growth of 5 pixels worth of scale var incrementalGrowthAmount = baseGrowthAmount + woodPlacementCount * 2.0 / 100.0; // Additional 2 pixels per placement // Apply the incremental growth using tween for smooth effect var currentFireScale = game.fireScaleObj ? game.fireScaleObj.value : fireScale; var targetFireScale = Math.min(currentFireScale + incrementalGrowthAmount, maxFireScale); if (game.fireScaleObj) { // Stop current tween and start new one tween.stop(game.fireScaleObj, { value: true }); } var fireScaleObj = { value: currentFireScale }; tween(fireScaleObj, { value: targetFireScale }, { duration: 800, easing: tween.easeOut, onFinish: function onFinish() { fireScale = targetFireScale; } }); game.fireScaleObj = fireScaleObj; // Update fireScale immediately for particle system fireScale = targetFireScale; // Check if fire has reached 200x200 and trigger vanish if (fireScale >= maxFireScale) { fireScale = maxFireScale; // Vanish fire when it reaches 200x200 pixels var fireScaleObj = { value: fireScale }; tween(fireScaleObj, { value: 0 }, { duration: 2000, easing: tween.linear, onFinish: function onFinish() { // Create bright overlay for win screen fade var brightOverlay = LK.getAsset('fireCore', { anchorX: 0, anchorY: 0, scaleX: 20.48, scaleY: 27.32, alpha: 0, x: 0, y: 0 }); brightOverlay.tint = 0xffd700; game.addChild(brightOverlay); // Fade screen to golden then show you win tween(brightOverlay, { alpha: 0.8 }, { duration: 1500, easing: tween.easeIn, onFinish: function onFinish() { LK.showYouWin(); } }); } }); game.fireScaleObj = fireScaleObj; } startWoodBurning(draggedWood, draggedWood.x, draggedWood.y); } draggedWood.isDragging = false; draggedWood = null; } }; // Function to start wood burning at touch position function startWoodBurning(wood, touchX, touchY) { // Wood now burns indefinitely - no destruction timer needed // Create fire particles on the touched side of the wood var fireTimer = LK.setInterval(function () { for (var j = 0; j < 6; j++) { var burnParticle = new FireParticle(); // Use different fire color assets randomly for burning wood var fireTypes = ['fireParticle', 'fireOrange', 'fireLightOrange', 'fireGold', 'fireBlue', 'fireGreen', 'fireMagenta', 'fireCyan', 'firePurple']; var randomFireType = fireTypes[Math.floor(Math.random() * fireTypes.length)]; if (burnParticle.graphics) { burnParticle.removeChild(burnParticle.graphics); } burnParticle.graphics = burnParticle.attachAsset(randomFireType, { anchorX: 0.5, anchorY: 0.5 }); burnParticle.graphics.blendMode = 1; burnParticle.x = touchX + (Math.random() - 0.5) * 60; burnParticle.y = touchY + (Math.random() - 0.5) * 30; burnParticle.velocityX = (Math.random() - 0.5) * 2; burnParticle.velocityY = -Math.random() * 4 - 1; burnParticle.life = 1.0; burnParticle.maxLife = 1.0; burnParticle.graphics.scaleX = 0.5 + Math.random() * 0.5; burnParticle.graphics.scaleY = 0.5 + Math.random() * 0.5; wood.burnParticles.push(burnParticle); fireParticles.push(burnParticle); game.addChild(burnParticle); } }, 200); wood.fireTimer = fireTimer; }
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var FireParticle = Container.expand(function () {
var self = Container.call(this);
// Create particle graphics based on type
var graphics;
self.particleType = 'fire'; // default type
self.setType = function (type) {
if (self.graphics) {
self.removeChild(self.graphics);
}
self.particleType = type;
if (type === 'fire') {
self.graphics = self.attachAsset('fireParticle', {
anchorX: 0.5,
anchorY: 0.5
});
self.graphics.blendMode = 1;
} else if (type === 'core') {
self.graphics = self.attachAsset('fireCore', {
anchorX: 0.5,
anchorY: 0.5
});
self.graphics.blendMode = 1;
} else if (type === 'smoke') {
self.graphics = self.attachAsset('smoke', {
anchorX: 0.5,
anchorY: 0.5
});
}
};
// Initialize with default type
self.setType('fire');
// Particle properties
self.velocityX = 0;
self.velocityY = 0;
self.life = 1.0;
self.maxLife = 1.0;
self.update = function () {
// Move particle
self.x += self.velocityX;
self.y += self.velocityY;
// Reduce life - slower for smoke particles
if (self.particleType === 'smoke') {
self.life -= 0.0054;
} else {
self.life -= 0.0154;
}
// Update appearance based on life
if (self.graphics) {
self.graphics.alpha = Math.max(0, self.life / self.maxLife);
if (self.particleType !== 'smoke') {
self.graphics.scaleX = self.life;
self.graphics.scaleY = self.life;
}
}
// Add some randomness to movement - less for smoke
if (self.particleType === 'smoke') {
self.velocityX += (Math.random() - 0.5) * 0.1;
self.velocityY += (Math.random() - 0.5) * 0.05;
} else {
self.velocityX += (Math.random() - 0.5) * 0.25;
self.velocityY += (Math.random() - 0.5) * 0.15;
}
// Gravity effect for smoke
if (self.particleType === 'smoke') {
self.velocityY -= 0.02;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x51ff00
});
/****
* Game Code
****/
// Add background image fullscreen
// Fire color assets that grow with wood placement
var fireColorSize = 100; // Base size that will grow by 5 each wood placement
var background = game.attachAsset('background1', {
x: 0,
y: 0,
width: 2048,
height: 2732
});
// Fire animation system
var fireParticles = [];
var fireBaseX = 1024; // Center of screen
var fireBaseY = 1800; // Center of screen vertically
var baseFireScale = 0.2; // Base scale factor for fire size (20x20)
var fireScale = baseFireScale; // Current fire scale (will increase with burning wood)
var burningWoodCount = 0; // Track number of burning wood pieces
var lastWoodPlacedTime = LK.ticks; // Track when wood was last placed on fire
var fireReductionTimer = 10 * 60; // 10 seconds at 60fps
var gameStartTime = LK.ticks; // Track when game started
var initialFireReductionStarted = true; // Track if initial reduction has started
var fireGrowthTimer = null; // Timer for automatic fire growth
var maxFireScale = 2.0; // Maximum fire scale (200x200 pixels)
// Play fire sound repeatedly
var fireSoundTimer = LK.setInterval(function () {
LK.getSound('Firesound').play();
}, 2000); // Play every 2 seconds
// Track wood placement count for incremental growth
var woodPlacementCount = 0;
// Function to update fire color asset sizes
function updateFireColorSizes() {
fireColorSize = Math.min(100 + woodPlacementCount * 5, 200); // Grow by 5 pixels per wood, max 200
// Reinitialize all fire color assets with new size
}
// Create fire particles continuously
var fireTimer = LK.setInterval(function () {
// Create main fire particles
for (var i = 0; i < 16; i++) {
var particle = new FireParticle();
// Use different fire color assets randomly
var fireTypes = ['fireParticle', 'fireOrange', 'fireLightOrange', 'fireGold', 'fireBlue', 'fireGreen', 'fireMagenta', 'fireCyan', 'firePurple'];
var randomFireType = fireTypes[Math.floor(Math.random() * fireTypes.length)];
if (particle.graphics) {
particle.removeChild(particle.graphics);
}
particle.graphics = particle.attachAsset(randomFireType, {
anchorX: 0.5,
anchorY: 0.5
});
particle.graphics.blendMode = 1;
particle.x = fireBaseX + (Math.random() - 0.5) * 2080 * fireScale;
particle.y = fireBaseY + 300 + (Math.random() - 0.5) * 832 * fireScale;
particle.velocityX = (Math.random() - 0.5) * 4;
particle.velocityY = -Math.random() * 10 - 4;
particle.life = 1.0;
particle.maxLife = 1.0;
// Scale animation - much bigger particles
particle.graphics.scaleX = 2.0 + Math.random() * 2.0;
particle.graphics.scaleY = 2.0 + Math.random() * 2.0;
tween(particle.graphics, {
scaleX: particle.graphics.scaleX * 3.0,
scaleY: particle.graphics.scaleY * 3.0
}, {
duration: 500 + Math.random() * 500,
easing: tween.easeOut
});
fireParticles.push(particle);
game.addChild(particle);
}
// Create core fire particles (yellow/white)
for (var j = 0; j < 10; j++) {
var coreParticle = new FireParticle();
// Use core fire assets randomly
var coreTypes = ['fireCore', 'fireYellowWhite', 'whiteParticle'];
var randomCoreType = coreTypes[Math.floor(Math.random() * coreTypes.length)];
if (coreParticle.graphics) {
coreParticle.removeChild(coreParticle.graphics);
}
coreParticle.graphics = coreParticle.attachAsset(randomCoreType, {
anchorX: 0.5,
anchorY: 0.5
});
coreParticle.graphics.blendMode = 1;
coreParticle.x = fireBaseX + (Math.random() - 0.5) * 1300 * fireScale;
coreParticle.y = fireBaseY + 300 + (Math.random() - 0.5) * 624 * fireScale;
coreParticle.velocityX = (Math.random() - 0.5) * 3;
coreParticle.velocityY = -Math.random() * 9 - 5;
coreParticle.life = 1.0;
coreParticle.maxLife = 1.0;
// Much bigger core particles
coreParticle.graphics.scaleX = 2.5;
coreParticle.graphics.scaleY = 2.5;
fireParticles.push(coreParticle);
game.addChild(coreParticle);
}
// Create bright white hot center particles
for (var k = 0; k < 6; k++) {
var whiteParticle = new FireParticle();
if (whiteParticle.graphics) {
whiteParticle.removeChild(whiteParticle.graphics);
}
whiteParticle.graphics = whiteParticle.attachAsset('whiteParticle', {
anchorX: 0.5,
anchorY: 0.5
});
whiteParticle.graphics.blendMode = 1;
whiteParticle.x = fireBaseX + (Math.random() - 0.5) * 780 * fireScale;
whiteParticle.y = fireBaseY + 300 + (Math.random() - 0.5) * 416 * fireScale;
whiteParticle.velocityX = (Math.random() - 0.5) * 2;
whiteParticle.velocityY = -Math.random() * 7.5 - 4;
whiteParticle.life = 1.0;
whiteParticle.maxLife = 1.0;
// Intense white hot center particles
whiteParticle.graphics.scaleX = 1.8;
whiteParticle.graphics.scaleY = 1.8;
// Add white glow effect with tween
tween(whiteParticle.graphics, {
scaleX: whiteParticle.graphics.scaleX * 2.5,
scaleY: whiteParticle.graphics.scaleY * 2.5
}, {
duration: 400 + Math.random() * 300,
easing: tween.easeOut
});
fireParticles.push(whiteParticle);
game.addChild(whiteParticle);
}
// Create white base particles at the bottom of the fire
for (var m = 0; m < 12; m++) {
var whiteBaseParticle = new FireParticle();
if (whiteBaseParticle.graphics) {
whiteBaseParticle.removeChild(whiteBaseParticle.graphics);
}
whiteBaseParticle.graphics = whiteBaseParticle.attachAsset('whiteParticle', {
anchorX: 0.5,
anchorY: 0.5
});
whiteBaseParticle.graphics.blendMode = 1;
whiteBaseParticle.x = fireBaseX + (Math.random() - 0.5) * 1040 * fireScale;
whiteBaseParticle.y = fireBaseY + 300 + 150 * fireScale + (Math.random() - 0.5) * 520 * fireScale;
whiteBaseParticle.velocityX = (Math.random() - 0.5) * 1.5;
whiteBaseParticle.velocityY = -Math.random() * 2.5 - 1;
whiteBaseParticle.life = 1.0;
whiteBaseParticle.maxLife = 1.0;
// Base white particles same size as other fire particles
whiteBaseParticle.graphics.scaleX = 2.0 + Math.random() * 1.0;
whiteBaseParticle.graphics.scaleY = 2.0 + Math.random() * 1.0;
// Add gentle scaling animation
tween(whiteBaseParticle.graphics, {
scaleX: whiteBaseParticle.graphics.scaleX * 2.0,
scaleY: whiteBaseParticle.graphics.scaleY * 2.0
}, {
duration: 600 + Math.random() * 400,
easing: tween.easeOut
});
fireParticles.push(whiteBaseParticle);
game.addChild(whiteBaseParticle);
// Move white base particles to back (behind fire)
game.setChildIndex(whiteBaseParticle, 1);
}
// Create smoke particles (black/dark) - 10x more particles
for (var s = 0; s < 10; s++) {
var smokeParticle = new FireParticle();
// Use different smoke color assets randomly
var smokeTypes = ['smoke', 'smokeGray', 'smokeLightGray', 'smokePurple', 'smokeTeal', 'smokeYellow'];
var randomSmokeType = smokeTypes[Math.floor(Math.random() * smokeTypes.length)];
if (smokeParticle.graphics) {
smokeParticle.removeChild(smokeParticle.graphics);
}
smokeParticle.graphics = smokeParticle.attachAsset(randomSmokeType, {
anchorX: 0.5,
anchorY: 0.5
});
smokeParticle.x = fireBaseX + (Math.random() - 0.5) * 1664 * fireScale;
smokeParticle.y = fireBaseY + 300 - 300 * fireScale - Math.random() * 1040 * fireScale;
smokeParticle.velocityX = (Math.random() - 0.5) * 3;
smokeParticle.velocityY = -Math.random() * 3 - 1;
smokeParticle.life = 3.9;
smokeParticle.maxLife = 3.9;
// Smoke particles start small (5-10px range) and grow slightly
var startScale = 0.05 + Math.random() * 0.05; // 5-10px range from 100px base
tween(smokeParticle.graphics, {
scaleX: startScale * 2,
scaleY: startScale * 2
}, {
duration: 7800,
easing: tween.easeOut
});
smokeParticle.graphics.scaleX = startScale;
smokeParticle.graphics.scaleY = startScale;
fireParticles.push(smokeParticle);
game.addChild(smokeParticle);
// Move smoke particles to back (behind fire particles)
game.setChildIndex(smokeParticle, 1);
}
}, 80);
// Update fire system
game.update = function () {
// Count burning wood pieces and update fire scale
burningWoodCount = 0;
for (var w = 0; w < woodPieces.length; w++) {
if (woodPieces[w].isBurning) {
burningWoodCount++;
}
}
// Start fire reduction only after no wood has been placed for a while AND fire has stopped growing
var timeSinceLastWood = LK.ticks - lastWoodPlacedTime;
var delayBeforeReduction = 5 * 60; // 5 seconds delay before starting reduction
var fireFinishedGrowing = fireScale >= maxFireScale || fireGrowthTimer === null;
if (!initialFireReductionStarted && timeSinceLastWood >= delayBeforeReduction && burningWoodCount === 0 && fireFinishedGrowing) {
// Create a dummy object to tween the fireScale value
var fireScaleObj = {
value: fireScale
};
// Begin fire reduction after delay using tween - first phase to 5x5 size
var minSize = 5.0 / 100.0; // 5x5 pixels out of 100 pixel base asset
tween(fireScaleObj, {
value: minSize
}, {
duration: 8000,
// 8 seconds to reach minimum size
easing: tween.linear,
onFinish: function onFinish() {
// Start second phase: reduce from 5x5 to 0x0
tween(fireScaleObj, {
value: 0
}, {
duration: 2000,
// 2 seconds to reach 0
easing: tween.linear,
onFinish: function onFinish() {
// Create dark overlay for screen fade
var darkOverlay = LK.getAsset('smoke', {
anchorX: 0,
anchorY: 0,
scaleX: 20.48,
scaleY: 27.32,
alpha: 0,
x: 0,
y: 0
});
darkOverlay.tint = 0x000000;
game.addChild(darkOverlay);
// Fade screen to black then show game over
tween(darkOverlay, {
alpha: 1
}, {
duration: 1500,
easing: tween.easeIn,
onFinish: function onFinish() {
LK.showGameOver();
}
});
}
});
}
});
// Store reference to update fireScale each frame
game.fireScaleObj = fireScaleObj;
initialFireReductionStarted = true;
}
// Update fire scale from tween if active
if (game.fireScaleObj) {
fireScale = game.fireScaleObj.value;
}
// Add scale increase from burning wood
var scaleIncrease = burningWoodCount * (30.0 / 100.0); // 30 pixels out of 100 pixel base asset
fireScale = Math.max(0, fireScale + scaleIncrease);
// Fire continues burning even at 400x400 pixels - no cleanup needed
// Update and clean up particles
for (var i = fireParticles.length - 1; i >= 0; i--) {
var particle = fireParticles[i];
// Remove dead particles
if (particle.life <= 0) {
particle.destroy();
fireParticles.splice(i, 1);
continue;
}
}
// Update wood burning particles - wood now burns indefinitely
for (var w = woodPieces.length - 1; w >= 0; w--) {
var wood = woodPieces[w];
if (wood.isBurning) {
// Clean up dead burn particles
for (var b = wood.burnParticles.length - 1; b >= 0; b--) {
var burnParticle = wood.burnParticles[b];
if (burnParticle.life <= 0) {
wood.burnParticles.splice(b, 1);
}
}
}
}
// Add flickering effect to the fire base
if (LK.ticks % 10 === 0) {
fireBaseX = 1024 + (Math.random() - 0.5) * 120 * fireScale;
}
};
// Array to track wood pieces
var woodPieces = [];
var draggedWood = null; // Track currently dragged wood
var woodButton = game.attachAsset('woodButton', {
x: 2048 - 100 - 100,
y: 2732 - 100 - 50,
// Adjusted Y to account for button height
anchorX: 0.5,
anchorY: 0.5
});
// Ensure wood button is visible on top of background
game.setChildIndex(woodButton, game.children.length - 1);
// Wood button click handler
woodButton.down = function (x, y, obj) {
// Create new wood piece at button position
var newWood = game.attachAsset('Wood', {
x: woodButton.x,
y: woodButton.y,
anchorX: 0.5,
anchorY: 0.5
});
// Add wood piece properties
newWood.isBurning = false;
newWood.burnParticles = [];
newWood.isDragging = true; // Mark as dragging
woodPieces.push(newWood);
// Ensure wood piece is visible on top of background
game.setChildIndex(newWood, game.children.length - 1);
// Set as active dragged wood
draggedWood = newWood;
};
// Game move handler for dragging wood
game.move = function (x, y, obj) {
if (draggedWood) {
draggedWood.x = x;
draggedWood.y = y;
}
};
// Game touch handler to start dragging existing wood pieces
game.down = function (x, y, obj) {
// Check if touch is on any existing wood piece
for (var i = 0; i < woodPieces.length; i++) {
var wood = woodPieces[i];
// Check if touch is within wood bounds
var woodLeft = wood.x - wood.width / 2;
var woodRight = wood.x + wood.width / 2;
var woodTop = wood.y - wood.height / 2;
var woodBottom = wood.y + wood.height / 2;
if (x >= woodLeft && x <= woodRight && y >= woodTop && y <= woodBottom) {
// Set this wood as the dragged piece
draggedWood = wood;
wood.isDragging = true;
// Stop current burning if it was burning
if (wood.isBurning && wood.fireTimer) {
LK.clearInterval(wood.fireTimer);
wood.fireTimer = null;
// Clean up current burn particles
for (var b = wood.burnParticles.length - 1; b >= 0; b--) {
var burnParticle = wood.burnParticles[b];
burnParticle.destroy();
wood.burnParticles.splice(b, 1);
}
}
// Reset burning state to allow re-placement
wood.isBurning = false;
wood.burnStartTime = null;
break;
}
}
};
// Game up handler to stop dragging and check for fire placement
game.up = function (x, y, obj) {
if (draggedWood) {
// Check if wood is placed on fire area when released
var fireDistance = Math.sqrt(Math.pow(draggedWood.x - fireBaseX, 2) + Math.pow(draggedWood.y - fireBaseY, 2));
if (fireDistance < 200 * fireScale) {
// Always allow placement on fire, regardless of previous burning state
draggedWood.isBurning = true;
lastWoodPlacedTime = LK.ticks; // Update last wood placement time
// Stop and reset the fire reduction system when wood is placed
if (initialFireReductionStarted && game.fireScaleObj) {
tween.stop(game.fireScaleObj, {
value: true
});
// Reset fire scale to a stable value while wood is burning
game.fireScaleObj.value = Math.max(baseFireScale, game.fireScaleObj.value);
// Reset the reduction system to allow it to restart after delay
initialFireReductionStarted = false;
game.fireScaleObj = null;
}
// Increment wood placement count for growing effect
woodPlacementCount++;
// Update fire color asset sizes by 5 pixels
updateFireColorSizes();
// Calculate incremental growth - each wood placement grows more than the previous
var baseGrowthAmount = 5.0 / 100.0; // Base growth of 5 pixels worth of scale
var incrementalGrowthAmount = baseGrowthAmount + woodPlacementCount * 2.0 / 100.0; // Additional 2 pixels per placement
// Apply the incremental growth using tween for smooth effect
var currentFireScale = game.fireScaleObj ? game.fireScaleObj.value : fireScale;
var targetFireScale = Math.min(currentFireScale + incrementalGrowthAmount, maxFireScale);
if (game.fireScaleObj) {
// Stop current tween and start new one
tween.stop(game.fireScaleObj, {
value: true
});
}
var fireScaleObj = {
value: currentFireScale
};
tween(fireScaleObj, {
value: targetFireScale
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
fireScale = targetFireScale;
}
});
game.fireScaleObj = fireScaleObj;
// Update fireScale immediately for particle system
fireScale = targetFireScale;
// Check if fire has reached 200x200 and trigger vanish
if (fireScale >= maxFireScale) {
fireScale = maxFireScale;
// Vanish fire when it reaches 200x200 pixels
var fireScaleObj = {
value: fireScale
};
tween(fireScaleObj, {
value: 0
}, {
duration: 2000,
easing: tween.linear,
onFinish: function onFinish() {
// Create bright overlay for win screen fade
var brightOverlay = LK.getAsset('fireCore', {
anchorX: 0,
anchorY: 0,
scaleX: 20.48,
scaleY: 27.32,
alpha: 0,
x: 0,
y: 0
});
brightOverlay.tint = 0xffd700;
game.addChild(brightOverlay);
// Fade screen to golden then show you win
tween(brightOverlay, {
alpha: 0.8
}, {
duration: 1500,
easing: tween.easeIn,
onFinish: function onFinish() {
LK.showYouWin();
}
});
}
});
game.fireScaleObj = fireScaleObj;
}
startWoodBurning(draggedWood, draggedWood.x, draggedWood.y);
}
draggedWood.isDragging = false;
draggedWood = null;
}
};
// Function to start wood burning at touch position
function startWoodBurning(wood, touchX, touchY) {
// Wood now burns indefinitely - no destruction timer needed
// Create fire particles on the touched side of the wood
var fireTimer = LK.setInterval(function () {
for (var j = 0; j < 6; j++) {
var burnParticle = new FireParticle();
// Use different fire color assets randomly for burning wood
var fireTypes = ['fireParticle', 'fireOrange', 'fireLightOrange', 'fireGold', 'fireBlue', 'fireGreen', 'fireMagenta', 'fireCyan', 'firePurple'];
var randomFireType = fireTypes[Math.floor(Math.random() * fireTypes.length)];
if (burnParticle.graphics) {
burnParticle.removeChild(burnParticle.graphics);
}
burnParticle.graphics = burnParticle.attachAsset(randomFireType, {
anchorX: 0.5,
anchorY: 0.5
});
burnParticle.graphics.blendMode = 1;
burnParticle.x = touchX + (Math.random() - 0.5) * 60;
burnParticle.y = touchY + (Math.random() - 0.5) * 30;
burnParticle.velocityX = (Math.random() - 0.5) * 2;
burnParticle.velocityY = -Math.random() * 4 - 1;
burnParticle.life = 1.0;
burnParticle.maxLife = 1.0;
burnParticle.graphics.scaleX = 0.5 + Math.random() * 0.5;
burnParticle.graphics.scaleY = 0.5 + Math.random() * 0.5;
wood.burnParticles.push(burnParticle);
fireParticles.push(burnParticle);
game.addChild(burnParticle);
}
}, 200);
wood.fireTimer = fireTimer;
}