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 } }; 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 () { 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 () { self.health--; 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']; // 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 ($' + hunter.weapon * 100 + ')', { size: 40, fill: 0xFFFF00 }); upgradeBtn.anchor.set(0, 0); upgradeBtn.y = 300; LK.gui.topRight.addChild(upgradeBtn); function updateUI() { moneyTxt.setText('$' + money); killsTxt.setText('Kills: ' + totalKills); weaponTxt.setText('Weapon: Level ' + hunter.weapon); inventoryTxt.setText('Inventory: ' + huntedAnimals.length); upgradeBtn.setText('UPGRADE ($' + hunter.weapon * 100 + ')'); // 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 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) { // 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 UI buttons in top right area if (x > 1648 && y < 350) { // Upgrade button area (y: 300-340) if (y >= 300 && y < 340) { var upgradeCost = hunter.weapon * 100; if (money >= upgradeCost) { money -= upgradeCost; hunter.weapon++; hunter.maxReloadTime = Math.max(10, 30 - hunter.weapon * 2); updateUI(); storage.money = money; } return; } 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)) { if (animal.takeDamage()) { // 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
@@ -171,9 +171,9 @@
hunter.x = 2048 / 2;
hunter.y = 2732 / 2;
var bullets = [];
var animals = [];
-var money = storage.money || 0;
+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'];
// UI Elements - Money Counter
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