User prompt
Make the player shoot auto when the dog is following the animal
User prompt
Make the ammo inf
Code edit (1 edits merged)
Please save this source code
User prompt
Add Diffrent seasons and diffrent dogs with diffrent ablities every season change ↪💡 Consider importing and using the following plugins: @upit/tween.v1, @upit/storage.v1
User prompt
Make The Player not able to go in the ponds
User prompt
Create Small Ponds in the map and add Ducks in to the ponds Make Sure the dogs go slower in the pond ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add More Sounds
User prompt
Modify dog to only follow one animal at a time by setting single target priority ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
while the animal is running form the dog it cannot turn invis
User prompt
Make the dog go after the animal untill it is shot ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Remove the stamina bar and replace it with an ammo
User prompt
Make the dog walk animation ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make Sure the dog follows the animal to the player to shoot easier ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make The Dog follow footprints and find the animal ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Animals go slower than the dog
User prompt
After the dog stops barking make it come backt to the player ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the animals invis after some time that dog sees them ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Remove The animal hiding under trees
User prompt
Make the dog go after the animals ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make The Footprints Almost invis to the player and make it so you cant shoot trough trees
User prompt
Make the animals hide under trees and bushes after beeing Seen By The Dog
User prompt
Make the animals invis untill the dog sees them,Make The Dog Follow animal footprints ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make an hunting dog ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make More Maps
User prompt
Shop Does not oppen
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Animal = Container.expand(function (animalType) {
var self = Container.call(this);
self.animalType = animalType || 'deer';
self.graphics = self.attachAsset(self.animalType, {
anchorX: 0.5,
anchorY: 0.5
});
// Animal properties
self.health = 100;
self.alertLevel = 0;
self.speed = 1 + Math.random() * 2;
self.direction = Math.random() * Math.PI * 2;
self.isAlive = true;
self.detectionRadius = 150 + Math.random() * 100;
self.lastX = self.x;
self.lastY = self.y;
// Movement timer
self.moveTimer = 0;
self.moveChangeInterval = 60 + Math.random() * 120;
self.update = function () {
if (!self.isAlive) return;
// Random movement behavior
self.moveTimer++;
if (self.moveTimer >= self.moveChangeInterval) {
self.direction += (Math.random() - 0.5) * 0.5;
self.moveTimer = 0;
self.moveChangeInterval = 60 + Math.random() * 120;
}
// Move animal
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
// Keep within bounds
if (self.x < 50) {
self.x = 50;
self.direction = Math.random() * Math.PI * 2;
}
if (self.x > 1998) {
self.x = 1998;
self.direction = Math.random() * Math.PI * 2;
}
if (self.y < 50) {
self.y = 50;
self.direction = Math.random() * Math.PI * 2;
}
if (self.y > 2682) {
self.y = 2682;
self.direction = Math.random() * Math.PI * 2;
}
// Player detection
var distanceToPlayer = Math.sqrt(Math.pow(self.x - hunter.x, 2) + Math.pow(self.y - hunter.y, 2));
if (distanceToPlayer < self.detectionRadius) {
self.alertLevel = Math.min(100, self.alertLevel + 2);
// Flee from player
var fleeAngle = Math.atan2(self.y - hunter.y, self.x - hunter.x);
self.direction = fleeAngle;
self.speed = Math.min(4, self.speed + 0.1);
} else {
self.alertLevel = Math.max(0, self.alertLevel - 1);
self.speed = Math.max(1, self.speed - 0.05);
}
// Create footprints occasionally
if (Math.random() < 0.02) {
createFootprint(self.x, self.y);
}
};
return self;
});
var Footprint = Container.expand(function () {
var self = Container.call(this);
self.graphics = self.attachAsset('footprint', {
anchorX: 0.5,
anchorY: 0.5
});
self.graphics.alpha = 0.6;
self.lifetime = 600; // 10 seconds at 60fps
self.update = function () {
self.lifetime--;
self.graphics.alpha = self.lifetime / 600 * 0.6;
if (self.lifetime <= 0) {
self.destroy();
for (var i = footprints.length - 1; i >= 0; i--) {
if (footprints[i] === self) {
footprints.splice(i, 1);
break;
}
}
}
};
return self;
});
// Game variables
var Hunter = Container.expand(function () {
var self = Container.call(this);
self.graphics = self.attachAsset('hunter', {
anchorX: 0.5,
anchorY: 0.5
});
self.rifle = self.addChild(LK.getAsset('rifle', {
anchorX: 0,
anchorY: 0.5
}));
self.rifle.x = 30;
self.rifle.y = 0;
// Hunter stats
self.stamina = 100;
self.hunger = 100;
self.accuracy = 50;
self.stealth = 50;
self.tracking = 50;
self.isMoving = false;
self.lastMoveTime = 0;
return self;
});
var Shop = Container.expand(function () {
var self = Container.call(this);
self.isOpen = false;
// Shop background panel
self.background = self.addChild(LK.getAsset('shop_panel', {
anchorX: 0.5,
anchorY: 0.5
}));
self.background.scaleX = 1.2;
self.background.scaleY = 1.5;
// Shop title
self.title = self.addChild(new Text2('HUNTING SHOP', {
size: 32,
fill: 0xFFFFFF
}));
self.title.anchor.set(0.5, 0);
self.title.y = -450;
// Close button
self.closeButton = self.addChild(LK.getAsset('buy_button', {
anchorX: 0.5,
anchorY: 0.5
}));
self.closeButton.y = 420;
self.closeButton.tint = 0xFF4444;
self.closeText = self.addChild(new Text2('CLOSE', {
size: 18,
fill: 0xFFFFFF
}));
self.closeText.anchor.set(0.5, 0.5);
self.closeText.y = 420;
// Shop items
self.items = [];
self.itemsContainer = self.addChild(new Container());
self.itemsContainer.y = -350;
self.open = function () {
self.isOpen = true;
self.visible = true;
self.setupItems();
// Bring shop to front
if (self.parent) {
self.parent.removeChild(self);
self.parent.addChild(self);
}
};
self.close = function () {
self.isOpen = false;
self.visible = false;
};
self.setupItems = function () {
// Clear existing items
for (var i = 0; i < self.items.length; i++) {
if (self.items[i].parent) {
self.items[i].destroy();
}
}
self.items = [];
// Add shop items
var yOffset = 0;
for (var i = 0; i < shopItemsData.length; i++) {
var item = self.itemsContainer.addChild(new ShopItem(shopItemsData[i]));
item.y = yOffset;
item.x = -200; // Center the items
self.items.push(item);
yOffset += 100;
}
};
self.down = function (x, y, obj) {
if (!self.isOpen) return;
// Check close button
if (x >= -60 && x <= 60 && y >= 400 && y <= 440) {
self.close();
}
};
// Initially hidden
self.visible = false;
return self;
});
var ShopItem = Container.expand(function (itemData) {
var self = Container.call(this);
self.itemData = itemData;
self.name = itemData.name;
self.price = itemData.price;
self.description = itemData.description;
self.type = itemData.type;
self.effect = itemData.effect;
// Create item display
self.panel = self.addChild(LK.getAsset('shop_panel', {
anchorX: 0,
anchorY: 0
}));
self.panel.scaleX = 0.8;
self.panel.scaleY = 0.3;
// Item name
self.nameText = self.addChild(new Text2(self.name, {
size: 24,
fill: 0xFFFFFF
}));
self.nameText.anchor.set(0, 0);
self.nameText.x = 10;
self.nameText.y = 10;
// Item price
self.priceText = self.addChild(new Text2('$' + self.price, {
size: 20,
fill: 0xFFD700
}));
self.priceText.anchor.set(0, 0);
self.priceText.x = 10;
self.priceText.y = 35;
// Description
self.descText = self.addChild(new Text2(self.description, {
size: 16,
fill: 0xCCCCCC
}));
self.descText.anchor.set(0, 0);
self.descText.x = 10;
self.descText.y = 60;
// Buy button
self.buyButton = self.addChild(LK.getAsset('buy_button', {
anchorX: 0,
anchorY: 0
}));
self.buyButton.x = 250;
self.buyButton.y = 30;
self.buyText = self.addChild(new Text2('BUY', {
size: 18,
fill: 0xFFFFFF
}));
self.buyText.anchor.set(0.5, 0.5);
self.buyText.x = 310;
self.buyText.y = 50;
self.down = function (x, y, obj) {
// Check if click is on buy button
if (x >= 250 && x <= 370 && y >= 30 && y <= 70) {
if (playerCoins >= self.price) {
playerCoins -= self.price;
applyItemEffect(self);
coinText.setText('Coins: ' + playerCoins);
// Visual feedback
LK.effects.flashObject(self.buyButton, 0x00FF00, 300);
} else {
// Not enough coins
LK.effects.flashObject(self.buyButton, 0xFF0000, 300);
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2F4F2F // Dark forest green
});
/****
* Game Code
****/
// Sounds
// UI elements
// Environment
// Animals
// Hunter and equipment
// Game variables
var hunter;
var animals = [];
var trees = [];
var footprints = [];
var gameScore = 0;
var dayTime = 0; // 0-1440 (24 hours in minutes)
var isAiming = false;
// Shop system variables
var playerCoins = 100; // Starting coins
var shop;
var shopButton;
var coinText;
// Shop items data
var shopItemsData = [{
name: 'Better Rifle',
price: 150,
description: 'Increases accuracy by 20%',
type: 'weapon',
effect: 'accuracy'
}, {
name: 'Camouflage Gear',
price: 100,
description: 'Improves stealth by 25%',
type: 'equipment',
effect: 'stealth'
}, {
name: 'Tracking Boots',
price: 80,
description: 'Better tracking skills +15%',
type: 'equipment',
effect: 'tracking'
}, {
name: 'Energy Drink',
price: 50,
description: 'Restores stamina to full',
type: 'consumable',
effect: 'stamina'
}, {
name: 'Food Rations',
price: 30,
description: 'Restores hunger to full',
type: 'consumable',
effect: 'hunger'
}];
// UI elements
var staminaBar, hungerBar, scoreText, timeText;
// Initialize hunter
hunter = game.addChild(new Hunter());
hunter.x = 1024;
hunter.y = 1366;
// Create environment
for (var i = 0; i < 30; i++) {
var tree = game.addChild(LK.getAsset('tree', {
anchorX: 0.5,
anchorY: 1.0
}));
tree.x = Math.random() * 1948 + 50;
tree.y = Math.random() * 2582 + 100;
trees.push(tree);
}
// Add some bushes
for (var i = 0; i < 50; i++) {
var bush = game.addChild(LK.getAsset('bush', {
anchorX: 0.5,
anchorY: 0.5
}));
bush.x = Math.random() * 1948 + 50;
bush.y = Math.random() * 2582 + 100;
}
// Spawn animals
function spawnAnimals() {
var animalTypes = ['deer', 'rabbit', 'boar', 'wolf'];
for (var i = 0; i < 15; i++) {
var animalType = animalTypes[Math.floor(Math.random() * animalTypes.length)];
var animal = game.addChild(new Animal(animalType));
animal.x = Math.random() * 1848 + 100;
animal.y = Math.random() * 2482 + 100;
animals.push(animal);
}
}
spawnAnimals();
// Create UI
staminaBar = LK.getAsset('stamina_bar', {
anchorX: 0,
anchorY: 0
});
LK.gui.topLeft.addChild(staminaBar);
staminaBar.x = 120;
staminaBar.y = 20;
hungerBar = LK.getAsset('hunger_bar', {
anchorX: 0,
anchorY: 0
});
LK.gui.topLeft.addChild(hungerBar);
hungerBar.x = 120;
hungerBar.y = 50;
scoreText = new Text2('Score: 0', {
size: 40,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -200;
scoreText.y = 20;
timeText = new Text2('Dawn', {
size: 35,
fill: 0xFFD700
});
timeText.anchor.set(0.5, 0);
LK.gui.top.addChild(timeText);
timeText.y = 20;
// Coin display
coinText = new Text2('Coins: ' + playerCoins, {
size: 40,
fill: 0xFFD700
});
coinText.anchor.set(1, 0);
LK.gui.topRight.addChild(coinText);
coinText.x = -10;
coinText.y = 60;
// Shop button
shopButton = LK.getAsset('shop_button', {
anchorX: 0.5,
anchorY: 0.5
});
LK.gui.bottomRight.addChild(shopButton);
shopButton.x = -100;
shopButton.y = -50;
var shopButtonText = new Text2('SHOP', {
size: 24,
fill: 0xFFFFFF
});
shopButtonText.anchor.set(0.5, 0.5);
LK.gui.bottomRight.addChild(shopButtonText);
shopButtonText.x = -100;
shopButtonText.y = -50;
// Initialize shop
shop = game.addChild(new Shop());
shop.x = 1024;
shop.y = 1366;
shop.visible = false;
// Create footprint function
function createFootprint(x, y) {
var footprint = game.addChild(new Footprint());
footprint.x = x;
footprint.y = y;
footprints.push(footprint);
}
// Shop item effects function
function applyItemEffect(shopItem) {
var effect = shopItem.effect;
var type = shopItem.type;
if (type === 'consumable') {
if (effect === 'stamina') {
hunter.stamina = 100;
} else if (effect === 'hunger') {
hunter.hunger = 100;
}
} else if (type === 'equipment' || type === 'weapon') {
if (effect === 'accuracy') {
hunter.accuracy = Math.min(100, hunter.accuracy + 20);
} else if (effect === 'stealth') {
hunter.stealth = Math.min(100, hunter.stealth + 25);
} else if (effect === 'tracking') {
hunter.tracking = Math.min(100, hunter.tracking + 15);
}
}
}
// Function to award coins for hunting
function awardCoins(animalType) {
var coinReward = 5;
if (animalType === 'deer') coinReward = 10;else if (animalType === 'boar') coinReward = 15;else if (animalType === 'wolf') coinReward = 25;
playerCoins += coinReward;
coinText.setText('Coins: ' + playerCoins);
// Create coin visual effect
var coinEffect = game.addChild(LK.getAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
}));
coinEffect.x = hunter.x;
coinEffect.y = hunter.y - 50;
// Animate coin moving up and fading
tween(coinEffect, {
y: coinEffect.y - 100,
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
if (coinEffect.parent) {
coinEffect.destroy();
}
}
});
}
// Shooting function
function shootAtTarget(targetX, targetY) {
if (hunter.stamina < 10) return;
hunter.stamina -= 10;
LK.getSound('gunshot').play();
// Check if we hit any animals
for (var i = animals.length - 1; i >= 0; i--) {
var animal = animals[i];
var distance = Math.sqrt(Math.pow(animal.x - targetX, 2) + Math.pow(animal.y - targetY, 2));
if (distance < 60) {
// Hit!
animal.isAlive = false;
animal.graphics.alpha = 0.5;
// Award points based on animal type
var points = 10;
if (animal.animalType === 'deer') points = 20;else if (animal.animalType === 'boar') points = 30;else if (animal.animalType === 'wolf') points = 50;
gameScore += points;
LK.setScore(gameScore);
scoreText.setText('Score: ' + gameScore);
// Award coins
awardCoins(animal.animalType);
// Flash effect
LK.effects.flashObject(animal, 0xff0000, 500);
// Remove animal after delay
LK.setTimeout(function () {
if (animal.parent) {
animal.destroy();
for (var j = animals.length - 1; j >= 0; j--) {
if (animals[j] === animal) {
animals.splice(j, 1);
break;
}
}
}
}, 1000);
break;
}
}
}
// Movement handling
var targetX = hunter.x;
var targetY = hunter.y;
var isMovingToTarget = false;
function handleMove(x, y, obj) {
targetX = x;
targetY = y;
isMovingToTarget = true;
}
game.move = handleMove;
game.down = function (x, y, obj) {
// Convert to GUI coordinates for shop button check - with null check
if (obj && obj.parent && obj.position) {
var guiPos = LK.gui.bottomRight.toLocal(obj.parent.toGlobal(obj.position));
// Check if shop button was clicked
if (guiPos.x >= -175 && guiPos.x <= -25 && guiPos.y >= -75 && guiPos.y <= -25) {
console.log("Shop button clicked!");
if (!shop.isOpen) {
shop.open();
console.log("Shop opened, visible:", shop.visible);
}
return;
}
}
if (isAiming) {
shootAtTarget(x, y);
isAiming = false;
} else {
isAiming = true;
LK.setTimeout(function () {
isAiming = false;
}, 2000);
}
};
// Main game update loop
game.update = function () {
// Update day/night cycle
dayTime += 0.5; // 0.5 minutes per frame at 60fps = 48 minutes real time for full day
if (dayTime >= 1440) dayTime = 0;
// Update time display
var hour = Math.floor(dayTime / 60);
var timeOfDay = '';
if (hour >= 5 && hour < 12) timeOfDay = 'Morning';else if (hour >= 12 && hour < 18) timeOfDay = 'Afternoon';else if (hour >= 18 && hour < 21) timeOfDay = 'Evening';else timeOfDay = 'Night';
timeText.setText(timeOfDay + ' (' + hour + ':' + Math.floor(dayTime % 60).toString().padStart(2, '0') + ')');
// Move hunter towards target
if (isMovingToTarget) {
var dx = targetX - hunter.x;
var dy = targetY - hunter.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
var moveSpeed = 3;
hunter.x += dx / distance * moveSpeed;
hunter.y += dy / distance * moveSpeed;
// Consume stamina while moving
if (LK.ticks % 10 === 0) {
hunter.stamina = Math.max(0, hunter.stamina - 0.5);
hunter.hunger = Math.max(0, hunter.hunger - 0.1);
}
// Play footstep sound occasionally
if (LK.ticks % 30 === 0) {
LK.getSound('footstep').play();
}
} else {
isMovingToTarget = false;
}
}
// Regenerate stamina when not moving
if (!isMovingToTarget && hunter.stamina < 100) {
hunter.stamina += 0.2;
}
// Update UI bars
staminaBar.scaleX = hunter.stamina / 100;
hungerBar.scaleX = hunter.hunger / 100;
// Update animals
for (var i = 0; i < animals.length; i++) {
animals[i].update();
}
// Update footprints
for (var i = 0; i < footprints.length; i++) {
footprints[i].update();
}
// Spawn new animals occasionally
if (animals.length < 10 && LK.ticks % 600 === 0) {
var animalTypes = ['deer', 'rabbit', 'boar', 'wolf'];
var animalType = animalTypes[Math.floor(Math.random() * animalTypes.length)];
var animal = game.addChild(new Animal(animalType));
animal.x = Math.random() * 1848 + 100;
animal.y = Math.random() * 2482 + 100;
animals.push(animal);
}
// Game over condition - if hunter runs out of stamina and hunger
if (hunter.stamina <= 0 && hunter.hunger <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Animal = Container.expand(function (animalType) {
var self = Container.call(this);
self.animalType = animalType || 'deer';
self.graphics = self.attachAsset(self.animalType, {
anchorX: 0.5,
anchorY: 0.5
});
// Animal properties
self.health = 100;
self.alertLevel = 0;
self.speed = 1 + Math.random() * 2;
self.direction = Math.random() * Math.PI * 2;
self.isAlive = true;
self.detectionRadius = 150 + Math.random() * 100;
self.lastX = self.x;
self.lastY = self.y;
// Movement timer
self.moveTimer = 0;
self.moveChangeInterval = 60 + Math.random() * 120;
self.update = function () {
if (!self.isAlive) return;
// Random movement behavior
self.moveTimer++;
if (self.moveTimer >= self.moveChangeInterval) {
self.direction += (Math.random() - 0.5) * 0.5;
self.moveTimer = 0;
self.moveChangeInterval = 60 + Math.random() * 120;
}
// Move animal
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
// Keep within bounds
if (self.x < 50) {
self.x = 50;
self.direction = Math.random() * Math.PI * 2;
}
if (self.x > 1998) {
self.x = 1998;
self.direction = Math.random() * Math.PI * 2;
}
if (self.y < 50) {
self.y = 50;
self.direction = Math.random() * Math.PI * 2;
}
if (self.y > 2682) {
self.y = 2682;
self.direction = Math.random() * Math.PI * 2;
}
// Player detection
var distanceToPlayer = Math.sqrt(Math.pow(self.x - hunter.x, 2) + Math.pow(self.y - hunter.y, 2));
if (distanceToPlayer < self.detectionRadius) {
self.alertLevel = Math.min(100, self.alertLevel + 2);
// Flee from player
var fleeAngle = Math.atan2(self.y - hunter.y, self.x - hunter.x);
self.direction = fleeAngle;
self.speed = Math.min(4, self.speed + 0.1);
} else {
self.alertLevel = Math.max(0, self.alertLevel - 1);
self.speed = Math.max(1, self.speed - 0.05);
}
// Create footprints occasionally
if (Math.random() < 0.02) {
createFootprint(self.x, self.y);
}
};
return self;
});
var Footprint = Container.expand(function () {
var self = Container.call(this);
self.graphics = self.attachAsset('footprint', {
anchorX: 0.5,
anchorY: 0.5
});
self.graphics.alpha = 0.6;
self.lifetime = 600; // 10 seconds at 60fps
self.update = function () {
self.lifetime--;
self.graphics.alpha = self.lifetime / 600 * 0.6;
if (self.lifetime <= 0) {
self.destroy();
for (var i = footprints.length - 1; i >= 0; i--) {
if (footprints[i] === self) {
footprints.splice(i, 1);
break;
}
}
}
};
return self;
});
// Game variables
var Hunter = Container.expand(function () {
var self = Container.call(this);
self.graphics = self.attachAsset('hunter', {
anchorX: 0.5,
anchorY: 0.5
});
self.rifle = self.addChild(LK.getAsset('rifle', {
anchorX: 0,
anchorY: 0.5
}));
self.rifle.x = 30;
self.rifle.y = 0;
// Hunter stats
self.stamina = 100;
self.hunger = 100;
self.accuracy = 50;
self.stealth = 50;
self.tracking = 50;
self.isMoving = false;
self.lastMoveTime = 0;
return self;
});
var Shop = Container.expand(function () {
var self = Container.call(this);
self.isOpen = false;
// Shop background panel
self.background = self.addChild(LK.getAsset('shop_panel', {
anchorX: 0.5,
anchorY: 0.5
}));
self.background.scaleX = 1.2;
self.background.scaleY = 1.5;
// Shop title
self.title = self.addChild(new Text2('HUNTING SHOP', {
size: 32,
fill: 0xFFFFFF
}));
self.title.anchor.set(0.5, 0);
self.title.y = -450;
// Close button
self.closeButton = self.addChild(LK.getAsset('buy_button', {
anchorX: 0.5,
anchorY: 0.5
}));
self.closeButton.y = 420;
self.closeButton.tint = 0xFF4444;
self.closeText = self.addChild(new Text2('CLOSE', {
size: 18,
fill: 0xFFFFFF
}));
self.closeText.anchor.set(0.5, 0.5);
self.closeText.y = 420;
// Shop items
self.items = [];
self.itemsContainer = self.addChild(new Container());
self.itemsContainer.y = -350;
self.open = function () {
self.isOpen = true;
self.visible = true;
self.setupItems();
// Bring shop to front
if (self.parent) {
self.parent.removeChild(self);
self.parent.addChild(self);
}
};
self.close = function () {
self.isOpen = false;
self.visible = false;
};
self.setupItems = function () {
// Clear existing items
for (var i = 0; i < self.items.length; i++) {
if (self.items[i].parent) {
self.items[i].destroy();
}
}
self.items = [];
// Add shop items
var yOffset = 0;
for (var i = 0; i < shopItemsData.length; i++) {
var item = self.itemsContainer.addChild(new ShopItem(shopItemsData[i]));
item.y = yOffset;
item.x = -200; // Center the items
self.items.push(item);
yOffset += 100;
}
};
self.down = function (x, y, obj) {
if (!self.isOpen) return;
// Check close button
if (x >= -60 && x <= 60 && y >= 400 && y <= 440) {
self.close();
}
};
// Initially hidden
self.visible = false;
return self;
});
var ShopItem = Container.expand(function (itemData) {
var self = Container.call(this);
self.itemData = itemData;
self.name = itemData.name;
self.price = itemData.price;
self.description = itemData.description;
self.type = itemData.type;
self.effect = itemData.effect;
// Create item display
self.panel = self.addChild(LK.getAsset('shop_panel', {
anchorX: 0,
anchorY: 0
}));
self.panel.scaleX = 0.8;
self.panel.scaleY = 0.3;
// Item name
self.nameText = self.addChild(new Text2(self.name, {
size: 24,
fill: 0xFFFFFF
}));
self.nameText.anchor.set(0, 0);
self.nameText.x = 10;
self.nameText.y = 10;
// Item price
self.priceText = self.addChild(new Text2('$' + self.price, {
size: 20,
fill: 0xFFD700
}));
self.priceText.anchor.set(0, 0);
self.priceText.x = 10;
self.priceText.y = 35;
// Description
self.descText = self.addChild(new Text2(self.description, {
size: 16,
fill: 0xCCCCCC
}));
self.descText.anchor.set(0, 0);
self.descText.x = 10;
self.descText.y = 60;
// Buy button
self.buyButton = self.addChild(LK.getAsset('buy_button', {
anchorX: 0,
anchorY: 0
}));
self.buyButton.x = 250;
self.buyButton.y = 30;
self.buyText = self.addChild(new Text2('BUY', {
size: 18,
fill: 0xFFFFFF
}));
self.buyText.anchor.set(0.5, 0.5);
self.buyText.x = 310;
self.buyText.y = 50;
self.down = function (x, y, obj) {
// Check if click is on buy button
if (x >= 250 && x <= 370 && y >= 30 && y <= 70) {
if (playerCoins >= self.price) {
playerCoins -= self.price;
applyItemEffect(self);
coinText.setText('Coins: ' + playerCoins);
// Visual feedback
LK.effects.flashObject(self.buyButton, 0x00FF00, 300);
} else {
// Not enough coins
LK.effects.flashObject(self.buyButton, 0xFF0000, 300);
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2F4F2F // Dark forest green
});
/****
* Game Code
****/
// Sounds
// UI elements
// Environment
// Animals
// Hunter and equipment
// Game variables
var hunter;
var animals = [];
var trees = [];
var footprints = [];
var gameScore = 0;
var dayTime = 0; // 0-1440 (24 hours in minutes)
var isAiming = false;
// Shop system variables
var playerCoins = 100; // Starting coins
var shop;
var shopButton;
var coinText;
// Shop items data
var shopItemsData = [{
name: 'Better Rifle',
price: 150,
description: 'Increases accuracy by 20%',
type: 'weapon',
effect: 'accuracy'
}, {
name: 'Camouflage Gear',
price: 100,
description: 'Improves stealth by 25%',
type: 'equipment',
effect: 'stealth'
}, {
name: 'Tracking Boots',
price: 80,
description: 'Better tracking skills +15%',
type: 'equipment',
effect: 'tracking'
}, {
name: 'Energy Drink',
price: 50,
description: 'Restores stamina to full',
type: 'consumable',
effect: 'stamina'
}, {
name: 'Food Rations',
price: 30,
description: 'Restores hunger to full',
type: 'consumable',
effect: 'hunger'
}];
// UI elements
var staminaBar, hungerBar, scoreText, timeText;
// Initialize hunter
hunter = game.addChild(new Hunter());
hunter.x = 1024;
hunter.y = 1366;
// Create environment
for (var i = 0; i < 30; i++) {
var tree = game.addChild(LK.getAsset('tree', {
anchorX: 0.5,
anchorY: 1.0
}));
tree.x = Math.random() * 1948 + 50;
tree.y = Math.random() * 2582 + 100;
trees.push(tree);
}
// Add some bushes
for (var i = 0; i < 50; i++) {
var bush = game.addChild(LK.getAsset('bush', {
anchorX: 0.5,
anchorY: 0.5
}));
bush.x = Math.random() * 1948 + 50;
bush.y = Math.random() * 2582 + 100;
}
// Spawn animals
function spawnAnimals() {
var animalTypes = ['deer', 'rabbit', 'boar', 'wolf'];
for (var i = 0; i < 15; i++) {
var animalType = animalTypes[Math.floor(Math.random() * animalTypes.length)];
var animal = game.addChild(new Animal(animalType));
animal.x = Math.random() * 1848 + 100;
animal.y = Math.random() * 2482 + 100;
animals.push(animal);
}
}
spawnAnimals();
// Create UI
staminaBar = LK.getAsset('stamina_bar', {
anchorX: 0,
anchorY: 0
});
LK.gui.topLeft.addChild(staminaBar);
staminaBar.x = 120;
staminaBar.y = 20;
hungerBar = LK.getAsset('hunger_bar', {
anchorX: 0,
anchorY: 0
});
LK.gui.topLeft.addChild(hungerBar);
hungerBar.x = 120;
hungerBar.y = 50;
scoreText = new Text2('Score: 0', {
size: 40,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -200;
scoreText.y = 20;
timeText = new Text2('Dawn', {
size: 35,
fill: 0xFFD700
});
timeText.anchor.set(0.5, 0);
LK.gui.top.addChild(timeText);
timeText.y = 20;
// Coin display
coinText = new Text2('Coins: ' + playerCoins, {
size: 40,
fill: 0xFFD700
});
coinText.anchor.set(1, 0);
LK.gui.topRight.addChild(coinText);
coinText.x = -10;
coinText.y = 60;
// Shop button
shopButton = LK.getAsset('shop_button', {
anchorX: 0.5,
anchorY: 0.5
});
LK.gui.bottomRight.addChild(shopButton);
shopButton.x = -100;
shopButton.y = -50;
var shopButtonText = new Text2('SHOP', {
size: 24,
fill: 0xFFFFFF
});
shopButtonText.anchor.set(0.5, 0.5);
LK.gui.bottomRight.addChild(shopButtonText);
shopButtonText.x = -100;
shopButtonText.y = -50;
// Initialize shop
shop = game.addChild(new Shop());
shop.x = 1024;
shop.y = 1366;
shop.visible = false;
// Create footprint function
function createFootprint(x, y) {
var footprint = game.addChild(new Footprint());
footprint.x = x;
footprint.y = y;
footprints.push(footprint);
}
// Shop item effects function
function applyItemEffect(shopItem) {
var effect = shopItem.effect;
var type = shopItem.type;
if (type === 'consumable') {
if (effect === 'stamina') {
hunter.stamina = 100;
} else if (effect === 'hunger') {
hunter.hunger = 100;
}
} else if (type === 'equipment' || type === 'weapon') {
if (effect === 'accuracy') {
hunter.accuracy = Math.min(100, hunter.accuracy + 20);
} else if (effect === 'stealth') {
hunter.stealth = Math.min(100, hunter.stealth + 25);
} else if (effect === 'tracking') {
hunter.tracking = Math.min(100, hunter.tracking + 15);
}
}
}
// Function to award coins for hunting
function awardCoins(animalType) {
var coinReward = 5;
if (animalType === 'deer') coinReward = 10;else if (animalType === 'boar') coinReward = 15;else if (animalType === 'wolf') coinReward = 25;
playerCoins += coinReward;
coinText.setText('Coins: ' + playerCoins);
// Create coin visual effect
var coinEffect = game.addChild(LK.getAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
}));
coinEffect.x = hunter.x;
coinEffect.y = hunter.y - 50;
// Animate coin moving up and fading
tween(coinEffect, {
y: coinEffect.y - 100,
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
if (coinEffect.parent) {
coinEffect.destroy();
}
}
});
}
// Shooting function
function shootAtTarget(targetX, targetY) {
if (hunter.stamina < 10) return;
hunter.stamina -= 10;
LK.getSound('gunshot').play();
// Check if we hit any animals
for (var i = animals.length - 1; i >= 0; i--) {
var animal = animals[i];
var distance = Math.sqrt(Math.pow(animal.x - targetX, 2) + Math.pow(animal.y - targetY, 2));
if (distance < 60) {
// Hit!
animal.isAlive = false;
animal.graphics.alpha = 0.5;
// Award points based on animal type
var points = 10;
if (animal.animalType === 'deer') points = 20;else if (animal.animalType === 'boar') points = 30;else if (animal.animalType === 'wolf') points = 50;
gameScore += points;
LK.setScore(gameScore);
scoreText.setText('Score: ' + gameScore);
// Award coins
awardCoins(animal.animalType);
// Flash effect
LK.effects.flashObject(animal, 0xff0000, 500);
// Remove animal after delay
LK.setTimeout(function () {
if (animal.parent) {
animal.destroy();
for (var j = animals.length - 1; j >= 0; j--) {
if (animals[j] === animal) {
animals.splice(j, 1);
break;
}
}
}
}, 1000);
break;
}
}
}
// Movement handling
var targetX = hunter.x;
var targetY = hunter.y;
var isMovingToTarget = false;
function handleMove(x, y, obj) {
targetX = x;
targetY = y;
isMovingToTarget = true;
}
game.move = handleMove;
game.down = function (x, y, obj) {
// Convert to GUI coordinates for shop button check - with null check
if (obj && obj.parent && obj.position) {
var guiPos = LK.gui.bottomRight.toLocal(obj.parent.toGlobal(obj.position));
// Check if shop button was clicked
if (guiPos.x >= -175 && guiPos.x <= -25 && guiPos.y >= -75 && guiPos.y <= -25) {
console.log("Shop button clicked!");
if (!shop.isOpen) {
shop.open();
console.log("Shop opened, visible:", shop.visible);
}
return;
}
}
if (isAiming) {
shootAtTarget(x, y);
isAiming = false;
} else {
isAiming = true;
LK.setTimeout(function () {
isAiming = false;
}, 2000);
}
};
// Main game update loop
game.update = function () {
// Update day/night cycle
dayTime += 0.5; // 0.5 minutes per frame at 60fps = 48 minutes real time for full day
if (dayTime >= 1440) dayTime = 0;
// Update time display
var hour = Math.floor(dayTime / 60);
var timeOfDay = '';
if (hour >= 5 && hour < 12) timeOfDay = 'Morning';else if (hour >= 12 && hour < 18) timeOfDay = 'Afternoon';else if (hour >= 18 && hour < 21) timeOfDay = 'Evening';else timeOfDay = 'Night';
timeText.setText(timeOfDay + ' (' + hour + ':' + Math.floor(dayTime % 60).toString().padStart(2, '0') + ')');
// Move hunter towards target
if (isMovingToTarget) {
var dx = targetX - hunter.x;
var dy = targetY - hunter.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
var moveSpeed = 3;
hunter.x += dx / distance * moveSpeed;
hunter.y += dy / distance * moveSpeed;
// Consume stamina while moving
if (LK.ticks % 10 === 0) {
hunter.stamina = Math.max(0, hunter.stamina - 0.5);
hunter.hunger = Math.max(0, hunter.hunger - 0.1);
}
// Play footstep sound occasionally
if (LK.ticks % 30 === 0) {
LK.getSound('footstep').play();
}
} else {
isMovingToTarget = false;
}
}
// Regenerate stamina when not moving
if (!isMovingToTarget && hunter.stamina < 100) {
hunter.stamina += 0.2;
}
// Update UI bars
staminaBar.scaleX = hunter.stamina / 100;
hungerBar.scaleX = hunter.hunger / 100;
// Update animals
for (var i = 0; i < animals.length; i++) {
animals[i].update();
}
// Update footprints
for (var i = 0; i < footprints.length; i++) {
footprints[i].update();
}
// Spawn new animals occasionally
if (animals.length < 10 && LK.ticks % 600 === 0) {
var animalTypes = ['deer', 'rabbit', 'boar', 'wolf'];
var animalType = animalTypes[Math.floor(Math.random() * animalTypes.length)];
var animal = game.addChild(new Animal(animalType));
animal.x = Math.random() * 1848 + 100;
animal.y = Math.random() * 2482 + 100;
animals.push(animal);
}
// Game over condition - if hunter runs out of stamina and hunger
if (hunter.stamina <= 0 && hunter.hunger <= 0) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
Wild Boar. In-Game asset. 2d. High contrast. No shadows
Bush. In-Game asset. 2d. High contrast. No shadows
Tree. In-Game asset. 2d. High contrast. No shadows
Deer. In-Game asset. 2d. High contrast. No shadows
Hunter. In-Game asset. 2d. High contrast. No shadows
Rifle. In-Game asset. 2d. High contrast. No shadows
Wolf. In-Game asset. 2d. High contrast. No shadows
Rabbit. High contrast. No shadows
Coin. In-Game asset. 2d. High contrast. No shadows
Animal Footprint. High contrast. No shadows
Shop Button. In-Game asset. 2d. High contrast. No shadows
Duck Flying. In-Game asset. 2d. No shadows