User prompt
Add a cat to the game and since it has good reflexes, when our bullet approaches the cat it will accelerate and run away, its price will be high and it will be hard to catch. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Put the shop button above the sell all button
User prompt
ADD A SHOP WHERE WE CAN BUY MORE WEAPONS
User prompt
Let's start the game with 0 money
User prompt
The sell button is hard to touch, make hitbox bigger
User prompt
When you hit an animal, it becomes an animal and comes to inventory and we sell it and make money. THE SALE PRICE OF EACH ANIMAL IS DIFFERENT.
User prompt
MAKE THE CHEETAS FAST
User prompt
ADD A MONEY COUNTER
User prompt
Play music when you start the game
User prompt
a little higher
User prompt
Put the sell all button a little higher
User prompt
Where is the button, put the button at the bottom of the screen
User prompt
ADD A BUTTON WHERE WE CAN SELL ANIMALS
User prompt
ADD A BUTTON WHERE WE CAN SELL ANIMALS AND A MONEY COUNTER AND A SHOP WHERE WE CAN BUY MORE WEAPONS
User prompt
LET IT FIRE EXACTLY WHERE WE CLICK
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'toGlobal')' in or related to this line: 'var upgradeArea = LK.gui.topRight.toLocal(obj.parent.toGlobal(obj.position));' Line Number: 286
User prompt
LET'S SHOOT WHERE WE CLICK
Code edit (1 edits merged)
Please save this source code
User prompt
Safari Hunter
Initial prompt
LET THERE BE A MAN IN THE MIDDLE, LET HIM SHOOTS ANIMALS WITH HIS GUN, LET THERE BE 11 DIFFERENT ANIMALS AND LET'S SELL THE ANIMALS WE KILLED AND EARN MONEY TO BUY MORE GUNS, LET THERE BE 11 DIFFERENT ANIMALS IN THE GAME, LET EACH ONE HAVE A DIFFERENT SELLING PRICE
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Animal = Container.expand(function (animalType) { var self = Container.call(this); var animalData = { rabbit: { asset: 'rabbit', price: 10, speed: 2, health: 1, chance: 0.85 }, deer: { asset: 'deer', price: 23, speed: 1.5, health: 2, chance: 0.75 }, bear: { asset: 'bear', price: 62, speed: 1, health: 5, chance: 0.30 }, lion: { asset: 'lion', price: 180, speed: 2, health: 4, chance: 0.007 }, elephant: { asset: 'elephant', price: 250, speed: 0.5, health: 8, chance: 0.005 }, rhino: { asset: 'rhino', price: 84, speed: 1, health: 6, chance: 0.20 }, zebra: { asset: 'zebra', price: 62, speed: 3, health: 2, chance: 0.60 }, giraffe: { asset: 'giraffe', price: 73, speed: 1, health: 3, chance: 0.23 }, hippo: { asset: 'hippo', price: 90, speed: 0.8, health: 5, chance: 0.17 }, crocodile: { asset: 'crocodile', price: 80, speed: 1.2, health: 3, chance: 0.45 }, cheetah: { asset: 'cheetah', price: 50, speed: 6, health: 2, chance: 0.10 }, cat: { asset: 'cat', price: 60, speed: 1.5, health: 1, evasive: true, chance: 0.10 }, trex: { asset: 'trex', price: 215, speed: 1.5, health: 10, chance: 0.005 }, dragon: { asset: 'dragon', price: 300, speed: 2, health: 15, chance: 0.0005 } }; self.type = animalType; self.data = animalData[animalType]; self.health = self.data.health; self.maxHealth = self.data.health; self.angle = Math.random() * Math.PI * 2; self.speed = self.data.speed; var animalGraphics = self.attachAsset(self.data.asset, { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Cat evasion behavior if (self.data.evasive && bullets) { // Initialize tracking variables if not set if (self.lastClosestDistance === undefined) { self.lastClosestDistance = 999; } if (self.wasNearBullet === undefined) { self.wasNearBullet = false; } var closestBullet = null; var closestDistance = 150; // Detection range for (var b = 0; b < bullets.length; b++) { var bullet = bullets[b]; var dx = bullet.x - self.x; var dy = bullet.y - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < closestDistance) { closestBullet = bullet; closestDistance = distance; } } var isNearBullet = closestBullet !== null; // Check if bullet is approaching (getting closer) if (isNearBullet && !self.wasNearBullet) { // Bullet just entered detection range - increase speed self.speed = self.data.speed * 4; // Calculate escape direction (opposite to bullet direction) var bulletDx = closestBullet.velocityX; var bulletDy = closestBullet.velocityY; self.angle = Math.atan2(-bulletDy, -bulletDx) + (Math.random() - 0.5) * 0.5; } else if (!isNearBullet && self.wasNearBullet) { // Bullet left detection range - return to normal speed self.speed = self.data.speed; } else if (isNearBullet && closestDistance < self.lastClosestDistance) { // Bullet is still approaching and getting closer - maintain high speed and update direction self.speed = self.data.speed * 4; var bulletDx = closestBullet.velocityX; var bulletDy = closestBullet.velocityY; self.angle = Math.atan2(-bulletDy, -bulletDx) + (Math.random() - 0.5) * 0.5; } // Update tracking variables self.wasNearBullet = isNearBullet; self.lastClosestDistance = isNearBullet ? closestDistance : 999; } self.x += Math.cos(self.angle) * self.speed; self.y += Math.sin(self.angle) * self.speed; // Change direction randomly if (Math.random() < 0.02) { self.angle = Math.random() * Math.PI * 2; } // Keep animals within bounds if (self.x < 100) { self.angle = Math.random() * Math.PI - Math.PI / 2; } if (self.x > 1948) { self.angle = Math.random() * Math.PI + Math.PI / 2; } if (self.y < 100) { self.angle = Math.random() * Math.PI; } if (self.y > 2632) { self.angle = Math.random() * Math.PI + Math.PI; } animalGraphics.rotation = self.angle; }; self.takeDamage = function (damage) { damage = damage || 1; self.health -= damage; if (self.health <= 0) { return true; } return false; }; return self; }); var Bullet = Container.expand(function () { var self = Container.call(this); var bulletGraphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.angle = 0; self.velocityX = 0; self.velocityY = 0; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; }; return self; }); var Hunter = Container.expand(function () { var self = Container.call(this); var hunterGraphics = self.attachAsset('hunter', { anchorX: 0.5, anchorY: 0.5 }); self.aimAngle = 0; self.weapon = 1; self.reloadTime = 0; self.maxReloadTime = 25; // Set initial reload time to 25 self.update = function () { if (self.reloadTime > 0) { self.reloadTime--; } hunterGraphics.rotation = self.aimAngle; }; self.canShoot = function () { return self.reloadTime <= 0; }; self.shoot = function () { if (self.canShoot()) { self.reloadTime = self.maxReloadTime; return true; } return false; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x228B22 }); /**** * Game Code ****/ // Play background music LK.playMusic('bgmusic'); var hunter = game.addChild(new Hunter()); hunter.x = 2048 / 2; hunter.y = 2732 / 2; hunter.weapon = 1; hunter.maxReloadTime = 25; // Set initial reload time to 25 var bullets = []; var animals = []; var money = storage.money || 0; var totalKills = storage.totalKills || 0; upgradeCount = storage.upgradeCount || 0; var huntedAnimals = []; // Array to store hunted animals before selling var basicAnimalTypes = ['rabbit', 'deer', 'bear', 'rhino', 'zebra', 'crocodile', 'cheetah', 'cat']; var advancedAnimalTypes = ['rabbit', 'deer', 'bear', 'lion', 'elephant', 'rhino', 'zebra', 'giraffe', 'hippo', 'crocodile', 'cheetah', 'cat', 'trex', 'dragon']; // UI Elements - Money Counter var moneyTxt = new Text2('$' + money, { size: 80, fill: 0xFFD700 }); moneyTxt.anchor.set(0.5, 0); LK.gui.top.addChild(moneyTxt); var killsTxt = new Text2('Kills: ' + totalKills, { size: 60, fill: 0xFFFFFF }); killsTxt.anchor.set(0, 0); killsTxt.y = 70; LK.gui.topRight.addChild(killsTxt); var weaponTxt = new Text2('Weapon: Level ' + hunter.weapon, { size: 50, fill: 0xFFFFFF }); weaponTxt.anchor.set(0, 0); weaponTxt.y = 140; LK.gui.topRight.addChild(weaponTxt); // Inventory counter var inventoryTxt = new Text2('Inventory: 0', { size: 40, fill: 0x00FF00 }); inventoryTxt.anchor.set(0, 0); inventoryTxt.y = 200; LK.gui.topRight.addChild(inventoryTxt); // Sell button var sellBtn = new Text2('SELL ALL', { size: 50, fill: 0x00FF00 }); sellBtn.anchor.set(0.5, 1); sellBtn.y = -100; // Move button 100 pixels higher LK.gui.bottom.addChild(sellBtn); // Upgrade button var upgradeBtn = new Text2('UPGRADE', { size: 50, fill: 0x00FFFF }); upgradeBtn.anchor.set(0.5, 1); upgradeBtn.y = -200; // Position above sell button LK.gui.bottom.addChild(upgradeBtn); // Upgrade tracking var upgradeCount = 0; var maxUpgrades = 26; // Stats display in lower left corner var statsContainer = new Container(); LK.gui.bottomLeft.addChild(statsContainer); var damageTxt = new Text2('Damage: ' + getCurrentDamage(), { size: 40, fill: 0xFFFFFF }); damageTxt.anchor.set(0, 1); damageTxt.y = -50; statsContainer.addChild(damageTxt); var reloadTxt = new Text2('Reload: ' + getCurrentReloadTime(), { size: 40, fill: 0xFFFFFF }); reloadTxt.anchor.set(0, 1); reloadTxt.y = -10; statsContainer.addChild(reloadTxt); // Upgrade system var baseDamage = 1; var baseReloadTime = 25; function getUpgradePrice() { if (upgradeCount >= maxUpgrades) { return 500 + 250 * maxUpgrades; // Cap at 15 upgrades } return 500 + upgradeCount * 250; } function getCurrentDamage() { var damage = baseDamage; damage += Math.floor(upgradeCount / 4); // Increase damage by 1 every 4 upgrades return damage; } function getCurrentReloadTime() { return baseReloadTime - upgradeCount * 2; // Reload time decreases by 2 for each upgrade } function updateUI() { moneyTxt.setText('$' + money); killsTxt.setText('Kills: ' + totalKills); weaponTxt.setText('Damage: ' + getCurrentDamage() + ' | Reload: ' + getCurrentReloadTime()); inventoryTxt.setText('Inventory: ' + huntedAnimals.length); // Update stats display damageTxt.setText('Damage: ' + getCurrentDamage()); reloadTxt.setText('Reload: ' + getCurrentReloadTime()); // Update sell button to show potential earnings var totalValue = 0; for (var i = 0; i < huntedAnimals.length; i++) { totalValue += huntedAnimals[i].price; } if (huntedAnimals.length > 0) { sellBtn.setText('SELL ALL ($' + totalValue + ')'); sellBtn.fill = 0x00FF00; } else { sellBtn.setText('SELL ALL'); sellBtn.fill = 0x666666; } // Update upgrade button var upgradePrice = getUpgradePrice(); if (upgradeCount >= maxUpgrades) { upgradeBtn.setText('UPGRADE (MAX)'); upgradeBtn.fill = 0x666666; } else if (money >= upgradePrice) { upgradeBtn.setText('UPGRADE ($' + upgradePrice + ')'); upgradeBtn.fill = 0x00FFFF; } else { upgradeBtn.setText('UPGRADE ($' + upgradePrice + ')'); upgradeBtn.fill = 0x666666; } } function buyUpgrade() { var upgradePrice = getUpgradePrice(); // Check if max upgrades reached if (upgradeCount >= maxUpgrades) { return; } if (money >= upgradePrice) { money -= upgradePrice; upgradeCount++; hunter.maxReloadTime = getCurrentReloadTime(); updateUI(); storage.money = money; storage.upgradeCount = upgradeCount; LK.effects.flashScreen(0x00FF00, 300); } } function sellAllAnimals() { var totalValue = 0; for (var i = 0; i < huntedAnimals.length; i++) { totalValue += huntedAnimals[i].price; } money += totalValue; huntedAnimals = []; updateUI(); storage.money = money; if (totalValue > 0) { LK.effects.flashScreen(0x00FF00, 300); } } function spawnAnimal() { var currentAnimalTypes = totalKills > 8 ? advancedAnimalTypes : basicAnimalTypes; var animalType = null; var attempts = 0; var maxAttempts = 50; // Keep trying to spawn an animal based on chance until successful or max attempts reached while (animalType === null && attempts < maxAttempts) { var randomType = currentAnimalTypes[Math.floor(Math.random() * currentAnimalTypes.length)]; var tempAnimal = new Animal(randomType); var chance = tempAnimal.data.chance || 1.0; // Default to 100% if no chance specified if (Math.random() < chance) { animalType = randomType; } else { tempAnimal.destroy(); // Clean up the temporary animal if not spawned } attempts++; } // If we couldn't spawn anything after max attempts, force spawn a common animal if (animalType === null) { animalType = 'rabbit'; // Fallback to rabbit as it has high chance } var animal = new Animal(animalType); // Spawn at edge of screen var side = Math.floor(Math.random() * 4); switch (side) { case 0: // Top animal.x = Math.random() * 2048; animal.y = 0; break; case 1: // Right animal.x = 2048; animal.y = Math.random() * 2732; break; case 2: // Bottom animal.x = Math.random() * 2048; animal.y = 2732; break; case 3: // Left animal.x = 0; animal.y = Math.random() * 2732; break; } animals.push(animal); game.addChild(animal); } function shootBullet(targetX, targetY) { if (hunter.shoot()) { var bullet = new Bullet(); bullet.x = hunter.x; bullet.y = hunter.y; var dx = targetX - hunter.x; var dy = targetY - hunter.y; var distance = Math.sqrt(dx * dx + dy * dy); bullet.velocityX = dx / distance * bullet.speed; bullet.velocityY = dy / distance * bullet.speed; bullet.angle = Math.atan2(dy, dx); bullets.push(bullet); game.addChild(bullet); LK.getSound('shoot').play(); } } game.down = function (x, y, obj) { // Check if clicking sell button at bottom of screen (moved 100px higher) - larger hitbox for mobile if (y > 2480 && y < 2620 && x > 800 && x < 1248) { // Bottom area, centered button with expanded touch area if (huntedAnimals.length > 0) { sellAllAnimals(); LK.effects.flashObject(sellBtn, 0xFFFFFF, 200); } return; } // Check if clicking upgrade button above sell button if (y > 2380 && y < 2480 && x > 800 && x < 1248) { // Upgrade button area buyUpgrade(); LK.effects.flashObject(upgradeBtn, 0xFFFFFF, 200); return; } // Aim and shoot at clicked location - use x,y directly as they are already in game coordinates var dx = x - hunter.x; var dy = y - hunter.y; hunter.aimAngle = Math.atan2(dy, dx); shootBullet(x, y); }; game.update = function () { // Spawn animals if (LK.ticks % 120 == 0) { spawnAnimal(); } // Update bullets for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; // Remove off-screen bullets if (bullet.x < -50 || bullet.x > 2098 || bullet.y < -50 || bullet.y > 2782) { bullet.destroy(); bullets.splice(i, 1); continue; } // Check bullet-animal collisions for (var j = animals.length - 1; j >= 0; j--) { var animal = animals[j]; if (bullet.intersects(animal)) { var weaponDamage = getCurrentDamage(); if (animal.takeDamage(weaponDamage)) { // Animal killed - add to inventory with complete pricing data huntedAnimals.push({ type: animal.type, price: animal.data.price, asset: animal.data.asset }); totalKills++; LK.getSound('hit').play(); LK.effects.flashObject(animal, 0xFF0000, 200); animal.destroy(); animals.splice(j, 1); updateUI(); storage.totalKills = totalKills; } bullet.destroy(); bullets.splice(i, 1); break; } } } // Remove animals that are too far off screen for (var k = animals.length - 1; k >= 0; k--) { var animal = animals[k]; if (animal.x < -200 || animal.x > 2248 || animal.y < -200 || animal.y > 2932) { animal.destroy(); animals.splice(k, 1); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Animal = Container.expand(function (animalType) {
var self = Container.call(this);
var animalData = {
rabbit: {
asset: 'rabbit',
price: 10,
speed: 2,
health: 1,
chance: 0.85
},
deer: {
asset: 'deer',
price: 23,
speed: 1.5,
health: 2,
chance: 0.75
},
bear: {
asset: 'bear',
price: 62,
speed: 1,
health: 5,
chance: 0.30
},
lion: {
asset: 'lion',
price: 180,
speed: 2,
health: 4,
chance: 0.007
},
elephant: {
asset: 'elephant',
price: 250,
speed: 0.5,
health: 8,
chance: 0.005
},
rhino: {
asset: 'rhino',
price: 84,
speed: 1,
health: 6,
chance: 0.20
},
zebra: {
asset: 'zebra',
price: 62,
speed: 3,
health: 2,
chance: 0.60
},
giraffe: {
asset: 'giraffe',
price: 73,
speed: 1,
health: 3,
chance: 0.23
},
hippo: {
asset: 'hippo',
price: 90,
speed: 0.8,
health: 5,
chance: 0.17
},
crocodile: {
asset: 'crocodile',
price: 80,
speed: 1.2,
health: 3,
chance: 0.45
},
cheetah: {
asset: 'cheetah',
price: 50,
speed: 6,
health: 2,
chance: 0.10
},
cat: {
asset: 'cat',
price: 60,
speed: 1.5,
health: 1,
evasive: true,
chance: 0.10
},
trex: {
asset: 'trex',
price: 215,
speed: 1.5,
health: 10,
chance: 0.005
},
dragon: {
asset: 'dragon',
price: 300,
speed: 2,
health: 15,
chance: 0.0005
}
};
self.type = animalType;
self.data = animalData[animalType];
self.health = self.data.health;
self.maxHealth = self.data.health;
self.angle = Math.random() * Math.PI * 2;
self.speed = self.data.speed;
var animalGraphics = self.attachAsset(self.data.asset, {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Cat evasion behavior
if (self.data.evasive && bullets) {
// Initialize tracking variables if not set
if (self.lastClosestDistance === undefined) {
self.lastClosestDistance = 999;
}
if (self.wasNearBullet === undefined) {
self.wasNearBullet = false;
}
var closestBullet = null;
var closestDistance = 150; // Detection range
for (var b = 0; b < bullets.length; b++) {
var bullet = bullets[b];
var dx = bullet.x - self.x;
var dy = bullet.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < closestDistance) {
closestBullet = bullet;
closestDistance = distance;
}
}
var isNearBullet = closestBullet !== null;
// Check if bullet is approaching (getting closer)
if (isNearBullet && !self.wasNearBullet) {
// Bullet just entered detection range - increase speed
self.speed = self.data.speed * 4;
// Calculate escape direction (opposite to bullet direction)
var bulletDx = closestBullet.velocityX;
var bulletDy = closestBullet.velocityY;
self.angle = Math.atan2(-bulletDy, -bulletDx) + (Math.random() - 0.5) * 0.5;
} else if (!isNearBullet && self.wasNearBullet) {
// Bullet left detection range - return to normal speed
self.speed = self.data.speed;
} else if (isNearBullet && closestDistance < self.lastClosestDistance) {
// Bullet is still approaching and getting closer - maintain high speed and update direction
self.speed = self.data.speed * 4;
var bulletDx = closestBullet.velocityX;
var bulletDy = closestBullet.velocityY;
self.angle = Math.atan2(-bulletDy, -bulletDx) + (Math.random() - 0.5) * 0.5;
}
// Update tracking variables
self.wasNearBullet = isNearBullet;
self.lastClosestDistance = isNearBullet ? closestDistance : 999;
}
self.x += Math.cos(self.angle) * self.speed;
self.y += Math.sin(self.angle) * self.speed;
// Change direction randomly
if (Math.random() < 0.02) {
self.angle = Math.random() * Math.PI * 2;
}
// Keep animals within bounds
if (self.x < 100) {
self.angle = Math.random() * Math.PI - Math.PI / 2;
}
if (self.x > 1948) {
self.angle = Math.random() * Math.PI + Math.PI / 2;
}
if (self.y < 100) {
self.angle = Math.random() * Math.PI;
}
if (self.y > 2632) {
self.angle = Math.random() * Math.PI + Math.PI;
}
animalGraphics.rotation = self.angle;
};
self.takeDamage = function (damage) {
damage = damage || 1;
self.health -= damage;
if (self.health <= 0) {
return true;
}
return false;
};
return self;
});
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.angle = 0;
self.velocityX = 0;
self.velocityY = 0;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
};
return self;
});
var Hunter = Container.expand(function () {
var self = Container.call(this);
var hunterGraphics = self.attachAsset('hunter', {
anchorX: 0.5,
anchorY: 0.5
});
self.aimAngle = 0;
self.weapon = 1;
self.reloadTime = 0;
self.maxReloadTime = 25; // Set initial reload time to 25
self.update = function () {
if (self.reloadTime > 0) {
self.reloadTime--;
}
hunterGraphics.rotation = self.aimAngle;
};
self.canShoot = function () {
return self.reloadTime <= 0;
};
self.shoot = function () {
if (self.canShoot()) {
self.reloadTime = self.maxReloadTime;
return true;
}
return false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x228B22
});
/****
* Game Code
****/
// Play background music
LK.playMusic('bgmusic');
var hunter = game.addChild(new Hunter());
hunter.x = 2048 / 2;
hunter.y = 2732 / 2;
hunter.weapon = 1;
hunter.maxReloadTime = 25; // Set initial reload time to 25
var bullets = [];
var animals = [];
var money = storage.money || 0;
var totalKills = storage.totalKills || 0;
upgradeCount = storage.upgradeCount || 0;
var huntedAnimals = []; // Array to store hunted animals before selling
var basicAnimalTypes = ['rabbit', 'deer', 'bear', 'rhino', 'zebra', 'crocodile', 'cheetah', 'cat'];
var advancedAnimalTypes = ['rabbit', 'deer', 'bear', 'lion', 'elephant', 'rhino', 'zebra', 'giraffe', 'hippo', 'crocodile', 'cheetah', 'cat', 'trex', 'dragon'];
// UI Elements - Money Counter
var moneyTxt = new Text2('$' + money, {
size: 80,
fill: 0xFFD700
});
moneyTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(moneyTxt);
var killsTxt = new Text2('Kills: ' + totalKills, {
size: 60,
fill: 0xFFFFFF
});
killsTxt.anchor.set(0, 0);
killsTxt.y = 70;
LK.gui.topRight.addChild(killsTxt);
var weaponTxt = new Text2('Weapon: Level ' + hunter.weapon, {
size: 50,
fill: 0xFFFFFF
});
weaponTxt.anchor.set(0, 0);
weaponTxt.y = 140;
LK.gui.topRight.addChild(weaponTxt);
// Inventory counter
var inventoryTxt = new Text2('Inventory: 0', {
size: 40,
fill: 0x00FF00
});
inventoryTxt.anchor.set(0, 0);
inventoryTxt.y = 200;
LK.gui.topRight.addChild(inventoryTxt);
// Sell button
var sellBtn = new Text2('SELL ALL', {
size: 50,
fill: 0x00FF00
});
sellBtn.anchor.set(0.5, 1);
sellBtn.y = -100; // Move button 100 pixels higher
LK.gui.bottom.addChild(sellBtn);
// Upgrade button
var upgradeBtn = new Text2('UPGRADE', {
size: 50,
fill: 0x00FFFF
});
upgradeBtn.anchor.set(0.5, 1);
upgradeBtn.y = -200; // Position above sell button
LK.gui.bottom.addChild(upgradeBtn);
// Upgrade tracking
var upgradeCount = 0;
var maxUpgrades = 26;
// Stats display in lower left corner
var statsContainer = new Container();
LK.gui.bottomLeft.addChild(statsContainer);
var damageTxt = new Text2('Damage: ' + getCurrentDamage(), {
size: 40,
fill: 0xFFFFFF
});
damageTxt.anchor.set(0, 1);
damageTxt.y = -50;
statsContainer.addChild(damageTxt);
var reloadTxt = new Text2('Reload: ' + getCurrentReloadTime(), {
size: 40,
fill: 0xFFFFFF
});
reloadTxt.anchor.set(0, 1);
reloadTxt.y = -10;
statsContainer.addChild(reloadTxt);
// Upgrade system
var baseDamage = 1;
var baseReloadTime = 25;
function getUpgradePrice() {
if (upgradeCount >= maxUpgrades) {
return 500 + 250 * maxUpgrades; // Cap at 15 upgrades
}
return 500 + upgradeCount * 250;
}
function getCurrentDamage() {
var damage = baseDamage;
damage += Math.floor(upgradeCount / 4); // Increase damage by 1 every 4 upgrades
return damage;
}
function getCurrentReloadTime() {
return baseReloadTime - upgradeCount * 2; // Reload time decreases by 2 for each upgrade
}
function updateUI() {
moneyTxt.setText('$' + money);
killsTxt.setText('Kills: ' + totalKills);
weaponTxt.setText('Damage: ' + getCurrentDamage() + ' | Reload: ' + getCurrentReloadTime());
inventoryTxt.setText('Inventory: ' + huntedAnimals.length);
// Update stats display
damageTxt.setText('Damage: ' + getCurrentDamage());
reloadTxt.setText('Reload: ' + getCurrentReloadTime());
// Update sell button to show potential earnings
var totalValue = 0;
for (var i = 0; i < huntedAnimals.length; i++) {
totalValue += huntedAnimals[i].price;
}
if (huntedAnimals.length > 0) {
sellBtn.setText('SELL ALL ($' + totalValue + ')');
sellBtn.fill = 0x00FF00;
} else {
sellBtn.setText('SELL ALL');
sellBtn.fill = 0x666666;
}
// Update upgrade button
var upgradePrice = getUpgradePrice();
if (upgradeCount >= maxUpgrades) {
upgradeBtn.setText('UPGRADE (MAX)');
upgradeBtn.fill = 0x666666;
} else if (money >= upgradePrice) {
upgradeBtn.setText('UPGRADE ($' + upgradePrice + ')');
upgradeBtn.fill = 0x00FFFF;
} else {
upgradeBtn.setText('UPGRADE ($' + upgradePrice + ')');
upgradeBtn.fill = 0x666666;
}
}
function buyUpgrade() {
var upgradePrice = getUpgradePrice();
// Check if max upgrades reached
if (upgradeCount >= maxUpgrades) {
return;
}
if (money >= upgradePrice) {
money -= upgradePrice;
upgradeCount++;
hunter.maxReloadTime = getCurrentReloadTime();
updateUI();
storage.money = money;
storage.upgradeCount = upgradeCount;
LK.effects.flashScreen(0x00FF00, 300);
}
}
function sellAllAnimals() {
var totalValue = 0;
for (var i = 0; i < huntedAnimals.length; i++) {
totalValue += huntedAnimals[i].price;
}
money += totalValue;
huntedAnimals = [];
updateUI();
storage.money = money;
if (totalValue > 0) {
LK.effects.flashScreen(0x00FF00, 300);
}
}
function spawnAnimal() {
var currentAnimalTypes = totalKills > 8 ? advancedAnimalTypes : basicAnimalTypes;
var animalType = null;
var attempts = 0;
var maxAttempts = 50;
// Keep trying to spawn an animal based on chance until successful or max attempts reached
while (animalType === null && attempts < maxAttempts) {
var randomType = currentAnimalTypes[Math.floor(Math.random() * currentAnimalTypes.length)];
var tempAnimal = new Animal(randomType);
var chance = tempAnimal.data.chance || 1.0; // Default to 100% if no chance specified
if (Math.random() < chance) {
animalType = randomType;
} else {
tempAnimal.destroy(); // Clean up the temporary animal if not spawned
}
attempts++;
}
// If we couldn't spawn anything after max attempts, force spawn a common animal
if (animalType === null) {
animalType = 'rabbit'; // Fallback to rabbit as it has high chance
}
var animal = new Animal(animalType);
// Spawn at edge of screen
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// Top
animal.x = Math.random() * 2048;
animal.y = 0;
break;
case 1:
// Right
animal.x = 2048;
animal.y = Math.random() * 2732;
break;
case 2:
// Bottom
animal.x = Math.random() * 2048;
animal.y = 2732;
break;
case 3:
// Left
animal.x = 0;
animal.y = Math.random() * 2732;
break;
}
animals.push(animal);
game.addChild(animal);
}
function shootBullet(targetX, targetY) {
if (hunter.shoot()) {
var bullet = new Bullet();
bullet.x = hunter.x;
bullet.y = hunter.y;
var dx = targetX - hunter.x;
var dy = targetY - hunter.y;
var distance = Math.sqrt(dx * dx + dy * dy);
bullet.velocityX = dx / distance * bullet.speed;
bullet.velocityY = dy / distance * bullet.speed;
bullet.angle = Math.atan2(dy, dx);
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
}
}
game.down = function (x, y, obj) {
// Check if clicking sell button at bottom of screen (moved 100px higher) - larger hitbox for mobile
if (y > 2480 && y < 2620 && x > 800 && x < 1248) {
// Bottom area, centered button with expanded touch area
if (huntedAnimals.length > 0) {
sellAllAnimals();
LK.effects.flashObject(sellBtn, 0xFFFFFF, 200);
}
return;
}
// Check if clicking upgrade button above sell button
if (y > 2380 && y < 2480 && x > 800 && x < 1248) {
// Upgrade button area
buyUpgrade();
LK.effects.flashObject(upgradeBtn, 0xFFFFFF, 200);
return;
}
// Aim and shoot at clicked location - use x,y directly as they are already in game coordinates
var dx = x - hunter.x;
var dy = y - hunter.y;
hunter.aimAngle = Math.atan2(dy, dx);
shootBullet(x, y);
};
game.update = function () {
// Spawn animals
if (LK.ticks % 120 == 0) {
spawnAnimal();
}
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Remove off-screen bullets
if (bullet.x < -50 || bullet.x > 2098 || bullet.y < -50 || bullet.y > 2782) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check bullet-animal collisions
for (var j = animals.length - 1; j >= 0; j--) {
var animal = animals[j];
if (bullet.intersects(animal)) {
var weaponDamage = getCurrentDamage();
if (animal.takeDamage(weaponDamage)) {
// Animal killed - add to inventory with complete pricing data
huntedAnimals.push({
type: animal.type,
price: animal.data.price,
asset: animal.data.asset
});
totalKills++;
LK.getSound('hit').play();
LK.effects.flashObject(animal, 0xFF0000, 200);
animal.destroy();
animals.splice(j, 1);
updateUI();
storage.totalKills = totalKills;
}
bullet.destroy();
bullets.splice(i, 1);
break;
}
}
}
// Remove animals that are too far off screen
for (var k = animals.length - 1; k >= 0; k--) {
var animal = animals[k];
if (animal.x < -200 || animal.x > 2248 || animal.y < -200 || animal.y > 2932) {
animal.destroy();
animals.splice(k, 1);
}
}
};
Hunter pixel. In-Game asset. 2d. High contrast. No shadows
Pixel bear. In-Game asset. 2d. High contrast. No shadows
Pixel deer. In-Game asset. 2d. High contrast. No shadows
Pixel Cheetah. In-Game asset. 2d. High contrast. No shadows
Pixel Rabbit. In-Game asset. 2d. High contrast. No shadows
Pixel cat. In-Game asset. 2d. High contrast. No shadows
elephant pixel. In-Game asset. 2d. High contrast. No shadows
Hippo pixel. In-Game asset. 2d. High contrast. No shadows
Pixel lion. In-Game asset. 2d. High contrast. No shadows
Pixel rhino. In-Game asset. 2d. High contrast. No shadows
Giraffe Pixel. In-Game asset. 2d. High contrast. No shadows
Crocodile pixel. In-Game asset. 2d. High contrast. No shadows
Zebra pixel. In-Game asset. 2d. High contrast. No shadows
T rex 8bit. In-Game asset. 2d. High contrast. No shadows
Dragon 8 bit. In-Game asset. 2d. High contrast. No shadows