User prompt
Please fix the bug: 'Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.' in or related to this line: 'return ufo;' Line Number: 1060 βͺπ‘ Consider importing and using the following plugins: @upit/storage.v1
User prompt
Fix second game update method with cloud handling and merging functionality from first implementation
User prompt
Fix second game update method with cloud handling and merging functionality from first implementation
User prompt
save the code
User prompt
why is the game not starting or showing?
User prompt
continue with next step, then wait for my input
User prompt
ensure we are using the following plugins: @upit/storage.v1 Fix UpgradeButton update method for proper button state handling βͺπ‘ Consider importing and using the following plugins: @upit/storage.v1
User prompt
continue expanding game bit by bit. save code first βͺπ‘ Consider importing and using the following plugins: @upit/storage.v1
User prompt
Fix UpgradeButton update method for proper button state handling
User prompt
β Bird Movement Implement Bird1Movement class properly to handle bird movement Implement Bird2Movement class properly to handle bird movement β Spawn Functions Fix spawnBird1 function to properly initialize birds Fix spawnBird2 function to properly initialize birds β Upgrade Buttons Revise upgrade buttons game mechanics Fix UpgradeButton class to properly handle: Interactivity and events Hover effects Down method Move method Up method Update method Fix upgrade buttons initialization in Game Code β IdleManager Fix upgradePointsPerSecond method to properly update values Fix upgradeLaserPower method to properly update values Fix upgradeAutoShooting method to properly update values β Game Mechanics Fix shootLaser function to properly handle laser targeting Fix Storage plugin initialization with proper defaults Improve secondary game update function to handle: Upgrades Button interactivity Improve button setup and initialization in Game Code
User prompt
β Implement Bird1Movement class properly to handle bird movement β Implement Bird2Movement class properly to handle bird movement β Fix spawnBird1 function to properly reference and add birds β Fix spawnBird2 function to properly reference and add birds β Fix UpgradeButton class to properly handle interactivity and events β Fix IdleManager's upgradePointsPerSecond method to properly update values β Fix IdleManager's upgradeLaserPower method to properly update values β Fix IdleManager's upgradeAutoShooting method to properly update values β Fix shootLaser function to properly handle lasers and targeting β Fix Storage plugin initialization and defaults β Improve button setup and initialization in Game Code to ensure interactivity βͺRevert to here SM revise the upgrade buttons game mechanics β Fix storage plugin initialization with proper defaults β Fix UpgradeButton class to properly handle interactivity and hover effects β Fix IdleManager upgradePointsPerSecond function to properly update values β Fix IdleManager upgradeLaserPower function to properly update values β Fix IdleManager upgradeAutoShooting function to properly update values β Fix upgrade buttons initialization in Game Code β Fix Bird1Movement class implementation β Fix Bird2Movement class implementation β Fix spawnBird1 function to properly initialize birds β Fix spawnBird2 function to properly initialize birds β Fix shootLaser function to properly handle laser targeting β Improve secondary game update function to properly handle upgrades SM continue β Fix Bird1Movement class implementation β Fix Bird2Movement class implementation β Fix IdleManager upgradePointsPerSecond function β Fix IdleManager upgradeLaserPower function β Fix IdleManager upgradeAutoShooting function β Fix storage plugin initialization and defaults β Fix UpgradeButton class to properly handle hover effects and interactivity β Fix UpgradeButton down method β Fix UpgradeButton move method β Fix UpgradeButton up method β Fix UpgradeButton update method β Fix spawnBird1 function to properly initialize birds β Fix spawnBird2 function to properly initialize birds β Fix shootLaser function to properly handle laser targeting β Fix upgrade buttons initialization in Game Code π Fix secondary game update function to handle button interactivity
User prompt
revise the upgrade buttons game mechanics
User prompt
continue
Code edit (1 edits merged)
Please save this source code
User prompt
continue
User prompt
i dont see hover effects, upgraed buttons are still not showing feedback or upgrades. βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1, @upit/storage.v1
User prompt
revise the upgrade buttons game mechanics
User prompt
increase the height of the instructions text box by 50px
User prompt
nothing happens when i click upgrade buttons. no feedback, no upgrades.
User prompt
increase width of instructions by 80px
User prompt
make the instructions text container 200px wide, shrink the font a little
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'x')' in or related to this line: 'instructionsText.x = scoreDisplay.x + 220;' Line Number: 1160
User prompt
move instructions text to right of scoreimg
User prompt
how do i upgrade, by shooting, or clicking the buttons? they are still not responding.
User prompt
upgrade buttons are not upgrading
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
points: 0,
pointsPerSecond: 0.1,
laserPower: 1,
autoShooting: false,
upgrades: {
pointsPerSecond: {
level: 1,
cost: 10,
multiplier: 1.5
},
laserPower: {
level: 1,
cost: 20,
multiplier: 2
},
autoShooting: {
level: 0,
cost: 100,
multiplier: 2
}
}
});
/****
* Classes
****/
// Branch asset
// Bird1 class to represent the first kind of bird
var Bird1 = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird1-right', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize properties
self.speed = Math.random() * 1.6 + 1;
self.lastY = self.y;
self.lastX = self.x;
self.type = 'bird1';
self.lastIntersecting = false;
// Update function for bird movement
self.update = function () {
self.y += self.speed;
self.x += Math.sin(self.y / 100) * 6.5;
// Check if the bird has moved off-screen
if (self.lastY <= 2732 && self.y > 2732) {
self.y = -self.height;
self.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048;
}
// Update bird texture based on direction
if (birdGraphics) {
if (self.lastX <= 2048 / 2 && self.x > 2048 / 2) {
birdGraphics.texture = LK.getAsset(self.type + '-right', {}).texture;
} else if (self.lastX > 2048 / 2 && self.x <= 2048 / 2) {
birdGraphics.texture = LK.getAsset(self.type, {}).texture;
}
}
// Update last positions after movements
self.lastY = self.y;
self.lastX = self.x;
};
return self;
});
// Bird2 class to represent the second kind of bird
var Bird2 = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird2-right', {
anchorX: 0.5,
anchorY: 0.5
});
// Initialize properties
self.speed = Math.random() * 1.6 + 1;
self.lastY = self.y;
self.lastX = self.x;
self.type = 'bird2';
self.lastIntersecting = false;
// Update function for bird movement
self.update = function () {
self.y += self.speed;
self.x += Math.sin(self.y / 100) * 6.5;
// Update bird texture based on direction
if (birdGraphics) {
if (self.lastX <= 2048 / 2 && self.x > 2048 / 2) {
birdGraphics.texture = LK.getAsset(self.type + '-right', {}).texture;
} else if (self.lastX > 2048 / 2 && self.x <= 2048 / 2) {
birdGraphics.texture = LK.getAsset(self.type, {}).texture;
}
}
// Check if the bird has moved off-screen
if (self.lastY <= 2732 && self.y > 2732) {
self.y = -self.height;
self.x = Math.random() < 0.5 ? 0 : 2048;
}
// Update last positions after movements
self.lastX = self.x;
self.lastY = self.y;
};
return self;
});
// Cat class to manage cat behavior
var Cat = Container.expand(function () {
var self = Container.call(this);
var catGraphics = self.attachAsset('cat', {
anchorX: 0.5,
anchorY: 1
});
self.update = function () {
// Add any specific update logic for the cat here
};
});
// Cloud class to represent cloud behavior
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8 // Set default opacity to 80%
});
self.movement = new CloudMovement(self, cloudGraphics);
});
// GrassBack class to represent the grass image
var GrassBack = Container.expand(function () {
var self = Container.call(this);
var grassGraphics = self.attachAsset('grass-back', {
anchorX: 0.5,
anchorY: 1
});
self.update = function () {
// Add any specific update logic for the grass here
// Example: Slightly move the grass to simulate wind effect
self.x += Math.sin((LK.ticks + 100) / 90) * 0.15; // Swaying effect, increased speed
};
});
// GrassFront class to represent the second grass image
var GrassFront = Container.expand(function () {
var self = Container.call(this);
var grass2Graphics = self.attachAsset('grass-front', {
anchorX: 0.5,
anchorY: 1
});
self.lastX = self.x; // Initialize lastX for tracking changes on X
self.addChild(grass2Graphics); // Add grass2 graphics to the container
self.update = function () {
// Add any specific update logic for the grass here
// Example: Slightly move the grass to simulate wind effect
self.x += Math.sin((LK.ticks + 50) / 100) * 0.125; // Swaying effect, reduced by 50%
self.lastX = self.x; // Update lastX after movement
};
});
var IdleManager = Container.expand(function () {
var self = Container.call(this);
var _storage$upgrades, _storage$upgrades2, _storage$upgrades3, _storage$upgrades4, _storage$upgrades5, _storage$upgrades6, _storage$upgrades7, _storage$upgrades8, _storage$upgrades9;
// Idle game resources
self.points = storage.points || 0;
self.pointsPerSecond = storage.pointsPerSecond || 0.1;
self.laserPower = storage.laserPower || 1;
self.autoBirdsInterval = null;
self.autoShooting = storage.autoShooting || false;
// Upgrade costs and multipliers
self.upgrades = {
pointsPerSecond: {
level: ((_storage$upgrades = storage.upgrades) === null || _storage$upgrades === void 0 || (_storage$upgrades = _storage$upgrades.pointsPerSecond) === null || _storage$upgrades === void 0 ? void 0 : _storage$upgrades.level) || 1,
cost: ((_storage$upgrades2 = storage.upgrades) === null || _storage$upgrades2 === void 0 || (_storage$upgrades2 = _storage$upgrades2.pointsPerSecond) === null || _storage$upgrades2 === void 0 ? void 0 : _storage$upgrades2.cost) || 10,
multiplier: ((_storage$upgrades3 = storage.upgrades) === null || _storage$upgrades3 === void 0 || (_storage$upgrades3 = _storage$upgrades3.pointsPerSecond) === null || _storage$upgrades3 === void 0 ? void 0 : _storage$upgrades3.multiplier) || 1.5
},
laserPower: {
level: ((_storage$upgrades4 = storage.upgrades) === null || _storage$upgrades4 === void 0 || (_storage$upgrades4 = _storage$upgrades4.laserPower) === null || _storage$upgrades4 === void 0 ? void 0 : _storage$upgrades4.level) || 1,
cost: ((_storage$upgrades5 = storage.upgrades) === null || _storage$upgrades5 === void 0 || (_storage$upgrades5 = _storage$upgrades5.laserPower) === null || _storage$upgrades5 === void 0 ? void 0 : _storage$upgrades5.cost) || 20,
multiplier: ((_storage$upgrades6 = storage.upgrades) === null || _storage$upgrades6 === void 0 || (_storage$upgrades6 = _storage$upgrades6.laserPower) === null || _storage$upgrades6 === void 0 ? void 0 : _storage$upgrades6.multiplier) || 2
},
autoShooting: {
level: ((_storage$upgrades7 = storage.upgrades) === null || _storage$upgrades7 === void 0 || (_storage$upgrades7 = _storage$upgrades7.autoShooting) === null || _storage$upgrades7 === void 0 ? void 0 : _storage$upgrades7.level) || 0,
cost: ((_storage$upgrades8 = storage.upgrades) === null || _storage$upgrades8 === void 0 || (_storage$upgrades8 = _storage$upgrades8.autoShooting) === null || _storage$upgrades8 === void 0 ? void 0 : _storage$upgrades8.cost) || 100,
multiplier: ((_storage$upgrades9 = storage.upgrades) === null || _storage$upgrades9 === void 0 || (_storage$upgrades9 = _storage$upgrades9.autoShooting) === null || _storage$upgrades9 === void 0 ? void 0 : _storage$upgrades9.multiplier) || 2
}
};
// Initialize storage with current values
self.saveToStorage = function () {
// Save all values to storage
storage.points = self.points;
storage.pointsPerSecond = self.pointsPerSecond;
storage.laserPower = self.laserPower;
storage.autoShooting = self.autoShooting;
storage.upgrades = {
pointsPerSecond: {
level: self.upgrades.pointsPerSecond.level,
cost: self.upgrades.pointsPerSecond.cost,
multiplier: self.upgrades.pointsPerSecond.multiplier
},
laserPower: {
level: self.upgrades.laserPower.level,
cost: self.upgrades.laserPower.cost,
multiplier: self.upgrades.laserPower.multiplier
},
autoShooting: {
level: self.upgrades.autoShooting.level,
cost: self.upgrades.autoShooting.cost,
multiplier: self.upgrades.autoShooting.multiplier
}
};
};
// Save initial state
self.saveToStorage();
// Generate passive income
self.update = function () {
self.points += self.pointsPerSecond / 60; // Divide by 60 since update runs at 60fps
if (LK.ticks % 60 == 0) {
// Update storage every second
self.saveToStorage();
}
if (self.autoShooting && LK.ticks % 90 == 0) {
// Auto shoot at a random position every 1.5 seconds
var targetX = Math.random() * 2048;
var targetY = Math.random() * (2732 / 2); // Target upper half of screen
shootLaser(cat.x, cat.y - 430, targetX, targetY);
}
};
// Upgrade functions
self.upgradePointsPerSecond = function () {
var upgrade = self.upgrades.pointsPerSecond;
if (upgrade && self.points >= upgrade.cost) {
// Subtract the cost from points
self.points -= upgrade.cost;
// Increase points per second by 20%
self.pointsPerSecond = self.pointsPerSecond * 1.2;
// Increase upgrade level
upgrade.level += 1;
// Increase the cost for next upgrade using the multiplier
upgrade.cost = Math.floor(upgrade.cost * upgrade.multiplier);
// Save to storage
self.saveToStorage();
console.log("Points per second upgraded to: " + self.pointsPerSecond);
return true;
}
return false;
};
self.upgradeLaserPower = function () {
var upgrade = self.upgrades.laserPower;
if (upgrade && self.points >= upgrade.cost) {
// Subtract the cost from points
self.points -= upgrade.cost;
// Increase laser power by 50%
self.laserPower = self.laserPower * 1.5;
// Increase upgrade level
upgrade.level += 1;
// Increase the cost for next upgrade using the multiplier
upgrade.cost = Math.floor(upgrade.cost * upgrade.multiplier);
// Save to storage
self.saveToStorage();
console.log("Laser power upgraded to: " + self.laserPower);
return true;
}
return false;
};
self.upgradeAutoShooting = function () {
var upgrade = self.upgrades.autoShooting;
if (upgrade && self.points >= upgrade.cost) {
// Subtract the cost from points
self.points -= upgrade.cost;
// Increase upgrade level
upgrade.level += 1;
// Increase the cost for next upgrade using the multiplier
upgrade.cost = Math.floor(upgrade.cost * upgrade.multiplier);
// Enable auto shooting
self.autoShooting = true;
// Save to storage
self.saveToStorage();
console.log("Auto shooting enabled");
return true;
}
return false;
};
return self;
});
// Laser class to represent a laser shot from the cat
var Laser = Container.expand(function (startX, startY, targetX, targetY) {
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser2', {
anchorX: 0.5,
anchorY: 0.5,
brightness: 2.0,
// Increase brightness by 200%
scaleX: idleManager ? 1.0 + idleManager.laserPower * 0.1 : 1.0,
scaleY: idleManager ? 1.0 + idleManager.laserPower * 0.1 : 1.0
});
// Play the laser1 sound when the laser is created
LK.getSound('laser1').play();
// Calculate direction and speed
var dx = targetX - startX;
var dy = targetY - startY;
var distance = Math.sqrt(dx * dx + dy * dy);
var speed = 60; // Speed of the laser increased by 200%
self.vx = dx / distance * speed;
self.vy = dy / distance * speed;
// Set initial position
self.x = startX;
self.y = startY;
self.lastIntersecting = false;
self.power = idleManager ? idleManager.laserPower : 1;
// Add trail effect for upgraded lasers
if (idleManager && idleManager.laserPower > 1.5) {
self.trailTimer = LK.setInterval(function () {
var trail = new Container();
var trailGraphics = trail.attachAsset('laser2', {
anchorX: 0.5,
anchorY: 0.5,
brightness: 2.0,
scaleX: laserGraphics.scaleX * 0.7,
scaleY: laserGraphics.scaleY * 0.7,
alpha: 0.7
});
trail.x = self.x;
trail.y = self.y;
game.addChild(trail);
tween(trail, {
alpha: 0,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
trail.destroy();
}
});
}, 100);
}
// Update function to move the laser
self.update = function () {
self.x += self.vx;
self.y += self.vy;
// Remove laser if it goes off-screen
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
if (self.trailTimer) {
LK.clearInterval(self.trailTimer);
}
self.destroy();
}
};
// Override destroy to clean up
var originalDestroy = self.destroy;
self.destroy = function () {
if (self.trailTimer) {
LK.clearInterval(self.trailTimer);
}
originalDestroy.call(self);
};
return self;
});
// Reticle class to manage reticle behavior
var Reticle = Container.expand(function () {
var self = Container.call(this);
var reticleGraphics = self.attachAsset('reticle1', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Add any specific update logic for the reticle here
};
});
// ScoreDisplay class to manage score display
var ScoreDisplay = Container.expand(function () {
var self = Container.call(this);
var scoreGraphics = self.attachAsset('scoreImage', {
anchorX: 0.5,
anchorY: 0.5,
width: 400,
height: 450
});
var scoreText = new Text2('0', {
size: 100,
fill: 0x800080,
font: "Courier New, Courier, monospace",
// Segmented clock style font
stroke: 0x000000,
strokeThickness: 5,
dropShadow: true,
dropShadowColor: 0x000000,
dropShadowBlur: 5,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
var incomeText = new Text2('0/sec', {
size: 60,
fill: 0x008800,
font: "Arial, sans-serif",
stroke: 0x000000,
strokeThickness: 3
});
scoreText.anchor.set(0.5, 0);
incomeText.anchor.set(0.5, 0);
scoreText.y = -130; // Moved up 100px more (was -30)
incomeText.y = -30; // Adjusted to maintain spacing (was 70)
self.addChild(scoreText);
self.addChild(incomeText);
self.updateScore = function (newScore) {
scoreText.setText(newScore);
if (idleManager) {
incomeText.setText(idleManager.pointsPerSecond.toFixed(1) + '/sec');
// Visual feedback for score increase
if (self.lastScore && newScore > self.lastScore) {
tween(scoreText, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(scoreText, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
});
}
self.lastScore = newScore;
}
};
});
// Stack1 class to represent the stack1 image
var Stack1 = Container.expand(function () {
var self = Container.call(this);
var stackGraphics = self.attachAsset('stack1', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Add any specific update logic for stack1 here
};
});
// ScoreManager class to manage score logic
// ScoreManager class to manage score logic
// Sun class to represent a sun in the top right corner
var Sun = Container.expand(function () {
var self = Container.call(this);
var sunGraphics = self.attachAsset('sun', {
anchorX: 0.5,
anchorY: 0.5
});
startPulsating(self); // Start the pulsating effect
});
// Function to create a pulsating effect
// Tree class to represent a tree with a 9:16 aspect ratio
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1,
antialias: true // Apply antialias effect
});
self.update = function () {
// Add any specific update logic for the tree here
};
});
// UFO class to represent a UFO
var UFO = Container.expand(function () {
var self = Container.call(this);
var ufoGraphics = self.attachAsset('ufo', {
anchorX: 0.5,
anchorY: 0.5
});
self.movement = new UFOMovement(self, ufoGraphics);
});
var UpgradeButton = Container.expand(function (type, x, y) {
var self = Container.call(this);
self.type = type;
self.x = x;
self.y = y;
self.interactive = true; // Make button interactive
// Create button background
var buttonBackground = self.attachAsset('scoreImage', {
anchorX: 0.5,
anchorY: 0.5,
width: 400,
height: 120,
tint: type === 'pointsPerSecond' ? 0x00AA00 : type === 'laserPower' ? 0xAA0000 : 0x0000AA
});
// Create button text
self.buttonText = new Text2('', {
size: 50,
fill: 0xFFFFFF,
font: "Arial, sans-serif"
});
self.buttonText.anchor.set(0.5, 0.5);
self.addChild(self.buttonText);
// Initialize button properties
self.buttonBackground = buttonBackground;
self.isHovering = false;
self.originalTint = buttonBackground.tint;
self.hoverTint = 0xFFFFFF;
// Handle hover events
self.move = function (x, y, obj) {
// Convert global position to local if needed
if (obj && obj.event) {
var local = self.toLocal({
x: obj.event.x,
y: obj.event.y
});
x = local.x;
y = local.y;
}
// Check if the point is within the button bounds
var bounds = new Rectangle(-buttonBackground.width / 2, -buttonBackground.height / 2, buttonBackground.width, buttonBackground.height);
var isOver = x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height;
if (isOver && !self.isHovering) {
self.isHovering = true;
tween(buttonBackground, {
tint: self.hoverTint,
scaleX: 1.05,
scaleY: 1.05
}, {
duration: 100,
easing: tween.easeOut
});
} else if (!isOver && self.isHovering) {
self.isHovering = false;
tween(buttonBackground, {
tint: self.originalTint,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
}
};
// Handle end of hover
self.up = function (x, y, obj) {
// Convert global position to local if needed
if (obj && obj.event) {
var local = self.toLocal({
x: obj.event.x,
y: obj.event.y
});
x = local.x;
y = local.y;
}
// Check if the point is within the button bounds
var bounds = new Rectangle(-buttonBackground.width / 2, -buttonBackground.height / 2, buttonBackground.width, buttonBackground.height);
var isOver = x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height;
var upgraded = false;
if (isOver) {
self.isHovering = false;
// Try to upgrade based on button type
if (idleManager) {
switch (self.type) {
case 'pointsPerSecond':
upgraded = idleManager.upgradePointsPerSecond();
break;
case 'laserPower':
upgraded = idleManager.upgradeLaserPower();
break;
case 'autoShooting':
upgraded = idleManager.upgradeAutoShooting();
break;
}
}
// Return button to normal state
tween(buttonBackground, {
tint: self.originalTint,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100,
easing: tween.easeIn
});
// If upgrade was successful, show visual feedback
if (upgraded && scoreDisplay) {
// Update the score display immediately
scoreDisplay.updateScore(Math.floor(idleManager.points));
// Visual feedback animation
tween(buttonBackground, {
scaleX: 1.2,
scaleY: 1.2,
tint: 0xFFFFFF
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(buttonBackground, {
scaleX: 1.0,
scaleY: 1.0,
tint: self.originalTint
}, {
duration: 200,
easing: tween.easeIn
});
}
});
}
}
};
// Handle click events
self.down = function (x, y, obj) {
// Convert global position to local if needed
if (obj && obj.event) {
var local = self.toLocal({
x: obj.event.x,
y: obj.event.y
});
x = local.x;
y = local.y;
}
// Check if the point is within the button bounds
var bounds = new Rectangle(-buttonBackground.width / 2, -buttonBackground.height / 2, buttonBackground.width, buttonBackground.height);
var isOver = x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height;
self.isHovering = isOver;
if (!isOver) {
return;
}
// Visual feedback that button was pressed
tween(buttonBackground, {
scaleX: 0.95,
scaleY: 0.95
}, {
duration: 100,
easing: tween.easeOut
});
};
// Update button text
self.update = function () {
if (!idleManager) {
return;
}
// Get upgrade information from idleManager
var upgrade = idleManager.upgrades ? idleManager.upgrades[self.type] : null;
// Cache affordable state to avoid redundant calculations
var isAffordable = upgrade && idleManager.points >= upgrade.cost;
var label = '';
// Set appropriate button label based on upgrade type and availability
if (upgrade && upgrade.cost !== undefined) {
switch (self.type) {
case 'pointsPerSecond':
label = 'Income +20%\nCost: ' + Math.floor(upgrade.cost);
break;
case 'laserPower':
label = 'Laser +50%\nCost: ' + Math.floor(upgrade.cost);
break;
case 'autoShooting':
label = (upgrade.level > 0 ? 'Upgrade Auto' : 'Auto Shoot') + '\nCost: ' + Math.floor(upgrade.cost);
break;
}
} else {
// Default label text when upgrade is not defined
switch (self.type) {
case 'pointsPerSecond':
label = 'Income +20%\nCost: 10';
break;
case 'laserPower':
label = 'Laser +50%\nCost: 20';
break;
case 'autoShooting':
label = 'Auto Shoot\nCost: 100';
break;
}
}
// Update button text
self.buttonText.setText(label);
// Set base tint colors based on button type if not already defined
if (self.baseOriginalTint === undefined) {
if (self.type === 'pointsPerSecond') {
self.baseOriginalTint = 0x00AA00; // Green for income
} else if (self.type === 'laserPower') {
self.baseOriginalTint = 0xAA0000; // Red for laser power
} else {
// autoShooting
self.baseOriginalTint = 0x0000AA; // Blue for auto shooting
}
// Initialize original tint to base color
self.originalTint = self.baseOriginalTint;
}
// Check if affordability has changed since last update
var wasAffordable = self.isAffordable;
self.isAffordable = isAffordable;
// Only update visual state if affordability changed or this is the first update
if (wasAffordable !== self.isAffordable || self.lastUpdateTick === undefined) {
if (isAffordable) {
// Button is affordable - show at full opacity
buttonBackground.alpha = 1.0;
self.buttonText.alpha = 1.0;
self.originalTint = self.baseOriginalTint;
self.hoverTint = 0xFFFFFF;
} else {
// Button is not affordable - show at reduced opacity
buttonBackground.alpha = 0.6;
self.buttonText.alpha = 0.8;
self.originalTint = 0x888888; // Gray for unaffordable
self.hoverTint = 0xAAAAAA; // Light gray for hover on unaffordable
}
// Only update the tint if not hovering to avoid visual flicker
if (!self.isHovering) {
buttonBackground.tint = self.originalTint;
}
}
// Track the last update tick to optimize performance
self.lastUpdateTick = LK.ticks;
};
return self;
});
/****
* Initialize Game
****/
// Helper function to shoot laser
// Initialize clouds array
var game = new LK.Game({
// No title, no description
backgroundColor: 0x000000 // Black
});
/****
* Game Code
****/
// Ensure storage has all required properties initialized
// Bird2Effects class to handle effects and animations for Bird2
// Function to create a pulsating effect
// UFOSound class to manage UFO sound effects
// UFOMovement class to handle UFO movement
// Ensure storage has all required properties initialized
if (!storage.upgrades) {
storage.upgrades = {
pointsPerSecond: {
level: 1,
cost: 10,
multiplier: 1.5
},
laserPower: {
level: 1,
cost: 20,
multiplier: 2
},
autoShooting: {
level: 0,
cost: 100,
multiplier: 2
}
};
}
// Helper function to shoot laser
function shootLaser(startX, startY, targetX, targetY) {
// Create a new laser with the specified start and target coordinates
var laser = new Laser(startX, startY, targetX, targetY);
// Add the laser to the game
game.addChild(laser);
// Play laser sound
LK.getSound('laser1').play();
laser.lastIntersecting = false;
return laser;
}
// Load data from storage on startup
console.log("Loading game data from storage:", storage.points, "points");
var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
this.ufo = ufo;
this.ufoGraphics = ufoGraphics;
this.ufo.speed = 3.2; // Decrease speed by 20%
this.ufo.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
this.ufo.lastX = this.ufo.x; // Track last X position for future checks
this.ufo.update = function () {
this.x += this.speed * this.direction;
this.y = 100 + Math.sin(this.x / 70) * 165; // Increase the wave pattern depth by 10%
// Stop playing ufo1 sound after UFO leaves the screen
if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2 || this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
this.destroy();
ufo = null;
LK.getSound('ufo1').stop();
}
this.lastX = this.x; // Update lastX after movement
};
};
var UFOSound = function UFOSound() {
this.play = function () {
LK.getSound('ufo1').play();
};
};
// BackgroundMusic class to manage background music
var BackgroundMusic = function BackgroundMusic() {
this.play = function () {
LK.playMusic('bgm1', {
loop: true,
fade: {
start: 0,
end: 1,
duration: 4000
},
onEnd: onBgm1End
});
};
};
// LaserSound class to manage laser sound effects
var LaserSound = function LaserSound() {
this.play = function () {
LK.getSound('laser1').play();
};
};
var Bird1Movement = function Bird1Movement(bird, birdGraphics) {
this.bird = bird;
this.birdGraphics = birdGraphics;
// Set initial properties for the bird
bird.speed = Math.random() * 1.6 + 1;
bird.lastY = bird.y; // Initialize lastY for tracking changes on Y
bird.lastX = bird.x; // Initialize lastX for tracking changes on X
bird.type = 'bird1'; // Set bird type for texture changes
bird.lastIntersecting = false; // Initialize lastIntersecting for collision detection
// Set the update method for the bird
bird.update = function () {
this.y += this.speed;
this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
// Check if the bird has moved off-screen
if (this.lastY <= 2732 && this.y > 2732) {
this.y = -this.height;
this.x = Math.random() < 0.33 ? Math.random() * 2048 : Math.random() < 0.5 ? 0 : 2048;
}
// Update bird texture based on direction
if (birdGraphics) {
if (this.lastX <= 2048 / 2 && this.x > 2048 / 2) {
birdGraphics.texture = LK.getAsset(this.type + '-right', {}).texture;
} else if (this.lastX > 2048 / 2 && this.x <= 2048 / 2) {
birdGraphics.texture = LK.getAsset(this.type, {}).texture;
}
}
// Always update last positions after movements
this.lastY = this.y; // Update lastY after movement
this.lastX = this.x; // Update lastX after movement
};
};
var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
this.bird = bird;
this.birdGraphics = birdGraphics;
// Set initial properties for the bird
bird.speed = Math.random() * 1.6 + 1;
bird.lastY = bird.y; // Initialize lastY for tracking changes on Y
bird.lastX = bird.x; // Initialize lastX for tracking changes on X
bird.type = 'bird2'; // Set bird type for texture changes
bird.lastIntersecting = false; // Initialize lastIntersecting for collision detection
// Set the update method for the bird
bird.update = function () {
this.y += this.speed;
this.x += Math.sin(this.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
// Update bird texture based on direction
if (birdGraphics) {
if (this.lastX <= 2048 / 2 && this.x > 2048 / 2) {
birdGraphics.texture = LK.getAsset(this.type + '-right', {}).texture;
} else if (this.lastX > 2048 / 2 && this.x <= 2048 / 2) {
birdGraphics.texture = LK.getAsset(this.type, {}).texture;
}
}
// Check if the bird has moved off-screen
if (this.lastY <= 2732 && this.y > 2732) {
this.y = -this.height; // Respawn at the top
this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
}
// Always update last positions after movements
this.lastX = this.x; // Update lastX after movement
this.lastY = this.y; // Update lastY after movement
};
};
var CloudMovement = function CloudMovement(cloud, cloudGraphics) {
this.cloud = cloud;
this.cloudGraphics = cloudGraphics;
this.cloud.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8
this.cloud.hasAccelerated = false; // Track if the cloud has already accelerated
this.cloud.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
this.cloud.lastX = this.cloud.x; // Track last X position for future checks
this.cloud.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections
this.cloud.update = function () {
this.x += this.speed * this.direction;
// If the cloud moves off-screen, reposition it to the opposite side
if (this.lastX <= 2048 + this.width / 2 && this.x > 2048 + this.width / 2) {
this.x = -this.width / 2;
} else if (this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
this.x = 2048 + this.width / 2;
}
// Check for overlap with other clouds
if (clouds && clouds.length > 0) {
for (var i = 0; i < clouds.length; i++) {
if (clouds[i] !== this && this.intersects(clouds[i])) {
if (!this.hasAccelerated) {
this.speed *= 1.5; // Increase speed by 50%
this.hasAccelerated = true; // Mark as accelerated
}
break;
} else if (this.hasAccelerated && !this.intersects(clouds[i])) {
this.speed /= 1.5; // Reset speed to original
this.hasAccelerated = false; // Reset acceleration state
}
}
}
// Check if the cloud intersects with the sun
if (sun && !this.lastIntersecting && this.intersects(sun)) {
this.speed *= 2; // Double the speed when touching the sun
if (this.cloudGraphics) {
tween(this.cloudGraphics, {
alpha: 0.5
}, {
duration: 3000,
easing: tween.linear
});
}
// Double the sun's pulsating rate
startPulsating(sun, 444); // Pass the new duration for faster pulsating
} else if (sun && this.lastIntersecting && !this.intersects(sun)) {
this.speed /= 2; // Reset speed to original when not touching the sun
if (this.cloudGraphics) {
tween(this.cloudGraphics, {
alpha: 1.0
}, {
duration: 3000,
easing: tween.linear
});
}
// Reset the sun's pulsating rate to normal
startPulsating(sun, 888); // Pass the original duration for normal pulsating
}
this.lastIntersecting = sun ? this.intersects(sun) : false;
this.lastX = this.x; // Update lastX after movement
};
};
var Bird2Effects = function Bird2Effects(bird) {
this.bird = bird;
this.applyEffects = function () {
// Add any specific effects or animations for Bird2 here
};
};
// Bird1Effects class to handle effects and animations for Bird1
var Bird1Effects = function Bird1Effects(bird) {
this.bird = bird;
this.applyEffects = function () {
// Add any specific effects or animations for Bird1 here
};
};
function startPulsating(target) {
var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 888;
function pulsate() {
tween(target, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: duration,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(target, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: duration,
easing: tween.easeInOut,
onFinish: pulsate
});
}
});
}
pulsate();
}
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2 - 200;
game.addChild(background);
// ScoreManager has already been defined, using IdleManager instead
var birds = [];
game.down = function (x, y, obj) {
if (!game.reticle) {
game.reticle = game.addChild(new Reticle());
var reticleChildIndex = 7;
if (reticleChildIndex >= 0 && reticleChildIndex < game.children.length) {
game.setChildIndex(game.reticle, reticleChildIndex); // Set reticle to be rendered after the tree
}
}
game.reticle.x = x;
game.reticle.y = y;
shootLaser(cat.x, cat.y - 430, x, y);
};
var VOLUME_BGM1 = 0.02;
var VOLUME_BREEZE1 = 0.02;
var VOLUME_CRICKET1 = 0.02;
var VOLUME_FROG1 = 0.02;
var VOLUME_SONGBIRD1 = 0.02;
var VOLUME_UFO1 = 0.02;
var VOLUME_WINGS1 = 0.02;
game.move = function (x, y, obj) {
if (!game.reticle) {
game.reticle = game.addChild(new Reticle());
}
if (obj.event) {
var x = obj.event.x;
var y = obj.event.y;
}
game.reticle.x = x;
game.reticle.y = y;
};
// Add a sun to the game in the top left corner
var sun = game.addChild(new Sun());
sun.x = 480;
sun.y = 590;
var sunChildIndex = 1;
game.setChildIndex(sun, sunChildIndex); // Set sun to be rendered after the background
// Function to add a UFO to the game
function addUFO() {
var ufo = game.addChild(new UFO());
ufo.x = Math.random() < 0.5 ? 2048 + ufo.width / 2 : -ufo.width / 2; // Start from either the far right or left edge of the screen
ufo.y = Math.random() * (2732 - ufo.height); // Random initial y position within the screen height, ensuring it stays within bounds
ufo.customUpdate = function () {
ufo.update();
};
// Removed ufo sound playing at startup
return ufo;
}
// Initialize clouds array
var clouds = [];
for (var i = 0; i < 4; i++) {
// Add 3 clouds for variety
var cloud = new Cloud();
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * (2732 / 2); // Position clouds in the upper half of the screen
clouds.push(cloud);
game.addChild(cloud);
var cloudChildIndex = 2;
game.setChildIndex(cloud, cloudChildIndex); // Set clouds to be rendered after the sun
}
// Initialize birds
spawnBird1();
spawnBird2();
// Initialize a timer to add a UFO at a random time between 20 and 30 seconds
var ufo; // Define the ufo variable in the global scope
var laser; // Define the laser variable in the global scope
var ufoTimer = LK.setTimeout(function () {
addUFO();
}, Math.random() * 5000 + 5000); // Adjusted interval for UFO appearances between 5 to 10 seconds
game.update = function () {
for (var i = 0; i < clouds.length; i++) {
clouds[i].update();
}
if (ufo) {
ufo.customUpdate();
// Update each laser
game.children.forEach(function (child) {
if (child instanceof Laser) {
child.update();
// Check for intersections with birds and UFO
birds.forEach(function (bird) {
if (!child.lastIntersecting && child.intersects(bird)) {
var points = 0;
if (bird instanceof Bird1) {
points = 5 * child.power;
} else if (bird instanceof Bird2 || bird instanceof Bird3) {
points = 1 * child.power;
}
idleManager.points += points;
scoreDisplay.updateScore(Math.floor(idleManager.points)); // Update the score display
// Visual feedback
tween(bird, {
alpha: 0,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
bird.destroy();
birds.splice(birds.indexOf(bird), 1);
}
});
child.destroy();
}
child.lastIntersecting = birds.some(function (bird) {
return child.intersects(bird);
});
});
if (ufo && !child.lastIntersecting && child.intersects(ufo)) {
score += 25;
score.updateScore(score);
child.destroy();
}
child.lastIntersecting = birds.some(function (bird) {
return child.intersects(bird);
}) || ufo && child.intersects(ufo);
}
});
if (ufo.lastX <= 2048 + ufo.width / 2 && ufo.x > 2048 + ufo.width / 2 || ufo.lastX >= -ufo.width / 2 && ufo.x < -ufo.width / 2) {
// Destroy the UFO and set it to null
ufo.destroy();
ufo = null;
// Start a timer for the UFO to reappear between 30-50 seconds
ufoTimer = LK.setTimeout(function () {
ufo = addUFO();
}, Math.random() * 20000 + 30000);
} else {}
ufo.lastX = ufo.x; // Update lastX for the UFO
}
// Removed auto-targeting update function
};
// Function to spawn a third kind of bird
function spawnBird1() {
// Create a new Bird1 instance
var bird = new Bird1();
// Set initial position
bird.x = Math.random() * 2048;
bird.y = -bird.height;
// Set initial properties
bird.speed = 1 + Math.random() * 0.6;
bird.lastIntersecting = false;
bird.type = 'bird1'; // Specific property for Bird1
bird.color = 0x746130; // Specific color for Bird1
// Add to game container
game.addChild(bird);
// Set rendering order
var bird1ChildIndex = 4;
if (bird1ChildIndex >= 0 && bird1ChildIndex < game.children.length) {
game.setChildIndex(bird, bird1ChildIndex); // Set Bird1 to be rendered after the laser
}
// Add to birds array for tracking
birds.push(bird);
}
function spawnBird2() {
// Create a new Bird2 instance
var bird = new Bird2();
// Set initial position
bird.y = Math.random() * 2732; // Random initial y position within the screen height
bird.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
// Set initial properties
bird.speed = 1 + Math.random() * 0.6;
bird.lastIntersecting = false;
bird.type = 'bird2'; // Specific property for Bird2
bird.color = 0xFFFFFF; // Specific color for Bird2
// Add to game container
game.addChild(bird);
// Set rendering order
var bird2ChildIndex = 6;
if (bird2ChildIndex >= 0 && bird2ChildIndex < game.children.length) {
game.setChildIndex(bird, bird2ChildIndex); // Set Bird2 to be rendered after the tree
}
// Add to birds array for tracking
birds.push(bird);
}
// Ensure there are always 3 birds on screen
game.update = function () {
// Update idle manager
if (idleManager) {
idleManager.update();
}
// Update upgrade buttons to reflect current state
if (upgradeButtons && upgradeButtons.length) {
upgradeButtons.forEach(function (button) {
if (button.update) {
button.update();
}
});
}
// Update score display with points from idle manager
if (scoreDisplay && idleManager) {
scoreDisplay.updateScore(Math.floor(idleManager.points));
}
// Automatically spawn birds if there are less than 3
if (birds && birds.length < 3 && LK.ticks % 120 == 0) {
var randomChoice = Math.random();
if (randomChoice < 0.5) {
spawnBird1();
} else {
spawnBird2();
}
}
// Idle game visual feedback - show floating points for passive income
if (idleManager && scoreDisplay && LK.ticks % 30 == 0 && idleManager.pointsPerSecond > 0) {
var floatingPoint = new Text2('+' + idleManager.pointsPerSecond.toFixed(1), {
size: 40,
fill: 0x00FF00,
stroke: 0x000000,
strokeThickness: 3
});
floatingPoint.anchor.set(0.5, 0.5);
floatingPoint.x = scoreDisplay.x + (Math.random() * 100 - 50);
floatingPoint.y = scoreDisplay.y + (Math.random() * 60 - 30) + 60;
game.addChild(floatingPoint);
// Animate the floating point indicator
tween(floatingPoint, {
y: floatingPoint.y - 50,
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
floatingPoint.destroy();
}
});
}
// Pulse effect on cat when auto-shooting is enabled
if (cat && idleManager && idleManager.autoShooting && LK.ticks % 90 == 0) {
tween(cat, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(cat, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeIn
});
}
});
// Auto shoot at a random position
if (idleManager.autoShooting) {
var targetX = Math.random() * 2048;
var targetY = Math.random() * (2732 / 2); // Target upper half of screen
shootLaser(cat.x, cat.y - 430, targetX, targetY);
}
}
// Update each bird
if (birds) {
birds.forEach(function (bird) {
if (bird && bird.update) {
bird.update();
}
// Check if the bird has moved off-screen
if (bird && bird.lastY !== undefined && bird.lastY <= 2732 && bird.y > 2732) {
bird.y = -bird.height; // Respawn the bird at the top
bird.x = Math.random() * 2048; // Randomize the x position
bird.speed = 1 + Math.random() * 0.6; // Reset speed for new bird
}
// Check for collisions with lasers
if (bird) {
game.children.forEach(function (child) {
if (child instanceof Laser) {
if (!child.lastIntersecting && child.intersects(bird)) {
var points = 0;
if (bird instanceof Bird1) {
points = 5 * child.power;
} else if (bird instanceof Bird2) {
points = 1 * child.power;
}
if (idleManager) {
idleManager.points += points;
if (scoreDisplay) {
scoreDisplay.updateScore(Math.floor(idleManager.points));
}
}
// Visual feedback
tween(bird, {
alpha: 0,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
bird.destroy();
birds.splice(birds.indexOf(bird), 1);
}
});
child.destroy();
}
child.lastIntersecting = child.intersects(bird);
}
});
}
});
}
};
// Add a tree to the game
var tree = game.addChild(new Tree());
tree.x = 2048 / 2 + 500; // Move the tree 500px to the right
tree.y = 2765; // Position the tree on the grass
// Ensure treeChildIndex is within valid range before setting child index
var treeChildIndex = Math.min(7, game.children.length - 1); // Ensure index is within bounds
// Only set the child index if the tree is actually a child of the game container
if (tree && tree.parent === game && treeChildIndex >= 0 && treeChildIndex < game.children.length) {
game.setChildIndex(tree, treeChildIndex); // Set tree to be rendered at index 7 or the last valid index
}
// Initialize idle game manager
var idleManager = new IdleManager();
game.addChild(idleManager);
// Create upgrade buttons
var upgradeButtons = [];
var incomeButton = new UpgradeButton('pointsPerSecond', 1800, 200);
var laserButton = new UpgradeButton('laserPower', 1800, 350);
var autoButton = new UpgradeButton('autoShooting', 1800, 500);
// Add buttons to game
game.addChild(incomeButton);
game.addChild(laserButton);
game.addChild(autoButton);
upgradeButtons.push(incomeButton, laserButton, autoButton);
// Configure button properties
upgradeButtons.forEach(function (button) {
// Ensure interactive is set
button.interactive = true;
// Set proper hit area for the button
var buttonBackground = button.buttonBackground;
if (buttonBackground) {
var hitArea = new Rectangle(-buttonBackground.width / 2, -buttonBackground.height / 2, buttonBackground.width, buttonBackground.height);
button.hitArea = hitArea;
}
// Force update visual state
if (button.update) {
button.update();
}
});
// Add visibility check to ensure buttons are displayed
console.log("Buttons initialized:", upgradeButtons.length);
upgradeButtons.forEach(function (button, index) {
console.log("Button " + index + " position:", button.x, button.y);
});
// Initialize score for compatibility
var score = 0;
// Add instructions text declaration (will be positioned after scoreDisplay is defined)
var instructionsText = new Text2('Shoot birds for points!\nClick upgrade buttons to improve', {
size: 40,
fill: 0xFFFFFF,
font: "Arial, sans-serif",
stroke: 0x000000,
strokeThickness: 3,
align: "center",
wordWrap: true,
wordWrapWidth: 280,
wordWrapHeight: 330
});
instructionsText.anchor.set(0, 0.5);
// Add stack1 image to the game
var stack1 = game.addChild(new Stack1());
stack1.x = 1650; // Move 500px to the right
stack1.y = 2200; // Move down by 800px
var stack1ChildIndex = 6;
game.setChildIndex(stack1, stack1ChildIndex); // Set stack1 to be rendered at index 9 or the last valid index
// Add the grass floor to the game
var grassBack = new GrassBack();
grassBack.x = 1020;
grassBack.y = 2735; // Position grassBack at the bottom
game.addChild(grassBack);
var grassBackChildIndex = 5;
game.setChildIndex(grassBack, grassBackChildIndex); // Set grassBack to be rendered after Bird3
var grassFront = new GrassFront();
grassFront.x = 1020;
grassFront.y = 2735; // Position grassFront at the bottom
game.addChild(grassFront);
var grassFrontChildIndex = 8;
game.setChildIndex(grassFront, grassFrontChildIndex); // Set grassFront to be rendered at index 8
var scoreDisplay = new ScoreDisplay();
scoreDisplay.x = 2048 / 2 + 520; // Move the score display 400px to the right
scoreDisplay.y = 2732 - 185 - 80 - 128; // Move the score display up by 128px
game.addChild(scoreDisplay);
// Position and add instructionsText now that scoreDisplay is defined
instructionsText.x = scoreDisplay.x + 220;
instructionsText.y = scoreDisplay.y;
game.addChild(instructionsText);
// Ensure laser is added to the game before setting scoreDisplay's index
if (game.children.includes(laser)) {
game.setChildIndex(laser, 10); // Set laser to be rendered before the scoreDisplay
}
// Function to handle bgm1 end event
function onBgm1End() {
// Set a timer to replay bgm1 after 50-80 seconds
var bgmTimer = LK.setTimeout(function () {
LK.playMusic('bgm1', {
loop: true,
fade: {
start: 0,
end: 1,
duration: 4000
},
onEnd: onBgm1End
});
}, Math.random() * 30000 + 50000);
}
;
// Add the cat to the game
var cat = game.addChild(new Cat());
cat.x = 200; // Position the cat to the far left
cat.y = 2732; // Position the cat at the bottom of the screen
var catChildIndex = 9;
game.setChildIndex(cat, catChildIndex); // Set cat to be rendered after the grass
// Play bgm1 once on load and set a timer to replay it every 20-50 seconds
LK.playMusic('bgm1', {
loop: false,
// Play once
fade: {
start: 0,
end: 0.02,
// Set to the lowest volume
duration: 4000
},
onEnd: function onEnd() {
// Set a timer to replay bgm1 every 20-50 seconds
LK.setTimeout(function () {
LK.playMusic('bgm1', {
loop: false,
// Play once
fade: {
start: 0,
end: 0.5,
// Set to the lowest volume
duration: 4000
},
onEnd: onEnd // Set the onEnd function to replay bgm1
});
}, Math.random() * 30000 + 20000); // Random time between 20-50 seconds
}
});
// Initialize a timer to play the wings1 sound at a random time between 10 and 30 seconds
var wingsTimer = LK.setTimeout(function () {
LK.getSound('wings1').play();
wingsTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 10000);
}, Math.random() * 20000 + 10000);
// Create an array for all sounds except ufo1, including all birdsong sounds
var sounds = ['cricket1', 'frog1', 'wings1', 'songbird1'];
var currentAmbientSound = null;
// Initialize random timers for each sound to play between 30-50 seconds
sounds.forEach(function (soundId) {
var sound = LK.getSound(soundId);
var ambientSoundTimer = LK.setTimeout(function () {
if (currentAmbientSound) {
currentAmbientSound.stop(); // Stop the currently playing ambient sound
}
sound.play();
currentAmbientSound = sound; // Set the current ambient sound
// Set a timeout to reset the current ambient sound after it finishes playing
LK.setTimeout(function () {
currentAmbientSound = null;
}, sound.duration * 1000); // Convert duration from seconds to milliseconds
// Reset the timer to play the sound again between 30-50 seconds, plus an additional 5 seconds
ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000 + 5000);
}, Math.random() * 20000 + 30000);
});
// Helper function to shoot laser ===================================================================
--- original.js
+++ change.js
@@ -719,9 +719,8 @@
/****
* Game Code
****/
// Ensure storage has all required properties initialized
-// Ensure storage has values initialized
// Bird2Effects class to handle effects and animations for Bird2
// Function to create a pulsating effect
// UFOSound class to manage UFO sound effects
// UFOMovement class to handle UFO movement
@@ -755,27 +754,8 @@
LK.getSound('laser1').play();
laser.lastIntersecting = false;
return laser;
}
-if (!storage.upgrades) {
- storage.upgrades = {
- pointsPerSecond: {
- level: 1,
- cost: 10,
- multiplier: 1.5
- },
- laserPower: {
- level: 1,
- cost: 20,
- multiplier: 2
- },
- autoShooting: {
- level: 0,
- cost: 100,
- multiplier: 2
- }
- };
-}
// Load data from storage on startup
console.log("Loading game data from storage:", storage.points, "points");
var UFOMovement = function UFOMovement(ufo, ufoGraphics) {
this.ufo = ufo;
@@ -898,22 +878,24 @@
} else if (this.lastX >= -this.width / 2 && this.x < -this.width / 2) {
this.x = 2048 + this.width / 2;
}
// Check for overlap with other clouds
- for (var i = 0; i < clouds.length; i++) {
- if (clouds[i] !== this && this.intersects(clouds[i])) {
- if (!this.hasAccelerated) {
- this.speed *= 1.5; // Increase speed by 50%
- this.hasAccelerated = true; // Mark as accelerated
+ if (clouds && clouds.length > 0) {
+ for (var i = 0; i < clouds.length; i++) {
+ if (clouds[i] !== this && this.intersects(clouds[i])) {
+ if (!this.hasAccelerated) {
+ this.speed *= 1.5; // Increase speed by 50%
+ this.hasAccelerated = true; // Mark as accelerated
+ }
+ break;
+ } else if (this.hasAccelerated && !this.intersects(clouds[i])) {
+ this.speed /= 1.5; // Reset speed to original
+ this.hasAccelerated = false; // Reset acceleration state
}
- break;
- } else if (this.hasAccelerated && !this.intersects(clouds[i])) {
- this.speed /= 1.5; // Reset speed to original
- this.hasAccelerated = false; // Reset acceleration state
}
}
// Check if the cloud intersects with the sun
- if (!this.lastIntersecting && this.intersects(sun)) {
+ if (sun && !this.lastIntersecting && this.intersects(sun)) {
this.speed *= 2; // Double the speed when touching the sun
if (this.cloudGraphics) {
tween(this.cloudGraphics, {
alpha: 0.5
@@ -923,9 +905,9 @@
});
}
// Double the sun's pulsating rate
startPulsating(sun, 444); // Pass the new duration for faster pulsating
- } else if (this.lastIntersecting && !this.intersects(sun)) {
+ } else if (sun && this.lastIntersecting && !this.intersects(sun)) {
this.speed /= 2; // Reset speed to original when not touching the sun
if (this.cloudGraphics) {
tween(this.cloudGraphics, {
alpha: 1.0
@@ -936,9 +918,9 @@
}
// Reset the sun's pulsating rate to normal
startPulsating(sun, 888); // Pass the original duration for normal pulsating
}
- this.lastIntersecting = this.intersects(sun);
+ this.lastIntersecting = sun ? this.intersects(sun) : false;
this.lastX = this.x; // Update lastX after movement
};
};
var Bird2Effects = function Bird2Effects(bird) {
@@ -983,23 +965,9 @@
});
background.x = 2048 / 2;
background.y = 2732 / 2 - 200;
game.addChild(background);
-// ScoreManager class to manage score logic
-var ScoreManager = function ScoreManager() {
- var self = this;
- self.score = 0;
- self.addScore = function (points) {
- self.score += points;
- return self.score;
- };
- self.resetScore = function () {
- self.score = 0;
- };
- self.getScore = function () {
- return self.score;
- };
-};
+// ScoreManager has already been defined, using IdleManager instead
var birds = [];
game.down = function (x, y, obj) {
if (!game.reticle) {
game.reticle = game.addChild(new Reticle());
an orange and white cat facing away from the camera. the cat is sitting straight up and looking up, ready to pounce. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
remove black box
fluffy translucent cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
bright sun with wincing cartoon face and a black eye. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
a goofy ufo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
red gaming reticle. Minimal. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sunny day, hilly landscape. there is an alien invasion taking place in the distance. cities burning.
large AUTUMN SHADES tree with sparse bunches of leaves. branches are exposed, but the tree is tough and old.. true-color, realistic, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
glowing orange sphere. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sideway view of a fighter jet. . . In-Game 2d asset. transparent background. horizontal. No shadows.
shiny purple and black attack ufo.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
wings1
Sound effect
ufo1
Sound effect
cricket1
Sound effect
frog1
Sound effect
bgm1
Music
breeze1
Sound effect
songbird1
Sound effect
laser1
Sound effect
teslacoil
Sound effect
chitter
Sound effect
laser2
Sound effect
dead1
Sound effect
electro
Sound effect