Code edit (3 edits merged)
Please save this source code
User prompt
In Fish class make speed depend on sharklevel
User prompt
Increase fishes speed a bit at each level
User prompt
When player passes level nbFishTypes, call game over too
Code edit (2 edits merged)
Please save this source code
User prompt
Remove Fish1 class
Code edit (2 edits merged)
Please save this source code
User prompt
Reduce frequency of fish of shark level+2
Code edit (10 edits merged)
Please save this source code
User prompt
Now in baby shark class use widthRatio to calculate width from currentHeight
Code edit (1 edits merged)
Please save this source code
User prompt
Use nbFishPerLevel in updateFishCollisions
User prompt
Add a new global nbFishPerLevel = 10
User prompt
In spawnFish check if fishType argument is less or equal to nbFishTypes, if no, force it to nbFishTypes
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: updateFish1Collisions' in or related to this line: 'updateFish1Collisions();' Line Number: 287
Code edit (1 edits merged)
Please save this source code
User prompt
Move background1 declaration with other globals
User prompt
Move global variables declarations to one unique place
User prompt
Play level up when shark gains a level
User prompt
In spawnFishes, instead of 1,2,3 use sharkLevel, sharkLevel+1 and sharkLevel+2
User prompt
Now remove spawnFish3, fish3s and updateFish3Collisions and Fish3 class but not fish3 asset
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: updateFish2Collisions' in or related to this line: 'updateFish2Collisions();' Line Number: 336
User prompt
Now remove spawnFish2, fish2s and updateFish2Collisions and Fish2 class but not fish2 asset
User prompt
Now remove spawnFish2, fish2s and updateFish2Collisions
/**** * 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 = 200; // Initialize currentSize property 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.currentWidth, height: self.currentWidth * self.heightRatio }); 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 <= self.shark.height * 0.5) { self.y = self.shark.height * 0.5; self.velocityY = 0; } // Update logic for Baby Shark if (isDebug) { debugTxt.setText("Y: ".concat(self.y.toFixed(0), ", Height: ").concat(self.shark.height)); } }; self.grow = function () { self.currentWidth += 50; self.shark.width = self.currentWidth; self.shark.height = self.currentWidth * self.heightRatio; //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; }; }); // 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: 0.7, x: -self.fish.width * 0.25, width: self.fish.width * 0.5, height: self.fish.width * 0.5 }); self.speed = 5; self.update = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); // Fish1 class var Fish1 = Container.expand(function () { var self = Container.call(this); self.fish = self.attachAsset('fish1', { anchorX: 0.5, anchorY: 0.5 }); self.collisionBody = self.attachAsset('collisionBody', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7, x: -self.fish.width * 0.25, width: self.fish.width * 0.5, height: self.fish.width * 0.5 }); self.speed = 5; self.collided = false; self.update = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0000ff // Init game with blue background }); /**** * Game Code ****/ // Global variable declarations var babyShark; var nbFishTypes = 6; 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 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; function spawnFish(fishType) { if (fishType > nbFishTypes) { fishType = nbFishTypes; } var fish = new Fish(fishType); fish.x = 2048 + 50; fish.y = Math.random() * (2732 - fish.height) + 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 % 300 == 0) { spawnFish(sharkLevel + 2); } if (LK.ticks % 180 == 0) { spawnFish(sharkLevel + 1); } } 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 += 10; scoreTxt.setText(score); currentProgress += 1; currentProgressTxt.setText(currentProgress + "/10"); if (currentProgress >= 10) { sharkLevel += 1; currentProgress = 0; babyShark.grow(); LK.getSound('levelUp').play(); // Play level up sound } 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()); 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: 100, 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: 100, fill: "#ffffff", dropShadow: true, dropShadowColor: "#000000", dropShadowBlur: 4, dropShadowDistance: 6 }); currentProgressTxt.anchor.set(1, 0); LK.gui.topRight.addChild(currentProgressTxt); debugTxt = new Text2('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; }; game.update = function () { updateBackgrounds(); spawnFishes(); updateFishCollisions(); }; gameInitialize();
===================================================================
--- original.js
+++ change.js
@@ -126,8 +126,11 @@
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;
function spawnFish(fishType) {
+ if (fishType > nbFishTypes) {
+ fishType = nbFishTypes;
+ }
var fish = new Fish(fishType);
fish.x = 2048 + 50;
fish.y = Math.random() * (2732 - fish.height) + fish.height / 2;
fishes.push(fish);
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.