/**** * Classes ****/ var Button = Container.expand(function (onPress, size, text) { var self = Container.call(this); self.onPress = onPress; self.isPressed = false; var background = self.attachAsset('buttonBackground', { width: size, height: size }); var backgroundPressed = self.attachAsset('buttonBackgroundPressed', { visible: false, width: size, height: size }); var buttonText = new Text2(text, { size: size / 5, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); buttonText.x = size / 2; buttonText.y = size / 2; self.addChild(buttonText); self.down = function (x, y, obj) { self.isPressed = true; background.visible = false; backgroundPressed.visible = true; currentButton = self; if (self.onPress) { self.onPress(); } }; self.up = function (x, y, obj) { self.isPressed = false; background.visible = true; backgroundPressed.visible = false; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x83C7FF }); /**** * Game Code ****/ game.attachAsset('waterBackground', {}); ; // Create add fish button var addFishButton = new Button(function () { // Function to add a fish will be implemented when fish spawning is added console.log("Add fish button pressed"); }, 150, "Add Fish"); // Position button in bottom left with margin addFishButton.x = 100; addFishButton.y = 2732 - 250; game.addChild(addFishButton);
===================================================================
--- original.js
+++ change.js
@@ -1,174 +1,62 @@
/****
-* Plugins
-****/
-var tween = LK.import("@upit/tween.v1");
-
-/****
* Classes
****/
-var Fish = Container.expand(function (fishType) {
+var Button = Container.expand(function (onPress, size, text) {
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
+ self.onPress = onPress;
+ self.isPressed = false;
+ var background = self.attachAsset('buttonBackground', {
+ width: size,
+ height: size
});
- // 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;
+ var backgroundPressed = self.attachAsset('buttonBackgroundPressed', {
+ visible: false,
+ width: size,
+ height: size
+ });
+ var buttonText = new Text2(text, {
+ size: size / 5,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ buttonText.x = size / 2;
+ buttonText.y = size / 2;
+ self.addChild(buttonText);
+ self.down = function (x, y, obj) {
+ self.isPressed = true;
+ background.visible = false;
+ backgroundPressed.visible = true;
+ currentButton = self;
+ if (self.onPress) {
+ self.onPress();
}
};
- 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);
+ self.up = function (x, y, obj) {
+ self.isPressed = false;
+ background.visible = true;
+ backgroundPressed.visible = false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB
+ backgroundColor: 0x83C7FF
});
/****
* 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
+game.attachAsset('waterBackground', {});
+;
+// Create add fish button
+var addFishButton = new Button(function () {
+ // Function to add a fish will be implemented when fish spawning is added
+ console.log("Add fish button pressed");
+}, 150, "Add Fish");
+// Position button in bottom left with margin
+addFishButton.x = 100;
+addFishButton.y = 2732 - 250;
+game.addChild(addFishButton);
\ No newline at end of file