User prompt
Play lose sound when lose wait 1500 ms before game over
Code edit (2 edits merged)
Please save this source code
User prompt
Use LK to store final score
Code edit (1 edits merged)
Please save this source code
User prompt
In current target limit target size within 200x100; keep the asset aspect ratio
Code edit (1 edits merged)
Please save this source code
User prompt
Only call currentTarget.updateTarget after sharklevel increase
User prompt
Add a currentTarget class. It will show the asset of the current eatable fish in the top right corner
Code edit (9 edits merged)
Please save this source code
User prompt
Higher fishTypes should give more points
Code edit (1 edits merged)
Please save this source code
User prompt
Now use topBorderY to constrain fishes spawns too (donβt forget height *0.5)
User prompt
You forgot self.shark.height * 0.5
User prompt
Use topBorderY to limit shark jumps
User prompt
Add a new global topBorderY=250
User prompt
After sharkLevel increase and currentProgress is set to 0, update currentProgressTxt after 1 sec
User prompt
When progress bar reaches 100% it should return progressively to 0
Code edit (2 edits merged)
Please save this source code
User prompt
In shark update, in debugtxt, also display currentProgress
Code edit (2 edits merged)
Please save this source code
User prompt
Fix progressFrame currently starts from the middle of the screen
Code edit (4 edits merged)
Please save this source code
User prompt
Use anchorX:0 for frame too
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: progressBar' in or related to this line: 'progressBar.updateProgress(currentProgress, nbFishPerLevel);' Line Number: 213
User prompt
Create a new class progressBar, use progressBar and progressFrame, it should represent the currentprogress
/**** * 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 () { 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.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; }; }); 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 - self.target.width / 2 - 20; self.target.y = 20 + self.target.height / 2; }; }); // 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 () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); 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 ****/ // Global variable declarations var topBorderY = 250; var babyShark; var nbFishTypes = 10; var fishes = []; var score; var scoreTxt; var currentProgressTxt; var debugTxt; var isDebug = true; // Global variable for debugging mode 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 = 3; // Global variable for the number of fish per level 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 % 60 == 0) { spawnFish(sharkLevel); } if (LK.ticks % 180 == 0) { spawnFish(sharkLevel + 1); } if (LK.ticks % 600 == 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 LK.getSound('crunch').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.showGameOver(); } LK.setTimeout(function () { currentProgressTxt.setText(currentProgress + "/" + nbFishPerLevel); }, 1000); } fishes[i].destroy(); fishes.splice(i, 1); } else { // Baby shark gets eaten LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } 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); babyShark = game.addChild(new BabyShark()); 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) { babyShark.velocityY = -20; LK.getSound('jump').play(); }; game.update = function () { updateBackgrounds(); spawnFishes(); updateFishCollisions(); }; gameInitialize();
===================================================================
--- original.js
+++ change.js
@@ -65,8 +65,20 @@
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 - self.target.width / 2 - 20;
self.target.y = 20 + self.target.height / 2;
};
});
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.