/**** * 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