User prompt
Maden boyutunda ağaç yani Wood ve Berries spawnlanmasın ve zombi yerine iskelet spawn olsun ve arka planını siyah yap oranın
User prompt
Maden boyutunda Demir Elmas kömür ruby ve çok fazla taş spawn olsun ve maden boyutuna girmek için bir tuş yarat
User prompt
2. bir kısım olarak Maden boyutunu yarat oradada iskeletler bize ok atsın
User prompt
yazıları daha küçük yapabilirmisin ekrana sığmıyor bazıları
User prompt
Yay için Ok yapmamız gereksin zombi hızını düşür
User prompt
oyunda craft yapabilelim bu kaynakları da Wood Stone Berries gibi alt kısma yaz çalışma masası fırın zırh masası silah masası yapabilelim
User prompt
bunları taş odun ve meyveler gibi bulabilelim haritada vede açık dünyası olsun yani haritayı biraz daha büyüt
User prompt
yeni kaynaklar ekle mesela demir altın elmas ruby zümrüt gibi kömür vb zırh yapabilelim ve açık dünyası olsun
User prompt
geceleri bize saldırmaya zombiler gelsin ve kılıç ve yay üretebilelim
Code edit (1 edits merged)
Please save this source code
User prompt
Craft Survival: Island Escape
Initial prompt
Craft Survival Game island
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
// Arrow projectile
var Arrow = Container.expand(function () {
var self = Container.call(this);
self.type = 'arrow';
self.speed = 38;
self.damage = 18;
self.target = null;
self.lastX = 0;
self.lastY = 0;
self.attachAsset('wood', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.5,
scaleY: 0.2
});
self.children[0].tint = 0xffe066;
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
if (self.target) {
var dx = self.target.x - self.x;
var dy = self.target.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 2) {
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
}
}
};
return self;
});
// Bow weapon
var Bow = Container.expand(function () {
var self = Container.call(this);
self.type = 'bow';
self.damage = 18;
self.range = 600;
self.cooldown = 50;
self.lastAttackTick = -1000;
self.attachAsset('wood', {
anchorX: 0.5,
anchorY: 0.5
});
self.children[0].tint = 0x8fd3ff;
return self;
});
// Bush (for berries)
var Bush = Container.expand(function () {
var self = Container.call(this);
self.type = 'bush';
self.attachAsset('bush', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerSprite = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 18;
self.inventory = {
wood: 0,
stone: 0,
berry: 0,
iron: 0,
gold: 0,
diamond: 0,
ruby: 0,
emerald: 0,
coal: 0,
// Workstations
workbench: 0,
furnace: 0,
armorbench: 0,
weaponbench: 0
};
self.health = 100;
self.hunger = 100;
self.hasShelter = false;
self.hasRaft = false;
self.update = function () {};
return self;
});
// Raft
var Raft = Container.expand(function () {
var self = Container.call(this);
self.attachAsset('raft', {
anchorX: 0.5,
anchorY: 1
});
return self;
});
// Resource base class
var Resource = Container.expand(function () {
var self = Container.call(this);
self.type = '';
self.collected = false;
self.update = function () {};
return self;
});
// Wood resource
var Wood = Resource.expand(function () {
var self = Resource.call(this);
self.type = 'wood';
self.attachAsset('wood', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
// Stone resource
var Stone = Resource.expand(function () {
var self = Resource.call(this);
self.type = 'stone';
self.attachAsset('stone', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
// Berry resource
var Berry = Resource.expand(function () {
var self = Resource.call(this);
self.type = 'berry';
self.attachAsset('berry', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
// Rock (for stone)
var Rock = Container.expand(function () {
var self = Container.call(this);
self.type = 'rock';
self.attachAsset('rock', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
// Shelter
var Shelter = Container.expand(function () {
var self = Container.call(this);
self.attachAsset('shelter', {
anchorX: 0.5,
anchorY: 1
});
return self;
});
// Sword weapon
var Sword = Container.expand(function () {
var self = Container.call(this);
self.type = 'sword';
self.damage = 30;
self.range = 180;
self.cooldown = 30;
self.lastAttackTick = -1000;
self.attachAsset('wood', {
anchorX: 0.5,
anchorY: 0.5
});
self.children[0].tint = 0xcccccc;
return self;
});
// Tree (for wood)
var Tree = Container.expand(function () {
var self = Container.call(this);
self.type = 'tree';
self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1
});
return self;
});
// Zombie enemy (attacks at night)
var Zombie = Container.expand(function () {
var self = Container.call(this);
self.type = 'zombie';
self.speed = 8 + Math.random() * 4;
self.target = null;
self.damage = 12;
self.lastX = 0;
self.lastY = 0;
self.attachAsset('player', {
// reuse player shape, but tint
anchorX: 0.5,
anchorY: 0.5
});
self.children[0].tint = 0x4b2e83; // purple zombie
self.update = function () {
self.lastX = self.x;
self.lastY = self.y;
if (self.target) {
var dx = self.target.x - self.x;
var dy = self.target.y - self.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist > 2) {
self.x += dx / dist * self.speed;
self.y += dy / dist * self.speed;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Sky blue for day
});
/****
* Game Code
****/
// --- Global variables ---
// Shapes for resources, player, and environment
var player;
var resources = [];
var interactables = [];
var shelter = null;
var raft = null;
var day = 1;
var isNight = false;
var nightOverlay;
var hungerTimer;
var dayNightTimer;
var dragging = false;
var dragOffset = {
x: 0,
y: 0
};
var selectedInteractable = null;
// --- Zombies, weapons, arrows ---
var zombies = [];
var zombieSpawnTimer = null;
var playerWeapon = null;
var arrows = [];
// --- UI Elements ---
var healthTxt = new Text2('Health: 100', {
size: 70,
fill: "#fff"
});
healthTxt.anchor.set(0, 0);
LK.gui.top.addChild(healthTxt);
var hungerTxt = new Text2('Hunger: 100', {
size: 70,
fill: "#fff"
});
hungerTxt.anchor.set(0, 0);
LK.gui.top.addChild(hungerTxt);
hungerTxt.y = 80;
var dayTxt = new Text2('Day: 1', {
size: 70,
fill: "#fff"
});
dayTxt.anchor.set(0, 0);
LK.gui.top.addChild(dayTxt);
dayTxt.y = 160;
// --- Inventory UI for all resources ---
var invTxt = new Text2('Wood: 0 Stone: 0 Berries: 0 Iron: 0 Gold: 0 Diamond: 0 Ruby: 0 Emerald: 0 Coal: 0', {
size: 60,
fill: "#fff"
});
invTxt.anchor.set(0.5, 0);
LK.gui.bottom.addChild(invTxt);
invTxt.y = -120;
// --- Crafting UI for workstations ---
var craftWorkbenchBtn = new Text2('Craft Workbench', {
size: 60,
fill: 0xFFE4B5
});
craftWorkbenchBtn.anchor.set(0.5, 0);
craftWorkbenchBtn.y = -620;
craftWorkbenchBtn.x = 0;
LK.gui.bottom.addChild(craftWorkbenchBtn);
var craftFurnaceBtn = new Text2('Craft Furnace', {
size: 60,
fill: 0xFFE4B5
});
craftFurnaceBtn.anchor.set(0.5, 0);
craftFurnaceBtn.y = -700;
craftFurnaceBtn.x = 0;
LK.gui.bottom.addChild(craftFurnaceBtn);
var craftArmorBenchBtn = new Text2('Craft Armor Bench', {
size: 60,
fill: 0xFFE4B5
});
craftArmorBenchBtn.anchor.set(0.5, 0);
craftArmorBenchBtn.y = -780;
craftArmorBenchBtn.x = 0;
LK.gui.bottom.addChild(craftArmorBenchBtn);
var craftWeaponBenchBtn = new Text2('Craft Weapon Bench', {
size: 60,
fill: 0xFFE4B5
});
craftWeaponBenchBtn.anchor.set(0.5, 0);
craftWeaponBenchBtn.y = -860;
craftWeaponBenchBtn.x = 0;
LK.gui.bottom.addChild(craftWeaponBenchBtn);
// --- Helper functions ---
function updateUI() {
healthTxt.setText('Health: ' + Math.max(0, Math.round(player.health)));
hungerTxt.setText('Hunger: ' + Math.max(0, Math.round(player.hunger)));
dayTxt.setText('Day: ' + day);
invTxt.setText('Wood: ' + player.inventory.wood + ' Stone: ' + player.inventory.stone + ' Berries: ' + player.inventory.berry + ' Iron: ' + player.inventory.iron + ' Gold: ' + player.inventory.gold + ' Diamond: ' + player.inventory.diamond + ' Ruby: ' + player.inventory.ruby + ' Emerald: ' + player.inventory.emerald + ' Coal: ' + player.inventory.coal);
}
function spawnResource(type, x, y) {
var res;
if (type === 'wood') {
res = new Wood();
} else if (type === 'stone') {
res = new Stone();
} else if (type === 'berry') {
res = new Berry();
} else if (type === 'iron') {
res = new Resource();
res.type = 'iron';
res.attachAsset('stone', {
anchorX: 0.5,
anchorY: 0.5
});
res.children[0].tint = 0xaaaaaa;
} else if (type === 'gold') {
res = new Resource();
res.type = 'gold';
res.attachAsset('stone', {
anchorX: 0.5,
anchorY: 0.5
});
res.children[0].tint = 0xffd700;
} else if (type === 'diamond') {
res = new Resource();
res.type = 'diamond';
res.attachAsset('stone', {
anchorX: 0.5,
anchorY: 0.5
});
res.children[0].tint = 0x00ffff;
} else if (type === 'ruby') {
res = new Resource();
res.type = 'ruby';
res.attachAsset('stone', {
anchorX: 0.5,
anchorY: 0.5
});
res.children[0].tint = 0xff0044;
} else if (type === 'emerald') {
res = new Resource();
res.type = 'emerald';
res.attachAsset('stone', {
anchorX: 0.5,
anchorY: 0.5
});
res.children[0].tint = 0x00ff44;
} else if (type === 'coal') {
res = new Resource();
res.type = 'coal';
res.attachAsset('stone', {
anchorX: 0.5,
anchorY: 0.5
});
res.children[0].tint = 0x222222;
}
res.x = x;
res.y = y;
resources.push(res);
game.addChild(res);
}
function spawnInteractable(type, x, y) {
var obj;
if (type === 'tree') {
obj = new Tree();
} else if (type === 'rock') {
obj = new Rock();
} else if (type === 'bush') {
obj = new Bush();
}
obj.x = x;
obj.y = y;
interactables.push(obj);
game.addChild(obj);
}
function removeResource(res) {
res.destroy();
var idx = resources.indexOf(res);
if (idx !== -1) resources.splice(idx, 1);
}
function removeInteractable(obj) {
obj.destroy();
var idx = interactables.indexOf(obj);
if (idx !== -1) interactables.splice(idx, 1);
}
function showNightOverlay() {
if (!nightOverlay) {
nightOverlay = LK.getAsset('nightOverlay', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
nightOverlay.alpha = 0.5;
game.addChild(nightOverlay);
} else {
nightOverlay.alpha = 0.5;
}
}
function hideNightOverlay() {
if (nightOverlay) nightOverlay.alpha = 0;
}
// --- Zombie spawning and cleanup ---
function spawnZombie() {
var z = new Zombie();
// Spawn at random edge
var edge = Math.floor(Math.random() * 4);
if (edge === 0) {
// left
z.x = 0;
z.y = 400 + Math.random() * 1800;
} else if (edge === 1) {
// right
z.x = 2048;
z.y = 400 + Math.random() * 1800;
} else if (edge === 2) {
// top
z.x = 200 + Math.random() * 1600;
z.y = 0;
} else {
// bottom
z.x = 200 + Math.random() * 1600;
z.y = 2732;
}
z.target = player;
zombies.push(z);
game.addChild(z);
}
function clearZombies() {
for (var i = 0; i < zombies.length; i++) {
zombies[i].destroy();
}
zombies = [];
}
function startZombieSpawning() {
zombieSpawnTimer = LK.setInterval(function () {
if (isNight) {
spawnZombie();
}
}, 2500);
}
function stopZombieSpawning() {
if (zombieSpawnTimer) LK.clearInterval(zombieSpawnTimer);
clearZombies();
}
function startDayNightCycle() {
dayNightTimer = LK.setInterval(function () {
isNight = !isNight;
if (isNight) {
showNightOverlay();
startZombieSpawning();
} else {
hideNightOverlay();
stopZombieSpawning();
day += 1;
updateUI();
}
}, 20000); // 20 seconds per phase
}
function stopDayNightCycle() {
if (dayNightTimer) LK.clearInterval(dayNightTimer);
}
function startHunger() {
hungerTimer = LK.setInterval(function () {
if (isNight && !player.hasShelter) {
player.health -= 2;
}
player.hunger -= 1;
if (player.hunger <= 0) {
player.health -= 2;
}
if (player.health <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
updateUI();
}, 1200);
}
function stopHunger() {
if (hungerTimer) LK.clearInterval(hungerTimer);
}
function tryCollectResource(res) {
if (res.type === 'wood') {
player.inventory.wood += 1;
} else if (res.type === 'stone') {
player.inventory.stone += 1;
} else if (res.type === 'berry') {
player.inventory.berry += 1;
player.hunger = Math.min(100, player.hunger + 10);
} else if (res.type === 'iron') {
player.inventory.iron += 1;
} else if (res.type === 'gold') {
player.inventory.gold += 1;
} else if (res.type === 'diamond') {
player.inventory.diamond += 1;
} else if (res.type === 'ruby') {
player.inventory.ruby += 1;
} else if (res.type === 'emerald') {
player.inventory.emerald += 1;
} else if (res.type === 'coal') {
player.inventory.coal += 1;
}
removeResource(res);
updateUI();
}
function tryInteract(obj) {
if (obj.type === 'tree') {
spawnResource('wood', obj.x + Math.random() * 60 - 30, obj.y + 80);
removeInteractable(obj);
} else if (obj.type === 'rock') {
spawnResource('stone', obj.x, obj.y + 40);
removeInteractable(obj);
} else if (obj.type === 'bush') {
spawnResource('berry', obj.x, obj.y + 20);
removeInteractable(obj);
}
}
function canBuildShelter() {
return !player.hasShelter && player.inventory.wood >= 5 && player.inventory.stone >= 3;
}
function buildShelter() {
player.inventory.wood -= 5;
player.inventory.stone -= 3;
player.hasShelter = true;
shelter = new Shelter();
shelter.x = player.x + 180;
shelter.y = player.y + 100;
game.addChild(shelter);
updateUI();
}
function canBuildRaft() {
return !player.hasRaft && player.inventory.wood >= 10 && player.inventory.stone >= 5;
}
function buildRaft() {
player.inventory.wood -= 10;
player.inventory.stone -= 5;
player.hasRaft = true;
raft = new Raft();
raft.x = 2048 - 300;
raft.y = 2732 - 200;
game.addChild(raft);
updateUI();
}
function tryEscape() {
if (player.hasRaft && Math.abs(player.x - raft.x) < 150 && Math.abs(player.y - raft.y) < 150) {
LK.showYouWin();
}
}
// --- Game Setup ---
function setupIsland() {
// Place trees, rocks, bushes randomly
for (var i = 0; i < 6; i++) {
spawnInteractable('tree', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
}
for (var i = 0; i < 5; i++) {
spawnInteractable('rock', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
}
for (var i = 0; i < 4; i++) {
spawnInteractable('bush', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
}
// New resource spawns
for (var i = 0; i < 3; i++) {
spawnResource('iron', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
spawnResource('gold', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
spawnResource('diamond', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
spawnResource('ruby', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
spawnResource('emerald', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
spawnResource('coal', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
}
}
// --- Player Setup ---
player = new Player();
player.x = 2048 / 2;
player.y = 2732 / 2;
game.addChild(player);
// --- Initial Island ---
setupIsland();
updateUI();
startDayNightCycle();
startHunger();
// --- Touch Controls ---
game.down = function (x, y, obj) {
// Don't allow dragging from top left 100x100
if (x < 100 && y < 100) return;
// --- WEAPON ATTACK ---
if (playerWeapon) {
// Sword: tap near player to attack
if (playerWeapon.type === 'sword') {
if (LK.ticks - playerWeapon.lastAttackTick > playerWeapon.cooldown) {
for (var i = zombies.length - 1; i >= 0; i--) {
var z = zombies[i];
var dx = z.x - player.x;
var dy = z.y - player.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < playerWeapon.range) {
z.destroy();
zombies.splice(i, 1);
playerWeapon.lastAttackTick = LK.ticks;
LK.effects.flashObject(playerWeapon, 0xffff00, 200);
break;
}
}
}
}
// Bow: tap anywhere to shoot arrow toward tap
else if (playerWeapon.type === 'bow') {
if (LK.ticks - playerWeapon.lastAttackTick > playerWeapon.cooldown) {
// Find closest zombie in range
var closest = null;
var minDist = 99999;
for (var i = 0; i < zombies.length; i++) {
var z = zombies[i];
var dx = z.x - player.x;
var dy = z.y - player.y;
var dist = Math.sqrt(dx * dx + dy * dy);
if (dist < playerWeapon.range && dist < minDist) {
closest = z;
minDist = dist;
}
}
if (closest) {
var arrow = new Arrow();
arrow.x = player.x + 60;
arrow.y = player.y;
arrow.target = closest;
arrows.push(arrow);
game.addChild(arrow);
playerWeapon.lastAttackTick = LK.ticks;
LK.effects.flashObject(playerWeapon, 0x66ccff, 200);
}
}
}
}
// Check if touching interactable
for (var i = 0; i < interactables.length; i++) {
var it = interactables[i];
if (player.intersects(it)) {
selectedInteractable = it;
return;
}
}
// Check if touching resource
for (var j = 0; j < resources.length; j++) {
var res = resources[j];
if (player.intersects(res)) {
tryCollectResource(res);
return;
}
}
// Check if touching raft
if (raft && player.intersects(raft)) {
tryEscape();
return;
}
// Start dragging player
dragging = true;
dragOffset.x = x - player.x;
dragOffset.y = y - player.y;
};
game.move = function (x, y, obj) {
if (dragging) {
player.x = Math.max(60, Math.min(2048 - 60, x - dragOffset.x));
player.y = Math.max(120, Math.min(2732 - 60, y - dragOffset.y));
// If shelter exists, keep it near player
if (shelter) {
shelter.x = player.x + 180;
shelter.y = player.y + 100;
}
}
};
game.up = function (x, y, obj) {
dragging = false;
if (selectedInteractable) {
if (player.intersects(selectedInteractable)) {
tryInteract(selectedInteractable);
}
selectedInteractable = null;
}
};
// --- Crafting Buttons ---
var craftShelterBtn = new Text2('Build Shelter', {
size: 70,
fill: 0xFFE4B5
});
craftShelterBtn.anchor.set(0.5, 0);
craftShelterBtn.y = -220;
craftShelterBtn.x = 0;
LK.gui.bottom.addChild(craftShelterBtn);
var craftRaftBtn = new Text2('Build Raft', {
size: 70,
fill: 0xFFE4B5
});
craftRaftBtn.anchor.set(0.5, 0);
craftRaftBtn.y = -320;
craftRaftBtn.x = 0;
LK.gui.bottom.addChild(craftRaftBtn);
// --- Craft Sword and Bow Buttons ---
var craftSwordBtn = new Text2('Craft Sword', {
size: 70,
fill: 0xeeeeee
});
craftSwordBtn.anchor.set(0.5, 0);
craftSwordBtn.y = -420;
craftSwordBtn.x = 0;
LK.gui.bottom.addChild(craftSwordBtn);
var craftBowBtn = new Text2('Craft Bow', {
size: 70,
fill: 0xeeeeee
});
craftBowBtn.anchor.set(0.5, 0);
craftBowBtn.y = -520;
craftBowBtn.x = 0;
LK.gui.bottom.addChild(craftBowBtn);
// --- Crafting logic for workstations ---
function canCraftWorkbench() {
return player.inventory.wood >= 6 && player.inventory.stone >= 2;
}
function canCraftFurnace() {
return player.inventory.stone >= 8 && player.inventory.coal >= 2;
}
function canCraftArmorBench() {
return player.inventory.wood >= 4 && player.inventory.iron >= 2;
}
function canCraftWeaponBench() {
return player.inventory.wood >= 4 && player.inventory.stone >= 2 && player.inventory.iron >= 1;
}
function craftWorkbench() {
player.inventory.wood -= 6;
player.inventory.stone -= 2;
player.inventory.workbench += 1;
updateUI();
}
function craftFurnace() {
player.inventory.stone -= 8;
player.inventory.coal -= 2;
player.inventory.furnace += 1;
updateUI();
}
function craftArmorBench() {
player.inventory.wood -= 4;
player.inventory.iron -= 2;
player.inventory.armorbench += 1;
updateUI();
}
function craftWeaponBench() {
player.inventory.wood -= 4;
player.inventory.stone -= 2;
player.inventory.iron -= 1;
player.inventory.weaponbench += 1;
updateUI();
}
craftWorkbenchBtn.down = function (x, y, obj) {
if (canCraftWorkbench()) {
craftWorkbench();
}
};
craftFurnaceBtn.down = function (x, y, obj) {
if (canCraftFurnace()) {
craftFurnace();
}
};
craftArmorBenchBtn.down = function (x, y, obj) {
if (canCraftArmorBench()) {
craftArmorBench();
}
};
craftWeaponBenchBtn.down = function (x, y, obj) {
if (canCraftWeaponBench()) {
craftWeaponBench();
}
};
craftShelterBtn.down = function (x, y, obj) {
if (canBuildShelter()) {
buildShelter();
}
};
craftRaftBtn.down = function (x, y, obj) {
if (canBuildRaft()) {
buildRaft();
}
};
// --- Crafting logic for sword and bow ---
function canCraftSword() {
return (!playerWeapon || playerWeapon.type !== 'sword') && player.inventory.wood >= 3 && player.inventory.stone >= 2;
}
function canCraftBow() {
return (!playerWeapon || playerWeapon.type !== 'bow') && player.inventory.wood >= 4 && player.inventory.berry >= 2;
}
function craftSword() {
player.inventory.wood -= 3;
player.inventory.stone -= 2;
if (playerWeapon) {
playerWeapon.destroy();
}
playerWeapon = new Sword();
playerWeapon.x = player.x + 60;
playerWeapon.y = player.y;
game.addChild(playerWeapon);
updateUI();
}
function craftBow() {
player.inventory.wood -= 4;
player.inventory.berry -= 2;
if (playerWeapon) {
playerWeapon.destroy();
}
playerWeapon = new Bow();
playerWeapon.x = player.x + 60;
playerWeapon.y = player.y;
game.addChild(playerWeapon);
updateUI();
}
craftSwordBtn.down = function (x, y, obj) {
if (canCraftSword()) {
craftSword();
}
};
craftBowBtn.down = function (x, y, obj) {
if (canCraftBow()) {
craftBow();
}
};
// --- Game Update Loop ---
game.update = function () {
// Randomly respawn resources
if (LK.ticks % 180 === 0) {
var t = Math.random();
if (t < 0.33) {
spawnInteractable('tree', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
} else if (t < 0.66) {
spawnInteractable('rock', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
} else {
spawnInteractable('bush', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
}
}
// --- ZOMBIE LOGIC ---
for (var i = zombies.length - 1; i >= 0; i--) {
var z = zombies[i];
z.update();
// If zombie reaches player
if (z.lastWasIntersecting === undefined) z.lastWasIntersecting = false;
var nowIntersect = z.intersects(player);
if (!z.lastWasIntersecting && nowIntersect) {
if (!player.hasShelter) {
player.health -= z.damage;
LK.effects.flashObject(player, 0xff0000, 400);
updateUI();
if (player.health <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}
z.lastWasIntersecting = nowIntersect;
// Remove zombie if dead or off screen
if (z.x < -100 || z.x > 2148 || z.y < -100 || z.y > 2832) {
z.destroy();
zombies.splice(i, 1);
}
}
// --- ARROW LOGIC ---
for (var j = arrows.length - 1; j >= 0; j--) {
var a = arrows[j];
a.update();
// Hit zombie?
for (var k = zombies.length - 1; k >= 0; k--) {
var z = zombies[k];
if (a.intersects(z)) {
z.destroy();
zombies.splice(k, 1);
a.destroy();
arrows.splice(j, 1);
break;
}
}
// Remove arrow if off screen
if (a.x < -100 || a.x > 2148 || a.y < -100 || a.y > 2832) {
a.destroy();
arrows.splice(j, 1);
}
}
// --- WEAPON FOLLOW PLAYER ---
if (playerWeapon) {
playerWeapon.x = player.x + 60;
playerWeapon.y = player.y;
}
// If night and no shelter, health drops faster
if (isNight && !player.hasShelter) {
healthTxt.tint = 0xff4444;
} else {
healthTxt.tint = 0xffffff;
}
// If raft built, show escape hint
if (player.hasRaft && raft) {
// Optionally, could show a message
}
};
// --- Cleanup on Game Over/Win ---
LK.on('gameover', function () {
stopDayNightCycle();
stopHunger();
stopZombieSpawning();
clearZombies();
for (var i = 0; i < arrows.length; i++) {
arrows[i].destroy();
}
arrows = [];
if (playerWeapon) {
playerWeapon.destroy();
playerWeapon = null;
}
});
LK.on('youwin', function () {
stopDayNightCycle();
stopHunger();
stopZombieSpawning();
clearZombies();
for (var i = 0; i < arrows.length; i++) {
arrows[i].destroy();
}
arrows = [];
if (playerWeapon) {
playerWeapon.destroy();
playerWeapon = null;
}
}); ===================================================================
--- original.js
+++ change.js
@@ -73,9 +73,20 @@
self.speed = 18;
self.inventory = {
wood: 0,
stone: 0,
- berry: 0
+ berry: 0,
+ iron: 0,
+ gold: 0,
+ diamond: 0,
+ ruby: 0,
+ emerald: 0,
+ coal: 0,
+ // Workstations
+ workbench: 0,
+ furnace: 0,
+ armorbench: 0,
+ weaponbench: 0
};
self.health = 100;
self.hunger = 100;
self.hasShelter = false;
@@ -214,10 +225,10 @@
/****
* Game Code
****/
-// Shapes for resources, player, and environment
// --- Global variables ---
+// Shapes for resources, player, and environment
var player;
var resources = [];
var interactables = [];
var shelter = null;
@@ -258,21 +269,55 @@
});
dayTxt.anchor.set(0, 0);
LK.gui.top.addChild(dayTxt);
dayTxt.y = 160;
-var invTxt = new Text2('Wood: 0 Stone: 0 Berries: 0', {
+// --- Inventory UI for all resources ---
+var invTxt = new Text2('Wood: 0 Stone: 0 Berries: 0 Iron: 0 Gold: 0 Diamond: 0 Ruby: 0 Emerald: 0 Coal: 0', {
size: 60,
fill: "#fff"
});
invTxt.anchor.set(0.5, 0);
LK.gui.bottom.addChild(invTxt);
invTxt.y = -120;
+// --- Crafting UI for workstations ---
+var craftWorkbenchBtn = new Text2('Craft Workbench', {
+ size: 60,
+ fill: 0xFFE4B5
+});
+craftWorkbenchBtn.anchor.set(0.5, 0);
+craftWorkbenchBtn.y = -620;
+craftWorkbenchBtn.x = 0;
+LK.gui.bottom.addChild(craftWorkbenchBtn);
+var craftFurnaceBtn = new Text2('Craft Furnace', {
+ size: 60,
+ fill: 0xFFE4B5
+});
+craftFurnaceBtn.anchor.set(0.5, 0);
+craftFurnaceBtn.y = -700;
+craftFurnaceBtn.x = 0;
+LK.gui.bottom.addChild(craftFurnaceBtn);
+var craftArmorBenchBtn = new Text2('Craft Armor Bench', {
+ size: 60,
+ fill: 0xFFE4B5
+});
+craftArmorBenchBtn.anchor.set(0.5, 0);
+craftArmorBenchBtn.y = -780;
+craftArmorBenchBtn.x = 0;
+LK.gui.bottom.addChild(craftArmorBenchBtn);
+var craftWeaponBenchBtn = new Text2('Craft Weapon Bench', {
+ size: 60,
+ fill: 0xFFE4B5
+});
+craftWeaponBenchBtn.anchor.set(0.5, 0);
+craftWeaponBenchBtn.y = -860;
+craftWeaponBenchBtn.x = 0;
+LK.gui.bottom.addChild(craftWeaponBenchBtn);
// --- Helper functions ---
function updateUI() {
healthTxt.setText('Health: ' + Math.max(0, Math.round(player.health)));
hungerTxt.setText('Hunger: ' + Math.max(0, Math.round(player.hunger)));
dayTxt.setText('Day: ' + day);
- invTxt.setText('Wood: ' + player.inventory.wood + ' Stone: ' + player.inventory.stone + ' Berries: ' + player.inventory.berry);
+ invTxt.setText('Wood: ' + player.inventory.wood + ' Stone: ' + player.inventory.stone + ' Berries: ' + player.inventory.berry + ' Iron: ' + player.inventory.iron + ' Gold: ' + player.inventory.gold + ' Diamond: ' + player.inventory.diamond + ' Ruby: ' + player.inventory.ruby + ' Emerald: ' + player.inventory.emerald + ' Coal: ' + player.inventory.coal);
}
function spawnResource(type, x, y) {
var res;
if (type === 'wood') {
@@ -280,8 +325,56 @@
} else if (type === 'stone') {
res = new Stone();
} else if (type === 'berry') {
res = new Berry();
+ } else if (type === 'iron') {
+ res = new Resource();
+ res.type = 'iron';
+ res.attachAsset('stone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ res.children[0].tint = 0xaaaaaa;
+ } else if (type === 'gold') {
+ res = new Resource();
+ res.type = 'gold';
+ res.attachAsset('stone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ res.children[0].tint = 0xffd700;
+ } else if (type === 'diamond') {
+ res = new Resource();
+ res.type = 'diamond';
+ res.attachAsset('stone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ res.children[0].tint = 0x00ffff;
+ } else if (type === 'ruby') {
+ res = new Resource();
+ res.type = 'ruby';
+ res.attachAsset('stone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ res.children[0].tint = 0xff0044;
+ } else if (type === 'emerald') {
+ res = new Resource();
+ res.type = 'emerald';
+ res.attachAsset('stone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ res.children[0].tint = 0x00ff44;
+ } else if (type === 'coal') {
+ res = new Resource();
+ res.type = 'coal';
+ res.attachAsset('stone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ res.children[0].tint = 0x222222;
}
res.x = x;
res.y = y;
resources.push(res);
@@ -414,8 +507,20 @@
player.inventory.stone += 1;
} else if (res.type === 'berry') {
player.inventory.berry += 1;
player.hunger = Math.min(100, player.hunger + 10);
+ } else if (res.type === 'iron') {
+ player.inventory.iron += 1;
+ } else if (res.type === 'gold') {
+ player.inventory.gold += 1;
+ } else if (res.type === 'diamond') {
+ player.inventory.diamond += 1;
+ } else if (res.type === 'ruby') {
+ player.inventory.ruby += 1;
+ } else if (res.type === 'emerald') {
+ player.inventory.emerald += 1;
+ } else if (res.type === 'coal') {
+ player.inventory.coal += 1;
}
removeResource(res);
updateUI();
}
@@ -473,8 +578,17 @@
}
for (var i = 0; i < 4; i++) {
spawnInteractable('bush', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
}
+ // New resource spawns
+ for (var i = 0; i < 3; i++) {
+ spawnResource('iron', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
+ spawnResource('gold', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
+ spawnResource('diamond', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
+ spawnResource('ruby', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
+ spawnResource('emerald', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
+ spawnResource('coal', 200 + Math.random() * 1600, 400 + Math.random() * 1800);
+ }
}
// --- Player Setup ---
player = new Player();
player.x = 2048 / 2;
@@ -617,8 +731,66 @@
craftBowBtn.anchor.set(0.5, 0);
craftBowBtn.y = -520;
craftBowBtn.x = 0;
LK.gui.bottom.addChild(craftBowBtn);
+// --- Crafting logic for workstations ---
+function canCraftWorkbench() {
+ return player.inventory.wood >= 6 && player.inventory.stone >= 2;
+}
+function canCraftFurnace() {
+ return player.inventory.stone >= 8 && player.inventory.coal >= 2;
+}
+function canCraftArmorBench() {
+ return player.inventory.wood >= 4 && player.inventory.iron >= 2;
+}
+function canCraftWeaponBench() {
+ return player.inventory.wood >= 4 && player.inventory.stone >= 2 && player.inventory.iron >= 1;
+}
+function craftWorkbench() {
+ player.inventory.wood -= 6;
+ player.inventory.stone -= 2;
+ player.inventory.workbench += 1;
+ updateUI();
+}
+function craftFurnace() {
+ player.inventory.stone -= 8;
+ player.inventory.coal -= 2;
+ player.inventory.furnace += 1;
+ updateUI();
+}
+function craftArmorBench() {
+ player.inventory.wood -= 4;
+ player.inventory.iron -= 2;
+ player.inventory.armorbench += 1;
+ updateUI();
+}
+function craftWeaponBench() {
+ player.inventory.wood -= 4;
+ player.inventory.stone -= 2;
+ player.inventory.iron -= 1;
+ player.inventory.weaponbench += 1;
+ updateUI();
+}
+craftWorkbenchBtn.down = function (x, y, obj) {
+ if (canCraftWorkbench()) {
+ craftWorkbench();
+ }
+};
+craftFurnaceBtn.down = function (x, y, obj) {
+ if (canCraftFurnace()) {
+ craftFurnace();
+ }
+};
+craftArmorBenchBtn.down = function (x, y, obj) {
+ if (canCraftArmorBench()) {
+ craftArmorBench();
+ }
+};
+craftWeaponBenchBtn.down = function (x, y, obj) {
+ if (canCraftWeaponBench()) {
+ craftWeaponBench();
+ }
+};
craftShelterBtn.down = function (x, y, obj) {
if (canBuildShelter()) {
buildShelter();
}
@@ -629,12 +801,12 @@
}
};
// --- Crafting logic for sword and bow ---
function canCraftSword() {
- return !playerWeapon || playerWeapon.type !== 'sword' && player.inventory.wood >= 3 && player.inventory.stone >= 2;
+ return (!playerWeapon || playerWeapon.type !== 'sword') && player.inventory.wood >= 3 && player.inventory.stone >= 2;
}
function canCraftBow() {
- return !playerWeapon || playerWeapon.type !== 'bow' && player.inventory.wood >= 4 && player.inventory.berry >= 2;
+ return (!playerWeapon || playerWeapon.type !== 'bow') && player.inventory.wood >= 4 && player.inventory.berry >= 2;
}
function craftSword() {
player.inventory.wood -= 3;
player.inventory.stone -= 2;