User prompt
Zemini çimen yap
User prompt
Addsilingshoutbase
User prompt
Please fix the bug: 'Uncaught TypeError: LK.effects.shakeScreen is not a function' in or related to this line: 'LK.effects.shakeScreen(distance / 10, 200);' Line Number: 499
User prompt
Sapanı daha gerçekçi yap efekt animasyon ekle. Top giderken de animasyonlu gitsin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Top bitince yeniden başlat
User prompt
Tamam yap
User prompt
Topa vurdugumda ses çalsın. Birde sapan asset yükledim bunu playerin eline ekle
User prompt
Player hize düzelt büyüt
User prompt
Please fix the bug: 'Uncaught TypeError: tween.to is not a function' in or related to this line: 'tween.to(self, 0.1, {' Line Number: 44 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Player yok
Code edit (1 edits merged)
Please save this source code
User prompt
Slingshot Strike
Initial prompt
Angry birds tarzı
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Projectile = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('projectile', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.5;
self.launched = false;
self.destroyed = false;
self.launch = function (vx, vy) {
self.velocityX = vx;
self.velocityY = vy;
self.launched = true;
LK.getSound('launch').play();
};
self.update = function () {
if (self.launched && !self.destroyed) {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += self.gravity;
// Check ground collision
if (self.y >= groundY - 30) {
self.y = groundY - 30;
self.velocityY = -self.velocityY * 0.3;
self.velocityX *= 0.8;
if (Math.abs(self.velocityY) < 2) {
self.launched = false;
}
}
// Check screen bounds
if (self.x > 2200 || self.x < -100 || self.y > 2800) {
self.destroyed = true;
}
}
};
return self;
});
var TargetBlock = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('targetBlock', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 1;
self.destroyed = false;
self.takeDamage = function () {
self.health--;
if (self.health <= 0) {
self.destroyed = true;
LK.getSound('destroy').play();
LK.setScore(LK.getScore() + 100);
LK.effects.flashObject(self, 0xFFFFFF, 200);
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var slingshot;
var slingshotBase;
var currentProjectile = null;
var isAiming = false;
var aimStartX = 0;
var aimStartY = 0;
var trajectoryDots = [];
var targetBlocks = [];
var projectiles = [];
var shotsRemaining = 5;
var level = 1;
var groundY = 2600;
// UI elements
var shotsText = new Text2('Shots: 5', {
size: 80,
fill: 0x000000
});
shotsText.anchor.set(0, 0);
LK.gui.topRight.addChild(shotsText);
shotsText.x = -300;
shotsText.y = 100;
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0x000000
});
scoreText.anchor.set(0, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 100;
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 0.5
}));
ground.x = 1024;
ground.y = groundY;
// Create slingshot
slingshotBase = game.addChild(LK.getAsset('slingshotBase', {
anchorX: 0.5,
anchorY: 1
}));
slingshotBase.x = 200;
slingshotBase.y = groundY;
slingshot = game.addChild(LK.getAsset('slingshot', {
anchorX: 0.5,
anchorY: 1
}));
slingshot.x = 200;
slingshot.y = groundY;
// Create trajectory dots
for (var i = 0; i < 15; i++) {
var dot = game.addChild(LK.getAsset('trajectoryDot', {
anchorX: 0.5,
anchorY: 0.5
}));
dot.visible = false;
trajectoryDots.push(dot);
}
// Create target structures
function createLevel() {
// Clear existing targets
for (var i = targetBlocks.length - 1; i >= 0; i--) {
if (targetBlocks[i].destroyed) {
targetBlocks[i].destroy();
targetBlocks.splice(i, 1);
}
}
targetBlocks = [];
// Create target blocks in tower formation
var startX = 1400;
var startY = groundY - 50;
// Bottom row
for (var i = 0; i < 4; i++) {
var block = game.addChild(new TargetBlock());
block.x = startX + i * 110;
block.y = startY;
targetBlocks.push(block);
}
// Middle row
for (var i = 0; i < 3; i++) {
var block = game.addChild(new TargetBlock());
block.x = startX + 55 + i * 110;
block.y = startY - 110;
targetBlocks.push(block);
}
// Top row
for (var i = 0; i < 2; i++) {
var block = game.addChild(new TargetBlock());
block.x = startX + 110 + i * 110;
block.y = startY - 220;
targetBlocks.push(block);
}
// Top block
var block = game.addChild(new TargetBlock());
block.x = startX + 165;
block.y = startY - 330;
targetBlocks.push(block);
}
// Initialize first level
createLevel();
// Helper functions
function calculateTrajectory(startX, startY, velocityX, velocityY) {
var points = [];
var x = startX;
var y = startY;
var vx = velocityX;
var vy = velocityY;
for (var i = 0; i < 15; i++) {
points.push({
x: x,
y: y
});
x += vx * 2;
y += vy * 2;
vy += 0.5 * 2;
if (y >= groundY - 30) break;
}
return points;
}
function updateTrajectoryDisplay(points) {
for (var i = 0; i < trajectoryDots.length; i++) {
if (i < points.length) {
trajectoryDots[i].x = points[i].x;
trajectoryDots[i].y = points[i].y;
trajectoryDots[i].visible = true;
} else {
trajectoryDots[i].visible = false;
}
}
}
function hideTrajectoryDisplay() {
for (var i = 0; i < trajectoryDots.length; i++) {
trajectoryDots[i].visible = false;
}
}
function checkProjectileCollisions(projectile) {
for (var i = 0; i < targetBlocks.length; i++) {
var block = targetBlocks[i];
if (!block.destroyed && projectile.intersects(block)) {
block.takeDamage();
LK.getSound('impact').play();
projectile.velocityX *= -0.3;
projectile.velocityY *= -0.3;
return true;
}
}
return false;
}
function checkLevelComplete() {
var remainingBlocks = 0;
for (var i = 0; i < targetBlocks.length; i++) {
if (!targetBlocks[i].destroyed) {
remainingBlocks++;
}
}
if (remainingBlocks === 0) {
// Level complete
level++;
shotsRemaining = 5;
LK.setTimeout(function () {
createLevel();
}, 1000);
return true;
}
if (shotsRemaining <= 0 && projectiles.length === 0) {
// Game over
LK.showGameOver();
return true;
}
return false;
}
// Event handlers
game.down = function (x, y, obj) {
if (!currentProjectile && shotsRemaining > 0) {
var distance = Math.sqrt((x - slingshot.x) * (x - slingshot.x) + (y - slingshot.y) * (y - slingshot.y));
if (distance < 150) {
isAiming = true;
aimStartX = x;
aimStartY = y;
currentProjectile = game.addChild(new Projectile());
currentProjectile.x = slingshot.x;
currentProjectile.y = slingshot.y - 100;
}
}
};
game.move = function (x, y, obj) {
if (isAiming && currentProjectile) {
var deltaX = aimStartX - x;
var deltaY = aimStartY - y;
// Limit drag distance
var maxDistance = 150;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > maxDistance) {
deltaX = deltaX / distance * maxDistance;
deltaY = deltaY / distance * maxDistance;
}
currentProjectile.x = slingshot.x - deltaX * 0.5;
currentProjectile.y = slingshot.y - 100 - deltaY * 0.5;
// Calculate and show trajectory
var velocityX = deltaX * 0.3;
var velocityY = deltaY * 0.3;
var trajectoryPoints = calculateTrajectory(currentProjectile.x, currentProjectile.y, velocityX, velocityY);
updateTrajectoryDisplay(trajectoryPoints);
}
};
game.up = function (x, y, obj) {
if (isAiming && currentProjectile) {
var deltaX = aimStartX - x;
var deltaY = aimStartY - y;
// Limit drag distance
var maxDistance = 150;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > maxDistance) {
deltaX = deltaX / distance * maxDistance;
deltaY = deltaY / distance * maxDistance;
}
if (distance > 20) {
var velocityX = deltaX * 0.3;
var velocityY = deltaY * 0.3;
currentProjectile.launch(velocityX, velocityY);
projectiles.push(currentProjectile);
shotsRemaining--;
shotsText.setText('Shots: ' + shotsRemaining);
} else {
currentProjectile.destroy();
}
currentProjectile = null;
isAiming = false;
hideTrajectoryDisplay();
}
};
game.update = function () {
// Update score display
scoreText.setText('Score: ' + LK.getScore());
// Update projectiles
for (var i = projectiles.length - 1; i >= 0; i--) {
var projectile = projectiles[i];
if (projectile.destroyed) {
projectile.destroy();
projectiles.splice(i, 1);
continue;
}
if (projectile.launched) {
checkProjectileCollisions(projectile);
}
}
// Remove destroyed blocks
for (var i = targetBlocks.length - 1; i >= 0; i--) {
if (targetBlocks[i].destroyed) {
targetBlocks[i].destroy();
targetBlocks.splice(i, 1);
}
}
// Check level completion
checkLevelComplete();
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,333 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Projectile = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('projectile', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocityX = 0;
+ self.velocityY = 0;
+ self.gravity = 0.5;
+ self.launched = false;
+ self.destroyed = false;
+ self.launch = function (vx, vy) {
+ self.velocityX = vx;
+ self.velocityY = vy;
+ self.launched = true;
+ LK.getSound('launch').play();
+ };
+ self.update = function () {
+ if (self.launched && !self.destroyed) {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityY += self.gravity;
+ // Check ground collision
+ if (self.y >= groundY - 30) {
+ self.y = groundY - 30;
+ self.velocityY = -self.velocityY * 0.3;
+ self.velocityX *= 0.8;
+ if (Math.abs(self.velocityY) < 2) {
+ self.launched = false;
+ }
+ }
+ // Check screen bounds
+ if (self.x > 2200 || self.x < -100 || self.y > 2800) {
+ self.destroyed = true;
+ }
+ }
+ };
+ return self;
+});
+var TargetBlock = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('targetBlock', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.health = 1;
+ self.destroyed = false;
+ self.takeDamage = function () {
+ self.health--;
+ if (self.health <= 0) {
+ self.destroyed = true;
+ LK.getSound('destroy').play();
+ LK.setScore(LK.getScore() + 100);
+ LK.effects.flashObject(self, 0xFFFFFF, 200);
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var slingshot;
+var slingshotBase;
+var currentProjectile = null;
+var isAiming = false;
+var aimStartX = 0;
+var aimStartY = 0;
+var trajectoryDots = [];
+var targetBlocks = [];
+var projectiles = [];
+var shotsRemaining = 5;
+var level = 1;
+var groundY = 2600;
+// UI elements
+var shotsText = new Text2('Shots: 5', {
+ size: 80,
+ fill: 0x000000
+});
+shotsText.anchor.set(0, 0);
+LK.gui.topRight.addChild(shotsText);
+shotsText.x = -300;
+shotsText.y = 100;
+var scoreText = new Text2('Score: 0', {
+ size: 80,
+ fill: 0x000000
+});
+scoreText.anchor.set(0, 0);
+LK.gui.top.addChild(scoreText);
+scoreText.y = 100;
+// Create ground
+var ground = game.addChild(LK.getAsset('ground', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}));
+ground.x = 1024;
+ground.y = groundY;
+// Create slingshot
+slingshotBase = game.addChild(LK.getAsset('slingshotBase', {
+ anchorX: 0.5,
+ anchorY: 1
+}));
+slingshotBase.x = 200;
+slingshotBase.y = groundY;
+slingshot = game.addChild(LK.getAsset('slingshot', {
+ anchorX: 0.5,
+ anchorY: 1
+}));
+slingshot.x = 200;
+slingshot.y = groundY;
+// Create trajectory dots
+for (var i = 0; i < 15; i++) {
+ var dot = game.addChild(LK.getAsset('trajectoryDot', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ dot.visible = false;
+ trajectoryDots.push(dot);
+}
+// Create target structures
+function createLevel() {
+ // Clear existing targets
+ for (var i = targetBlocks.length - 1; i >= 0; i--) {
+ if (targetBlocks[i].destroyed) {
+ targetBlocks[i].destroy();
+ targetBlocks.splice(i, 1);
+ }
+ }
+ targetBlocks = [];
+ // Create target blocks in tower formation
+ var startX = 1400;
+ var startY = groundY - 50;
+ // Bottom row
+ for (var i = 0; i < 4; i++) {
+ var block = game.addChild(new TargetBlock());
+ block.x = startX + i * 110;
+ block.y = startY;
+ targetBlocks.push(block);
+ }
+ // Middle row
+ for (var i = 0; i < 3; i++) {
+ var block = game.addChild(new TargetBlock());
+ block.x = startX + 55 + i * 110;
+ block.y = startY - 110;
+ targetBlocks.push(block);
+ }
+ // Top row
+ for (var i = 0; i < 2; i++) {
+ var block = game.addChild(new TargetBlock());
+ block.x = startX + 110 + i * 110;
+ block.y = startY - 220;
+ targetBlocks.push(block);
+ }
+ // Top block
+ var block = game.addChild(new TargetBlock());
+ block.x = startX + 165;
+ block.y = startY - 330;
+ targetBlocks.push(block);
+}
+// Initialize first level
+createLevel();
+// Helper functions
+function calculateTrajectory(startX, startY, velocityX, velocityY) {
+ var points = [];
+ var x = startX;
+ var y = startY;
+ var vx = velocityX;
+ var vy = velocityY;
+ for (var i = 0; i < 15; i++) {
+ points.push({
+ x: x,
+ y: y
+ });
+ x += vx * 2;
+ y += vy * 2;
+ vy += 0.5 * 2;
+ if (y >= groundY - 30) break;
+ }
+ return points;
+}
+function updateTrajectoryDisplay(points) {
+ for (var i = 0; i < trajectoryDots.length; i++) {
+ if (i < points.length) {
+ trajectoryDots[i].x = points[i].x;
+ trajectoryDots[i].y = points[i].y;
+ trajectoryDots[i].visible = true;
+ } else {
+ trajectoryDots[i].visible = false;
+ }
+ }
+}
+function hideTrajectoryDisplay() {
+ for (var i = 0; i < trajectoryDots.length; i++) {
+ trajectoryDots[i].visible = false;
+ }
+}
+function checkProjectileCollisions(projectile) {
+ for (var i = 0; i < targetBlocks.length; i++) {
+ var block = targetBlocks[i];
+ if (!block.destroyed && projectile.intersects(block)) {
+ block.takeDamage();
+ LK.getSound('impact').play();
+ projectile.velocityX *= -0.3;
+ projectile.velocityY *= -0.3;
+ return true;
+ }
+ }
+ return false;
+}
+function checkLevelComplete() {
+ var remainingBlocks = 0;
+ for (var i = 0; i < targetBlocks.length; i++) {
+ if (!targetBlocks[i].destroyed) {
+ remainingBlocks++;
+ }
+ }
+ if (remainingBlocks === 0) {
+ // Level complete
+ level++;
+ shotsRemaining = 5;
+ LK.setTimeout(function () {
+ createLevel();
+ }, 1000);
+ return true;
+ }
+ if (shotsRemaining <= 0 && projectiles.length === 0) {
+ // Game over
+ LK.showGameOver();
+ return true;
+ }
+ return false;
+}
+// Event handlers
+game.down = function (x, y, obj) {
+ if (!currentProjectile && shotsRemaining > 0) {
+ var distance = Math.sqrt((x - slingshot.x) * (x - slingshot.x) + (y - slingshot.y) * (y - slingshot.y));
+ if (distance < 150) {
+ isAiming = true;
+ aimStartX = x;
+ aimStartY = y;
+ currentProjectile = game.addChild(new Projectile());
+ currentProjectile.x = slingshot.x;
+ currentProjectile.y = slingshot.y - 100;
+ }
+ }
+};
+game.move = function (x, y, obj) {
+ if (isAiming && currentProjectile) {
+ var deltaX = aimStartX - x;
+ var deltaY = aimStartY - y;
+ // Limit drag distance
+ var maxDistance = 150;
+ var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ if (distance > maxDistance) {
+ deltaX = deltaX / distance * maxDistance;
+ deltaY = deltaY / distance * maxDistance;
+ }
+ currentProjectile.x = slingshot.x - deltaX * 0.5;
+ currentProjectile.y = slingshot.y - 100 - deltaY * 0.5;
+ // Calculate and show trajectory
+ var velocityX = deltaX * 0.3;
+ var velocityY = deltaY * 0.3;
+ var trajectoryPoints = calculateTrajectory(currentProjectile.x, currentProjectile.y, velocityX, velocityY);
+ updateTrajectoryDisplay(trajectoryPoints);
+ }
+};
+game.up = function (x, y, obj) {
+ if (isAiming && currentProjectile) {
+ var deltaX = aimStartX - x;
+ var deltaY = aimStartY - y;
+ // Limit drag distance
+ var maxDistance = 150;
+ var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ if (distance > maxDistance) {
+ deltaX = deltaX / distance * maxDistance;
+ deltaY = deltaY / distance * maxDistance;
+ }
+ if (distance > 20) {
+ var velocityX = deltaX * 0.3;
+ var velocityY = deltaY * 0.3;
+ currentProjectile.launch(velocityX, velocityY);
+ projectiles.push(currentProjectile);
+ shotsRemaining--;
+ shotsText.setText('Shots: ' + shotsRemaining);
+ } else {
+ currentProjectile.destroy();
+ }
+ currentProjectile = null;
+ isAiming = false;
+ hideTrajectoryDisplay();
+ }
+};
+game.update = function () {
+ // Update score display
+ scoreText.setText('Score: ' + LK.getScore());
+ // Update projectiles
+ for (var i = projectiles.length - 1; i >= 0; i--) {
+ var projectile = projectiles[i];
+ if (projectile.destroyed) {
+ projectile.destroy();
+ projectiles.splice(i, 1);
+ continue;
+ }
+ if (projectile.launched) {
+ checkProjectileCollisions(projectile);
+ }
+ }
+ // Remove destroyed blocks
+ for (var i = targetBlocks.length - 1; i >= 0; i--) {
+ if (targetBlocks[i].destroyed) {
+ targetBlocks[i].destroy();
+ targetBlocks.splice(i, 1);
+ }
+ }
+ // Check level completion
+ checkLevelComplete();
+};
\ No newline at end of file