User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'to')' in or related to this line: 'tween(coinEffect).to({' Line Number: 492 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: tween.to is not a function' in or related to this line: 'tween.to(coinEffect, 1000, {' Line Number: 492
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toGlobal')' in or related to this line: 'var guiPos = LK.gui.bottomRight.toLocal(obj.parent.toGlobal(obj.position));' Line Number: 560
User prompt
make a Shop System
User prompt
make The First Version
User prompt
Forest Hunter: Wilderness Survival
Initial prompt
Create a fully detailed hunting simulation game set in a large open-world forest environment. The player takes the role of a skilled hunter equipped with realistic gear such as rifles, bows, animal calls, and camouflage clothing. Include dynamic weather (rain, fog, snow, wind), a realistic day-night cycle, and an immersive survival system with hunger, stamina, and temperature. The game should feature a variety of wild animals like deer, wild boar, rabbits, birds, wolves, and bears, each with realistic AI behavior. Animals react to sound, smell, and movement. Players can track animals using footprints, broken branches, droppings, and sound cues. Design multiple hunting zones such as pine forests, wetlands, mountains, and open plains. Each zone should have different species, visibility, and difficulty. Add a leveling and skill system for tracking, shooting, and survival abilities. Include a crafting system to create lures, traps, and upgrades. Add base building mechanics where players can set up a hunting cabin or camp. Implement a photo mode and trophy wall feature to track and display successful hunts. Make the game playable in single-player and multiplayer co-op. Add seasonal changes that affect animal behavior and migration. Keep the game visually stunning with 4K textures, realistic lighting, and ambient forest sounds. Output: Game design document, basic gameplay loop, starter level layout, animal behavior scripts, and visual style guide.
/****
* 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();
};
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;
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;
// 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.to(coinEffect, 1000, {
y: coinEffect.y - 100,
alpha: 0
}).onComplete(function () {
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
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) {
if (!shop.isOpen) {
shop.open();
}
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();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,5 +1,10 @@
/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
* Classes
****/
var Animal = Container.expand(function (animalType) {
var self = Container.call(this);
@@ -113,8 +118,149 @@
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();
+ };
+ 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;
+ 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
****/
@@ -124,21 +270,58 @@
/****
* Game Code
****/
-// Game variables
-// Hunter and equipment
-// Animals
-// Environment
-// UI elements
// 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());
@@ -204,15 +387,87 @@
});
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;
// 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.to(coinEffect, 1000, {
+ y: coinEffect.y - 100,
+ alpha: 0
+ }).onComplete(function () {
+ if (coinEffect.parent) {
+ coinEffect.destroy();
+ }
+ });
+}
// Shooting function
function shootAtTarget(targetX, targetY) {
if (hunter.stamina < 10) return;
hunter.stamina -= 10;
@@ -230,8 +485,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 () {
@@ -259,8 +516,17 @@
isMovingToTarget = true;
}
game.move = handleMove;
game.down = function (x, y, obj) {
+ // Convert to GUI coordinates for shop button check
+ 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) {
+ if (!shop.isOpen) {
+ shop.open();
+ }
+ return;
+ }
if (isAiming) {
shootAtTarget(x, y);
isAiming = false;
} else {
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