Code edit (1 edits merged)
Please save this source code
User prompt
Territory Tycoon
Initial prompt
bana tycoon tarzı oyun yap oyunun arka planı olsun ve karakterimiz olsun heryeri gezebilsin mauseyi takip etsin ve bir yer olsun o yer küçük bir daire hareket etmesin o nesne gibi bişey ve onun üstünde claim yazsın onun üstüne karakterimiz gelince onun olsun etrafa duvar gelsin
/****
* Classes
****/
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetX = 0;
self.targetY = 0;
self.moveSpeed = 8;
self.update = function () {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
var moveX = dx / distance * self.moveSpeed;
var moveY = dy / distance * self.moveSpeed;
var newX = self.x + moveX;
var newY = self.y + moveY;
// Keep character within bounds (accounting for character size)
if (newX >= 90 && newX <= 1958 && newY >= 90 && newY <= 2642) {
self.x = newX;
self.y = newY;
}
}
};
self.setTarget = function (x, y) {
self.targetX = x;
self.targetY = y;
};
return self;
});
var ClaimZone = Container.expand(function () {
var self = Container.call(this);
var zoneGraphics = self.attachAsset('claimZone', {
anchorX: 0.5,
anchorY: 0.5
});
var claimText = new Text2('CLAIM', {
size: 24,
fill: '#FFFFFF'
});
claimText.anchor.set(0.5, 1);
claimText.y = -40;
self.addChild(claimText);
self.isClaimed = false;
self.claim = function () {
if (!self.isClaimed) {
self.isClaimed = true;
self.removeChild(zoneGraphics);
self.removeChild(claimText);
var claimedGraphics = self.attachAsset('claimedZone', {
anchorX: 0.5,
anchorY: 0.5
});
var claimedText = new Text2('CLAIMED', {
size: 20,
fill: '#FFFFFF'
});
claimedText.anchor.set(0.5, 1);
claimedText.y = -40;
self.addChild(claimedText);
return true;
}
return false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2E8B57
});
/****
* Game Code
****/
var character = new Character();
character.x = 1024;
character.y = 1366;
game.addChild(character);
var claimZones = [];
var totalZones = 15;
// Create walls around the perimeter
var walls = [];
// Top wall
for (var i = 0; i < 42; i++) {
var topWall = LK.getAsset('wall', {
anchorX: 0.5,
anchorY: 0.5,
x: i * 50 + 25,
y: 25
});
game.addChild(topWall);
walls.push(topWall);
}
// Bottom wall
for (var i = 0; i < 42; i++) {
var bottomWall = LK.getAsset('wall', {
anchorX: 0.5,
anchorY: 0.5,
x: i * 50 + 25,
y: 2707
});
game.addChild(bottomWall);
walls.push(bottomWall);
}
// Left wall
for (var i = 1; i < 54; i++) {
var leftWall = LK.getAsset('wall', {
anchorX: 0.5,
anchorY: 0.5,
x: 25,
y: i * 50 + 25
});
game.addChild(leftWall);
walls.push(leftWall);
}
// Right wall
for (var i = 1; i < 54; i++) {
var rightWall = LK.getAsset('wall', {
anchorX: 0.5,
anchorY: 0.5,
x: 2023,
y: i * 50 + 25
});
game.addChild(rightWall);
walls.push(rightWall);
}
// Create initial claim zones
function createClaimZone() {
var zone = new ClaimZone();
var validPosition = false;
var attempts = 0;
while (!validPosition && attempts < 50) {
zone.x = 150 + Math.random() * 1748;
zone.y = 150 + Math.random() * 2432;
// Check distance from character
var dx = zone.x - character.x;
var dy = zone.y - character.y;
var distanceFromCharacter = Math.sqrt(dx * dx + dy * dy);
// Check distance from other zones
var tooClose = false;
for (var i = 0; i < claimZones.length; i++) {
var otherZone = claimZones[i];
var zdx = zone.x - otherZone.x;
var zdy = zone.y - otherZone.y;
var distanceFromZone = Math.sqrt(zdx * zdx + zdy * zdy);
if (distanceFromZone < 200) {
tooClose = true;
break;
}
}
if (distanceFromCharacter > 150 && !tooClose) {
validPosition = true;
}
attempts++;
}
return zone;
}
// Generate initial claim zones
for (var i = 0; i < totalZones; i++) {
var zone = createClaimZone();
claimZones.push(zone);
game.addChild(zone);
}
// Score display
var scoreTxt = new Text2('Territory: 0', {
size: 60,
fill: '#FFFFFF'
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Mouse/touch controls
game.move = function (x, y, obj) {
character.setTarget(x, y);
};
game.down = function (x, y, obj) {
character.setTarget(x, y);
};
// Main game loop
game.update = function () {
// Check for zone claims
for (var i = claimZones.length - 1; i >= 0; i--) {
var zone = claimZones[i];
if (!zone.isClaimed) {
var dx = character.x - zone.x;
var dy = character.y - zone.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 50) {
if (zone.claim()) {
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Territory: ' + LK.getScore());
LK.getSound('claim').play();
// Create new zone to replace claimed one
var newZone = createClaimZone();
claimZones.push(newZone);
game.addChild(newZone);
// Check win condition
if (LK.getScore() >= 25) {
LK.showYouWin();
}
}
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,211 @@
-/****
+/****
+* Classes
+****/
+var Character = Container.expand(function () {
+ var self = Container.call(this);
+ var characterGraphics = self.attachAsset('character', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.targetX = 0;
+ self.targetY = 0;
+ self.moveSpeed = 8;
+ self.update = function () {
+ var dx = self.targetX - self.x;
+ var dy = self.targetY - self.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 5) {
+ var moveX = dx / distance * self.moveSpeed;
+ var moveY = dy / distance * self.moveSpeed;
+ var newX = self.x + moveX;
+ var newY = self.y + moveY;
+ // Keep character within bounds (accounting for character size)
+ if (newX >= 90 && newX <= 1958 && newY >= 90 && newY <= 2642) {
+ self.x = newX;
+ self.y = newY;
+ }
+ }
+ };
+ self.setTarget = function (x, y) {
+ self.targetX = x;
+ self.targetY = y;
+ };
+ return self;
+});
+var ClaimZone = Container.expand(function () {
+ var self = Container.call(this);
+ var zoneGraphics = self.attachAsset('claimZone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var claimText = new Text2('CLAIM', {
+ size: 24,
+ fill: '#FFFFFF'
+ });
+ claimText.anchor.set(0.5, 1);
+ claimText.y = -40;
+ self.addChild(claimText);
+ self.isClaimed = false;
+ self.claim = function () {
+ if (!self.isClaimed) {
+ self.isClaimed = true;
+ self.removeChild(zoneGraphics);
+ self.removeChild(claimText);
+ var claimedGraphics = self.attachAsset('claimedZone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var claimedText = new Text2('CLAIMED', {
+ size: 20,
+ fill: '#FFFFFF'
+ });
+ claimedText.anchor.set(0.5, 1);
+ claimedText.y = -40;
+ self.addChild(claimedText);
+ return true;
+ }
+ return false;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2E8B57
+});
+
+/****
+* Game Code
+****/
+var character = new Character();
+character.x = 1024;
+character.y = 1366;
+game.addChild(character);
+var claimZones = [];
+var totalZones = 15;
+// Create walls around the perimeter
+var walls = [];
+// Top wall
+for (var i = 0; i < 42; i++) {
+ var topWall = LK.getAsset('wall', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: i * 50 + 25,
+ y: 25
+ });
+ game.addChild(topWall);
+ walls.push(topWall);
+}
+// Bottom wall
+for (var i = 0; i < 42; i++) {
+ var bottomWall = LK.getAsset('wall', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: i * 50 + 25,
+ y: 2707
+ });
+ game.addChild(bottomWall);
+ walls.push(bottomWall);
+}
+// Left wall
+for (var i = 1; i < 54; i++) {
+ var leftWall = LK.getAsset('wall', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 25,
+ y: i * 50 + 25
+ });
+ game.addChild(leftWall);
+ walls.push(leftWall);
+}
+// Right wall
+for (var i = 1; i < 54; i++) {
+ var rightWall = LK.getAsset('wall', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 2023,
+ y: i * 50 + 25
+ });
+ game.addChild(rightWall);
+ walls.push(rightWall);
+}
+// Create initial claim zones
+function createClaimZone() {
+ var zone = new ClaimZone();
+ var validPosition = false;
+ var attempts = 0;
+ while (!validPosition && attempts < 50) {
+ zone.x = 150 + Math.random() * 1748;
+ zone.y = 150 + Math.random() * 2432;
+ // Check distance from character
+ var dx = zone.x - character.x;
+ var dy = zone.y - character.y;
+ var distanceFromCharacter = Math.sqrt(dx * dx + dy * dy);
+ // Check distance from other zones
+ var tooClose = false;
+ for (var i = 0; i < claimZones.length; i++) {
+ var otherZone = claimZones[i];
+ var zdx = zone.x - otherZone.x;
+ var zdy = zone.y - otherZone.y;
+ var distanceFromZone = Math.sqrt(zdx * zdx + zdy * zdy);
+ if (distanceFromZone < 200) {
+ tooClose = true;
+ break;
+ }
+ }
+ if (distanceFromCharacter > 150 && !tooClose) {
+ validPosition = true;
+ }
+ attempts++;
+ }
+ return zone;
+}
+// Generate initial claim zones
+for (var i = 0; i < totalZones; i++) {
+ var zone = createClaimZone();
+ claimZones.push(zone);
+ game.addChild(zone);
+}
+// Score display
+var scoreTxt = new Text2('Territory: 0', {
+ size: 60,
+ fill: '#FFFFFF'
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Mouse/touch controls
+game.move = function (x, y, obj) {
+ character.setTarget(x, y);
+};
+game.down = function (x, y, obj) {
+ character.setTarget(x, y);
+};
+// Main game loop
+game.update = function () {
+ // Check for zone claims
+ for (var i = claimZones.length - 1; i >= 0; i--) {
+ var zone = claimZones[i];
+ if (!zone.isClaimed) {
+ var dx = character.x - zone.x;
+ var dy = character.y - zone.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < 50) {
+ if (zone.claim()) {
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText('Territory: ' + LK.getScore());
+ LK.getSound('claim').play();
+ // Create new zone to replace claimed one
+ var newZone = createClaimZone();
+ claimZones.push(newZone);
+ game.addChild(newZone);
+ // Check win condition
+ if (LK.getScore() >= 25) {
+ LK.showYouWin();
+ }
+ }
+ }
+ }
+ }
+};
\ No newline at end of file