User prompt
make the font size for score text 175
User prompt
use @upit/tween.v1 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
when cloud touches sun, make it 50% transparent ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make clouds 50% alpha when touching the sun ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
that's not it. please fix this ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
return the fading effects of the clouds, exactly like it was before.
User prompt
all birds react correctly when being shot by laser, except Bird3
Code edit (1 edits merged)
Please save this source code
User prompt
create a new class for the bird on childindex 5, bird4
User prompt
swap images for bird2
User prompt
Please fix the bug: 'Bird3 is not defined' in or related to this line: 'var bird3 = new Bird3();' Line Number: 577
User prompt
Please fix the bug: 'spawnBird3 is not defined' in or related to this line: 'spawnBird3();' Line Number: 401
User prompt
there are two bird3's on two different childindexes
User prompt
there are two bird3's on two different childindexes. make laser accommodate that.
User prompt
place a label above each bird, bird1, bird2, bird3
User prompt
reverse swapping for Bird1
User prompt
one bird is now doing it correctly, and all the others are backwards
User prompt
make sure all birds image swapping is correct. one seems to be beckwards
User prompt
refactor laser logic for all birds to be the same.
User prompt
Ensure the bird in front of the tree reacts to the laser by updating collision logic. this bird is on a different childindex
User prompt
all birds behind the tree are correctly reacting to the laser. the bird that is in front of the tree is not. please fix that.
User prompt
play teslacoil evey time laser hits a bird or ufo
User prompt
the bird in front of the tree is not reacting correctly
User prompt
it works for two birds, but not the third, please fix
User prompt
when laser hits bird2, bird3, or ufo, the object should disappear and add points
/**** * 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('bird1', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 1.6 + 1; self.lastY = self.y; // Initialize lastY for tracking changes on Y self.update = function () { self.y += self.speed; self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% // 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; } self.lastY = self.y; // Update lastY after movement }; }); // Bird2 class to represent the second kind of bird var Bird2 = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird2b', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 1.6 + 1; self.lastY = self.y; // Initialize lastY for tracking changes on Y self.update = function () { self.y += self.speed; self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% if (self.x > self.lastX) { birdGraphics.texture = LK.getAsset('bird2', {}).texture; } else if (self.x < self.lastX) { birdGraphics.texture = LK.getAsset('bird2b', {}).texture; } self.lastX = self.x; // Update lastX after movement // Check if the bird has moved off-screen if (self.lastY <= 2732 && self.y > 2732) { self.y = Math.random() * 2732; // Random initial y position within the screen height self.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side } self.lastY = self.y; // Update lastY after movement }; }); // Bird3 class to represent a third kind of bird var Bird3 = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 1.6 + 1; self.lastY = self.y; // Initialize lastY for tracking changes on Y self.update = function () { self.y += self.speed; self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30% // 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; } self.lastY = self.y; // Update lastY after movement }; }); // 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 clouds moving across the screen var Cloud = Container.expand(function () { var self = Container.call(this); var cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5 }); self.speed = (Math.random() * 0.3 + 0.7) * 0.4; // Adjust speed to vary slightly for each cloud 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 *= 1.5; // Increase speed by 50% tween(cloudGraphics, { alpha: 0.5 }, { duration: 3000, easing: tween.linear }); } else if (self.lastIntersecting && !self.intersects(sun)) { self.speed /= 1.5; // Reset speed to original tween(cloudGraphics, { alpha: 1.0 }, { duration: 3000, easing: tween.linear }); } self.lastIntersecting = self.intersects(sun); self.lastX = self.x; // Update lastX after movement }; }); // Grass class to represent the grass image var Grass = Container.expand(function () { var self = Container.call(this); var grassGraphics = self.attachAsset('grass', { 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) * 0.125; // Swaying effect, reduced by 50% }; }); // 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('laser1', { anchorX: 0.5, anchorY: 0.5, brightness: 2.0 // Increase brightness by 200% }); // 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; // 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) { self.destroy(); } }; }); // 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 }); var scoreText = new Text2('0', { size: 175, fill: 0x00FF00, font: "Digital-7 Mono", // Segmented clock style font stroke: 0x000000, strokeThickness: 5, dropShadow: true, dropShadowColor: 0x000000, dropShadowBlur: 5, dropShadowAngle: Math.PI / 6, dropShadowDistance: 6 }); scoreText.y = -128; // Move score text up by 3px scoreText.x = -45; // Move score text left by 20px self.addChild(scoreText); self.updateScore = function (newScore) { scoreText.setText(newScore); }; }); // ScoreManager class to manage score logic // ScoreManager class to manage score logic // Sun class to represent a pulsating 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 }); self.x = sunGraphics.width / 2; self.y = sunGraphics.height / 2; // Function to create a pulsating effect function pulsate() { tween(self, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { scaleX: 1.0, scaleY: 1.0 }, { duration: 1000, easing: tween.easeInOut, onFinish: pulsate }); } }); } pulsate(); // Start the 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 }); self.update = function () { // Add any specific update logic for the tree here }; }); // UFO class to represent a UFO flying across the screen var UFO = Container.expand(function () { var self = Container.call(this); var ufoGraphics = self.attachAsset('ufo', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3.2; // Decrease speed by 20% 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; self.y = 100 + Math.sin(self.x / 70) * 165; // Increase the wave pattern depth by 10% // If the UFO moves off-screen, destroy it and set to null 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; } self.lastX = self.x; // Update lastX after movement }; }); /**** * Initialize Game ****/ /**** * Assets LK.init.shape('branch', {width:50, height:10, color:0x8b4513, shape:'box'}) ****/ // Initialize clouds array var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background to simulate the sky }); /**** * Game Code ****/ // Create an array to hold bird objects // ScoreManager class to manage score logic // 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 = []; // bird1 // Initialize with 3 birds spawnBird1(); // Add the cat to the game var cat = game.addChild(new Cat()); cat.x = 2048 - 200; // Position the cat to the far right cat.y = 2732; // Position the cat at the bottom of the screen game.down = function (x, y, obj) { if (!game.reticle) { game.reticle = game.addChild(new Reticle()); game.setChildIndex(game.reticle, 1); // Set reticle to be rendered after the background } game.reticle.x = x; game.reticle.y = y; var laser = new Laser(cat.x, cat.y, x, y); game.addChild(laser); game.setChildIndex(laser, game.getChildIndex(game.reticle) + 1); // Ensure laser is rendered after the reticle // Create a list in the bottom left of the screen that lists current ChildIndex objects in index order var childIndexList = new Text2('', { size: 50, fill: 0xFFFFFF, anchorX: 0, anchorY: 1 }); childIndexList.x = 0; childIndexList.y = 2732; LK.gui.bottomLeft.addChild(childIndexList); function updateChildIndexList() { var listText = ''; game.children.forEach(function (child, index) { listText += 'Index ' + index + ': ' + child.constructor.name + '\n'; }); childIndexList.setText(listText); } game.update = function () { updateChildIndexList(); // Existing update logic... }; }; 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 = 1750; sun.y = 280; game.setChildIndex(sun, 1); // 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() * 500; // Random initial y position in the upper part 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() * 500; // Position clouds in the upper part of the screen clouds.push(cloud); game.addChild(cloud); game.setChildIndex(cloud, 2); // Set clouds to be rendered after the sun } // Initialize a timer to add a UFO at a random time between 30 and 50 seconds var ufo; // Define the ufo variable in the global scope var ufoTimer = LK.setTimeout(function () { addUFO(); }, Math.random() * 20000 + 30000); 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)) { if (bird instanceof Bird1) { score += 5; } else if (bird instanceof Bird2 || bird instanceof Bird3) { score += 1; } score.updateScore(score); child.destroy(); } }); 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() { var bird = new Bird1(); bird.x = Math.random() * 2048; bird.y = -bird.height; bird.speed = 1 + Math.random() * 0.6; bird.lastIntersecting = false; bird.type = 'Bird1'; // Specific property for Bird1 bird.color = 0x746130; // Specific color for Bird1 LK.setTimeout(function () { game.addChild(bird); game.setChildIndex(bird, 5); // Set Bird1 to be rendered after the laser birds.push(bird); }, 2000); } function spawnBird2() { var bird = new Bird2(); 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 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); game.setChildIndex(bird, 7); // Set Bird2 to be rendered after the tree birds.push(bird); }, 2000); } function spawnBird3() { var bird = new Bird3(); 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 bird.speed = 1 + Math.random() * 0.6; bird.lastIntersecting = false; bird.type = 'Bird3'; // Specific property for Bird3 bird.color = 0xFF0000; // Specific color for Bird3 LK.setTimeout(function () { game.addChild(bird); game.setChildIndex(bird, 7); // Set Bird3 to be rendered after Bird2 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; // Center the tree to prevent it from being cut off on the right side tree.y = 2732 - 50; // Position the tree on the grass game.setChildIndex(tree, 6); // Set tree to be rendered after Bird1 var score = 0; // Add the grass floor to the game spawnBird2(); spawnBird3(); var grass = new Grass(); grass.x = 1020; grass.y = 2735; // Position grass at the bottom game.addChild(grass); game.setChildIndex(grass, Math.min(9, game.children.length - 1)); // Set grass to be rendered after Bird3 var scoreDisplay = new ScoreDisplay(); scoreDisplay.x = 2048 / 2; // Center the score display horizontally scoreDisplay.y = 2732 - 185; // Adjust the y-coordinate of the score display game.addChild(scoreDisplay); game.setChildIndex(scoreDisplay, game.getChildIndex(grass) + 1); // Set score image to be rendered after the grass // Add the cat to the game // 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); } ; var cat = game.addChild(new Cat()); cat.x = 2048 - 200; // Position the cat to the far right cat.y = 2732; // Position the cat at the bottom of the screen game.setChildIndex(cat, Math.min(10, game.children.length - 1)); // 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.02, // 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']; // 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 () { sound.play(); // Reset the timer to play the sound again between 30-50 seconds ambientSoundTimer = LK.setTimeout(arguments.callee, Math.random() * 20000 + 30000); }, Math.random() * 20000 + 30000); });
===================================================================
--- original.js
+++ change.js
@@ -9,20 +9,13 @@
// 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('bird1b', {
+ var birdGraphics = self.attachAsset('bird1', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 1.6 + 1;
- var label = new Text2('bird1', {
- size: 50,
- fill: 0xFFFFFF
- });
- label.anchor.set(0.5, 1);
- label.y = -birdGraphics.height / 2 - 10;
- self.addChild(label);
self.lastY = self.y; // Initialize lastY for tracking changes on Y
self.update = function () {
self.y += self.speed;
self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
@@ -30,14 +23,8 @@
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;
}
- if (self.lastX < self.x) {
- birdGraphics.scale.x = -1; // Flip horizontally
- } else if (self.lastX > self.x) {
- birdGraphics.scale.x = 1; // Normal orientation
- }
- self.lastX = self.x; // Update lastX after movement
self.lastY = self.y; // Update lastY after movement
};
});
// Bird2 class to represent the second kind of bird
@@ -47,23 +34,16 @@
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 1.6 + 1;
- var label = new Text2('bird2', {
- size: 50,
- fill: 0xFFFFFF
- });
- label.anchor.set(0.5, 1);
- label.y = -birdGraphics.height / 2 - 10;
- self.addChild(label);
self.lastY = self.y; // Initialize lastY for tracking changes on Y
self.update = function () {
self.y += self.speed;
self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- if (self.lastX < self.x) {
- birdGraphics.scale.x = -1; // Flip horizontally
- } else if (self.lastX > self.x) {
- birdGraphics.scale.x = 1; // Normal orientation
+ if (self.x > self.lastX) {
+ birdGraphics.texture = LK.getAsset('bird2', {}).texture;
+ } else if (self.x < self.lastX) {
+ birdGraphics.texture = LK.getAsset('bird2b', {}).texture;
}
self.lastX = self.x; // Update lastX after movement
// Check if the bird has moved off-screen
if (self.lastY <= 2732 && self.y > 2732) {
@@ -72,23 +52,16 @@
}
self.lastY = self.y; // Update lastY after movement
};
});
-// Bird3 class to represent the third kind of bird
+// Bird3 class to represent a third kind of bird
var Bird3 = Container.expand(function () {
var self = Container.call(this);
- var birdGraphics = self.attachAsset('bird2b', {
+ var birdGraphics = self.attachAsset('bird2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 1.6 + 1;
- var label = new Text2('bird3', {
- size: 50,
- fill: 0xFFFFFF
- });
- label.anchor.set(0.5, 1);
- label.y = -birdGraphics.height / 2 - 10;
- self.addChild(label);
self.lastY = self.y; // Initialize lastY for tracking changes on Y
self.update = function () {
self.y += self.speed;
self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
@@ -96,50 +69,11 @@
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;
}
- if (self.lastX < self.x) {
- birdGraphics.scale.x = -1; // Flip horizontally
- } else if (self.lastX > self.x) {
- birdGraphics.scale.x = 1; // Normal orientation
- }
- self.lastX = self.x; // Update lastX after movement
self.lastY = self.y; // Update lastY after movement
};
});
-// Bird4 class to represent the fourth kind of bird
-var Bird4 = Container.expand(function () {
- var self = Container.call(this);
- var birdGraphics = self.attachAsset('bird2b', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = Math.random() * 1.6 + 1;
- var label = new Text2('bird4', {
- size: 50,
- fill: 0xFFFFFF
- });
- label.anchor.set(0.5, 1);
- label.y = -birdGraphics.height / 2 - 10;
- self.addChild(label);
- self.lastY = self.y; // Initialize lastY for tracking changes on Y
- self.update = function () {
- self.y += self.speed;
- self.x += Math.sin(self.y / 100) * 6.5; // Increase the swooping motion of the bird's movement by 30%
- // 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;
- }
- if (self.lastX < self.x) {
- birdGraphics.scale.x = -1; // Flip horizontally
- } else if (self.lastX > self.x) {
- birdGraphics.scale.x = 1; // Normal orientation
- }
- self.lastX = self.x; // Update lastX after movement
- self.lastY = self.y; // Update lastY after movement
- };
-});
// Cat class to manage cat behavior
var Cat = Container.expand(function () {
var self = Container.call(this);
var catGraphics = self.attachAsset('cat', {
@@ -169,46 +103,41 @@
self.x = -self.width / 2;
} else if (self.lastX >= -self.width / 2 && self.x < -self.width / 2) {
self.x = 2048 + self.width / 2;
}
- // Removed intersection logic
- self.lastX = self.x; // Update lastX after movement
- // Check for intersection with the sun
- var currentIntersecting = self.intersects(sun);
- if (!self.lastIntersecting && currentIntersecting) {
- // Intersection just started
+ // 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 *= 1.5; // Increase speed by 50%
tween(cloudGraphics, {
alpha: 0.5
}, {
- duration: 500
+ duration: 3000,
+ easing: tween.linear
});
- } else if (self.lastIntersecting && !currentIntersecting) {
- // Intersection just ended
+ } else if (self.lastIntersecting && !self.intersects(sun)) {
+ self.speed /= 1.5; // Reset speed to original
tween(cloudGraphics, {
alpha: 1.0
}, {
- duration: 500
+ duration: 3000,
+ easing: tween.linear
});
}
- self.lastIntersecting = currentIntersecting; // Update lastIntersecting state
- // Apply fading effect using tween plugin
- tween(cloudGraphics, {
- alpha: 0.5
- }, {
- duration: 2000,
- easing: tween.easeInOut,
- onFinish: function onFinish() {
- tween(cloudGraphics, {
- alpha: 1.0
- }, {
- duration: 2000,
- easing: tween.easeInOut,
- onFinish: function onFinish() {
- self.update(); // Restart the update to loop the fading effect
- }
- });
- }
- });
+ self.lastIntersecting = self.intersects(sun);
+ self.lastX = self.x; // Update lastX after movement
};
});
// Grass class to represent the grass image
var Grass = Container.expand(function () {
@@ -228,9 +157,9 @@
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser1', {
anchorX: 0.5,
anchorY: 0.5,
- brightness: 5.0 // Increase brightness by 200%
+ brightness: 2.0 // Increase brightness by 200%
});
// Play the laser1 sound when the laser is created
LK.getSound('laser1').play();
// Calculate direction and speed
@@ -239,55 +168,15 @@
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;
- self.lastIntersecting = false; // Initialize lastIntersecting for tracking changes on intersections
- // Set initial position to fire from the cat's head
+ // Set initial position
self.x = startX;
- var catGraphics = LK.getAsset('cat', {
- anchorX: 1
- });
- self.y = startY - catGraphics.height / 2;
+ self.y = startY;
// Update function to move the laser
self.update = function () {
self.x += self.vx;
self.y += self.vy;
- // Check for collision with any bird
- birds.forEach(function (bird) {
- if (!self.lastIntersecting && self.intersects(bird)) {
- bird.destroy(); // Destroy the bird
- birds.splice(birds.indexOf(bird), 1); // Remove bird from array
- var scoreToAdd = bird instanceof Bird1 ? 5 : 1; // Add 5 points for Bird1, 1 point for others
- scoreManager.addScore(scoreToAdd); // Add points to score
- scoreDisplay.updateScore(scoreManager.getScore()); // Update score display
- var spawnFunction;
- if (bird instanceof Bird1) {
- spawnFunction = spawnBird1;
- } else if (bird instanceof Bird2) {
- spawnFunction = spawnBird2;
- } else if (bird instanceof Bird3) {
- spawnFunction = spawnBird3;
- } else {
- spawnFunction = spawnBird4;
- }
- LK.setTimeout(spawnFunction, 10000); // Respawn bird after 10 seconds
- LK.getSound('teslacoil').play(); // Play teslacoil sound
- self.destroy(); // Destroy the laser
- self.lastIntersecting = true; // Update lastIntersecting to true after collision
- } else {
- self.lastIntersecting = false; // Reset lastIntersecting if no collision
- }
- // Check for collision with UFO
- if (ufo && !self.lastIntersecting && self.intersects(ufo)) {
- ufo.destroy(); // Destroy the UFO
- ufo = null; // Set UFO to null
- scoreManager.addScore(10); // Add 10 points to score
- scoreDisplay.updateScore(scoreManager.getScore()); // Update score display
- ufoTimer = LK.setTimeout(addUFO, Math.random() * 20000 + 30000); // Respawn UFO after 30-50 seconds
- LK.getSound('teslacoil').play(); // Play teslacoil sound
- self.destroy(); // Destroy the laser
- }
- });
// Remove laser if it goes off-screen
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.destroy();
}
@@ -311,9 +200,9 @@
anchorX: 0.5,
anchorY: 0.5
});
var scoreText = new Text2('0', {
- size: 190,
+ size: 175,
fill: 0x00FF00,
font: "Digital-7 Mono",
// Segmented clock style font
stroke: 0x000000,
@@ -324,9 +213,9 @@
dropShadowAngle: Math.PI / 6,
dropShadowDistance: 6
});
scoreText.y = -128; // Move score text up by 3px
- scoreText.x = -125; // Move score text left by 80px
+ scoreText.x = -45; // Move score text left by 20px
self.addChild(scoreText);
self.updateScore = function (newScore) {
scoreText.setText(newScore);
};
@@ -411,22 +300,8 @@
/****
* Game Code
****/
-function spawnBird3() {
- var bird3 = new Bird4();
- bird3.y = Math.random() * 2732; // Random initial y position within the screen height
- bird3.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
- bird3.speed = 1 + Math.random() * 0.6;
- bird3.lastIntersecting = false;
- bird3.type = 'Bird3'; // Specific property for Bird3
- bird3.color = 0xFF0000; // Specific color for Bird3
- LK.setTimeout(function () {
- game.addChild(bird3);
- game.setChildIndex(bird3, 7); // Set Bird3 to be rendered after Bird2
- birds.push(bird3);
- }, 2000);
-}
// Create an array to hold bird objects
// ScoreManager class to manage score logic
// ScoreManager class to manage score logic
var ScoreManager = function ScoreManager() {
@@ -460,26 +335,43 @@
var birds = [];
// bird1
// Initialize with 3 birds
spawnBird1();
-spawnBird2();
-spawnBird3();
// Add the cat to the game
var cat = game.addChild(new Cat());
cat.x = 2048 - 200; // Position the cat to the far right
cat.y = 2732; // Position the cat at the bottom of the screen
game.down = function (x, y, obj) {
if (!game.reticle) {
game.reticle = game.addChild(new Reticle());
- game.setChildIndex(game.reticle, game.children.length - 1); // Ensure reticle renders after the laser
+ game.setChildIndex(game.reticle, 1); // Set reticle to be rendered after the background
}
game.reticle.x = x;
game.reticle.y = y;
var laser = new Laser(cat.x, cat.y, x, y);
game.addChild(laser);
- if (game.children.includes(laser)) {
- game.setChildIndex(laser, game.children.length - 2); // Ensure laser renders before the reticle
+ game.setChildIndex(laser, game.getChildIndex(game.reticle) + 1); // Ensure laser is rendered after the reticle
+ // Create a list in the bottom left of the screen that lists current ChildIndex objects in index order
+ var childIndexList = new Text2('', {
+ size: 50,
+ fill: 0xFFFFFF,
+ anchorX: 0,
+ anchorY: 1
+ });
+ childIndexList.x = 0;
+ childIndexList.y = 2732;
+ LK.gui.bottomLeft.addChild(childIndexList);
+ function updateChildIndexList() {
+ var listText = '';
+ game.children.forEach(function (child, index) {
+ listText += 'Index ' + index + ': ' + child.constructor.name + '\n';
+ });
+ childIndexList.setText(listText);
}
+ game.update = function () {
+ updateChildIndexList();
+ // Existing update logic...
+ };
};
var VOLUME_BGM1 = 0.02;
var VOLUME_BREEZE1 = 0.02;
var VOLUME_CRICKET1 = 0.02;
@@ -539,10 +431,28 @@
// Update each laser
game.children.forEach(function (child) {
if (child instanceof Laser) {
child.update();
- // Removed collision and intersection logic
- game.setChildIndex(child, game.children.indexOf(child)); // Ensure child index is updated
+ // Check for intersections with birds and UFO
+ birds.forEach(function (bird) {
+ if (!child.lastIntersecting && child.intersects(bird)) {
+ if (bird instanceof Bird1) {
+ score += 5;
+ } else if (bird instanceof Bird2 || bird instanceof Bird3) {
+ score += 1;
+ }
+ score.updateScore(score);
+ child.destroy();
+ }
+ });
+ 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
@@ -558,47 +468,47 @@
// Removed auto-targeting update function
};
// 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
+ var bird = new Bird1();
+ bird.x = Math.random() * 2048;
+ bird.y = -bird.height;
+ bird.speed = 1 + Math.random() * 0.6;
+ bird.lastIntersecting = false;
+ bird.type = 'Bird1'; // Specific property for Bird1
+ bird.color = 0x746130; // Specific color for Bird1
LK.setTimeout(function () {
- game.addChild(bird1);
- game.setChildIndex(bird1, 5); // Set Bird1 to be rendered after the laser
- birds.push(bird1);
+ game.addChild(bird);
+ game.setChildIndex(bird, 5); // Set Bird1 to be rendered after the laser
+ birds.push(bird);
}, 2000);
}
function spawnBird2() {
- var bird2 = new Bird2();
- bird2.y = Math.random() * 2732; // Random initial y position within the screen height
- bird2.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
- bird2.speed = 1 + Math.random() * 0.6;
- bird2.lastIntersecting = false;
- bird2.type = 'Bird2'; // Specific property for Bird2
- bird2.color = 0xFFFFFF; // Specific color for Bird2
+ var bird = new Bird2();
+ 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
+ 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(bird2);
- game.setChildIndex(bird2, 7); // Set Bird2 to be rendered after the tree
- birds.push(bird2);
+ game.addChild(bird);
+ game.setChildIndex(bird, 7); // Set Bird2 to be rendered after the tree
+ birds.push(bird);
}, 2000);
}
-function spawnBird4() {
- var bird4 = new Bird4();
- bird4.y = Math.random() * 2732; // Random initial y position within the screen height
- bird4.x = Math.random() < 0.5 ? 0 : 2048; // Start from either the left or right side
- bird4.speed = 1 + Math.random() * 0.6;
- bird4.lastIntersecting = false;
- bird4.type = 'Bird4'; // Specific property for Bird4
- bird4.color = 0xFF0000; // Specific color for Bird4
+function spawnBird3() {
+ var bird = new Bird3();
+ 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
+ bird.speed = 1 + Math.random() * 0.6;
+ bird.lastIntersecting = false;
+ bird.type = 'Bird3'; // Specific property for Bird3
+ bird.color = 0xFF0000; // Specific color for Bird3
LK.setTimeout(function () {
- game.addChild(bird4);
- game.setChildIndex(bird4, 5); // Set Bird4 to be rendered after Bird2
- birds.push(bird4);
+ game.addChild(bird);
+ game.setChildIndex(bird, 7); // Set Bird3 to be rendered after Bird2
+ birds.push(bird);
}, 2000);
}
// Ensure there are always 3 birds on screen
game.update = function () {
@@ -617,22 +527,22 @@
var tree = game.addChild(new Tree());
tree.x = 2048 / 2; // Center the tree to prevent it from being cut off on the right side
tree.y = 2732 - 50; // Position the tree on the grass
game.setChildIndex(tree, 6); // Set tree to be rendered after Bird1
-var scoreManager = new ScoreManager();
+var score = 0;
// Add the grass floor to the game
+spawnBird2();
+spawnBird3();
var grass = new Grass();
grass.x = 1020;
grass.y = 2735; // Position grass at the bottom
game.addChild(grass);
-var bird3 = new Bird3();
-game.addChild(bird3); // Ensure bird3 is added to the game
-game.setChildIndex(grass, 8); // Set grass to be rendered after Bird3
+game.setChildIndex(grass, Math.min(9, game.children.length - 1)); // Set grass to be rendered after Bird3
var scoreDisplay = new ScoreDisplay();
scoreDisplay.x = 2048 / 2; // Center the score display horizontally
scoreDisplay.y = 2732 - 185; // Adjust the y-coordinate of the score display
game.addChild(scoreDisplay);
-game.setChildIndex(scoreDisplay, 9); // Set score image to be rendered after the grass
+game.setChildIndex(scoreDisplay, game.getChildIndex(grass) + 1); // Set score image to be rendered after the grass
// Add the cat to the game
// Function to handle bgm1 end event
function onBgm1End() {
// Set a timer to replay bgm1 after 50-80 seconds
@@ -651,9 +561,9 @@
;
var cat = game.addChild(new Cat());
cat.x = 2048 - 200; // Position the cat to the far right
cat.y = 2732; // Position the cat at the bottom of the screen
-game.setChildIndex(cat, 9); // Set cat to be rendered after the grass
+game.setChildIndex(cat, Math.min(10, game.children.length - 1)); // 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
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