/****
* 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 ControlButton = Container.expand(function (direction) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = direction;
// Add directional indicator
var arrow = new Text2(direction === 'left' ? '←' : direction === 'right' ? '→' : direction === 'up' ? '↑' : '↓', {
size: 60,
fill: 0xFFFFFF
});
arrow.anchor.set(0.5, 0.5);
self.addChild(arrow);
self.down = function (x, y, obj) {
// Set button state to held
if (direction === 'left') {
leftButtonHeld = true;
} else if (direction === 'right') {
rightButtonHeld = true;
} else if (direction === 'up') {
upButtonHeld = true;
} else if (direction === 'down') {
downButtonHeld = true;
}
// Visual feedback - button pressed
tween.stop(self, {
scaleX: true,
scaleY: true
});
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
self.up = function (x, y, obj) {
// Set button state to not held
if (direction === 'left') {
leftButtonHeld = false;
} else if (direction === 'right') {
rightButtonHeld = false;
} else if (direction === 'up') {
upButtonHeld = false;
} else if (direction === 'down') {
downButtonHeld = false;
}
// Visual feedback - button released
tween.stop(self, {
scaleX: true,
scaleY: true
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
};
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) {
// Check if player is close enough to the house
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var maxDistance = 150; // Player must be within 150 pixels of the house
if (distance <= maxDistance) {
enterHouse();
}
}
};
return self;
});
var HungerBar = Container.expand(function () {
var self = Container.call(this);
// Background bar
var background = self.attachAsset('hungerBarBg', {
anchorX: 0,
anchorY: 0
});
// Fill bar (green to red based on hunger level)
var fill = self.attachAsset('hungerBarFill', {
anchorX: 0,
anchorY: 0,
x: 1,
y: 1
});
self.maxFood = 100;
self.currentFood = 100;
self.updateHunger = function (foodValue) {
self.currentFood = foodValue;
var percentage = Math.max(0, self.currentFood / self.maxFood);
// Update fill width based on percentage
fill.scaleX = percentage;
// Change color based on hunger level
if (percentage > 0.6) {
fill.tint = 0x00ff00; // Green
} else if (percentage > 0.3) {
fill.tint = 0xffff00; // Yellow
} else {
fill.tint = 0xff0000; // Red
}
};
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);
hungerBar.updateHunger(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('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.moveLeft = function () {
self.x -= self.speed;
if (self.x < 30) self.x = 30;
};
self.moveRight = function () {
self.x += self.speed;
if (self.x > 2018) self.x = 2018;
};
self.moveUp = function () {
self.y -= self.speed;
if (self.y < 30) self.y = 30;
};
self.moveDown = function () {
self.y += self.speed;
if (self.y > 2702) self.y = 2702;
};
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 pigSpawningEnabled = true;
var houseFloorClickTime = 0;
var player;
var controlButtons = [];
// Button state tracking for hold-to-move
var leftButtonHeld = false;
var rightButtonHeld = false;
var upButtonHeld = false;
var downButtonHeld = false;
// UI Elements
var foodText = new Text2('Food: ' + playerFood, {
size: 60,
fill: 0xFFFFFF
});
foodText.anchor.set(0, 0);
LK.gui.topRight.addChild(foodText);
// Create hunger bar
var hungerBar = new HungerBar();
hungerBar.x = -150; // Center it relative to topRight
hungerBar.y = 80; // Position below the food text
LK.gui.topRight.addChild(hungerBar);
// Add hunger bar label
var hungerLabel = new Text2('Hunger:', {
size: 40,
fill: 0xFFFFFF
});
hungerLabel.anchor.set(1, 0);
hungerLabel.x = -160; // Position to the left of the bar
hungerLabel.y = 85;
LK.gui.topRight.addChild(hungerLabel);
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);
// 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();
}
// Initialize player
player = new Player();
player.x = 1024;
player.y = 1366;
game.addChild(player);
// Create control buttons
var leftButton = new ControlButton('left');
leftButton.x = 200;
leftButton.y = 2500;
game.addChild(leftButton);
controlButtons.push(leftButton);
var rightButton = new ControlButton('right');
rightButton.x = 400;
rightButton.y = 2500;
game.addChild(rightButton);
controlButtons.push(rightButton);
var upButton = new ControlButton('up');
upButton.x = 300;
upButton.y = 2400;
game.addChild(upButton);
controlButtons.push(upButton);
var downButton = new ControlButton('down');
downButton.x = 300;
downButton.y = 2600;
game.addChild(downButton);
controlButtons.push(downButton);
// 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;
// Disable pig spawning
pigSpawningEnabled = false;
// Change background to light brown (house planks color)
game.setBackgroundColor(0x8b7355);
// 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;
}
player.visible = true;
for (var i = 0; i < controlButtons.length; i++) {
controlButtons[i].visible = true;
}
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;
// Re-enable pig spawning
pigSpawningEnabled = true;
// Restore forest background color
game.setBackgroundColor(0x2d5a2d);
// 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;
}
player.visible = true;
for (var i = 0; i < controlButtons.length; i++) {
controlButtons[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++;
// Handle continuous movement based on held buttons
if (leftButtonHeld) {
player.moveLeft();
}
if (rightButtonHeld) {
player.moveRight();
}
if (upButtonHeld) {
player.moveUp();
}
if (downButtonHeld) {
player.moveDown();
}
// Spawn new pigs occasionally (only if spawning is enabled and not in house)
if (spawnTimer % 600 === 0 && pigs.length < 12 && pigSpawningEnabled) {
spawnPig();
}
// Deplete food over time
if (foodTimer % 180 === 0) {
playerFood--;
if (playerFood < 0) {
playerFood = 0;
}
foodText.setText('Food: ' + playerFood);
hungerBar.updateHunger(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);
}
}
}; /****
* 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 ControlButton = Container.expand(function (direction) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = direction;
// Add directional indicator
var arrow = new Text2(direction === 'left' ? '←' : direction === 'right' ? '→' : direction === 'up' ? '↑' : '↓', {
size: 60,
fill: 0xFFFFFF
});
arrow.anchor.set(0.5, 0.5);
self.addChild(arrow);
self.down = function (x, y, obj) {
// Set button state to held
if (direction === 'left') {
leftButtonHeld = true;
} else if (direction === 'right') {
rightButtonHeld = true;
} else if (direction === 'up') {
upButtonHeld = true;
} else if (direction === 'down') {
downButtonHeld = true;
}
// Visual feedback - button pressed
tween.stop(self, {
scaleX: true,
scaleY: true
});
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
};
self.up = function (x, y, obj) {
// Set button state to not held
if (direction === 'left') {
leftButtonHeld = false;
} else if (direction === 'right') {
rightButtonHeld = false;
} else if (direction === 'up') {
upButtonHeld = false;
} else if (direction === 'down') {
downButtonHeld = false;
}
// Visual feedback - button released
tween.stop(self, {
scaleX: true,
scaleY: true
});
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 100
});
};
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) {
// Check if player is close enough to the house
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var maxDistance = 150; // Player must be within 150 pixels of the house
if (distance <= maxDistance) {
enterHouse();
}
}
};
return self;
});
var HungerBar = Container.expand(function () {
var self = Container.call(this);
// Background bar
var background = self.attachAsset('hungerBarBg', {
anchorX: 0,
anchorY: 0
});
// Fill bar (green to red based on hunger level)
var fill = self.attachAsset('hungerBarFill', {
anchorX: 0,
anchorY: 0,
x: 1,
y: 1
});
self.maxFood = 100;
self.currentFood = 100;
self.updateHunger = function (foodValue) {
self.currentFood = foodValue;
var percentage = Math.max(0, self.currentFood / self.maxFood);
// Update fill width based on percentage
fill.scaleX = percentage;
// Change color based on hunger level
if (percentage > 0.6) {
fill.tint = 0x00ff00; // Green
} else if (percentage > 0.3) {
fill.tint = 0xffff00; // Yellow
} else {
fill.tint = 0xff0000; // Red
}
};
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);
hungerBar.updateHunger(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('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.moveLeft = function () {
self.x -= self.speed;
if (self.x < 30) self.x = 30;
};
self.moveRight = function () {
self.x += self.speed;
if (self.x > 2018) self.x = 2018;
};
self.moveUp = function () {
self.y -= self.speed;
if (self.y < 30) self.y = 30;
};
self.moveDown = function () {
self.y += self.speed;
if (self.y > 2702) self.y = 2702;
};
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 pigSpawningEnabled = true;
var houseFloorClickTime = 0;
var player;
var controlButtons = [];
// Button state tracking for hold-to-move
var leftButtonHeld = false;
var rightButtonHeld = false;
var upButtonHeld = false;
var downButtonHeld = false;
// UI Elements
var foodText = new Text2('Food: ' + playerFood, {
size: 60,
fill: 0xFFFFFF
});
foodText.anchor.set(0, 0);
LK.gui.topRight.addChild(foodText);
// Create hunger bar
var hungerBar = new HungerBar();
hungerBar.x = -150; // Center it relative to topRight
hungerBar.y = 80; // Position below the food text
LK.gui.topRight.addChild(hungerBar);
// Add hunger bar label
var hungerLabel = new Text2('Hunger:', {
size: 40,
fill: 0xFFFFFF
});
hungerLabel.anchor.set(1, 0);
hungerLabel.x = -160; // Position to the left of the bar
hungerLabel.y = 85;
LK.gui.topRight.addChild(hungerLabel);
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);
// 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();
}
// Initialize player
player = new Player();
player.x = 1024;
player.y = 1366;
game.addChild(player);
// Create control buttons
var leftButton = new ControlButton('left');
leftButton.x = 200;
leftButton.y = 2500;
game.addChild(leftButton);
controlButtons.push(leftButton);
var rightButton = new ControlButton('right');
rightButton.x = 400;
rightButton.y = 2500;
game.addChild(rightButton);
controlButtons.push(rightButton);
var upButton = new ControlButton('up');
upButton.x = 300;
upButton.y = 2400;
game.addChild(upButton);
controlButtons.push(upButton);
var downButton = new ControlButton('down');
downButton.x = 300;
downButton.y = 2600;
game.addChild(downButton);
controlButtons.push(downButton);
// 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;
// Disable pig spawning
pigSpawningEnabled = false;
// Change background to light brown (house planks color)
game.setBackgroundColor(0x8b7355);
// 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;
}
player.visible = true;
for (var i = 0; i < controlButtons.length; i++) {
controlButtons[i].visible = true;
}
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;
// Re-enable pig spawning
pigSpawningEnabled = true;
// Restore forest background color
game.setBackgroundColor(0x2d5a2d);
// 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;
}
player.visible = true;
for (var i = 0; i < controlButtons.length; i++) {
controlButtons[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++;
// Handle continuous movement based on held buttons
if (leftButtonHeld) {
player.moveLeft();
}
if (rightButtonHeld) {
player.moveRight();
}
if (upButtonHeld) {
player.moveUp();
}
if (downButtonHeld) {
player.moveDown();
}
// Spawn new pigs occasionally (only if spawning is enabled and not in house)
if (spawnTimer % 600 === 0 && pigs.length < 12 && pigSpawningEnabled) {
spawnPig();
}
// Deplete food over time
if (foodTimer % 180 === 0) {
playerFood--;
if (playerFood < 0) {
playerFood = 0;
}
foodText.setText('Food: ' + playerFood);
hungerBar.updateHunger(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);
}
}
};
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