User prompt
Add a parameter fishType to Fish class, store it and use it for the asset : 1 => fish1, 2=>fish2,…
User prompt
Play crunch sound when eat a fish
User prompt
Ok so they are similar…add a new similar class named “Fish”
Code edit (1 edits merged)
Please save this source code
User prompt
Add a global nbFishTypes = 5
User prompt
Now use checkCollision instead of intersects
User prompt
In checkCollision, assume objects have x and y and a circle collisionBody with relative x and y. Return true if circles collide
User prompt
Create a new empty checkCollision function that takes two objects
User prompt
Place collisionBody of fishes at x: -0.25*fish.width
User prompt
CollisionBody are circles, use self.fish.width * 0.5 for both width and height
User prompt
Fix fishGraphics to self.fish
User prompt
In Fishes classes, change var fishGraphics to a public property fish
User prompt
Now add a collisionBody to fishes
User prompt
There is fish1 and fish2, now add fish3
Code edit (6 edits merged)
Please save this source code
User prompt
Use a different lastCollisionCheckTime global for updateFish1Collisions and updateFish2Collisions
User prompt
Use an offset in updateFish2Collisions too
User prompt
In updateFish1Collisions offset should depend on baby shark’s .shark.width
Code edit (1 edits merged)
Please save this source code
User prompt
Use collisionBody for collisions check
User prompt
Optimize updateFish2Collisions
Code edit (1 edits merged)
Please save this source code
User prompt
In baby shark update, write self.y and self.shark.height in debug txt
User prompt
Add a new text2 : debugTxt at center bottom for debugging
Code edit (1 edits merged)
Please save this source code
/**** * 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: 50, y: 10, width: 50, height: 50 }); self.update = function () { self.velocityY += 0.4; // Further reduced gravity effect self.y += self.velocityY; if (self.y >= 2732 - self.shark.height) { self.y = 2732 - self.shark.height; self.velocityY = 0; } if (self.y <= self.shark.height) { self.y = self.shark.height; 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.25; self.collisionBody.height = self.currentWidth * 0.25; self.collisionBody.x = self.shark.width * 0.15; //self.collisionBody.y = self.height * 0.05; }; }); // Fish1 class var Fish1 = Container.expand(function () { var self = Container.call(this); var fishGraphics = self.attachAsset('fish1', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.collided = false; self.update = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); // Fish2 class var Fish2 = Container.expand(function () { var self = Container.call(this); var fishGraphics = self.attachAsset('fish2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; 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 ****/ var isDebug = true; // Global variable for debugging mode var sharkLevel = 1; var currentProgress = 0; var lastCollisionCheckTime = 0; // Global variable to track the last collision check time var collisionCheckDelay = 1000; // Global variable for collision check delay in milliseconds function spawnFish() { if (LK.ticks % 60 == 0) { spawnSmallFish(); } if (LK.ticks % 180 == 0) { spawnFish2(); } } function updateFish2Collisions() { for (var j = fish2s.length - 1; j >= 0; j--) { if (babyShark.intersects(fish2s[j])) { if (fish2s[j].x - fish2s[j].width / 3 < babyShark.x) { // Bounce baby shark off the bigger fish babyShark.velocityY = -10; //babyShark.x -= 50; // Move baby shark back a bit } else { // Lose a life LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } } } function updateFish1Collisions() { var currentTime = Date.now(); if (currentTime - lastCollisionCheckTime < collisionCheckDelay) { return; } lastCollisionCheckTime = currentTime; var offset = 300; // Define the x offset range for (var i = fish1s.length - 1; i >= 0; i--) { if (Math.abs(babyShark.x - fish1s[i].x) > offset) { continue; // Skip fishes outside the x offset range } if (babyShark.intersects(fish1s[i])) { score += 10; scoreTxt.setText(score); currentProgress += 1; currentProgressTxt.setText(currentProgress + "/10"); if (currentProgress > 1) { sharkLevel += 1; currentProgress = 0; babyShark.grow(); } fish1s[i].destroy(); fish1s.splice(i, 1); 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; } } var background1; 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); } //background2.scale.x = -1; var babyShark; var fish1s; var fish2s; var score; var scoreTxt; var currentProgressTxt; var debugTxt; function spawnSmallFish() { var smallFish = new Fish1(); smallFish.x = 2048 + 50; smallFish.y = Math.random() * (2732 - smallFish.height) + smallFish.height / 2; fish1s.push(smallFish); game.addChild(smallFish); } function spawnFish2() { var fish2 = new Fish2(); fish2.x = 2048 + 50; fish2.y = Math.random() * (2732 - fish2.height) + fish2.height / 2; fish2s.push(fish2); game.addChild(fish2); } game.down = function (x, y, obj) { babyShark.velocityY = -20; }; game.update = function () { updateBackgrounds(); updateFish1Collisions(); updateFish2Collisions(); spawnFish(); }; gameInitialize();
===================================================================
--- original.js
+++ change.js
@@ -36,9 +36,9 @@
self.velocityY = 0;
}
// Update logic for Baby Shark
if (isDebug) {
- debugTxt.setText("Y: ".concat(self.y, ", Height: ").concat(self.shark.height));
+ debugTxt.setText("Y: ".concat(self.y.toFixed(0), ", Height: ").concat(self.shark.height));
}
};
self.grow = function () {
self.currentWidth += 50;
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.