Code edit (4 edits merged)
Please save this source code
User prompt
Add an y distance <= 512 condition for fishes flee
Code edit (5 edits merged)
Please save this source code
User prompt
Set currentTarget to be invisible until isPlaying goes true
User prompt
Set currentprogressTxt to be invisible until isPlaying goes true
User prompt
Set score to be invisible until isPlaying goes true
User prompt
When fleeing, fishes should take the opposite y direction to the shark
Code edit (1 edits merged)
Please save this source code
User prompt
Add some difficulty by making prey (fishType
User prompt
Reduce amplitude of Fish animation
User prompt
Reduce amplitude of Fish animation
Code edit (1 edits merged)
Please save this source code
User prompt
You placed self.animate(); at the wrong place
User prompt
Create an equivalent animation for Fish class
User prompt
Shark animation should simulate swimming also by a slight width and/or height change
User prompt
Shark animation should not be a rotation it should simulate swimming
User prompt
In shark update call animate()
User prompt
In shark class, add a new method animate
User prompt
Reduce spawn frequency of all fishes
User prompt
Set babyShark invisible initially, set it visible when isPlaying is set to true in down event
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'game.removeChild(startButton);' Line Number: 388
User prompt
On down, if !isPlaying, remove start button and set isPlaying = true;
Code edit (2 edits merged)
Please save this source code
User prompt
Add startButton in game initialize
/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Baby Shark class var BabyShark = Container.expand(function () { var self = Container.call(this); self.currentWidth = 242; // Initialize currentSize property self.currentHeight = 150; self.widthRatio = 242 / 150; self.heightRatio = 124.0 / 200; // Define height ratio property self.speed = 10; self.velocityY = 0; self.shark = self.attachAsset('babyShark', { anchorX: 0.5, anchorY: 0.5, width: self.currentHeight * self.widthRatio, height: self.currentHeight }); self.collisionBody = self.attachAsset('collisionBody', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7, x: self.currentWidth * 0.25, y: 10, width: self.shark.width * 0.5, height: self.shark.width * 0.5 }); self.update = function () { if (!isPlaying) { return; } ; self.velocityY += 0.4; // Further reduced gravity effect self.y += self.velocityY; if (self.y >= 2732 - self.shark.height * 0.5) { self.y = 2732 - self.shark.height * 0.5; self.velocityY = 0; } if (self.y <= topBorderY + self.shark.height * 0.5) { self.y = topBorderY + self.shark.height * 0.5; self.velocityY = 0; } // Update logic for Baby Shark if (isDebug) { debugTxt.setText("Level: ".concat(sharkLevel) + " / h:" + self.currentHeight.toFixed(0) + " / Progress: " + progressBar.x); } self.animate(); }; self.grow = function () { self.currentHeight += 50; self.currentWidth = self.currentHeight * self.widthRatio; self.shark.width = self.currentHeight * self.widthRatio; self.shark.height = self.currentHeight; //self.collisionBody.width = self.height / 2; //self.collisionBody.height = self.height / 2; self.collisionBody.width = self.currentWidth * 0.45; self.collisionBody.height = self.currentWidth * 0.45; self.collisionBody.x = self.shark.width * 0.25; self.collisionBody.y = self.height * 0.05; }; self.animate = function () { // Simulate swimming by moving the shark up and down var swimAmplitude = 10; // Amplitude of the swimming motion var swimFrequency = 0.1; // Frequency of the swimming motion self.shark.y = Math.sin(LK.ticks * swimFrequency) * swimAmplitude; // Simulate swimming by changing the width and height slightly var sizeAmplitude = 0.05; // Amplitude of the size change self.shark.width = self.currentWidth * (1 + sizeAmplitude * Math.sin(LK.ticks * swimFrequency)); self.shark.height = self.currentHeight * (1 + sizeAmplitude * Math.cos(LK.ticks * swimFrequency)); }; }); var CurrentTarget = Container.expand(function () { var self = Container.call(this); self.target = null; self.updateTarget = function (fishType) { if (self.target) { self.target.destroy(); } self.target = self.attachAsset('fish' + fishType, { anchorX: 0.5, anchorY: 0.5 }); // Calculate aspect ratio var aspectRatio = self.target.width / self.target.height; // Limit size within 200x100 while keeping aspect ratio if (self.target.width > 200 || self.target.height > 100) { if (aspectRatio > 2) { self.target.width = 200; self.target.height = 200 / aspectRatio; } else { self.target.height = 100; self.target.width = 100 * aspectRatio; } } self.target.x = 2048 - 100; self.target.y = 50; }; }); // Fish class var Fish = Container.expand(function (fishType) { var self = Container.call(this); self.fishType = fishType; self.fish = self.attachAsset('fish' + fishType, { anchorX: 0.5, anchorY: 0.5 }); self.collisionBody = self.attachAsset('collisionBody', { anchorX: 0.5, anchorY: 0.5, alpha: isDebug ? 0.7 : 0, x: -self.fish.width * 0.25, width: self.fish.width * 0.5, height: self.fish.width * 0.5 }); self.speed = 5 + sharkLevel * 1.5; self.update = function () { if (!isPlaying) { return; } self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } self.animate = function () { // Simulate swimming by moving the fish up and down var swimAmplitude = 5; // Amplitude of the swimming motion var swimFrequency = 0.2; // Frequency of the swimming motion self.fish.y = Math.sin(LK.ticks * swimFrequency) * swimAmplitude; // Simulate swimming by changing the width and height slightly var sizeAmplitude = 0.03; // Amplitude of the size change self.fish.width = self.fish.width * (1 + sizeAmplitude * Math.sin(LK.ticks * swimFrequency)); self.fish.height = self.fish.height * (1 + sizeAmplitude * Math.cos(LK.ticks * swimFrequency)); }; }; }); var ProgressBar = Container.expand(function () { var self = Container.call(this); // Create the frame of the progress bar self.frame = self.attachAsset('progressFrame', { anchorX: 0, anchorY: 0.5, alpha: 0.8 }); // Create the bar itself self.bar = self.attachAsset('progressBar', { anchorX: 0, anchorY: 0.5, alpha: 0.8, width: 0 // Initial width is 0 //height: self.frame.height }); // Method to update the progress bar self.updateProgress = function (progress, maxProgress) { var newWidth = progress % maxProgress / maxProgress * self.frame.width; self.bar.width = newWidth; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0000ff // Init game with blue background }); /**** * Game Code ****/ function loopBgMusic() { // This function will handle looping background music var currentTime = Date.now(); if (currentTime - lastBgMusicPlayTime >= 10000) { // 10 seconds interval LK.getSound('bgMusic').play(); lastBgMusicPlayTime = currentTime; } } // Global variable declarations var crunchSound = LK.getSound('crunch'); var topBorderY = 250; var babyShark; var nbFishTypes = 10; var fishes = []; var score; var scoreTxt; var currentProgressTxt; var debugTxt; var isDebug = false; // Global variable for debugging mode var isPlaying = false; // Global variable to track if the game is currently playing var sharkLevel = 1; var currentProgress = 0; var progressBar; var lastCollisionCheckTimeFish1 = 0; // Global variable to track the last collision check time for Fish1 var collisionCheckDelay = 128; // Global variable for collision check delay in milliseconds var background1; var lastCollisionCheckTime = 0; // Global variable to track the last collision check time for fishes; var nbFishPerLevel = 10; // Global variable for the number of fish per level var lastBgMusicPlayTime = 0; // Global variable to track the last background music play time var startButton; // Declare startButton as a global variable function spawnFish(fishType) { if (fishType > nbFishTypes) { fishType = nbFishTypes; } var fish = new Fish(fishType); fish.x = 2048 + 50; fish.y = Math.random() * (2732 - topBorderY - fish.height) + topBorderY + fish.height / 2; fishes.push(fish); game.addChild(fish); } function checkCollision(obj1, obj2) { // Calculate the center positions of the collision bodies var obj1CenterX = obj1.x + obj1.collisionBody.x; var obj1CenterY = obj1.y + obj1.collisionBody.y; var obj2CenterX = obj2.x + obj2.collisionBody.x; var obj2CenterY = obj2.y + obj2.collisionBody.y; // Calculate the distance between the centers var dx = obj1CenterX - obj2CenterX; var dy = obj1CenterY - obj2CenterY; var distance = Math.sqrt(dx * dx + dy * dy); // Calculate the sum of the radii var obj1Radius = obj1.collisionBody.width / 2; var obj2Radius = obj2.collisionBody.width / 2; var sumRadii = obj1Radius + obj2Radius; // Return true if the distance is less than the sum of the radii return distance < sumRadii; } function spawnFishes() { if (LK.ticks % 120 == 0) { spawnFish(sharkLevel); } if (LK.ticks % 360 == 0) { spawnFish(sharkLevel + 1); } if (LK.ticks % 1200 == 0) { spawnFish(sharkLevel + 2); } } function updateFishCollisions() { var currentTime = Date.now(); if (currentTime - lastCollisionCheckTime < collisionCheckDelay) { return; } lastCollisionCheckTime = currentTime; var offset = babyShark.shark.width * 1.5; // Define the x offset range based on baby shark's width for (var i = fishes.length - 1; i >= 0; i--) { if (Math.abs(babyShark.x - fishes[i].x) > offset) { continue; // Skip fishes outside the x offset range } if (checkCollision(babyShark, fishes[i])) { // Play crunch sound crunchSound.play(); if (fishes[i].fishType <= sharkLevel) { // Baby shark eats the fish score += fishes[i].fishType * 10; scoreTxt.setText(score); currentProgress += 1; currentProgressTxt.setText(currentProgress + "/" + nbFishPerLevel); progressBar.updateProgress(currentProgress, nbFishPerLevel); if (currentProgress >= nbFishPerLevel) { sharkLevel += 1; currentProgress = 0; babyShark.grow(); currentTarget.updateTarget(sharkLevel); LK.getSound('levelUp').play(); // Play level up sound if (sharkLevel > nbFishTypes) { LK.setScore(score); LK.getSound('lose').play(); LK.setTimeout(function () { LK.showGameOver(); }, 1500); } LK.setTimeout(function () { currentProgressTxt.setText(currentProgress + "/" + nbFishPerLevel); }, 1000); } fishes[i].destroy(); fishes.splice(i, 1); } else { // Baby shark gets eaten crunchSound.stop(); // Stop crunch sound LK.effects.flashScreen(0xff0000, 1000); LK.setScore(score); isPlaying = false; LK.getSound('lose').play(); LK.setTimeout(function () { LK.showGameOver(); }, 1500); } return; } } } function updateBackgrounds() { background1.x -= 2; background2.x -= 2; if (background1.x <= -2732 / 2) { background1.x = 2732 + 2732 / 2; } if (background2.x <= -2732 / 2) { background2.x = 2732 + 2732 / 2; } } function gameInitialize() { background1 = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2732 / 2, y: 2732 / 2 }); background2 = LK.getAsset('background2', { anchorX: 0.5, anchorY: 0.5, x: 2732 + 2732 / 2, y: 2732 / 2 }); game.addChild(background1); game.addChild(background2); // Add banner asset after the backgrounds var banner = LK.getAsset('banner', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 125 // Position the banner at the top of the screen }); game.addChild(banner); // Add start button asset startButton = LK.getAsset('startButton', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 // Position the start button at the center of the screen }); game.addChild(startButton); babyShark = game.addChild(new BabyShark()); babyShark.visible = false; currentTarget = game.addChild(new CurrentTarget()); currentTarget.updateTarget(1); // Initialize with the first fish type progressBar = new ProgressBar(); progressBar.x = 0; progressBar.y = 250; game.addChild(progressBar); babyShark.x = 150; babyShark.y = 2732 / 2; babyShark.velocityY = 0; babyShark.collisionBody.visible = isDebug; // Show collision body if debugging fish1s = []; fish2s = []; score = 0; scoreTxt = new Text2('0', { size: 130, fill: "#ffffff", dropShadow: true, dropShadowColor: "#000000", dropShadowBlur: 4, dropShadowDistance: 6 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); currentProgress = 0; currentProgressTxt = new Text2('0/10', { size: 80, fill: "#ffffff", dropShadow: true, dropShadowColor: "#000000", dropShadowBlur: 4, dropShadowDistance: 6 }); currentProgressTxt.anchor.set(1, -0.7); LK.gui.topRight.addChild(currentProgressTxt); debugTxt = new Text2(isDebug ? 'Debug Mode' : '', { size: 50, fill: "#ff0000", dropShadow: true, dropShadowColor: "#000000", dropShadowBlur: 4, dropShadowDistance: 6 }); debugTxt.anchor.set(0.5, 1); LK.gui.bottom.addChild(debugTxt); } game.down = function (x, y, obj) { if (!isPlaying) { game.removeChild(startButton); isPlaying = true; babyShark.visible = true; } babyShark.velocityY = -20; LK.getSound('jump').play(); }; game.update = function () { if (!isPlaying) { return; } updateBackgrounds(); spawnFishes(); updateFishCollisions(); loopBgMusic(); }; gameInitialize();
===================================================================
--- original.js
+++ change.js
@@ -28,9 +28,8 @@
});
self.update = function () {
if (!isPlaying) {
return;
- self.animate();
}
;
self.velocityY += 0.4; // Further reduced gravity effect
self.y += self.velocityY;
Orange Baby fish lateral view. 2024 game style
Pink Baby fish lateral view. 2024 game style
Empty Under water. water only. 2024 game style
Cute Baby shark.. . 2024 game style. Side view. Photorealistic
Classic fish lateral view.. 2024 game style
Classic fish with fangs lateral view.. 2024 game style. Photorealistic
Classic fish with fangs mouth closed lateral view.. 2024 game style. Photorealistic. Full side view.
Cachalot. Horizontal closed lateral view.... 2024 game style. Photorealistic. Full side view.
Straight horizontal Orca. Mouth open. 2024 game style. Photorealistic. Full side view
Start button in the shape of a shark mouth.
beluga swimming mouth open. 2024 game style. Photorealistic. Entire lateral profile view, perfectly horizontal.
North Pacific right whale. Horizontal complete lateral view..... 2024 game style. Photorealistic. Full side view.
Decomposition of Horizontal Swimming movement of a woman with a snorkel.. 2024 game style. 2 frames sprite sheet. Photorealistic
Very minimalist skeleton of a fish with a fin and cute shark head... 2d. Black background. High contrast. No shadows.