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 }, deer: { asset: 'deer', price: 25, speed: 1.5, health: 2 }, bear: { asset: 'bear', price: 100, speed: 1, health: 5 }, lion: { asset: 'lion', price: 150, speed: 2, health: 4 }, elephant: { asset: 'elephant', price: 200, speed: 0.5, health: 8 }, rhino: { asset: 'rhino', price: 180, speed: 1, health: 6 }, zebra: { asset: 'zebra', price: 60, speed: 3, health: 2 }, giraffe: { asset: 'giraffe', price: 120, speed: 1, health: 3 }, hippo: { asset: 'hippo', price: 90, speed: 0.8, health: 5 }, crocodile: { asset: 'crocodile', price: 80, speed: 1.2, health: 3 }, cheetah: { asset: 'cheetah', price: 140, speed: 6, health: 2 }, cat: { asset: 'cat', price: 300, speed: 1.5, health: 1, evasive: true } }; 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) { 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; } } if (closestBullet) { // 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; // Accelerate when evading tween(self, { speed: self.data.speed * 4 }, { duration: 500, onFinish: function onFinish() { self.speed = self.data.speed; } }); } } 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 = 30; 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; var bullets = []; var animals = []; var money = 0; var totalKills = storage.totalKills || 0; var huntedAnimals = []; // Array to store hunted animals before selling var animalTypes = ['rabbit', 'deer', 'bear', 'lion', 'elephant', 'rhino', 'zebra', 'giraffe', 'hippo', 'crocodile', 'cheetah', 'cat']; // 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); // Shop button var shopBtn = new Text2('SHOP', { size: 50, fill: 0x00FFFF }); shopBtn.anchor.set(0.5, 1); shopBtn.y = -200; // Position above sell button LK.gui.bottom.addChild(shopBtn); // Shop state var shopOpen = false; var shopContainer = null; // Weapon definitions var weaponData = [{ name: 'Basic Rifle', damage: 1, reloadTime: 30, price: 0 }, { name: 'Hunting Rifle', damage: 2, reloadTime: 25, price: 200 }, { name: 'Sniper Rifle', damage: 3, reloadTime: 20, price: 500 }, { name: 'Auto Rifle', damage: 2, reloadTime: 15, price: 800 }, { name: 'Power Rifle', damage: 4, reloadTime: 25, price: 1200 }]; function updateUI() { moneyTxt.setText('$' + money); killsTxt.setText('Kills: ' + totalKills); weaponTxt.setText('Weapon: ' + weaponData[hunter.weapon - 1].name); inventoryTxt.setText('Inventory: ' + huntedAnimals.length); // 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; } } function openShop() { shopOpen = true; // Create shop container shopContainer = new Container(); game.addChild(shopContainer); // Shop background var shopBg = LK.getAsset('crocodile', { scaleX: 15, scaleY: 40, x: 1024, y: 1366, anchorX: 0.5, anchorY: 0.5 }); shopBg.tint = 0x000000; shopBg.alpha = 0.8; shopContainer.addChild(shopBg); // Shop title var shopTitle = new Text2('WEAPON SHOP', { size: 80, fill: 0xFFFFFF }); shopTitle.anchor.set(0.5, 0.5); shopTitle.x = 1024; shopTitle.y = 600; shopContainer.addChild(shopTitle); // Close button var closeBtn = new Text2('CLOSE', { size: 60, fill: 0xFF0000 }); closeBtn.anchor.set(0.5, 0.5); closeBtn.x = 1024; closeBtn.y = 2100; shopContainer.addChild(closeBtn); // Weapon buttons for (var i = 0; i < weaponData.length; i++) { var weapon = weaponData[i]; var yPos = 800 + i * 200; // Weapon name and stats var weaponText = weapon.name + ' - Damage: ' + weapon.damage + ' - Reload: ' + weapon.reloadTime; if (weapon.price > 0) { weaponText += ' - $' + weapon.price; } var weaponBtn = new Text2(weaponText, { size: 40, fill: hunter.weapon === i + 1 ? 0x00FF00 : money >= weapon.price ? 0xFFFFFF : 0x666666 }); weaponBtn.anchor.set(0.5, 0.5); weaponBtn.x = 1024; weaponBtn.y = yPos; weaponBtn.weaponIndex = i + 1; shopContainer.addChild(weaponBtn); } } function closeShop() { shopOpen = false; if (shopContainer) { shopContainer.destroy(); shopContainer = null; } } function buyWeapon(weaponIndex) { var weapon = weaponData[weaponIndex - 1]; if (weaponIndex === hunter.weapon) { // Already owned return; } if (money >= weapon.price) { money -= weapon.price; hunter.weapon = weaponIndex; hunter.maxReloadTime = weapon.reloadTime; updateUI(); storage.money = money; LK.effects.flashScreen(0x00FF00, 300); closeShop(); } } 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 animalType = animalTypes[Math.floor(Math.random() * animalTypes.length)]; 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) { // Handle shop interactions first if (shopOpen) { // Close button if (y > 2050 && y < 2150 && x > 900 && x < 1150) { closeShop(); return; } // Weapon buttons for (var i = 0; i < weaponData.length; i++) { var buttonY = 800 + i * 200; if (y > buttonY - 50 && y < buttonY + 50 && x > 400 && x < 1650) { buyWeapon(i + 1); return; } } return; // Don't process other clicks when shop is open } // 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 shop button above sell button if (y > 2380 && y < 2480 && x > 800 && x < 1248) { // Shop button area openShop(); 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 = weaponData[hunter.weapon - 1].damage; 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); } } // Win condition - reach $1000 if (money >= 1000) { LK.showYouWin(); } };
===================================================================
--- original.js
+++ change.js
@@ -74,8 +74,15 @@
asset: 'cheetah',
price: 140,
speed: 6,
health: 2
+ },
+ cat: {
+ asset: 'cat',
+ price: 300,
+ speed: 1.5,
+ health: 1,
+ evasive: true
}
};
self.type = animalType;
self.data = animalData[animalType];
@@ -87,8 +94,38 @@
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
+ // Cat evasion behavior
+ if (self.data.evasive && bullets) {
+ 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;
+ }
+ }
+ if (closestBullet) {
+ // 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;
+ // Accelerate when evading
+ tween(self, {
+ speed: self.data.speed * 4
+ }, {
+ duration: 500,
+ onFinish: function onFinish() {
+ self.speed = self.data.speed;
+ }
+ });
+ }
+ }
self.x += Math.cos(self.angle) * self.speed;
self.y += Math.sin(self.angle) * self.speed;
// Change direction randomly
if (Math.random() < 0.02) {
@@ -175,9 +212,9 @@
var animals = [];
var money = 0;
var totalKills = storage.totalKills || 0;
var huntedAnimals = []; // Array to store hunted animals before selling
-var animalTypes = ['rabbit', 'deer', 'bear', 'lion', 'elephant', 'rhino', 'zebra', 'giraffe', 'hippo', 'crocodile', 'cheetah'];
+var animalTypes = ['rabbit', 'deer', 'bear', 'lion', 'elephant', 'rhino', 'zebra', 'giraffe', 'hippo', 'crocodile', 'cheetah', 'cat'];
// UI Elements - Money Counter
var moneyTxt = new Text2('$' + money, {
size: 80,
fill: 0xFFD700
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