Code edit (1 edits merged)
Please save this source code
User prompt
Render the caught fish on the cast screen.
Code edit (7 edits merged)
Please save this source code
User prompt
Render the caught fish on the cast screen.
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'size is not defined' in or related to this line: 'var buttonText = new Text2(self.text, {' Line Number: 43
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'var localPos = game.toLocal(obj.position);' Line Number: 201
User prompt
Hide the `tabBackground` when you tap anywhere else that is not on the `tabLayer`, I recommend using `game.down`
Code edit (14 edits merged)
Please save this source code
User prompt
Hide the `tabBackground` when you tap anywhere else that is not on the `tabLayer`, I recommend using `game.down`
User prompt
Hide the `tabBackground` when you don't tap on `tabLayer`
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'papyrus is not defined' in or related to this line: 'papyrus;' Line Number: 134
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Make a fish class that swims randomly around the screen
Code edit (1 edits merged)
Please save this source code
Code edit (14 edits merged)
Please save this source code
User prompt
Make an add fish button on the bottom left
Code edit (1 edits merged)
Please save this source code
User prompt
Bowlfish
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Fish = Container.expand(function (fishType) { var self = Container.call(this); // Fish properties based on type var fishData = { common: { asset: 'commonFish', points: 1, speed: 1 }, rare: { asset: 'rareFish', points: 3, speed: 0.8 }, epic: { asset: 'epicFish', points: 7, speed: 0.6 }, legendary: { asset: 'legendaryFish', points: 15, speed: 0.4 } }; self.fishType = fishType || 'common'; self.data = fishData[self.fishType]; var fishGraphics = self.attachAsset(self.data.asset, { anchorX: 0.5, anchorY: 0.5 }); // Swimming properties self.baseSpeed = self.data.speed; self.direction = Math.random() > 0.5 ? 1 : -1; self.amplitude = 50 + Math.random() * 100; self.frequency = 0.02 + Math.random() * 0.01; self.timeOffset = Math.random() * Math.PI * 2; self.collected = false; // Start position if (self.direction > 0) { self.x = -100; fishGraphics.scaleX = 1; } else { self.x = 2148; fishGraphics.scaleX = -1; } self.y = 300 + Math.random() * 2132; self.startY = self.y; self.update = function () { if (self.collected) return; // Move horizontally self.x += self.direction * self.baseSpeed * 2; // Sine wave swimming motion var time = LK.ticks * self.frequency + self.timeOffset; self.y = self.startY + Math.sin(time) * self.amplitude; // Remove if off screen if (self.direction > 0 && self.x > 2148) { self.markForRemoval = true; } else if (self.direction < 0 && self.x < -100) { self.markForRemoval = true; } }; self.down = function (x, y, obj) { if (self.collected) return; self.collected = true; // Add points LK.setScore(LK.getScore() + self.data.points); // Play collect sound LK.getSound('collect').play(); // Collection animation tween(fishGraphics, { scaleX: 0, scaleY: 0, alpha: 0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { self.markForRemoval = true; } }); // Flash effect LK.effects.flashObject(self, 0xFFFFFF, 200); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var activeFish = []; var spawnTimer = 0; var spawnRate = 120; // Spawn every 2 seconds at 60fps // Score display var scoreTxt = new Text2('Fish Collected: 0', { size: 60, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Fish unlock thresholds var unlockThresholds = { rare: 10, epic: 50, legendary: 150 }; function getRandomFishType() { var score = LK.getScore(); var fishTypes = ['common']; if (score >= unlockThresholds.rare) fishTypes.push('rare'); if (score >= unlockThresholds.epic) fishTypes.push('epic'); if (score >= unlockThresholds.legendary) fishTypes.push('legendary'); // Weight probabilities (common is most likely) var weights = []; for (var i = 0; i < fishTypes.length; i++) { if (fishTypes[i] === 'common') weights.push(70);else if (fishTypes[i] === 'rare') weights.push(20);else if (fishTypes[i] === 'epic') weights.push(8);else if (fishTypes[i] === 'legendary') weights.push(2); } var totalWeight = 0; for (var j = 0; j < weights.length; j++) { totalWeight += weights[j]; } var random = Math.random() * totalWeight; var currentWeight = 0; for (var k = 0; k < weights.length; k++) { currentWeight += weights[k]; if (random <= currentWeight) { return fishTypes[k]; } } return 'common'; } function spawnFish() { var fishType = getRandomFishType(); var fish = new Fish(fishType); activeFish.push(fish); game.addChild(fish); } game.update = function () { // Update score display scoreTxt.setText('Fish Collected: ' + LK.getScore()); // Spawn fish spawnTimer++; if (spawnTimer >= spawnRate) { spawnFish(); spawnTimer = 0; // Gradually increase spawn rate as score increases var baseRate = 120; var speedBonus = Math.floor(LK.getScore() / 20) * 5; spawnRate = Math.max(60, baseRate - speedBonus); } // Clean up fish that are marked for removal for (var i = activeFish.length - 1; i >= 0; i--) { var fish = activeFish[i]; if (fish.markForRemoval) { fish.destroy(); activeFish.splice(i, 1); } } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,174 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Fish = Container.expand(function (fishType) {
+ var self = Container.call(this);
+ // Fish properties based on type
+ var fishData = {
+ common: {
+ asset: 'commonFish',
+ points: 1,
+ speed: 1
+ },
+ rare: {
+ asset: 'rareFish',
+ points: 3,
+ speed: 0.8
+ },
+ epic: {
+ asset: 'epicFish',
+ points: 7,
+ speed: 0.6
+ },
+ legendary: {
+ asset: 'legendaryFish',
+ points: 15,
+ speed: 0.4
+ }
+ };
+ self.fishType = fishType || 'common';
+ self.data = fishData[self.fishType];
+ var fishGraphics = self.attachAsset(self.data.asset, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Swimming properties
+ self.baseSpeed = self.data.speed;
+ self.direction = Math.random() > 0.5 ? 1 : -1;
+ self.amplitude = 50 + Math.random() * 100;
+ self.frequency = 0.02 + Math.random() * 0.01;
+ self.timeOffset = Math.random() * Math.PI * 2;
+ self.collected = false;
+ // Start position
+ if (self.direction > 0) {
+ self.x = -100;
+ fishGraphics.scaleX = 1;
+ } else {
+ self.x = 2148;
+ fishGraphics.scaleX = -1;
+ }
+ self.y = 300 + Math.random() * 2132;
+ self.startY = self.y;
+ self.update = function () {
+ if (self.collected) return;
+ // Move horizontally
+ self.x += self.direction * self.baseSpeed * 2;
+ // Sine wave swimming motion
+ var time = LK.ticks * self.frequency + self.timeOffset;
+ self.y = self.startY + Math.sin(time) * self.amplitude;
+ // Remove if off screen
+ if (self.direction > 0 && self.x > 2148) {
+ self.markForRemoval = true;
+ } else if (self.direction < 0 && self.x < -100) {
+ self.markForRemoval = true;
+ }
+ };
+ self.down = function (x, y, obj) {
+ if (self.collected) return;
+ self.collected = true;
+ // Add points
+ LK.setScore(LK.getScore() + self.data.points);
+ // Play collect sound
+ LK.getSound('collect').play();
+ // Collection animation
+ tween(fishGraphics, {
+ scaleX: 0,
+ scaleY: 0,
+ alpha: 0
+ }, {
+ duration: 300,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.markForRemoval = true;
+ }
+ });
+ // Flash effect
+ LK.effects.flashObject(self, 0xFFFFFF, 200);
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var activeFish = [];
+var spawnTimer = 0;
+var spawnRate = 120; // Spawn every 2 seconds at 60fps
+// Score display
+var scoreTxt = new Text2('Fish Collected: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Fish unlock thresholds
+var unlockThresholds = {
+ rare: 10,
+ epic: 50,
+ legendary: 150
+};
+function getRandomFishType() {
+ var score = LK.getScore();
+ var fishTypes = ['common'];
+ if (score >= unlockThresholds.rare) fishTypes.push('rare');
+ if (score >= unlockThresholds.epic) fishTypes.push('epic');
+ if (score >= unlockThresholds.legendary) fishTypes.push('legendary');
+ // Weight probabilities (common is most likely)
+ var weights = [];
+ for (var i = 0; i < fishTypes.length; i++) {
+ if (fishTypes[i] === 'common') weights.push(70);else if (fishTypes[i] === 'rare') weights.push(20);else if (fishTypes[i] === 'epic') weights.push(8);else if (fishTypes[i] === 'legendary') weights.push(2);
+ }
+ var totalWeight = 0;
+ for (var j = 0; j < weights.length; j++) {
+ totalWeight += weights[j];
+ }
+ var random = Math.random() * totalWeight;
+ var currentWeight = 0;
+ for (var k = 0; k < weights.length; k++) {
+ currentWeight += weights[k];
+ if (random <= currentWeight) {
+ return fishTypes[k];
+ }
+ }
+ return 'common';
+}
+function spawnFish() {
+ var fishType = getRandomFishType();
+ var fish = new Fish(fishType);
+ activeFish.push(fish);
+ game.addChild(fish);
+}
+game.update = function () {
+ // Update score display
+ scoreTxt.setText('Fish Collected: ' + LK.getScore());
+ // Spawn fish
+ spawnTimer++;
+ if (spawnTimer >= spawnRate) {
+ spawnFish();
+ spawnTimer = 0;
+ // Gradually increase spawn rate as score increases
+ var baseRate = 120;
+ var speedBonus = Math.floor(LK.getScore() / 20) * 5;
+ spawnRate = Math.max(60, baseRate - speedBonus);
+ }
+ // Clean up fish that are marked for removal
+ for (var i = activeFish.length - 1; i >= 0; i--) {
+ var fish = activeFish[i];
+ if (fish.markForRemoval) {
+ fish.destroy();
+ activeFish.splice(i, 1);
+ }
+ }
+};
\ No newline at end of file