Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var levelText = new LK.Text("Lvl " + self.level, {' Line Number: 48
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var buttonText = new LK.Text(text, {' Line Number: 168
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var levelText = new LK.Text("Level: 1 (x1.0)", {' Line Number: 148
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var counterText = new LK.Text("Sparkles: 0", {' Line Number: 140
Code edit (1 edits merged)
Please save this source code
User prompt
make label text black
User prompt
move all objects to the top right of the screen
User prompt
make the game play itself until a player clicks a start button
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var levelText = new LK.Text("Lvl " + self.level, {' Line Number: 34
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var buttonText = new LK.Text(text, {' Line Number: 119
User prompt
Please fix the bug: 'LK.Text is not a constructor' in or related to this line: 'var counterText = new LK.Text("Sparkles: 0", {' Line Number: 102
Code edit (1 edits merged)
Please save this source code
User prompt
change all label text colors to white
User prompt
remove unused objects
User prompt
apply images to all image obects
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Graphics is not a constructor' in or related to this line: 'var laserGraphics = new Graphics();' Line Number: 273
Code edit (1 edits merged)
Please save this source code
User prompt
8. **Game Initialization**: During `Initialize Game`, only set `backgroundColor`. All other variables should be set in `Game Code`. 9. **Game Elements Centering**: Ensure game play elements that should be centered are properly centered, accounting for asset size. 10. **Dynamic Resizing and Orientation**: Do not handle dynamic resizing and orientation changes, as the LK engine will handle this automatically. 11. **Sound and Music**: Refrain from adding sound, music, or pause functions unless specifically directed. 12. **Background**: Never add a background to the game unless specifically asked. 13. **Tweening**: There is no `LK.Tween` library, so any animations should be written manually or use existing plugins. 14. **Asset Creation**: You do not need to create new assets in the `Assets` section as the engine will do this automatically. 15. **Import Statements**: Do not add any import or require statements to the code, even if it's commented out or a placeholder.
User prompt
8. **Game Initialization**: During `Initialize Game`, only set `backgroundColor`. All other variables should be set in `Game Code`. 9. **Game Elements Centering**: Ensure game play elements that should be centered are properly centered, accounting for asset size. 10. **Dynamic Resizing and Orientation**: Do not handle dynamic resizing and orientation changes, as the LK engine will handle this automatically. 11. **Sound and Music**: Refrain from adding sound, music, or pause functions unless specifically directed. 12. **Background**: Never add a background to the game unless specifically asked. 13. **Tweening**: There is no `LK.Tween` library, so any animations should be written manually or use existing plugins. 14. **Asset Creation**: You do not need to create new assets in the `Assets` section as the engine will do this automatically. 15. **Import Statements**: Do not add any import or require statements to the code, even if it's commented out or a placeholder.
User prompt
1. **Global Scope Initialization**: Ensure that all important variables, instances, arrays, and variables are initialized in the global scope of `gamecode.js`. This includes arrays for game objects like `cats`, `kittens`, `birds`, `ufos`, `clouds`, `powerUps`, and `sparkles`.
2. **Asset Classes**: Differentiate between asset classes for different behaviors, such as 'HeroBullets' and 'EnemyBullets', and ensure distinct assets are assigned to these classes.
3. **Event Listeners**: Ensure event listeners are correctly using the `obj.event` for the event object, and not assuming any standard libraries are included.
4. **Touchscreen Compatibility**: Ensure the game is touchscreen-compatible and does not rely on keyboard inputs or controls.
5. **Asset Retrieval**: Use `LK.getAsset('
User prompt
continue developing hte app
User prompt
ensure the game is initialized correctly
User prompt
continue
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* 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('bird', {
anchorX: 0.5,
anchorY: 0.5
});
// Add a label to the bird
var birdLabel = new Text2('Bird1', {
size: 20,
fill: 0xFFFFFF
});
birdLabel.anchor.set(0.5, 0.5); // Center the label
birdLabel.y = -40; // Position above the bird (increased from -30)
self.addChild(birdLabel);
self.speed = 1 + Math.random() * 0.6;
self.lastY = self.y;
self.update = function () {
self.y += self.speed;
self.lastY = self.y;
};
});
// Bird2 class to represent the second kind of bird
var Bird2 = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0x88CCFF // Light blue tint to differentiate
});
// Add a label to the bird
var birdLabel = new Text2('Bird2', {
size: 20,
fill: 0xFFFFFF
});
birdLabel.anchor.set(0.5, 0.5); // Center the label
birdLabel.y = -40; // Position above the bird (increased from -30)
self.addChild(birdLabel);
self.speed = 0.8 + Math.random() * 0.5;
self.lastY = self.y;
self.update = function () {
self.y += self.speed;
self.lastY = self.y;
};
});
// Add Bird3 class for variety
var Bird3 = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFFCC88 // Orange tint to differentiate
});
// Add a label to the bird
var birdLabel = new Text2('Bird3', {
size: 20,
fill: 0xFFFFFF
});
birdLabel.anchor.set(0.5, 0.5); // Center the label
birdLabel.y = -40; // Position above the bird (increased from -30)
self.addChild(birdLabel);
self.speed = 1.2 + Math.random() * 0.7;
self.lastY = self.y;
self.update = function () {
self.y += self.speed;
self.lastY = self.y;
};
});
// 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
});
// Add a label to the cat
var catLabel = new Text2('Cat', {
size: 30,
fill: 0xFFFFFF
});
catLabel.anchor.set(0.5, 0.5); // Center the label
catLabel.y = -120; // Position above the cat
self.addChild(catLabel);
self.level = 1;
self.attackRate = 2; // attacks per second
self.attackRange = 300;
self.lastAttackTime = 0;
self.update = function () {
// Check for nearby birds to attack
var currentTime = LK.ticks / 60;
if (currentTime - self.lastAttackTime > 1 / self.attackRate) {
for (var i = 0; i < birds.length; i++) {
var bird = birds[i];
var dx = bird.x - self.x;
var dy = bird.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < self.attackRange) {
// Create laser from cat to bird
var laser = new Laser(self.x, self.y - 100, bird.x, bird.y);
game.addChild(laser);
self.lastAttackTime = currentTime;
break;
}
}
}
};
});
// 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
});
// Add a label to the cloud
var cloudLabel = new Text2('Cloud', {
size: 25,
fill: 0xFFFFFF
});
cloudLabel.anchor.set(0.5, 0.5); // Center the label
cloudLabel.y = -60; // Position above the cloud
self.addChild(cloudLabel);
self.speed = 0.2 + Math.random() * 0.3;
self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction
self.lastX = self.x;
self.update = function () {
self.x += self.speed * self.direction;
// If the cloud moves off-screen, reposition it to the opposite side
if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2) {
self.x = -self.width / 2;
} else if (self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
self.x = 2048 + self.width / 2;
}
self.lastX = self.x;
};
});
// CloudMovement class to handle cloud movement and fade effects
var CloudMovement = 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.speed = Math.random() * 0.55 + 0.25; // Adjust speed to range between 0.25 and 0.8
self.hasAccelerated = false; // Track if the cloud has already accelerated
self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
self.lastX = self.x; // Track last X position for future checks
self.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections
self.update = function () {
self.x += self.speed * self.direction;
// If the cloud moves off-screen, reposition it to the opposite side
if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2) {
self.x = -self.width / 2;
} else if (self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
self.x = 2048 + self.width / 2;
}
// Check for overlap with other clouds
for (var i = 0; i < clouds.length; i++) {
if (clouds[i] !== self && self.intersects(clouds[i])) {
if (!self.hasAccelerated) {
self.speed *= 1.5; // Increase speed by 50%
self.hasAccelerated = true; // Mark as accelerated
}
break;
} else if (self.hasAccelerated && !self.intersects(clouds[i])) {
self.speed /= 1.5; // Reset speed to original
self.hasAccelerated = false; // Reset acceleration state
}
}
// Check if the cloud intersects with the sun
if (!self.lastIntersecting && self.intersects(sun)) {
self.speed *= 2; // Double the speed when touching the sun
tween(cloudGraphics, {
alpha: 0.5
}, {
duration: 3000,
easing: tween.linear
});
} else if (self.lastIntersecting && !self.intersects(sun)) {
self.speed /= 2; // Reset speed to original when not touching the sun
tween(cloudGraphics, {
alpha: 1.0
}, {
duration: 3000,
easing: tween.linear
});
}
self.lastIntersecting = self.intersects(sun);
self.lastX = self.x; // Update lastX after movement
};
});
// 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
};
self.addChild(grassGraphics); // Add grass 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 + 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
};
});
// Jet class to represent a jet flying across the screen
var Jet = Container.expand(function () {
var self = Container.call(this);
var jetGraphics = self.attachAsset('jet', {
anchorX: 0.5,
anchorY: 0.5
});
// Add a label to the jet
var jetLabel = new Text2('Jet', {
size: 50,
fill: 0xFFFFFF
});
jetLabel.anchor.set(0.5, 0.5); // Center the label on the jet
jetLabel.y = -70; // Position the label above the jet (increased from -60)
self.addChild(jetLabel);
self.speed = 10; // Set the speed of the jet
self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
self.lastX = self.x; // Track last X position for future checks
self.update = function () {
self.x += self.speed * self.direction;
// If the jet moves off-screen, reposition it to the opposite side
if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2) {
self.x = -self.width / 2;
} else if (self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
self.x = 2048 + self.width / 2;
}
self.lastX = self.x; // Update lastX after movement
};
});
// Add label to Kitten class if it exists
var Kitten = Container.expand(function () {
var self = Container.call(this);
var kittenGraphics = self.attachAsset('kitten', {
anchorX: 0.5,
anchorY: 1
});
// Add a label to the kitten
var kittenLabel = new Text2('Kitten', {
size: 20,
fill: 0xFFFFFF
});
kittenLabel.anchor.set(0.5, 0.5); // Center the label
kittenLabel.y = -90; // Position above the kitten (increased from -80)
self.addChild(kittenLabel);
self.level = 1;
self.collectRate = 1; // sparkles per second
self.lastCollectTime = 0;
self.update = function () {
// Collect sparkles over time
var currentTime = LK.ticks / 60;
if (currentTime - self.lastCollectTime > 1 / self.collectRate) {
// Add sparkle collection logic here
self.lastCollectTime = currentTime;
}
};
});
// Laser class to represent a laser shot from the cat
var Laser = Container.expand(function (startX, startY, endX, endY) {
var self = Container.call(this);
self.startX = startX;
self.startY = startY;
self.endX = endX;
self.endY = endY;
// Calculate angle and distance
var dx = endX - startX;
var dy = endY - startY;
var distance = Math.sqrt(dx * dx + dy * dy);
var angle = Math.atan2(dy, dx);
// Create laser graphics
var laserGraphics = self.attachAsset('laser', {
anchorX: 0.0,
anchorY: 0.5,
rotation: angle
});
laserGraphics.width = distance;
self.addChild(laserGraphics);
self.x = startX;
self.y = startY;
// Add a label to the laser
var laserLabel = new Text2('Laser', {
size: 15,
fill: 0xFF8888
});
laserLabel.anchor.set(0.5, 0.5); // Center the label
laserLabel.y = -10; // Position above the laser
laserLabel.x = distance / 2; // Center along the laser
laserLabel.rotation = angle; // Align with laser
self.addChild(laserLabel);
// Play laser sound
LK.getSound('laser1').play();
self.lastIntersecting = false;
self.lifespan = 30; // frames
self.update = function () {
self.lifespan--;
if (self.lifespan <= 0) {
self.destroy();
}
};
});
// Light1 class to represent a light object
var Light1 = Container.expand(function () {
var self = Container.call(this);
var lightGraphics = self.attachAsset('light1', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = 450, self.y = 450;
// Add a label to the light1 object
var lightLabel = new Text2('Light1', {
size: 50,
fill: 0xFFFFFF
});
lightLabel.anchor.set(0.5, 0.5); // Center the label on the light
lightLabel.y = -70; // Position the label above the light (increased from -60)
self.addChild(lightLabel);
self.update = function () {
// Add any specific update logic for the light here
};
});
// Mirror class to manage score display
var Mirror = Container.expand(function () {
var self = Container.call(this);
var scoreGraphics = self.attachAsset('mirror1', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.PI / 14 // Rotate image right 15 degrees
});
var scoreText = new Text2('0', {
size: 175,
fill: 0x800080,
font: "Courier New, Courier, monospace",
// Segmented clock style font
stroke: 0x00FF00,
strokeThickness: 15,
dropShadow: true,
dropShadowColor: 0x000000,
dropShadowBlur: 5,
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreText.y = 50; // Move score text up by 20px
scoreText.x = -145; // Move score text left by 10px
scoreText.rotation = Math.PI / 12; // Rotate score text right 15 degrees
x = 100;
y = 100;
self.addChild(scoreText);
self.updateScore = function (newScore) {
scoreText.setText(newScore);
};
});
// Add label to Powerup class if it exists
var Powerup = Container.expand(function () {
var self = Container.call(this);
var powerupGraphics = self.attachAsset('powerupImage', {
anchorX: 0.5,
anchorY: 0.5
});
// Add a label to the powerup
var powerupLabel = new Text2('Powerup', {
size: 15,
fill: 0xFFFFFF
});
powerupLabel.anchor.set(0.5, 0.5); // Center the label
powerupLabel.y = -35; // Position above the powerup (increased from -25)
self.addChild(powerupLabel);
self.lifespan = 300; // 5 seconds at 60fps
self.update = function () {
self.lifespan--;
if (self.lifespan <= 0) {
self.destroy();
}
};
});
// Reticle class to manage reticle behavior
var Reticle = Container.expand(function () {
var self = Container.call(this);
// Create reticle graphics
var reticleGraphics = new Graphics();
reticleGraphics.lineStyle(2, 0xFF0000, 1);
reticleGraphics.drawCircle(0, 0, 20);
reticleGraphics.moveTo(-25, 0);
reticleGraphics.lineTo(25, 0);
reticleGraphics.moveTo(0, -25);
reticleGraphics.lineTo(0, 25);
self.addChild(reticleGraphics);
// Add a label to the reticle
var reticleLabel = new Text2('Target', {
size: 15,
fill: 0xFF0000
});
reticleLabel.anchor.set(0.5, 0.5); // Center the label
reticleLabel.y = -30; // Position above the reticle
self.addChild(reticleLabel);
self.update = function () {
// Add any specific update logic for the reticle here
};
});
// 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,
rotation: Math.PI / -12
});
self.update = function () {
// Add any specific update logic for stack1 here
};
});
// 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
});
// Add a label to the sun
var sunLabel = new Text2('Sun', {
size: 30,
fill: 0x000000 // Black text for contrast
});
sunLabel.anchor.set(0.5, 0.5); // Center the label
sunLabel.y = -40; // Position above the sun
self.addChild(sunLabel);
startPulsating(sunGraphics); // Start the pulsating effect on the sun graphics
});
// 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
stroke: 0x000000,
// Add a black stroke
strokeThickness: 15 // Set stroke thickness to 15px
});
// Add a label to the tree
var treeLabel = new Text2('Tree', {
size: 40,
fill: 0xFFFFFF
});
treeLabel.anchor.set(0.5, 0.5); // Center the label
treeLabel.y = -treeGraphics.height - 20; // Position above the tree
self.addChild(treeLabel);
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
});
// Add a label to the UFO
var ufoLabel = new Text2('UFO', {
size: 25,
fill: 0xFFFFFF
});
ufoLabel.anchor.set(0.5, 0.5); // Center the label
ufoLabel.y = -50; // Position above the UFO (increased from -40)
self.addChild(ufoLabel);
self.speed = 2;
self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction
self.lastX = self.x;
self.customUpdate = function () {
self.x += self.speed * self.direction;
// Check if UFO has moved off-screen
if (self.lastX <= 2048 + self.width / 2 && self.x > 2048 + self.width / 2 || self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
self.destroy();
ufo = null;
LK.getSound('ufo1').stop();
}
self.lastX = self.x;
};
});
/****
* Initialize Game
****/
// UFOMovement class to handle UFO movement
/****
* Assets
LK.init.shape('branch', {width:50, height:10, color:0x8b4513, shape:'box'})
****/
// Initialize clouds array
var game = new LK.Game({
// No title, no description
backgroundColor: 0x000000 // Black
});
/****
* Game Code
****/
// JetMovement class to handle jet movement
var JetMovement = function JetMovement(jet, jetGraphics) {
this.jet = jet;
this.jetGraphics = jetGraphics;
this.jet.speed = Math.max(1.6, 3.2) * 2; // Set the jet speed to 200% faster than the fastest object (Bird2 or UFO)
this.jet.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
this.jet.lastX = this.jet.x; // Track last X position for future checks
this.jet.update = function () {
this.x += this.speed * this.direction;
// If the jet 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;
}
this.lastX = this.x; // Update lastX after movement
};
};
var bird2; // Define bird2 variable in the global scope
// Bird2Effects class to handle effects and animations for Bird2
// Function to create a pulsating effect
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();
}
// UFOSound class to manage UFO sound effects
// UFOMovement class to handle UFO movement
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 / 50) * 250; // Extend the wave pattern to be longer and wider
// 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;
this.bird.speed = Math.random() * 1.6 + 1;
this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y
this.bird.lastX = this.bird.x; // Initialize lastX for tracking changes on X
this.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;
}
if (this.birdGraphics) {
if (this.lastX <= this.x) {
this.birdGraphics.texture = LK.getAsset('bird1-right', {}).texture;
} else if (this.lastX > this.x) {
this.birdGraphics.texture = LK.getAsset('bird1-left', {}).texture;
}
this.lastX = this.x; // Update lastX after movement
}
this.lastY = this.y; // Update lastY after movement
};
};
var Bird2Movement = function Bird2Movement(bird, birdGraphics) {
this.bird = bird;
this.birdGraphics = birdGraphics;
this.bird.speed = Math.random() * 1.6 + 1;
this.bird.lastY = this.bird.y; // Initialize lastY for tracking changes on Y
this.bird.lastX = this.bird.x; // Initialize lastX for tracking changes on X
this.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%
if (this.birdGraphics) {
if (this.lastX <= this.x) {
this.birdGraphics.texture = LK.getAsset('bird2-right', {}).texture;
} else if (this.lastX > this.x) {
this.birdGraphics.texture = LK.getAsset('bird2-left', {}).texture;
}
this.lastX = this.x; // Update lastX after movement
}
// Check if the bird has moved off-screen
if (this.lastY <= 2732 && this.y > 2732) {
this.y = Math.random() * 2732; // Random initial y position within the screen height
this.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
}
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
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 (!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
});
}
} else if (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
});
}
}
this.lastIntersecting = this.intersects(sun);
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
};
};
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2 - 100;
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;
};
};
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;
};
};
var birds = [];
game.down = function (x, y, obj) {
if (!game.reticle) {
game.reticle = game.addChild(new Reticle());
if (game.children.includes(game.reticle)) {
game.setChildIndex(game.reticle, 7); // Set reticle to be rendered after the tree
}
}
game.reticle.x = x;
game.reticle.y = y;
var laser = new Laser(cat.x - 140, cat.y - 440, x, y); // laser starting point
game.addChild(laser);
if (game.children.includes(laser) && game.children.includes(game.reticle)) {
game.setChildIndex(laser, game.getChildIndex(game.reticle) + 1); // Ensure laser is rendered after the reticle
}
};
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 = 680;
// Ensure sun is added to the game before setting its index
if (game.children.includes(sun)) {
game.setChildIndex(sun, 1); // Set sun to be rendered after the background
}
var light1 = game.addChild(new Light1());
light1.x = 530; // Move light1 right by 50px
light1.y = 1490; // Move light1 down by 210px
// Ensure light1 is added to the game before setting its index
if (game.children.includes(light1)) {
game.setChildIndex(light1, 2); // Set light1 to be rendered after the sun
}
// Function to add a UFO to the game
function addUFO() {
var ufo = new UFO();
game.addChild(ufo);
// Ensure UFO is added to the game before setting its index
if (game.children.includes(ufo) && game.children.includes(clouds[0])) {
game.setChildIndex(ufo, game.getChildIndex(clouds[0]) + 1); // Set UFO to be rendered after the first cloud
}
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 / 2 - ufo.height); // Random initial y position within the top half of the screen
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);
// Ensure cloud is added to the game before setting its index
if (game.children.includes(cloud)) {
game.setChildIndex(cloud, 2); // Set clouds to be rendered after the sun
}
}
var bird1; // Define bird1 variable in the global scope
// Initialize birds
spawnBird1();
spawnBird2();
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();
// Reset the timer for the UFO to reappear between 10-20 seconds
ufoTimer = LK.setTimeout(arguments.callee, Math.random() * 10000 + 10000);
}, Math.random() * 10000 + 10000); // Initial interval for UFO appearances between 10 to 20 seconds
game.update = function () {
// Update each bird
birds.forEach(function (bird, index) {
bird.update();
// Check if the bird has moved off-screen
if (bird.lastY <= 2732 && bird.y > 2732) {
bird.destroy();
birds.splice(index, 1);
spawnBird();
}
});
// Update clouds
clouds.forEach(function (cloud) {
cloud.update();
});
// Update UFO if present
if (ufo) {
ufo.customUpdate();
}
// Spawn UFO randomly
if (!ufo && Math.random() < 0.001) {
spawnUFO();
}
// Ensure there are always 3 birds
while (birds.length < 3) {
spawnBird();
}
};
// Helper function to spawn birds
function spawnBird() {
var birdType = Math.random();
var bird;
if (birdType < 0.6) {
bird = new Bird1();
} else if (birdType < 0.9) {
bird = new Bird2();
} else {
bird = new Bird3();
}
bird.x = Math.random() * 2048;
bird.y = -bird.height;
game.addChild(bird);
birds.push(bird);
}
// Helper function to spawn UFO
function spawnUFO() {
ufo = new UFO();
ufo.x = ufo.direction > 0 ? -ufo.width / 2 : 2048 + ufo.width / 2;
ufo.y = Math.random() * 1000 + 200;
game.addChild(ufo);
LK.getSound('ufo1').play();
}
// Function to spawn a third kind of bird
function spawnBird1() {
var bird1 = new Bird1();
bird1.x = Math.random() * 2048;
bird1.y = -bird1.height;
bird1.speed = 1 + Math.random() * 0.6;
bird1.lastIntersecting = false;
bird1.type = 'bird1'; // Specific property for Bird1
bird1.color = 0x746130; // Specific color for Bird1
LK.setTimeout(function () {
game.addChild(bird1);
// Ensure bird1 is added to the game before setting its index
if (game.children.includes(bird1)) {
if (game.children.includes(bird1) && game.children.includes(tree)) {
game.setChildIndex(bird1, game.getChildIndex(tree)); // Set Bird1 to be rendered before tree
}
}
birds.push(bird1);
}, 2000);
}
function spawnBird2() {
var bird = new Bird2();
bird.y = Math.random() * (2732 / 2); // Random initial y position in the top half
bird.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
bird.speed = 1 + Math.random() * 0.6;
bird.lastIntersecting = false;
bird.type = 'bird2'; // Specific property for Bird2
bird.color = 0xFFFFFF; // Specific color for Bird2
LK.setTimeout(function () {
game.addChild(bird);
// Ensure bird is added to the game before setting its index
if (game.children.includes(bird)) {
game.setChildIndex(bird, game.getChildIndex(stack1) + 1); // Set Bird2 to be rendered after stack1
}
birds.push(bird);
}, 2000);
}
// Ensure there are always 3 birds on screen
game.update = function () {
// Update each bird
birds.forEach(function (bird) {
bird.update();
// Check if the bird has moved off-screen
if (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
}
});
};
// Add a tree to the game
var tree = game.addChild(new Tree());
tree.x = 2048 / 2 + 600; // Move the tree 500px to the right
tree.y = 2500; // Position the tree on the grass
// Ensure tree is added to the game before setting its index
if (game.children.includes(tree) && game.children.includes(bird1)) {
game.setChildIndex(tree, game.getChildIndex(bird1) + 1); // Set tree to be rendered after bird1
}
var score = 0;
// Add stack1 image to the game
var stack1 = game.addChild(new Stack1());
stack1.x = 1650; // Move 500px to the right
stack1.y = 2300; // Move down by 800px
// Ensure stack1 is added to the game before setting its index
if (game.children.includes(stack1) && game.children.includes(tree)) {
game.setChildIndex(stack1, game.getChildIndex(tree) + 1); // Set stack1 to be rendered after tree
}
// 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);
// Ensure grassBack is added to the game before setting its index
if (game.children.includes(grassBack)) {
game.setChildIndex(grassBack, 5); // Set grassBack to be rendered after Bird3
}
var grassFront = new GrassFront();
grassFront.x = 1020;
grassFront.y = 2785; // Position grassFront at the bottom, moved down by 50px
game.addChild(grassFront);
// Ensure grassFront is added to the game before setting its index
if (game.children.includes(grassFront) && game.children.includes(bird2)) {
game.setChildIndex(grassFront, game.getChildIndex(bird2) + 1); // Set grassFront to be rendered after bird2
}
var mirror = new Mirror();
mirror.x = 2048 / 2 + 400; // Move the score display 400px to the right
mirror.y = 2732 - 185 - 80 - 390; // Move the score display up by an additional 80px
game.addChild(mirror);
// Ensure mirror is added to the game before setting its index
if (game.children.includes(mirror) && game.children.includes(stack1)) {
game.setChildIndex(mirror, game.getChildIndex(stack1) + 1); // Set mirror to be rendered after stack1
}
// Ensure laser is added to the game before setting mirror's index
if (game.children.includes(laser) && game.children.includes(mirror)) {
game.setChildIndex(mirror, game.getChildIndex(laser) + 1); // Set mirror to be rendered after the laser
}
// 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 = 230; // Move the cat 20px to the left
cat.y = 2732; // Position the cat at the bottom of the screen
// Ensure cat is added to the game before setting its index
if (game.children.includes(cat)) {
game.setChildIndex(cat, game.children.length - 1); // Bring the cat to the front by setting its index to the highest value
}
// 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);
}); ===================================================================
--- original.js
+++ change.js
@@ -19,9 +19,9 @@
size: 20,
fill: 0xFFFFFF
});
birdLabel.anchor.set(0.5, 0.5); // Center the label
- birdLabel.y = -30; // Position above the bird
+ birdLabel.y = -40; // Position above the bird (increased from -30)
self.addChild(birdLabel);
self.speed = 1 + Math.random() * 0.6;
self.lastY = self.y;
self.update = function () {
@@ -42,9 +42,9 @@
size: 20,
fill: 0xFFFFFF
});
birdLabel.anchor.set(0.5, 0.5); // Center the label
- birdLabel.y = -30; // Position above the bird
+ birdLabel.y = -40; // Position above the bird (increased from -30)
self.addChild(birdLabel);
self.speed = 0.8 + Math.random() * 0.5;
self.lastY = self.y;
self.update = function () {
@@ -65,9 +65,9 @@
size: 20,
fill: 0xFFFFFF
});
birdLabel.anchor.set(0.5, 0.5); // Center the label
- birdLabel.y = -30; // Position above the bird
+ birdLabel.y = -40; // Position above the bird (increased from -30)
self.addChild(birdLabel);
self.speed = 1.2 + Math.random() * 0.7;
self.lastY = self.y;
self.update = function () {
@@ -246,18 +246,10 @@
size: 50,
fill: 0xFFFFFF
});
jetLabel.anchor.set(0.5, 0.5); // Center the label on the jet
- jetLabel.y = -60; // Position the label above the jet
+ jetLabel.y = -70; // Position the label above the jet (increased from -60)
self.addChild(jetLabel);
- // Add a label to the jet
- var jetLabel = new Text2('Jet', {
- size: 50,
- fill: 0xFFFFFF
- });
- jetLabel.anchor.set(0.5, 0.5); // Center the label on the jet
- jetLabel.y = -60; // Position the label above the jet
- self.addChild(jetLabel);
self.speed = 10; // Set the speed of the jet
self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for right, -1 for left
self.lastX = self.x; // Track last X position for future checks
self.update = function () {
@@ -283,9 +275,9 @@
size: 20,
fill: 0xFFFFFF
});
kittenLabel.anchor.set(0.5, 0.5); // Center the label
- kittenLabel.y = -80; // Position above the kitten
+ kittenLabel.y = -90; // Position above the kitten (increased from -80)
self.addChild(kittenLabel);
self.level = 1;
self.collectRate = 1; // sparkles per second
self.lastCollectTime = 0;
@@ -354,9 +346,9 @@
size: 50,
fill: 0xFFFFFF
});
lightLabel.anchor.set(0.5, 0.5); // Center the label on the light
- lightLabel.y = -60; // Position the label above the light
+ lightLabel.y = -70; // Position the label above the light (increased from -60)
self.addChild(lightLabel);
self.update = function () {
// Add any specific update logic for the light here
};
@@ -404,9 +396,9 @@
size: 15,
fill: 0xFFFFFF
});
powerupLabel.anchor.set(0.5, 0.5); // Center the label
- powerupLabel.y = -25; // Position above the powerup
+ powerupLabel.y = -35; // Position above the powerup (increased from -25)
self.addChild(powerupLabel);
self.lifespan = 300; // 5 seconds at 60fps
self.update = function () {
self.lifespan--;
@@ -464,8 +456,9 @@
size: 30,
fill: 0x000000 // Black text for contrast
});
sunLabel.anchor.set(0.5, 0.5); // Center the label
+ sunLabel.y = -40; // Position above the sun
self.addChild(sunLabel);
startPulsating(sunGraphics); // Start the pulsating effect on the sun graphics
});
// Function to create a pulsating effect
@@ -486,9 +479,9 @@
size: 40,
fill: 0xFFFFFF
});
treeLabel.anchor.set(0.5, 0.5); // Center the label
- treeLabel.y = -treeGraphics.height / 2; // Position in the middle of the tree
+ treeLabel.y = -treeGraphics.height - 20; // Position above the tree
self.addChild(treeLabel);
self.update = function () {
// Add any specific update logic for the tree here
};
@@ -505,9 +498,9 @@
size: 25,
fill: 0xFFFFFF
});
ufoLabel.anchor.set(0.5, 0.5); // Center the label
- ufoLabel.y = -40; // Position above the UFO
+ ufoLabel.y = -50; // Position above the UFO (increased from -40)
self.addChild(ufoLabel);
self.speed = 2;
self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction
self.lastX = self.x;
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