/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bug = Container.expand(function () {
var self = Container.call(this);
var bugGraphics = self.attachAsset('bug', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.directionX = (Math.random() - 0.5) * 2;
self.directionY = (Math.random() - 0.5) * 2;
self.lifetime = 0;
self.maxLifetime = 600; // 5 seconds at 60fps
self.update = function () {
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
self.lifetime++;
// Bounce off garden boundaries
if (self.x < gardenX || self.x > gardenX + gardenWidth) {
self.directionX *= -1;
}
if (self.y < gardenY || self.y > gardenY + gardenHeight) {
self.directionY *= -1;
}
// Keep bug within garden bounds
self.x = Math.max(gardenX, Math.min(gardenX + gardenWidth, self.x));
self.y = Math.max(gardenY, Math.min(gardenY + gardenHeight, self.y));
};
self.down = function (x, y, obj) {
// Bug caught!
LK.setScore(LK.getScore() + 100);
scoreText.setText(LK.getScore());
LK.getSound('bugSound').stop();
LK.getSound('catchBug').play();
// Remove bug
var bugIndex = bugs.indexOf(self);
if (bugIndex > -1) {
bugs.splice(bugIndex, 1);
self.destroy();
}
};
return self;
});
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.walkFrames = ['yuru1', 'yuru2', 'yuru3', 'yuru4', 'yuru3', 'yuru2'];
self.yon = 0;
self.walkIndex = 0;
self.walkTimer = 0;
self.setSkin = function (skinName) {
scoreText.setText(LK.getScore()) + 500;
if (characterGraphics) {
characterGraphics.destroy();
} // eskisini sil
characterGraphics = self.attachAsset(skinName, {
anchorX: 0.5,
anchorY: 0.5
});
};
self.yuru = function () {
self.yon = 2;
self.walkTimer++;
if (self.walkTimer % 10 === 0) {
self.setSkin(self.walkFrames[self.walkIndex]);
self.walkIndex = (self.walkIndex + 1) % self.walkFrames.length;
}
};
self.dur = function () {
if (self.x > 1024) {
if (self.yon == 1 || self.yon == 2) {
self.yon = 0;
self.setSkin('character2');
}
} else {
if (self.yon == 0 || self.yon == 2) {
self.yon = 1;
self.setSkin('character');
}
}
};
return self;
});
var Flower = Container.expand(function (flowerType) {
var self = Container.call(this);
var flowerGraphics = self.attachAsset('flower' + flowerType, {
anchorX: 0.5,
anchorY: 0.5
});
self.flowerType = flowerType;
self.growthScale = 1.0;
self.grow = function () {
self.growthScale *= 1.05;
flowerGraphics.scaleX = self.growthScale;
flowerGraphics.scaleY = self.growthScale;
};
return self;
});
var ToolBox = Container.expand(function (toolType, index) {
var self = Container.call(this);
var boxGraphics = self.attachAsset('toolBox', {
anchorX: 0.5,
anchorY: 0.5
});
var toolGraphics;
if (toolType === 'shovel') {
toolGraphics = self.attachAsset('shovel', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (toolType === 'water') {
toolGraphics = self.attachAsset('water', {
anchorX: 0.5,
anchorY: 0.5
});
} else {
toolGraphics = self.attachAsset('flower' + toolType, {
anchorX: 0.5,
anchorY: 0.5
});
}
self.toolType = toolType;
self.down = function (x, y, obj) {
if (self.toolType === 'shovel') {
var flowerToRemove = getFlowerAt(character.x, character.y);
if (flowerToRemove) {
var flowerIndex = flowers.indexOf(flowerToRemove);
if (flowerIndex > -1) {
flowers.splice(flowerIndex, 1);
flowerToRemove.destroy();
LK.getSound('shovel').play();
}
}
} else if (self.toolType === 'water') {
var flowerToWater = getFlowerAt(character.x, character.y);
if (flowerToWater) {
flowerToWater.grow();
LK.getSound('water').play();
}
} else if (LK.getScore() > 0) {
var newFlower = cicek.addChild(new Flower(parseInt(self.toolType)));
newFlower.x = character.x;
newFlower.y = character.y;
flowers.push(newFlower);
LK.setScore(LK.getScore() - 1);
scoreText.setText('Score: ' + LK.getScore());
LK.getSound('plant').play();
}
LK.getSound('select').play();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xc600d8
});
/****
* Game Code
****/
// Game variables
var character;
var flowers = [];
var toolBoxes = [];
var bugs = [];
var selectedTool = '1';
var dragNode = null;
var lastBugSpawn = 0;
var bugSpawnInterval = 3600; // 1 minute at 60fps
var gardenX = 240;
var gardenY = 200;
var secX = 0;
var secY = 0;
var itX = 0;
var itY = 0;
var sur = 0;
var gardenWidth = 1600;
var gardenHeight = 2200;
// Initialize score
LK.setScore(1000);
var melisa = new Container();
var bahce = new Container();
var bocek = new Container();
var cicek = new Container();
game.addChild(bahce);
var logo = game.addChild(LK.getAsset('logo', {
x: 1250,
y: 0
}));
game.addChild(cicek);
game.addChild(melisa);
game.addChild(bocek);
// Create garden background
var gardenArea = bahce.addChild(LK.getAsset('garden', {
x: gardenX,
y: gardenY
}));
// Create UI
var scoreText = new Text2('Score: 1000', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.top.addChild(scoreText);
scoreText.x = -550;
scoreText.y = 35;
// Create character
character = melisa.addChild(new Character());
character.x = 1024;
character.y = 1366;
// Create tool boxes
var flowerTypes = ['1', '2', '3', '4', '5', '6', '7', '8', 'shovel', 'water'];
for (var i = 0; i < flowerTypes.length; i++) {
var toolBox = cicek.addChild(new ToolBox(flowerTypes[i], i));
toolBox.x = 120;
toolBox.y = 300 + i * 245;
toolBoxes.push(toolBox);
}
// Set first flower as selected by default
function spawnBug() {
if (bugs.length >= 1) {
return;
} // Max 1 bug at a time
var bug = bocek.addChild(new Bug());
// Spawn from random edge
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top
bug.x = gardenX + Math.random() * gardenWidth;
bug.y = gardenY;
break;
case 1:
// Right
bug.x = gardenX + gardenWidth;
bug.y = gardenY + Math.random() * gardenHeight;
break;
case 2:
// Bottom
bug.x = gardenX + Math.random() * gardenWidth;
bug.y = gardenY + gardenHeight;
break;
case 3:
// Left
bug.x = gardenX;
bug.y = gardenY + Math.random() * gardenHeight;
break;
}
bugs.push(bug);
LK.getSound('bugSound').play();
lastBugSpawn = LK.ticks;
}
function isInGarden(x, y) {
return x >= gardenX && x <= gardenX + gardenWidth && y >= gardenY && y <= gardenY + gardenHeight;
}
function getFlowerAt(x, y) {
for (var i = 0; i < flowers.length; i++) {
var flower = flowers[i];
var distance = Math.sqrt((flower.x - x) * (flower.x - x) + (flower.y - y) * (flower.y - y));
if (distance < 40) {
return flower;
}
}
return null;
}
// Game event handlers
game.down = function (x, y, obj) {
secX = x;
secY = y;
sur = 1;
};
game.move = function (x, y, obj) {
if (sur == 1) {
itX = secX - x;
itY = secY - y;
} else {
itX = 0;
itY = 0;
}
};
game.up = function (x, y) {
secX = 0;
secY = 0;
sur = 0;
itX = 0;
itY = 0;
};
// Main game update loop
game.update = function () {
if (sur == 1) {
character.yuru();
} else {
character.dur();
}
// Update character position
character.x -= itX / 20;
character.y -= itY / 20;
if (character.x > 2040) {
character.x = 2040;
}
if (character.x < 250) {
character.x = 250;
}
if (character.y < 250) {
character.y = 250;
}
if (character.y > 2550) {
character.y = 2550;
}
for (var i = bugs.length - 1; i >= 0; i--) {
var bug = bugs[i];
if (bug.lifetime >= bug.maxLifetime) {
// Bug lived too long, remove it
bugs.splice(i, 1);
bug.destroy();
LK.getSound('bugSound').stop();
continue;
}
// Check if bug is eating flowers
for (var j = flowers.length - 1; j >= 0; j--) {
var flower = flowers[j];
if (bug.intersects(flower)) {
// Bug ate the flower
flowers.splice(j, 1);
flower.destroy();
break;
}
}
}
// Spawn bugs occasionally
if (LK.ticks - lastBugSpawn > bugSpawnInterval) {
if (Math.random() < 0.3) {
// 30% chance when timer is up
spawnBug();
}
}
};
// Start background music
LK.playMusic('bgMusic'); ===================================================================
--- original.js
+++ change.js
@@ -53,8 +53,9 @@
anchorX: 0.5,
anchorY: 0.5
});
self.walkFrames = ['yuru1', 'yuru2', 'yuru3', 'yuru4', 'yuru3', 'yuru2'];
+ self.yon = 0;
self.walkIndex = 0;
self.walkTimer = 0;
self.setSkin = function (skinName) {
scoreText.setText(LK.getScore()) + 500;
@@ -65,28 +66,27 @@
anchorX: 0.5,
anchorY: 0.5
});
};
- self.yuru = function (durum) {
- if (durum === 'yuru') {
- self.walkTimer++;
- if (self.walkTimer % 10 === 0) {
- self.setSkin(self.walkFrames[self.walkIndex]);
- self.walkIndex = (self.walkIndex + 1) % self.walkFrames.length;
- }
+ self.yuru = function () {
+ self.yon = 2;
+ self.walkTimer++;
+ if (self.walkTimer % 10 === 0) {
+ self.setSkin(self.walkFrames[self.walkIndex]);
+ self.walkIndex = (self.walkIndex + 1) % self.walkFrames.length;
}
- if (durum === 'dur') {
- if (self.x > 1024) {
- if (characteryon == 0) {
- characteryon = 1;
- self.setSkin('character2');
- }
- } else {
- if (characteryon == 1) {
- characteryon = 0;
- self.setSkin('character');
- }
+ };
+ self.dur = function () {
+ if (self.x > 1024) {
+ if (self.yon == 1 || self.yon == 2) {
+ self.yon = 0;
+ self.setSkin('character2');
}
+ } else {
+ if (self.yon == 0 || self.yon == 2) {
+ self.yon = 1;
+ self.setSkin('character');
+ }
}
};
return self;
});
@@ -171,9 +171,8 @@
* Game Code
****/
// Game variables
var character;
-var characteryon = 0;
var flowers = [];
var toolBoxes = [];
var bugs = [];
var selectedTool = '1';
@@ -280,29 +279,32 @@
game.down = function (x, y, obj) {
secX = x;
secY = y;
sur = 1;
- character.yuru('yuru');
};
game.move = function (x, y, obj) {
if (sur == 1) {
itX = secX - x;
itY = secY - y;
- character.yuru('yuru');
} else {
- character.yuru('dur');
+ itX = 0;
+ itY = 0;
}
};
game.up = function (x, y) {
- character.yuru('dur');
secX = 0;
secY = 0;
sur = 0;
itX = 0;
itY = 0;
};
// Main game update loop
game.update = function () {
+ if (sur == 1) {
+ character.yuru();
+ } else {
+ character.dur();
+ }
// Update character position
character.x -= itX / 20;
character.y -= itY / 20;
if (character.x > 2040) {