User prompt
Delete,innerring,middlering,outerring
User prompt
Undo 1 time
User prompt
When the bow is stretched, the arrow is at 90 degrees, while the bow and string are at 0 degrees. The rotation of the bow changes without changing its location.
User prompt
As the bow is stretched, the rotation of the bow changes without changing its location, just like the arrow.
User prompt
As the bow is drawn, draw a line in the direction the arrow will go.
User prompt
Change location of the bow and target,bow down left ,target top right
User prompt
Set rotation of the bow when streching bow with same of the arrow at where it is
User prompt
Set bow's rotation when streching the bow with same of the arrow
User prompt
Change arrow's location to center of the bow
User prompt
Undo 2 times
User prompt
Undo
User prompt
Rechange
User prompt
Change string's location to bow's top right and down left
User prompt
Change bow's location to left and change target's location to right
User prompt
İncrease 3 times arrow's speed and way lenght
Code edit (1 edits merged)
Please save this source code
User prompt
Archery Target Master
Initial prompt
There will be a bow and arrow, the arrow will fly out of the bow with the pull-release logic and there will be a target in front of you, with the scoring system, the more it hits the middle, the more points it will get
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Arrow = Container.expand(function () { var self = Container.call(this); var arrowBody = self.attachAsset('arrow', { anchorX: 0, anchorY: 0.5 }); var arrowHead = self.attachAsset('arrowHead', { anchorX: 0, anchorY: 0.5, x: 120 }); self.velocityX = 0; self.velocityY = 0; self.gravity = 0.3; self.isFlying = false; self.update = function () { if (self.isFlying) { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; // Update rotation based on velocity self.rotation = Math.atan2(self.velocityY, self.velocityX); // Check if arrow is off screen if (self.x > 6600 || self.y > 8400) { self.isFlying = false; self.destroy(); } } }; self.fire = function (power, angle) { var speed = power * 45; self.velocityX = Math.cos(angle) * speed; self.velocityY = Math.sin(angle) * speed; self.isFlying = true; self.rotation = angle; }; return self; }); var Bow = Container.expand(function () { var self = Container.call(this); var bowBody = self.attachAsset('bow', { anchorX: 0.5, anchorY: 1 }); var bowstring = self.attachAsset('bowstring', { anchorX: 0.5, anchorY: 0, x: 0, y: -180 }); self.isPulling = false; self.pullDistance = 0; self.maxPull = 150; return self; }); var Target = Container.expand(function () { var self = Container.call(this); var outerRing = self.attachAsset('outerRing', { anchorX: 0.5, anchorY: 0.5 }); var middleRing = self.attachAsset('middleRing', { anchorX: 0.5, anchorY: 0.5 }); var innerRing = self.attachAsset('innerRing', { anchorX: 0.5, anchorY: 0.5 }); var bullseye = self.attachAsset('bullseye', { anchorX: 0.5, anchorY: 0.5 }); self.getScore = function (hitX, hitY) { var dx = hitX - self.x; var dy = hitY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance <= 40) return 10; // Bullseye if (distance <= 80) return 8; // Inner ring if (distance <= 120) return 6; // Middle inner if (distance <= 160) return 4; // Middle outer if (distance <= 200) return 2; // Outer ring return 0; // Miss }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var target = game.addChild(new Target()); target.x = 1748; target.y = 400; var bow = game.addChild(new Bow()); bow.x = 300; bow.y = 2500; var arrows = []; var currentArrow = null; var isDragging = false; var dragStartX = 0; var dragStartY = 0; var pullDistance = 0; var arrowsRemaining = 10; // Score display var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Arrows remaining display var arrowsTxt = new Text2('Arrows: 10', { size: 60, fill: 0xFFFFFF }); arrowsTxt.anchor.set(1, 0); arrowsTxt.x = -50; arrowsTxt.y = 100; LK.gui.topRight.addChild(arrowsTxt); function createNewArrow() { if (currentArrow) { currentArrow.destroy(); } currentArrow = game.addChild(new Arrow()); currentArrow.x = bow.x; currentArrow.y = bow.y - 100; currentArrow.alpha = 0.8; } function updateScore() { scoreTxt.setText('Score: ' + LK.getScore()); } function updateArrowsDisplay() { arrowsTxt.setText('Arrows: ' + arrowsRemaining); } // Initialize first arrow createNewArrow(); game.down = function (x, y, obj) { if (currentArrow && arrowsRemaining > 0) { isDragging = true; dragStartX = x; dragStartY = y; } }; game.move = function (x, y, obj) { if (isDragging && currentArrow) { var dx = dragStartX - x; var dy = dragStartY - y; pullDistance = Math.sqrt(dx * dx + dy * dy); if (pullDistance > 200) { pullDistance = 200; var angle = Math.atan2(dy, dx); dx = Math.cos(angle) * 200; dy = Math.sin(angle) * 200; } // Update arrow position and rotation based on pull var angle = Math.atan2(dy, dx); currentArrow.x = bow.x - dx * 0.3; currentArrow.y = bow.y - 100 - dy * 0.3; currentArrow.rotation = angle; // Set bow rotation to match arrow angle bow.rotation = angle; // Visual feedback for pull strength var pullStrength = pullDistance / 200; currentArrow.alpha = 0.5 + pullStrength * 0.5; } }; game.up = function (x, y, obj) { if (isDragging && currentArrow && arrowsRemaining > 0) { isDragging = false; if (pullDistance > 20) { // Fire the arrow var dx = dragStartX - x; var dy = dragStartY - y; var angle = Math.atan2(dy, dx); var power = Math.min(pullDistance / 200, 1); currentArrow.fire(power, angle); arrows.push(currentArrow); arrowsRemaining--; updateArrowsDisplay(); LK.getSound('shoot').play(); currentArrow = null; // Create new arrow after a delay LK.setTimeout(function () { if (arrowsRemaining > 0) { createNewArrow(); } }, 1000); } else { // Reset arrow position if pull was too weak currentArrow.x = bow.x; currentArrow.y = bow.y - 100; currentArrow.rotation = 0; currentArrow.alpha = 0.8; } pullDistance = 0; // Reset bow rotation when releasing bow.rotation = 0; } }; game.update = function () { // Check arrow collisions with target for (var i = arrows.length - 1; i >= 0; i--) { var arrow = arrows[i]; if (arrow.isFlying && arrow.intersects(target)) { // Arrow hit target arrow.isFlying = false; arrow.velocityX = 0; arrow.velocityY = 0; var score = target.getScore(arrow.x, arrow.y); LK.setScore(LK.getScore() + score); updateScore(); // Visual feedback if (score > 0) { LK.effects.flashObject(target, 0x00FF00, 500); LK.getSound('hit').play(); // Show score popup var scorePopup = new Text2('+' + score, { size: 100, fill: 0xFFD700 }); scorePopup.anchor.set(0.5, 0.5); scorePopup.x = arrow.x; scorePopup.y = arrow.y - 50; game.addChild(scorePopup); tween(scorePopup, { y: scorePopup.y - 100, alpha: 0 }, { duration: 1500, onFinish: function onFinish() { scorePopup.destroy(); } }); } arrows.splice(i, 1); } } // Check win condition if (LK.getScore() >= 80) { LK.showYouWin(); } // Check game over condition if (arrowsRemaining <= 0 && arrows.length === 0 && !currentArrow) { LK.setTimeout(function () { if (LK.getScore() < 80) { LK.showGameOver(); } }, 2000); } };
===================================================================
--- original.js
+++ change.js
@@ -103,12 +103,12 @@
/****
* Game Code
****/
var target = game.addChild(new Target());
-target.x = 1024;
+target.x = 1748;
target.y = 400;
var bow = game.addChild(new Bow());
-bow.x = 1024;
+bow.x = 300;
bow.y = 2500;
var arrows = [];
var currentArrow = null;
var isDragging = false;
Wooden Bow. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Wood bow. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Arrow head. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat