User prompt
Group all global variables declarations In one place
User prompt
Group global variables declarations
User prompt
Remove useless assignations … = null; in global scope
Code edit (5 edits merged)
Please save this source code
User prompt
In baby shark grow, add 50 to width and height instead of using scale
Code edit (3 edits merged)
Please save this source code
User prompt
Fix the scope problem in updateFish1Collisions that makes collided property useless
User prompt
In updateFish1Collisions don’t check all fishes, only those within a certain x offset
User prompt
Add a flag to avoid counting fish1 collisions twice
User prompt
For currentProgress write “/10” at the end
Code edit (1 edits merged)
Please save this source code
User prompt
Like score, display currentProgress but on the top right
User prompt
currentProgress goes from 0 to 9, when it reaches 9 level up and reset currentProgress to zero
User prompt
Add a global currentProgress
User prompt
Add a global sharkLevel
User prompt
Add drop shadow to score
User prompt
Change score fill to black
Code edit (1 edits merged)
Please save this source code
User prompt
Continue moving initialisation code to gameInitialize
User prompt
Move gameInitialize call to the bottom of the code
User prompt
Move gameInitialize call to be the last instruction
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: background2' in or related to this line: 'background2.x -= 2;' Line Number: 118
User prompt
Move initialisations in a gameInitialize function
User prompt
In global scope, separate declarations and initialisations
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); var sharkGraphics = self.attachAsset('babyShark', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.velocityY = 0; self.update = function () { self.velocityY += 0.4; // Further reduced gravity effect self.y += self.velocityY; if (self.y > 2732 - self.height / 2) { self.y = 2732 - self.height / 2; self.velocityY = 0; } if (self.y < self.height / 2) { self.y = self.height / 2; self.velocityY = 0; } // Update logic for Baby Shark }; self.grow = function () { self.width += 50; self.height += 50; }; }); // 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 sharkLevel = 1; var currentProgress = 0; 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 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 (!fish1s[i].collided && babyShark.intersects(fish1s[i])) { fish1s[i].collided = true; score += 10; scoreTxt.setText(score); currentProgress += 1; currentProgressTxt.setText(currentProgress + "/10"); if (currentProgress > 9) { sharkLevel += 1; currentProgress = 0; babyShark.grow(); } fish1s[i].destroy(); fish1s.splice(i, 1); } } } 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; var background2; 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; 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); 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); } //background2.scale.x = -1; var babyShark; var fish1s = []; var fish2s = []; var score = 0; var scoreTxt; var currentProgressTxt; 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
@@ -128,8 +128,9 @@
background2.x = 2732 + 2732 / 2;
}
}
var background1;
+var background2;
function gameInitialize() {
background1 = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
@@ -147,20 +148,34 @@
babyShark = game.addChild(new BabyShark());
babyShark.x = 150;
babyShark.y = 2732 / 2;
babyShark.velocityY = 0;
- fish1s = [];
- fish2s = [];
- score = 0;
- scoreTxt.setText('0');
- currentProgress = 0;
- currentProgressTxt.setText('0/10');
+ 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);
+ 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);
}
//background2.scale.x = -1;
var babyShark;
-var fish1s;
-var fish2s;
-var score;
+var fish1s = [];
+var fish2s = [];
+var score = 0;
var scoreTxt;
var currentProgressTxt;
function spawnSmallFish() {
var smallFish = new Fish1();
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.