User prompt
Add a visible hunger bar ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
When the player enters the house, disable pig spawning and make the ground light brown, like house planks.
User prompt
Make it so that I can move the player in the house too
User prompt
Make it so I need to hold to move, not tap to move, and make the player faster ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make it so that the player needs to be close to the house to enter it
User prompt
Add a player u can move by clicking the left right forward and backwards squares, the player is blue
Code edit (1 edits merged)
Please save this source code
User prompt
Add a player which you can move by clicking the left, right, forward, backwards arrows that show up
Code edit (1 edits merged)
Please save this source code
User prompt
Forest Survivor
Initial prompt
Make a 2d survival game about survving in a forest, you can shoot animals (pink pigs) by clicking them, add trees, when yoh double click a tree it builds a house, when u click on the house it gets u în it, double click on the house floor to get out, when you kill a pink pig he becomes smaller, when he îs dead u can click on him to eat him
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.lifetime = 0;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.lifetime++;
// Remove bullet after 2 seconds
if (self.lifetime > 120) {
self.destroy();
var index = bullets.indexOf(self);
if (index > -1) {
bullets.splice(index, 1);
}
}
};
return self;
});
var House = Container.expand(function () {
var self = Container.call(this);
var houseGraphics = self.attachAsset('house', {
anchorX: 0.5,
anchorY: 1.0
});
var floor = self.addChild(LK.getAsset('houseFloor', {
anchorX: 0.5,
anchorY: 0.5
}));
floor.x = 0;
floor.y = -10;
self.down = function (x, y, obj) {
if (!playerInHouse) {
enterHouse();
}
};
return self;
});
var Pig = Container.expand(function () {
var self = Container.call(this);
var pigGraphics = self.attachAsset('pig', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 3;
self.isDead = false;
self.isEaten = false;
self.originalScale = 1.0;
self.takeDamage = function () {
if (self.isDead) return;
self.health--;
LK.getSound('pigHit').play();
// Shrink the pig
var newScale = self.originalScale * (self.health / 3);
tween(self, {
scaleX: newScale,
scaleY: newScale
}, {
duration: 200
});
// Flash effect
LK.effects.flashObject(self, 0xff0000, 300);
if (self.health <= 0) {
self.die();
}
};
self.die = function () {
self.isDead = true;
LK.getSound('pigDie').play();
tween(pigGraphics, {
tint: 0x666666
}, {
duration: 500
});
};
self.eat = function () {
if (!self.isDead || self.isEaten) return false;
self.isEaten = true;
playerFood += 20;
foodText.setText('Food: ' + playerFood);
tween(self, {
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 500,
onFinish: function onFinish() {
self.destroy();
var index = pigs.indexOf(self);
if (index > -1) {
pigs.splice(index, 1);
}
}
});
return true;
};
self.down = function (x, y, obj) {
if (self.isDead && !self.isEaten) {
self.eat();
} else if (!self.isDead) {
shootAt(self.x, self.y);
self.takeDamage();
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('pig', {
anchorX: 0.5,
anchorY: 0.5,
color: 0x00ff00
});
playerGraphics.tint = 0x00ff00; // Green color for player
self.moveSpeed = 8;
return self;
});
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1.0
});
self.isBuilt = false;
self.lastClickTime = 0;
self.buildHouse = function () {
if (self.isBuilt) return;
self.isBuilt = true;
LK.getSound('buildHouse').play();
// Remove tree and add house
var house = new House();
house.x = self.x;
house.y = self.y;
game.addChild(house);
houses.push(house);
self.destroy();
var index = trees.indexOf(self);
if (index > -1) {
trees.splice(index, 1);
}
};
self.down = function (x, y, obj) {
var currentTime = Date.now();
if (currentTime - self.lastClickTime < 500) {
// Double click detected
self.buildHouse();
}
self.lastClickTime = currentTime;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2d5a2d
});
/****
* Game Code
****/
// Game variables
var pigs = [];
var trees = [];
var houses = [];
var bullets = [];
var playerFood = 100;
var playerInHouse = false;
var houseFloorClickTime = 0;
var player;
// Create player
player = new Player();
player.x = 1024;
player.y = 1366;
game.addChild(player);
// UI Elements
var foodText = new Text2('Food: ' + playerFood, {
size: 60,
fill: 0xFFFFFF
});
foodText.anchor.set(0, 0);
LK.gui.topRight.addChild(foodText);
var instructionText = new Text2('Click pigs to hunt\nDouble-click trees to build', {
size: 40,
fill: 0xFFFF00
});
instructionText.anchor.set(0.5, 0);
instructionText.x = 2048 / 2;
instructionText.y = 50;
game.addChild(instructionText);
// Movement arrows
var upArrow = new Text2('↑', {
size: 80,
fill: 0xFFFFFF
});
upArrow.anchor.set(0.5, 0.5);
upArrow.x = 150;
upArrow.y = 2500;
LK.gui.bottomLeft.addChild(upArrow);
var downArrow = new Text2('↓', {
size: 80,
fill: 0xFFFFFF
});
downArrow.anchor.set(0.5, 0.5);
downArrow.x = 150;
downArrow.y = 2600;
LK.gui.bottomLeft.addChild(downArrow);
var leftArrow = new Text2('←', {
size: 80,
fill: 0xFFFFFF
});
leftArrow.anchor.set(0.5, 0.5);
leftArrow.x = 100;
leftArrow.y = 2550;
LK.gui.bottomLeft.addChild(leftArrow);
var rightArrow = new Text2('→', {
size: 80,
fill: 0xFFFFFF
});
rightArrow.anchor.set(0.5, 0.5);
rightArrow.x = 200;
rightArrow.y = 2550;
LK.gui.bottomLeft.addChild(rightArrow);
// Arrow click handlers
upArrow.down = function () {
if (player.y > 100) player.y -= player.moveSpeed * 5;
};
downArrow.down = function () {
if (player.y < 2632) player.y += player.moveSpeed * 5;
};
leftArrow.down = function () {
if (player.x > 100) player.x -= player.moveSpeed * 5;
};
rightArrow.down = function () {
if (player.x < 1948) player.x += player.moveSpeed * 5;
};
// Initialize forest
function spawnPig() {
var pig = new Pig();
pig.x = Math.random() * 1800 + 124;
pig.y = Math.random() * 2400 + 200;
game.addChild(pig);
pigs.push(pig);
}
function spawnTree() {
var tree = new Tree();
tree.x = Math.random() * 1800 + 124;
tree.y = Math.random() * 2400 + 300;
game.addChild(tree);
trees.push(tree);
}
// Spawn initial entities
for (var i = 0; i < 8; i++) {
spawnPig();
}
for (var i = 0; i < 15; i++) {
spawnTree();
}
// Shooting system
function shootAt(targetX, targetY) {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
var dx = targetX - bullet.x;
var dy = targetY - bullet.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var speed = 15;
bullet.speedX = dx / distance * speed;
bullet.speedY = dy / distance * speed;
game.addChild(bullet);
bullets.push(bullet);
LK.getSound('shoot').play();
}
// House system
function enterHouse() {
if (playerInHouse) return;
playerInHouse = true;
// Hide all game elements except houses
for (var i = 0; i < pigs.length; i++) {
pigs[i].visible = false;
}
for (var i = 0; i < trees.length; i++) {
trees[i].visible = false;
}
for (var i = 0; i < bullets.length; i++) {
bullets[i].visible = false;
}
instructionText.setText('Double-click floor to exit house');
// Show house interior (just the floor for now)
var houseFloor = LK.getAsset('houseFloor', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 8,
scaleY: 20,
x: 1024,
y: 1366
});
game.addChild(houseFloor);
houseFloor.name = 'houseFloor';
}
function exitHouse() {
if (!playerInHouse) return;
playerInHouse = false;
// Show all game elements
for (var i = 0; i < pigs.length; i++) {
pigs[i].visible = true;
}
for (var i = 0; i < trees.length; i++) {
trees[i].visible = true;
}
for (var i = 0; i < bullets.length; i++) {
bullets[i].visible = true;
}
instructionText.setText('Click pigs to hunt\nDouble-click trees to build');
// Remove house floor
var floor = game.children.find(function (child) {
return child.name === 'houseFloor';
});
if (floor) {
game.removeChild(floor);
}
}
// Game event handlers
game.down = function (x, y, obj) {
if (playerInHouse) {
var currentTime = Date.now();
if (currentTime - houseFloorClickTime < 500) {
exitHouse();
}
houseFloorClickTime = currentTime;
}
};
// Spawn timer
var spawnTimer = 0;
// Food depletion timer
var foodTimer = 0;
game.update = function () {
spawnTimer++;
foodTimer++;
// Spawn new pigs occasionally
if (spawnTimer % 600 === 0 && pigs.length < 12) {
spawnPig();
}
// Deplete food over time
if (foodTimer % 180 === 0) {
playerFood--;
if (playerFood < 0) playerFood = 0;
foodText.setText('Food: ' + playerFood);
if (playerFood <= 0) {
LK.showGameOver();
}
}
// Clean up destroyed bullets
for (var i = bullets.length - 1; i >= 0; i--) {
if (!bullets[i].parent) {
bullets.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -117,8 +117,19 @@
}
};
return self;
});
+var Player = Container.expand(function () {
+ var self = Container.call(this);
+ var playerGraphics = self.attachAsset('pig', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ color: 0x00ff00
+ });
+ playerGraphics.tint = 0x00ff00; // Green color for player
+ self.moveSpeed = 8;
+ return self;
+});
var Tree = Container.expand(function () {
var self = Container.call(this);
var treeGraphics = self.attachAsset('tree', {
anchorX: 0.5,
@@ -170,8 +181,14 @@
var bullets = [];
var playerFood = 100;
var playerInHouse = false;
var houseFloorClickTime = 0;
+var player;
+// Create player
+player = new Player();
+player.x = 1024;
+player.y = 1366;
+game.addChild(player);
// UI Elements
var foodText = new Text2('Food: ' + playerFood, {
size: 60,
fill: 0xFFFFFF
@@ -185,8 +202,54 @@
instructionText.anchor.set(0.5, 0);
instructionText.x = 2048 / 2;
instructionText.y = 50;
game.addChild(instructionText);
+// Movement arrows
+var upArrow = new Text2('↑', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+upArrow.anchor.set(0.5, 0.5);
+upArrow.x = 150;
+upArrow.y = 2500;
+LK.gui.bottomLeft.addChild(upArrow);
+var downArrow = new Text2('↓', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+downArrow.anchor.set(0.5, 0.5);
+downArrow.x = 150;
+downArrow.y = 2600;
+LK.gui.bottomLeft.addChild(downArrow);
+var leftArrow = new Text2('←', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+leftArrow.anchor.set(0.5, 0.5);
+leftArrow.x = 100;
+leftArrow.y = 2550;
+LK.gui.bottomLeft.addChild(leftArrow);
+var rightArrow = new Text2('→', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+rightArrow.anchor.set(0.5, 0.5);
+rightArrow.x = 200;
+rightArrow.y = 2550;
+LK.gui.bottomLeft.addChild(rightArrow);
+// Arrow click handlers
+upArrow.down = function () {
+ if (player.y > 100) player.y -= player.moveSpeed * 5;
+};
+downArrow.down = function () {
+ if (player.y < 2632) player.y += player.moveSpeed * 5;
+};
+leftArrow.down = function () {
+ if (player.x > 100) player.x -= player.moveSpeed * 5;
+};
+rightArrow.down = function () {
+ if (player.x < 1948) player.x += player.moveSpeed * 5;
+};
// Initialize forest
function spawnPig() {
var pig = new Pig();
pig.x = Math.random() * 1800 + 124;
@@ -210,10 +273,10 @@
}
// Shooting system
function shootAt(targetX, targetY) {
var bullet = new Bullet();
- bullet.x = 1024;
- bullet.y = 2600;
+ bullet.x = player.x;
+ bullet.y = player.y;
var dx = targetX - bullet.x;
var dy = targetY - bullet.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var speed = 15;
Make a house, with a wood door, the house is made of red wood and the door brown wood, the roof is made of wheat. 2d. High contrast. No shadows
Make a pig. In-Game asset. 2d. High contrast. No shadows
Make a lumberjack. In-Game asset. 2d. High contrast. No shadows
Make a tree. In-Game asset. 2d. High contrast. No shadows